Search in sources :

Example 11 with AppendResult

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

the class TestImapClient method testAppend.

@Test
public void testAppend() throws Exception {
    login();
    MailboxInfo mb = connection.select("INBOX");
    long exists = mb.getExists();
    Date date = new Date((System.currentTimeMillis() / 1000) * 1000);
    Flags flags = Flags.fromSpec("fs");
    AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), date, new Literal(Ascii.getBytes(MESSAGE)));
    assertNotNull(res);
    mb = connection.select("INBOX");
    assertEquals(1, mb.getExists() - exists);
    MessageData md = connection.uidFetch(res.getUid(), "(FLAGS BODY.PEEK[] INTERNALDATE)");
    assertNotNull(md);
    assertEquals(date, md.getInternalDate());
    assertEquals(res.getUid(), md.getUid());
    assertEquals(flags, md.getFlags());
    Body[] parts = md.getBodySections();
    assertNotNull(parts);
    assertEquals(1, parts.length);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Body(com.zimbra.cs.mailclient.imap.Body) Date(java.util.Date) Test(org.junit.Test)

Example 12 with AppendResult

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

the class TestImap method testCatenateUrl.

@Test
public void testCatenateUrl() throws Exception {
    assertTrue(connection.hasCapability("CATENATE"));
    assertTrue(connection.hasCapability("UIDPLUS"));
    String msg1 = simpleMessage("test message");
    AppendResult res1 = connection.append("INBOX", null, null, literal(msg1));
    String s1 = "first part\r\n";
    String s2 = "second part\r\n";
    String msg2 = msg1 + s1 + s2;
    AppendMessage am = new AppendMessage(null, null, url("INBOX", res1), literal(s1), literal(s2));
    AppendResult res2 = connection.append("INBOX", am);
    connection.select("INBOX");
    byte[] b2 = fetchBody(res2.getUid());
    assertArrayEquals("content mismatch", bytes(msg2), b2);
}
Also used : AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Test(org.junit.Test)

Example 13 with AppendResult

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

the class TestImap method testAppend.

@Test
public void testAppend() throws Exception {
    assertTrue(connection.hasCapability("UIDPLUS"));
    Flags flags = Flags.fromSpec("afs");
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(100000);
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        assertNotNull(res);
        byte[] b = fetchBody(res.getUid());
        assertArrayEquals("content mismatch", msg.getBytes(), b);
    } finally {
        msg.dispose();
    }
}
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) Test(org.junit.Test)

Example 14 with AppendResult

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

the class ImapTestBase method doAppend.

protected AppendResult doAppend(ImapConnection conn, String folderName, String subject, String body, Flags flags, boolean fetchResult) {
    checkConnection(conn);
    assertTrue("expecting UIDPLUS capability", conn.hasCapability("UIDPLUS"));
    String msg = simpleMessage(subject, body);
    Date date = new Date(System.currentTimeMillis());
    AppendMessage am = new AppendMessage(flags, date, literal(msg));
    try {
        AppendResult res = conn.append(folderName, am);
        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("FETCH content not same as APPENDed content", msg.getBytes(), b);
        }
        return res;
    } catch (IOException e) {
        ZimbraLog.test.info("Exception thrown trying to append", e);
        fail("Exception thrown trying to append:" + e.getMessage());
    }
    return null;
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) IOException(java.io.IOException) Date(java.util.Date)

Example 15 with AppendResult

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

the class SharedImapTests method testAppendFlags.

@Test(timeout = 100000)
public void testAppendFlags() throws Exception {
    connection = connectAndSelectInbox();
    assertTrue("expecting UIDPLUS capability", connection.hasCapability("UIDPLUS"));
    Flags flags = Flags.fromSpec("afs");
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(100000);
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        assertNotNull("result of append command should not be null", res);
        MessageData md = fetchMessage(connection, res.getUid());
        Flags msgFlags = md.getFlags();
        assertTrue("expecting isAnswered flag", msgFlags.isAnswered());
        assertTrue("expecting isFlagged flag", msgFlags.isFlagged());
        assertTrue("expecting isSeen flag", msgFlags.isSeen());
        byte[] b = getBody(md);
        assertArrayEquals("content mismatch", msg.getBytes(), b);
    } 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) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) Test(org.junit.Test)

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