use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class RemoteFolder method getFlags.
/*
* Fetch message flags for specific UID sequence. Exclude messages which
* have been flagged \Deleted.
*/
public List<MessageData> getFlags(long startUid, long endUid) throws IOException {
final List<MessageData> mds = new ArrayList<MessageData>();
String end = endUid > 0 ? String.valueOf(endUid) : "*";
connection.uidFetch(startUid + ":" + end, "FLAGS", new FetchResponseHandler() {
public void handleFetchResponse(MessageData md) {
Flags flags = md.getFlags();
if (flags != null && !flags.isDeleted()) {
mds.add(md);
}
}
});
// result.
if (endUid <= 0 && mds.size() == 1 && mds.get(0).getUid() < startUid) {
return Collections.emptyList();
}
return mds;
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class ImapTestBase method doAppend.
protected AppendResult doAppend(ImapConnection conn, String folderName, String subject, String body, Flags flags, boolean fetchResult) {
checkConnection(conn);
assertTrue("expecting UIDPLUS capability", conn.hasCapability("UIDPLUS"));
String msg = simpleMessage(subject, body);
Date date = new Date(System.currentTimeMillis());
AppendMessage am = new AppendMessage(flags, date, literal(msg));
try {
AppendResult res = conn.append(folderName, am);
assertNotNull("result of append command should not be null", res);
if (fetchResult) {
doSelectShouldSucceed(conn, folderName);
MessageData md = fetchMessage(conn, res.getUid());
byte[] b = getBody(md);
assertArrayEquals("FETCH content not same as APPENDed content", msg.getBytes(), b);
}
return res;
} catch (IOException e) {
ZimbraLog.test.info("Exception thrown trying to append", e);
fail("Exception thrown trying to append:" + e.getMessage());
}
return null;
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class SharedImapTests method doCopy.
private void doCopy(ImapConnection imapConn, ZMailbox shareeZmbox, String fromFolderName, String toFolderName, String srcMsgSubject) throws IOException, ServiceException, MessagingException {
imapConn.list("", "*");
imapConn.create(toFolderName);
// This loop is to create some distance between the IDs in the from and to mailboxes
for (int cnt = 1; cnt < 10; cnt++) {
TestUtil.addMessage(shareeZmbox, String.format("inbox msg %s", cnt));
}
doSelectShouldSucceed(imapConn, fromFolderName);
CopyResult copyResult = imapConn.copy("1", toFolderName);
assertNotNull("copyResult.getFromUids()", copyResult.getFromUids());
assertNotNull("copyResult.getToUids()", copyResult.getToUids());
assertEquals("Number of fromUIDs", 1, copyResult.getFromUids().length);
assertEquals("Number of toUIDs", 1, copyResult.getToUids().length);
MailboxInfo selectMboxInfo = imapConn.select(toFolderName);
assertNotNull(String.format("Select result for folder=%s", toFolderName), selectMboxInfo);
assertEquals("Select result Folder Name folder", toFolderName, selectMboxInfo.getName());
assertEquals(String.format("Number of exists for folder=%s after copy", toFolderName), 1, selectMboxInfo.getExists());
Map<Long, MessageData> mdMap = this.doFetchShouldSucceed(imapConn, "1:*", "(ENVELOPE)", Lists.newArrayList(srcMsgSubject));
MessageData md = mdMap.values().iterator().next();
assertNull("Internal date was NOT requested and should be NULL", md.getInternalDate());
BodyStructure bs = md.getBodyStructure();
assertNull("Body Structure was not requested and should be NULL", bs);
Body[] body = md.getBodySections();
assertNull("body sections were not requested and should be null", body);
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class SharedImapTests method testAppendFlags.
@Test(timeout = 100000)
public void testAppendFlags() throws Exception {
connection = connectAndSelectInbox();
assertTrue("expecting UIDPLUS capability", connection.hasCapability("UIDPLUS"));
Flags flags = Flags.fromSpec("afs");
Date date = new Date(System.currentTimeMillis());
Literal msg = message(100000);
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
assertNotNull("result of append command should not be null", res);
MessageData md = fetchMessage(connection, res.getUid());
Flags msgFlags = md.getFlags();
assertTrue("expecting isAnswered flag", msgFlags.isAnswered());
assertTrue("expecting isFlagged flag", msgFlags.isFlagged());
assertTrue("expecting isSeen flag", msgFlags.isSeen());
byte[] b = getBody(md);
assertArrayEquals("content mismatch", msg.getBytes(), b);
} finally {
msg.dispose();
}
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class SharedImapTests method testStoreInvalidSystemFlag.
@Test(timeout = 100000)
public void testStoreInvalidSystemFlag() throws Exception {
connection = connectAndSelectInbox();
ZMailbox mbox = TestUtil.getZMailbox(USER);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo"), true);
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);
}
Aggregations