use of com.zimbra.cs.mailclient.imap.BodyStructure in project zm-mailbox by Zimbra.
the class SharedImapTests method testListFolderContentsEnvelope.
@Test(timeout = 100000)
public void testListFolderContentsEnvelope() throws IOException, ServiceException, MessagingException {
String folderName = "SharedImapTests-testOpenFolder";
String subject = "SharedImapTests-testMessage";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
TestUtil.addMessage(zmbox, subject, folder.getId(), null);
connection = connect();
connection.login(PASS);
connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
assertEquals("Size of map returned by fetch", 1, mdMap.size());
MessageData md = mdMap.values().iterator().next();
assertNotNull("MessageData should not be null", md);
Envelope env = md.getEnvelope();
assertNotNull("Envelope should not be null", env);
assertEquals("Subject from envelope is wrong", subject, env.getSubject());
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 SharedImapTests method testListContactsContents.
@Test(timeout = 100000)
public void testListContactsContents() throws IOException, ServiceException, MessagingException {
// create a contact
ZMailbox zmbox = TestUtil.getZMailbox(USER);
Map<String, String> attrs = new HashMap<String, String>();
String contactName = "testListContactsContents";
attrs.put("fullName", contactName);
zmbox.createContact(Integer.toString(Mailbox.ID_FOLDER_CONTACTS), null, attrs);
// connect to IMAP
String folderName = "Contacts";
connection = connect();
connection.login(PASS);
connection.select(folderName);
// fetch
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY BODY.PEEK[])");
// verify
assertEquals("Size of map returned by fetch", 1, mdMap.size());
MessageData md = mdMap.values().iterator().next();
assertNotNull("MessageData should not be null", md);
Envelope env = md.getEnvelope();
assertNotNull("Envelope should not be null", env);
BodyStructure bs = md.getBodyStructure();
assertNotNull("Body Structure should not be null", bs);
Body[] body = md.getBodySections();
assertNotNull("body sections should not be null", body);
assertEquals("Expecting 1 body section. Found " + body.length, 1, body.length);
assertEquals("Envelope subject is wrong", contactName, env.getSubject());
assertEquals("Body type should be TEXT", "TEXT", bs.getType());
assertEquals("Body subtype should be X-VCARD", "X-VCARD", bs.getSubtype());
// fetch one contact
List<Long> uids = connection.getUids("1:*");
assertNotNull("uids should not be null", uids);
assertEquals("expecting to find 1 UID", 1, uids.size());
byte[] b = getBody(fetchMessage(connection, uids.get(0)));
assertNotNull("fetched body should not be null", b);
List<VCard> cards = VCard.parseVCard(new String(b, MimeConstants.P_CHARSET_UTF8));
assertNotNull("parsed vcards list should not be null", cards);
assertEquals("expecting to find 1 Vcard", 1, cards.size());
assertNotNull("parsed vcard should not be null", cards.get(0));
assertEquals("VCArd's full name is wrong", contactName, cards.get(0).fn);
}
use of com.zimbra.cs.mailclient.imap.BodyStructure in project zm-mailbox by Zimbra.
the class SharedImapNotificationTests method testDeleteMessageNotificationActiveFolder.
@Test
public void testDeleteMessageNotificationActiveFolder() throws Exception {
String folderName1 = "TestRemoteImapNotifications-folder";
String subject1 = "TestRemoteImapNotifications-testMessage1";
String subject2 = "TestRemoteImapNotifications-testMessage2";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
String msgId = TestUtil.addMessage(zmbox, subject1, folder.getId(), null);
TestUtil.addMessage(zmbox, subject2, folder.getId(), null);
connection = connect();
connection.login(PASS);
connection.select(folderName1);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
assertEquals("Size of map returned by initial fetch", 2, mdMap.size());
MailboxOperation deleteMessage = new MailboxOperation() {
@Override
protected void run(ZMailbox zmbox) throws Exception {
zmbox.deleteMessage(msgId);
}
@Override
protected String checkResult() throws Exception {
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
assertEquals("Size of map returned by fetch 2", 2, mdMap.size());
MessageData md = mdMap.get(1L);
// verify that the deleted message has a NIL response
Envelope envelope = md.getEnvelope();
if (envelope == null) {
return "Envelope should not be NULL";
}
if (envelope.getSubject() != null) {
return "Envelope::subject should be NULL";
}
BodyStructure bs = md.getBodyStructure();
if (bs.getSize() != 0) {
return "BodyStructure::geSize should return 0";
}
// verify that the second message is correct
md = mdMap.get(2L);
if (!subject2.equals(md.getEnvelope().getSubject())) {
return String.format("Subject should be %s. Getting %d", subject2, md.getEnvelope().getSubject());
}
connection.expunge();
mdMap = connection.fetch("1:*", "(ENVELOPE BODY)");
if (mdMap.size() != 1) {
return String.format("Size of map returned by fetch should be 1. Getting %d", mdMap.size());
}
return null;
}
};
runOp(deleteMessage, zmbox, folder);
}
use of com.zimbra.cs.mailclient.imap.BodyStructure in project zm-mailbox by Zimbra.
the class SharedImapTests method copyToMountpoint.
@Test(timeout = 100000)
public void copyToMountpoint() throws Exception {
TestUtil.createAccount(SHAREE);
ZMailbox userZmbox = TestUtil.getZMailbox(USER);
ZMailbox shareeZmbox = TestUtil.getZMailbox(SHAREE);
String sharedFolder = "INBOX/share";
String mountpoint = String.format("shared-", testInfo.getMethodName());
String subject = "SharedImapTests-testMessage";
TestUtil.createMountpoint(userZmbox, "/" + sharedFolder, shareeZmbox, mountpoint);
TestUtil.addMessage(shareeZmbox, subject, Integer.toString(Mailbox.ID_FOLDER_INBOX), null);
connection = connectAndSelectInbox(SHAREE);
CopyResult copyResult = connection.copy("1", mountpoint);
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 = connection.select(mountpoint);
assertNotNull(String.format("Select result for folder=%s", mountpoint), selectMboxInfo);
assertEquals("Select result Folder Name folder", mountpoint, selectMboxInfo.getName());
assertEquals(String.format("Number of exists for folder=%s after copy", mountpoint), 1, selectMboxInfo.getExists());
Map<Long, MessageData> mdMap = this.doFetchShouldSucceed(connection, "1:*", "(ENVELOPE)", Lists.newArrayList(subject));
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 SharedImapTests method testListFolderContents.
@Test(timeout = 100000)
public void testListFolderContents() throws IOException, ServiceException, MessagingException {
String folderName = "SharedImapTests-testOpenFolder";
String subject = "SharedImapTests-testMessage";
ZMailbox zmbox = TestUtil.getZMailbox(USER);
ZFolder folder = TestUtil.createFolder(zmbox, folderName);
TestUtil.addMessage(zmbox, subject, folder.getId(), null);
connection = connect();
connection.login(PASS);
connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE INTERNALDATE BODY BODY.PEEK[])");
assertEquals("Size of map returned by fetch", 1, mdMap.size());
MessageData md = mdMap.values().iterator().next();
assertNotNull("MessageData", md);
Envelope env = md.getEnvelope();
assertNotNull("Envelope", env);
assertEquals("Subject from envelope is wrong", subject, env.getSubject());
assertNotNull("Internal date was requested and should not be NULL", md.getInternalDate());
BodyStructure bs = md.getBodyStructure();
assertNotNull("Body Structure is null", bs);
if (bs.isMultipart()) {
BodyStructure[] parts = bs.getParts();
for (BodyStructure part : parts) {
assertNotNull("part type should not be null", part.getType());
assertNotNull("part subType should not be null", part.getSubtype());
}
} else {
assertNotNull("Body structure type", bs.getType());
assertNotNull("Body structure sub-type", bs.getSubtype());
}
Body[] body = md.getBodySections();
assertNotNull("body sections should not be null", body);
assertEquals("expecting one body section. Got " + body.length, 1, body.length);
}
Aggregations