use of com.zimbra.cs.mailclient.imap.ImapRequest 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.ImapRequest 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");
}
use of com.zimbra.cs.mailclient.imap.ImapRequest in project zm-mailbox by Zimbra.
the class RemoteFolder method copyMessage.
public CopyResult copyMessage(long uid, String mbox) throws IOException {
assert isSelected();
String seq = String.valueOf(uid);
ImapRequest req = connection.newUidRequest(CAtom.COPY, seq, new MailboxName(mbox));
ResponseText rt = req.sendCheckStatus().getResponseText();
if (rt.getCCode() == CAtom.COPYUID) {
CopyResult cr = (CopyResult) rt.getData();
// Bug 36373: If COPYUID result 0 then assume that message no longer exists.
if (cr != null && cr.getToUids()[0] != 0) {
return cr;
}
}
// Message not found
return null;
}
use of com.zimbra.cs.mailclient.imap.ImapRequest in project zm-mailbox by Zimbra.
the class SharedImapTests method testOverflowNotAppend.
@Test(timeout = 100000)
public void testOverflowNotAppend() throws Exception {
connection = connectAndSelectInbox();
int oldReadTimeout = connection.getConfig().getReadTimeout();
try {
connection.setReadTimeout(10);
ImapRequest req = connection.newRequest(CAtom.FETCH, "1:*");
req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "+}");
ImapResponse resp = req.send();
assertTrue("response should be NO or BAD", resp.isNO() || resp.isBAD());
} finally {
connection.setReadTimeout(oldReadTimeout);
}
}
use of com.zimbra.cs.mailclient.imap.ImapRequest in project zm-mailbox by Zimbra.
the class SharedImapTests method testAppendTagsDirty.
@Test(timeout = 100000)
public void testAppendTagsDirty() throws Exception {
connection = connectAndSelectInbox();
Flags flags = Flags.fromSpec("afs");
// new tag; does not exist in mbox
final String tag1 = "NEWDIRTYTAG";
MailboxInfo info = connection.select("INBOX");
assertFalse("INBOX contains unexpected flag " + tag1, info.getFlags().isSet(tag1));
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
ImapRequest req = connection.newRequest("APPEND", "INBOX", flags, date, msg);
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(tag1));
}
}
});
req.sendCheckStatus();
} finally {
msg.dispose();
}
}
Aggregations