use of com.zimbra.cs.mailclient.imap.BodyStructure 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.BodyStructure 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.BodyStructure in project zm-mailbox by Zimbra.
the class TestRemoteImapMultiServer method testListFolderContents.
@Test
public void testListFolderContents() throws IOException, ServiceException, MessagingException {
String folderName = "TestRemoteImap-testOpenFolder";
String subject = "TestRemoteImap-testMessage";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
String msgId = TestUtil.addMessage(zmbox, subject, folder.getId(), null);
ZMessage msg = zmbox.getMessageById(msgId);
connection = connect(imapServer);
connection.login(PASS);
MailboxInfo info = connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE INTERNALDATE BODY BODY[TEXT])");
assertEquals(1, mdMap.size());
MessageData md = mdMap.values().iterator().next();
assertNotNull(md);
Envelope env = md.getEnvelope();
assertNotNull(env);
assertEquals(msg.getSubject(), env.getSubject());
assertEquals(msg.getDate(), md.getInternalDate().getTime());
BodyStructure bs = md.getBodyStructure();
assertNotNull(bs);
assertEquals("TEXT", bs.getType());
assertEquals("PLAIN", bs.getSubtype());
assertNotNull(md.getBodySections());
assertEquals(1, md.getBodySections().length);
Body body = md.getBodySections()[0];
assertNotNull(body);
Literal imapData = (Literal) body.getData();
assertEquals(MessageBuilder.DEFAULT_MESSAGE_BODY, imapData.toString());
}
Aggregations