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, int size, Flags flags, boolean fetchResult) throws IOException {
checkConnection(conn);
assertTrue("expecting UIDPLUS capability", conn.hasCapability("UIDPLUS"));
Date date = new Date(System.currentTimeMillis());
Literal msg = message(size);
try {
AppendResult res = conn.append(folderName, flags, date, msg);
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("content mismatch", msg.getBytes(), b);
}
return res;
} finally {
msg.dispose();
}
}
use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.
the class SharedImapTests method testStoreTagsDirty.
@Test(timeout = 100000)
public void testStoreTagsDirty() throws Exception {
connection = connectAndSelectInbox();
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
final String tagName2 = "T2";
ZTag tag = mbox.getTag(tagName);
if (tag == null) {
tag = mbox.createTag(tagName, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String folderName = "newfolder1";
mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(1, data.size());
Iterator<Long> it = data.keySet().iterator();
Long seq = it.next();
assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
req.setResponseHandler(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
Flags flags = (Flags) res.getData();
assertTrue(flags.isSet(tagName2));
}
}
});
req.sendCheckStatus();
}
use of com.zimbra.cs.mailclient.imap.MessageData 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.MessageData in project zm-mailbox by Zimbra.
the class SharedImapTests method testCopy.
@Test(timeout = 100000)
public void testCopy() throws IOException {
connection = connectAndSelectInbox();
Flags flags = Flags.fromSpec("afs");
for (int i = 0; i < 3; i++) {
Date date = new Date(System.currentTimeMillis());
Literal msg = message(1000 + i * 1000);
try {
connection.append("INBOX", flags, date, msg);
} finally {
msg.dispose();
}
}
connection.create("FOO");
connection.copy("1:3", "FOO");
connection.select("FOO");
Map<Long, MessageData> mdMap = connection.fetch("1:3", "(ENVELOPE INTERNALDATE BODY BODY.PEEK[])");
assertEquals("Size of map returned by fetch", 3, mdMap.size());
}
use of com.zimbra.cs.mailclient.imap.MessageData 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