Search in sources :

Example 1 with AppendResult

use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.

the class TestImap method testCatenateSimple.

@Test
public void testCatenateSimple() throws Exception {
    assertTrue(connection.hasCapability("CATENATE"));
    assertTrue(connection.hasCapability("UIDPLUS"));
    String part1 = simpleMessage("test message");
    String part2 = "more text\r\n";
    AppendMessage am = new AppendMessage(null, null, literal(part1), literal(part2));
    AppendResult res = connection.append("INBOX", am);
    connection.select("INBOX");
    byte[] body = fetchBody(res.getUid());
    assertArrayEquals("content mismatch", bytes(part1 + part2), body);
}
Also used : AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Test(org.junit.Test)

Example 2 with AppendResult

use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.

the class TestImap method testAppendTags.

@Test
public void testAppendTags() throws Exception {
    Flags flags = Flags.fromSpec("afs");
    //new tag; does not exist in mbox
    String tag1 = "APPENDTAG1";
    flags.set(tag1);
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(10);
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
        assertTrue(data.getFlags().isSet(tag1));
    } finally {
        msg.dispose();
    }
    //should not have created a visible tag
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);
    //now create a visible tag, add it to a message in inbox then try append to message in different folder
    String tag2 = "APPENDTAG2";
    ZTag tag = mbox.getTag(tag2);
    if (tag == null) {
        tag = mbox.createTag(tag2, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals(tag2, tags.get(0).getName());
    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 " + tag2, info.getFlags().isSet(tag2));
    String folderName = "newfolder1";
    ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
    info = connection.select(folderName);
    assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));
    msg = message(10);
    flags = Flags.fromSpec("afs");
    flags.set(tag2);
    try {
        AppendResult res = connection.append(folderName, flags, date, msg);
        MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
        assertTrue(data.getFlags().isSet(tag2));
    } finally {
        msg.dispose();
    }
    info = connection.select(folderName);
    assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) ZTag(com.zimbra.client.ZTag) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) ZFolder(com.zimbra.client.ZFolder) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) Test(org.junit.Test)

Example 3 with AppendResult

use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.

the class TestImap method appendInvalidFlag.

private void appendInvalidFlag(String flag) throws IOException {
    Literal msg = message(10);
    Flags flags = Flags.fromSpec("afs");
    flags.set(flag);
    Date date = new Date(System.currentTimeMillis());
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        fail("server allowed client to set system flag " + flag);
    } catch (CommandFailedException e) {
    //expected
    } finally {
        msg.dispose();
    }
    //do a no-op so we don't hit max consecutive error limit
    connection.noop();
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Example 4 with AppendResult

use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.

the class TestImap method testMultiappend.

@Test
public void testMultiappend() throws Exception {
    assertTrue(connection.hasCapability("MULTIAPPEND"));
    assertTrue(connection.hasCapability("UIDPLUS"));
    AppendMessage msg1 = new AppendMessage(null, null, literal("test 1"));
    AppendMessage msg2 = new AppendMessage(null, null, literal("test 2"));
    AppendResult res = connection.append("INBOX", msg1, msg2);
    assertNotNull(res);
    assertEquals("expecting 2 uids", 2, res.getUids().length);
}
Also used : AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Test(org.junit.Test)

Example 5 with AppendResult

use of com.zimbra.cs.mailclient.imap.AppendResult in project zm-mailbox by Zimbra.

the class ImapAppender method append.

private long append(MessageInfo mi, Literal data) throws IOException {
    ImapRequest req = connection.newRequest(CAtom.APPEND, new MailboxName(mailbox));
    if (mi.flags != null) {
        req.addParam(mi.flags);
    }
    if (mi.date != null) {
        req.addParam(mi.date);
    }
    req.addParam(data);
    ResponseText rt = req.sendCheckStatus().getResponseText();
    if (rt != null && rt.getCCode() == CAtom.APPENDUID) {
        AppendResult ar = (AppendResult) rt.getData();
        if (ar.getUid() > 0) {
            return ar.getUid();
        }
    }
    throw req.failed("APPENDUID supported but UID missing from result");
}
Also used : MailboxName(com.zimbra.cs.mailclient.imap.MailboxName) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ResponseText(com.zimbra.cs.mailclient.imap.ResponseText) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult)

Aggregations

AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)21 Test (org.junit.Test)12 Literal (com.zimbra.cs.mailclient.imap.Literal)11 AppendMessage (com.zimbra.cs.mailclient.imap.AppendMessage)9 Flags (com.zimbra.cs.mailclient.imap.Flags)7 Date (java.util.Date)7 MessageData (com.zimbra.cs.mailclient.imap.MessageData)6 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)5 Date (java.sql.Date)4 ZMailbox (com.zimbra.client.ZMailbox)3 ZTag (com.zimbra.client.ZTag)2 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)2 IOException (java.io.IOException)2 MessagingException (javax.mail.MessagingException)2 ZFolder (com.zimbra.client.ZFolder)1 ServiceException (com.zimbra.common.service.ServiceException)1 MailException (com.zimbra.cs.mailclient.MailException)1 Body (com.zimbra.cs.mailclient.imap.Body)1 CopyResult (com.zimbra.cs.mailclient.imap.CopyResult)1 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)1