@Override
    public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
        if(directory.isRoot()) {
            return new DeepBoxesListService().list(directory, listener);
        }
        if(containerService.isDeepbox(directory)) { // in DeepBox
            return new BoxesListService().list(directory, listener);
        }
        if(containerService.isBox(directory)) { // in Box
            return new BoxListService().list(directory, listener);
        }
        final String deepBoxNodeId = fileid.getDeepBoxNodeId(directory);
        final String boxNodeId = fileid.getBoxNodeId(directory);
        if(containerService.isThirdLevel(directory)) { // in Inbox/Documents/Trash
            // N.B. although Documents and Trash have a nodeId, calling the listFiles1/listTrash1 API with
            // parentNode may fail!
            if(containerService.isInInbox(directory)) {
                return new NodeListService(new Contents() {
                    @Override
                    public NodeContent getNodes(final int offset) throws ApiException {
                        return new BoxRestControllerApi(session.getClient()).listQueue(deepBoxNodeId,
                                boxNodeId,
                                null,
                                offset, chunksize, "displayName asc");
                    }
                }).list(directory, listener);
            }
            if(containerService.isInDocuments(directory)) {
                return new NodeListService(new Contents() {
                    @Override
                    public NodeContent getNodes(final int offset) throws ApiException {
                        return new BoxRestControllerApi(session.getClient()).listFiles(
                                deepBoxNodeId,
                                boxNodeId,
                                offset, chunksize, "displayName asc");
                    }
                }).list(directory, listener);
            }
            if(containerService.isInTrash(directory)) {
                return new NodeListService(new Contents() {
                    @Override
                    public NodeContent getNodes(final int offset) throws ApiException {
                        return new BoxRestControllerApi(session.getClient()).listTrash(
                                deepBoxNodeId,
                                boxNodeId,
                                offset, chunksize, "displayName asc");
                    }
                }).list(directory, listener);
            }
        }
        // in subfolder of  Documents/Trash (Inbox has no subfolders)
        final String nodeId = fileid.getFileId(directory);
        if(containerService.isInTrash(directory)) {
            return new NodeListService(new Contents() {
                @Override
                public NodeContent getNodes(final int offset) throws ApiException {
                    return new BoxRestControllerApi(session.getClient()).listTrash1(
                            deepBoxNodeId,
                            boxNodeId,
                            nodeId,
                            offset, chunksize, "displayName asc");
                }
            }).list(directory, listener);
        }
        return new NodeListService(new Contents() {
            @Override
            public NodeContent getNodes(final int offset) throws ApiException {
                return new BoxRestControllerApi(session.getClient()).listFiles1(
                        deepBoxNodeId,
                        boxNodeId,
                        nodeId,
                        offset, chunksize, "displayName asc");
            }
        }).list(directory, listener);
    }
@Test
    public void testListInbox() throws Exception {
        final DeepboxIdProvider nodeid = new DeepboxIdProvider(session);
        final Path queue = new Path("/ORG 4 - DeepBox Desktop App/ORG3:Box1/Inbox", EnumSet.of(Path.Type.directory));
        final AttributedList<Path> list = new DeepboxListService(session, nodeid).list(queue, new DisabledListProgressListener());
        assertNotEquals(AttributedList.emptyList(), list);
        assertFalse(list.isEmpty());
        for(final Path f : list) {
            assertSame(queue, f.getParent());
            assertFalse(f.getName().contains(String.valueOf(Path.DELIMITER)));
            assertTrue(f.attributes().getModificationDate() > 0);
            assertTrue(f.attributes().getCreationDate() > 0);
            assertNotNull(nodeid.getFileId(new Path(f).withAttributes(new PathAttributes())));
            assertEquals(f.attributes(), new DeepboxAttributesFinderFeature(session, nodeid).find(new Path(f.getAbsolute(), f.getType())));
        }
    }