DbMailItem.search(conn, mbox.getId(), new Tag[] {mbox.mAttachFlag}, null, null, null, MailItem.TYPE_MESSAGE, (byte) (DbMailItem.SORT_BY_DATE | DbMailItem.SORT_DESCENDING));
{ DbSearchConstraints c = new DbSearchConstraints(); c.mailboxId = mbox.getId(); c.tags      = new ArrayList<Tag>(); c.tags.add(mbox.mAttachFlag); c.excludeTags = null; c.folders   = null; c.excludeFolders = null; c.types     = new ArrayList<Byte>(); c.types.add(MailItem.TYPE_MESSAGE); c.sort      = (byte) (DbMailItem.SORT_BY_DATE | DbMailItem.SORT_DESCENDING); DbMailItem.search(conn, c); }
    public static void main(String[] args) throws MessagingException, IOException, ParseException, ServiceException {    	Account acct = Provisioning.getInstance().getAccountByName("user1");        Mailbox mbox = Mailbox.getMailboxByAccount(acct);        System.out.println(mbox);        if (mbox != null) {            Connection conn = DbPool.getConnection();	        DbMailItem.search(conn, mbox.getId(), new Tag[] {mbox.mAttachFlag}, null, 	                null, null, MailItem.TYPE_MESSAGE, (byte) (DbMailItem.SORT_BY_DATE | DbMailItem.SORT_DESCENDING));//	        DbMailItem.listByFolder(mbox.getFolderById(Mailbox.ID_FOLDER_TRASH), MailItem.TYPE_MESSAGE);            Collection result = DbMailItem.search(conn, mbox.getId(), new Tag[] {mbox.mUnreadFlag}, null, new Folder[] {mbox.getFolderById(null, Mailbox.ID_FOLDER_INBOX)},	                null, MailItem.TYPE_MESSAGE, (byte) (DbMailItem.SORT_BY_SUBJECT | DbMailItem.SORT_DESCENDING));            for (Iterator it = result.iterator(); it.hasNext(); )                System.out.println(it.next());	        conn.close();        }        (new DbTest()).mainLoop();    }