Search in sources :

Example 36 with MessageData

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();
    }
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Date(java.util.Date)

Example 37 with MessageData

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();
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ZTag(com.zimbra.client.ZTag) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ZMailbox(com.zimbra.client.ZMailbox) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 38 with MessageData

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);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Body(com.zimbra.cs.mailclient.imap.Body) CopyResult(com.zimbra.cs.mailclient.imap.CopyResult) Test(org.junit.Test)

Example 39 with MessageData

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());
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) Test(org.junit.Test)

Example 40 with MessageData

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);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) ZFolder(com.zimbra.client.ZFolder) Envelope(com.zimbra.cs.mailclient.imap.Envelope) Body(com.zimbra.cs.mailclient.imap.Body) Test(org.junit.Test)

Aggregations

MessageData (com.zimbra.cs.mailclient.imap.MessageData)47 Test (org.junit.Test)33 ZMailbox (com.zimbra.client.ZMailbox)28 ZFolder (com.zimbra.client.ZFolder)19 Flags (com.zimbra.cs.mailclient.imap.Flags)16 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)14 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)11 ZTag (com.zimbra.client.ZTag)10 Body (com.zimbra.cs.mailclient.imap.Body)9 BodyStructure (com.zimbra.cs.mailclient.imap.BodyStructure)8 Envelope (com.zimbra.cs.mailclient.imap.Envelope)8 Literal (com.zimbra.cs.mailclient.imap.Literal)8 IOException (java.io.IOException)8 Date (java.util.Date)8 ServiceException (com.zimbra.common.service.ServiceException)7 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)6 MailException (com.zimbra.cs.mailclient.MailException)5 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)4 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 Atom (com.zimbra.cs.mailclient.imap.Atom)4