DbPop3Message.storeUid(mbox, ds, folder.getUID(pop3Msg), zimbraMsg.getId());
DbPop3Message.storeUid(mbox, ds.getId(), folder.getUID(pop3Msg), zimbraMsg.getId());
    private void fetchMessages(Account account, DataSource ds)    throws MessagingException, IOException, ServiceException {        ZimbraLog.mailbox.info("Importing POP3 messages from " + ds);                validateDataSource(ds);                // Connect (USER, PASS, STAT)        Store store = getStore(ds.getConnectionType());        store.connect(ds.getHost(), ds.getPort(), ds.getUsername(), ds.getDecryptedPassword());        POP3Folder folder = (POP3Folder) store.getFolder("INBOX");        folder.open(Folder.READ_WRITE);        Message[] msgs = folder.getMessages();        // Bail out if there are no messages        if (msgs.length == 0) {            folder.close(false);            store.close();            return;        }                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);                // Fetch message UID's for reconciliation (UIDL)        folder.fetch(msgs, UID_PROFILE);                // Check the UID of the first message to make sure the account isn't trying        // to POP itself        String uid = folder.getUID(msgs[0]);        if (poppingSelf(mbox, uid)) {            folder.close(false);            store.close();            throw ServiceException.INVALID_REQUEST(                "User attempted to import messages from his own mailbox", null);        }                sLog.debug("Retrieving " + msgs.length + " messages");        Set<String> uidsToFetch = null;        if (ds.leaveOnServer()) {            uidsToFetch = getUidsToFetch(mbox, ds, folder);        }        // Fetch message bodies (RETR)        for (int i = 0; i < msgs.length; i++) {            POP3Message pop3Msg = (POP3Message) msgs[i];            if (ds.leaveOnServer()) {                // Skip this message if we've already downloaded it                uid = folder.getUID(pop3Msg);                if (!uidsToFetch.contains(uid)) {                    continue;                }            }            // Add message to mailbox            ParsedMessage pm = null;            if (pop3Msg.getSentDate() != null) {                // Set received date to the original message's date                pm = new ParsedMessage(pop3Msg, pop3Msg.getSentDate().getTime(),                    mbox.attachmentsIndexingEnabled());            } else {                pm = new ParsedMessage(pop3Msg, mbox.attachmentsIndexingEnabled());            }            com.zimbra.cs.mailbox.Message zimbraMsg =                mbox.addMessage(null, pm, ds.getFolderId(), false, Flag.BITMASK_UNREAD, null);            if (ds.leaveOnServer()) {                DbPop3Message.storeUid(mbox, ds, folder.getUID(pop3Msg), zimbraMsg.getId());            }        }        if (!ds.leaveOnServer()) {            // Mark all messages for deletion (DELE)            for (Message msg : msgs) {                msg.setFlag(Flags.Flag.DELETED, true);            }        }                if (account.getUid() != null && account.getUid().equals("rossd")) {            hair(mbox, ds);        }        // Expunge if necessary and disconnect (QUIT)        folder.close(!ds.leaveOnServer());        store.close();    }