use of com.zimbra.cs.datasource.MessageContent in project zm-mailbox by Zimbra.
the class ImapFolderSync method handleFetch.
private void handleFetch(MessageData md, Map<Long, MessageData> flagsByUid, int folderId, boolean storeSync, boolean restorePurged) throws ServiceException, IOException {
long uid = md.getUid();
if (uid == -1) {
throw new MailException("Missing UID in FETCH response");
}
MessageData flagsData = flagsByUid.get(uid);
remoteFolder.debug("Found new IMAP message with uid %d", uid);
// Parse the message data
Date date = flagsData.getInternalDate();
Long receivedDate = date != null ? date.getTime() : null;
int zflags = SyncUtil.imapToZimbraFlags(flagsData.getFlags());
MessageContent mc = getContent(md);
Message msg;
try {
ParsedMessage pm = mc.getParsedMessage(receivedDate, mailbox.attachmentsIndexingEnabled());
if (pm == null) {
remoteFolder.warn("Empty message body for UID %d. Must be ignored.", uid);
return;
}
pm.setDataSourceId(ds.getId());
if (restorePurged) {
try {
refetchPurgedMsgsInConversation(pm);
} catch (ServiceException e) {
// refetching error should not halt import
ZimbraLog.datasource.error("error refetching purged message", e);
}
}
msg = imapSync.addMessage(null, pm, mc.getSize(), folderId, zflags, mc.getDeliveryContext());
} finally {
mc.cleanup();
}
if (msg != null && msg.getFolderId() == folderId) {
storeImapMessage(uid, msg.getId(), zflags, storeSync);
stats.msgsAddedLocally++;
} else {
// Message was filtered and discarded or moved to another folder.
// This can only happen for messages fetched from INBOX which is
// always imported first. Mark remote message for deletion and
// do not create a local tracker. If message was moved to another
// folder we will append it to the remote folder when we sync
// that folder.
addDeletedUid(uid);
}
}
Aggregations