use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.
the class TestImap method testCatenateSimple.
@Test
public void testCatenateSimple() throws Exception {
assertTrue(connection.hasCapability("CATENATE"));
assertTrue(connection.hasCapability("UIDPLUS"));
String part1 = simpleMessage("test message");
String part2 = "more text\r\n";
AppendMessage am = new AppendMessage(null, null, literal(part1), literal(part2));
AppendResult res = connection.append("INBOX", am);
connection.select("INBOX");
byte[] body = fetchBody(res.getUid());
assertArrayEquals("content mismatch", bytes(part1 + part2), body);
}
use of com.zimbra.cs.mailclient.imap.AppendResult 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.AppendResult 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.AppendResult in project zm-mailbox by Zimbra.
the class TestImap method testMultiappend.
@Test
public void testMultiappend() throws Exception {
assertTrue(connection.hasCapability("MULTIAPPEND"));
assertTrue(connection.hasCapability("UIDPLUS"));
AppendMessage msg1 = new AppendMessage(null, null, literal("test 1"));
AppendMessage msg2 = new AppendMessage(null, null, literal("test 2"));
AppendResult res = connection.append("INBOX", msg1, msg2);
assertNotNull(res);
assertEquals("expecting 2 uids", 2, res.getUids().length);
}
use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.
the class ImapAppender method append.
private long append(MessageInfo mi, Literal data) throws IOException {
ImapRequest req = connection.newRequest(CAtom.APPEND, new MailboxName(mailbox));
if (mi.flags != null) {
req.addParam(mi.flags);
}
if (mi.date != null) {
req.addParam(mi.date);
}
req.addParam(data);
ResponseText rt = req.sendCheckStatus().getResponseText();
if (rt != null && rt.getCCode() == CAtom.APPENDUID) {
AppendResult ar = (AppendResult) rt.getData();
if (ar.getUid() > 0) {
return ar.getUid();
}
}
throw req.failed("APPENDUID supported but UID missing from result");
}
Aggregations