use of com.zimbra.cs.mailclient.imap.Envelope 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.Envelope 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.Envelope in project zm-mailbox by Zimbra.
the class SharedImapTests method savedSearch.
@Test(timeout = 100000)
public void savedSearch() throws ServiceException, IOException, MessagingException {
ZMailbox mbox = TestUtil.getZMailbox(USER);
String subjectPrefix = String.format("%s test message ", testId);
TestUtil.addMessage(mbox, subjectPrefix + "1", ZFolder.ID_INBOX);
TestUtil.addMessage(mbox, subjectPrefix + "2", ZFolder.ID_DRAFTS);
TestUtil.addMessage(mbox, subjectPrefix + "3 - does not match search", ZFolder.ID_SENT);
String folderName = "searchFolderInDraftsOrInOnbox";
ZSearchFolder srchFolder = mbox.createSearchFolder(ZFolder.ID_USER_ROOT, folderName, "in:drafts or in:inbox", ZSearchParams.TYPE_CONVERSATION, SearchSortBy.nameAsc, ZFolder.Color.ORANGE);
assertNotNull("SearchFolder in Response to CreateSearchFolderRequest should not be null", srchFolder);
connection = this.connectAndLogin(USER);
List<ListData> listResult;
// LIST "" "mountpointName"
doListShouldSucceed(connection, "", folderName, Lists.newArrayList(folderName), "Just search folder");
listResult = connection.list("", "*");
assertNotNull("list result 'list \"\" \"*\"' should not be null", listResult);
boolean seenIt = false;
for (ListData listEnt : listResult) {
if (folderName.equals(listEnt.getMailbox())) {
seenIt = true;
break;
}
}
assertTrue(String.format("'%s' mailbox not in result of 'list \"\" \"*\"'", folderName), seenIt);
connection.select(folderName);
Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
assertEquals("Size of map returned by fetch", 2, mdMap.size());
Iterator<MessageData> iter = mdMap.values().iterator();
while (iter.hasNext()) {
MessageData md = iter.next();
assertNotNull("MessageData", md);
Envelope env = md.getEnvelope();
assertNotNull("Envelope", env);
assertTrue(String.format("Message subject was '%s' expected to contain '%s'", env.getSubject(), subjectPrefix), env.getSubject().contains(subjectPrefix));
}
connection.logout();
connection = null;
}
use of com.zimbra.cs.mailclient.imap.Envelope in project zm-mailbox by Zimbra.
the class ImapTestBase method doFetchShouldSucceed.
protected Map<Long, MessageData> doFetchShouldSucceed(ImapConnection conn, String range, String what, List<String> expectedSubjects) throws IOException {
checkConnection(conn);
try {
Map<Long, MessageData> mdMap = conn.fetch(range, what);
assertNotNull(String.format("map returned by 'FETCH %s %s' should not be null", range, what), mdMap);
assertEquals(String.format("Size of map returned by 'FETCH %s %s'", range, what), expectedSubjects.size(), mdMap.size());
int cnt = 0;
Iterator<MessageData> iter = mdMap.values().iterator();
while (iter.hasNext()) {
MessageData md = iter.next();
assertNotNull("MessageData should not be null", md);
Envelope env = md.getEnvelope();
assertNotNull(String.format("Envelope for MessageData for %s item in results of 'FETCH %s %s' should not be null", cnt, range, what), env);
assertEquals(String.format("Subject for %s item in results of 'FETCH %s %s'", cnt, range, what), expectedSubjects.get(cnt), env.getSubject());
cnt++;
}
return mdMap;
} catch (CommandFailedException cfe) {
fail(String.format("'FETCH %s %s' failed with '%s'", range, what, cfe.getError()));
return null;
}
}
use of com.zimbra.cs.mailclient.imap.Envelope 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);
}
Aggregations