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 fetchBody.
private byte[] fetchBody(long uid) throws IOException {
MessageData md = connection.uidFetch(uid, "(BODY.PEEK[])");
assertNotNull("message not found", md);
assertEquals(uid, md.getUid());
Body[] bs = md.getBodySections();
assertNotNull(bs);
assertEquals(1, bs.length);
return bs[0].getImapData().getBytes();
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class TestImap method testStoreInvalidSystemFlag.
@Test
public void testStoreInvalidSystemFlag() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo"), true);
MailboxInfo info = connection.select("INBOX");
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(1, data.size());
Iterator<Long> it = data.keySet().iterator();
Long seq = it.next();
storeInvalidFlag("\\Bulk", seq);
storeInvalidFlag("\\Unread", seq);
storeInvalidFlag("\\Forwarded", seq);
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class TestImapClient method testFetch.
@Test
public void testFetch() throws Exception {
connect();
login();
MailboxInfo mb = connection.select("INBOX");
final AtomicLong count = new AtomicLong(mb.getExists());
connection.uidFetch("1:*", "(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY BODY.PEEK[])", new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.getCCode() != CAtom.FETCH)
return;
MessageData md = (MessageData) res.getData();
assertNotNull(md);
Envelope env = md.getEnvelope();
assertNotNull(env);
assertNotNull(env.getSubject());
assertNotNull(md.getUid());
assertTrue(md.getRfc822Size() != -1);
assertNotNull(md.getInternalDate());
BodyStructure bs = md.getBodyStructure();
assertNotNull(bs);
if (bs.isMultipart()) {
BodyStructure[] parts = bs.getParts();
for (BodyStructure part : parts) {
assertNotNull(part.getType());
assertNotNull(part.getSubtype());
}
} else {
assertNotNull(bs.getType());
assertNotNull(bs.getSubtype());
}
Body[] body = md.getBodySections();
assertNotNull(body);
assertEquals(1, body.length);
// assertNotNull(body[0].getBytes());
count.decrementAndGet();
System.out.printf("Fetched uid = %s\n", md.getUid());
}
});
assertEquals(0, count.longValue());
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class TestImap method testStoreTags.
@Test
public void testStoreTags() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
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);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo2"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(2, 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));
seq = it.next();
assertFalse("flag unexpectedly set on second message", data.get(seq).getFlags().isSet(tagName));
connection.store(seq + "", "+FLAGS", tagName);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE in INBOX", data.get(seq).getFlags().isSet(tagName));
mbox.addMessage(folder.getId(), "u", "", System.currentTimeMillis(), simpleMessage("bar"), true);
info = connection.select(folderName);
assertFalse(folderName + " contains unexpected flag " + tagName, info.getFlags().isSet(tagName));
data = connection.fetch("*", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertFalse("flag unexpectedly set on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
connection.store(seq + "", "+FLAGS", tagName);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
info = connection.select(folderName);
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
String tagName2 = "T2";
connection.store(seq + "", "+FLAGS", tagName2);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
info = connection.select(folderName);
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName2));
//should not have created T2 as a visible tag
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String tagName3 = "T3";
connection.store(seq + "", "FLAGS", tagName3);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName3));
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName3));
assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName));
assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
//should not have created T2 or T3 as a visible tag
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
connection.store(seq + "", "-FLAGS", tagName3);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flags unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isEmpty());
info = connection.select("INBOX");
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
}
Aggregations