use of com.zimbra.cs.mailclient.imap.MessageData 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());
}
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());
}
Aggregations