use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class TestImap method testAppendTags.
@Test
public void testAppendTags() throws Exception {
Flags flags = Flags.fromSpec("afs");
//new tag; does not exist in mbox
String tag1 = "APPENDTAG1";
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag1));
} finally {
msg.dispose();
}
//should not have created a visible tag
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);
//now create a visible tag, add it to a message in inbox then try append to message in different folder
String tag2 = "APPENDTAG2";
ZTag tag = mbox.getTag(tag2);
if (tag == null) {
tag = mbox.createTag(tag2, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals(tag2, tags.get(0).getName());
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tag2, info.getFlags().isSet(tag2));
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
info = connection.select(folderName);
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));
msg = message(10);
flags = Flags.fromSpec("afs");
flags.set(tag2);
try {
AppendResult res = connection.append(folderName, flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag2));
} finally {
msg.dispose();
}
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class TestImap method testStoreTagsDirty.
@Test
public void testStoreTagsDirty() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
final String tagName2 = "T2";
ZTag tag = mbox.getTag(tagName);
if (tag == null) {
tag = mbox.createTag(tagName, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(1, data.size());
Iterator<Long> it = data.keySet().iterator();
Long seq = it.next();
assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
req.setResponseHandler(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
Flags flags = (Flags) res.getData();
assertTrue(flags.isSet(tagName2));
}
}
});
req.sendCheckStatus();
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class ImapFolderSync method refetchPurgedMsgsInConversation.
protected void refetchPurgedMsgsInConversation(ParsedMessage pm) throws ServiceException, IOException {
if (!mailbox.getAccount().isFeatureDataSourcePurgingEnabled()) {
return;
}
Threader threader = pm.getThreader(ds.getMailbox());
List<PurgedConversation> purgedConvs = threader.lookupPurgedConversations(ds);
if (purgedConvs.size() == 0) {
return;
} else {
for (PurgedConversation conv : purgedConvs) {
ImapConnection conn;
try {
conn = getRefetchConnection();
} catch (ServiceException e) {
ZimbraLog.datasource.warn("could not establish IMAP connection to refetch purged messages");
return;
}
for (PurgedMessage msg : conv.getMessages()) {
String remoteFolderId = msg.getRemoteFolder();
String msgUid = msg.getUid();
final Integer folderId = msg.getLocalFolderId();
ZimbraLog.datasource.info("restoring message " + msgUid + " in remote folder " + remoteFolderId);
conn.select(remoteFolderId);
final Map<Long, MessageData> msgFlags = conn.uidFetch(msgUid, "(FLAGS INTERNALDATE)");
FetchResponseHandler handler = new FetchResponseHandler() {
@Override
public void handleFetchResponse(MessageData md) throws Exception {
long uid = md.getUid();
IOExceptionHandler.getInstance().trackSyncItem(mailbox, uid);
try {
handleFetch(md, msgFlags, folderId, false, false);
clearError(uid);
} catch (OutOfMemoryError e) {
Zimbra.halt("Out of memory", e);
} catch (Exception e) {
if (!IOExceptionHandler.getInstance().isRecoverable(mailbox, uid, "Exception re-fetching UID " + uid, e)) {
syncFailed("re-fetch failed for uid " + uid, e);
SyncErrorManager.incrementErrorCount(ds, remoteId(uid));
}
}
}
};
conn.uidFetch(msgUid, "BODY.PEEK[]", handler);
}
conv.unpurge();
}
}
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class ImapFolderSync method removeDeleted.
// Discard messages that have been flagged \Deleted
private void removeDeleted(Map<Long, MessageData> mds) {
Iterator<MessageData> it = mds.values().iterator();
while (it.hasNext()) {
MessageData md = it.next();
Flags flags = md.getFlags();
if (flags != null && flags.isDeleted()) {
remoteFolder.debug("Remote message with uid %d is flagged \\Deleted", md.getUid());
it.remove();
}
}
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class ImapFolderSync method fetchFlags.
private void fetchFlags(String seq) throws ServiceException, IOException {
Map<Long, MessageData> mds = connection.uidFetch(seq, "FLAGS");
// Remove messages that have been flagged \Deleted
removeDeleted(mds);
for (MessageData md : mds.values()) {
long uid = md.getUid();
ImapMessage trackedMsg = trackedMsgs.getByUid(uid);
if (trackedMsg != null) {
int msgId = trackedMsg.getItemId();
if (localMsgIds.contains(msgId)) {
localMsgIds.remove(msgId);
try {
updateFlags(trackedMsg, md.getFlags());
clearError(msgId);
} catch (MailServiceException.NoSuchItemException e) {
// Message was deleted locally
addDeletedUid(uid);
clearError(msgId);
} catch (Exception e) {
syncMessageFailed(msgId, "Unable to update message flags", e);
}
} else {
addDeletedUid(uid);
clearError(msgId);
}
} else {
remoteFolder.debug("Adding new message with UID %d detected while syncing flags", uid);
addedUids.add(uid);
}
}
}
Aggregations