use of com.zimbra.cs.mailclient.imap.Flags 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.Flags in project zm-mailbox by Zimbra.
the class TestImap method appendInvalidFlag.
private void appendInvalidFlag(String flag) throws IOException {
Literal msg = message(10);
Flags flags = Flags.fromSpec("afs");
flags.set(flag);
Date date = new Date(System.currentTimeMillis());
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
fail("server allowed client to set system flag " + flag);
} catch (CommandFailedException e) {
//expected
} finally {
msg.dispose();
}
//do a no-op so we don't hit max consecutive error limit
connection.noop();
}
use of com.zimbra.cs.mailclient.imap.Flags 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.Flags in project zm-mailbox by Zimbra.
the class ImapFolderSync method updateFlags.
// Updates flags for specified message.
private void updateFlags(ImapMessage msg, Flags flags) throws ServiceException, IOException {
int id = msg.getItemId();
int localFlags = msg.getItemFlags();
int trackedFlags = msg.getFlags();
int remoteFlags = SyncUtil.imapToZimbraFlags(flags);
int newLocalFlags = mergeFlags(localFlags, trackedFlags, remoteFlags);
int newRemoteFlags = SyncUtil.imapFlagsOnly(newLocalFlags);
if (LOG.isDebugEnabled() && (newLocalFlags != localFlags || newRemoteFlags != remoteFlags || newRemoteFlags != trackedFlags)) {
localFolder.debug("Updating flags for message with item id %d: " + "local=%s, tracked=%s, remote=%s, new_local=%s, new_remote=%s", id, Flag.toString(localFlags), Flag.toString(trackedFlags), Flag.toString(remoteFlags), Flag.toString(newLocalFlags), Flag.toString(newRemoteFlags));
}
if (newLocalFlags != localFlags) {
localFolder.setMessageFlags(id, newLocalFlags);
stats.flagsUpdatedLocally++;
}
if (newRemoteFlags != remoteFlags) {
String uids = String.valueOf(msg.getUid());
Flags toAdd = SyncUtil.getFlagsToAdd(flags, newRemoteFlags);
Flags toRemove = SyncUtil.getFlagsToRemove(flags, newRemoteFlags);
// UID STORE never fails even if message was deleted
if (!toAdd.isEmpty()) {
connection.uidStore(uids, "+FLAGS.SILENT", toAdd);
}
if (!toRemove.isEmpty()) {
connection.uidStore(uids, "-FLAGS.SILENT", toRemove);
}
stats.flagsUpdatedRemotely++;
}
if (newRemoteFlags != trackedFlags) {
msg.setFlags(newRemoteFlags);
msg.update();
stats.flagsUpdatedLocally++;
}
}
use of com.zimbra.cs.mailclient.imap.Flags 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();
}
}
}
Aggregations