Search in sources :

Example 6 with AppendResult

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

the class TestImapClient method testDelete.

@Test
public void testDelete() throws Exception {
    login();
    MailboxInfo mb = connection.select("INBOX");
    long exists = mb.getExists();
    AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), new Date(System.currentTimeMillis()), new Literal(Ascii.getBytes(MESSAGE)));
    assertNotNull(res);
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists() - 1);
    connection.uidStore(String.valueOf(res.getUid()), "+FLAGS.SILENT", Flags.fromSpec("d"));
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists() - 1);
    connection.expunge();
    mb = connection.select("INBOX");
    assertEquals(exists, mb.getExists());
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Date(java.util.Date) Test(org.junit.Test)

Example 7 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 8 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 9 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 10 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)

Aggregations

AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)10 Test (org.junit.Test)7 Literal (com.zimbra.cs.mailclient.imap.Literal)6 Flags (com.zimbra.cs.mailclient.imap.Flags)4 AppendMessage (com.zimbra.cs.mailclient.imap.AppendMessage)3 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)3 Date (java.sql.Date)3 MessageData (com.zimbra.cs.mailclient.imap.MessageData)2 Date (java.util.Date)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZTag (com.zimbra.client.ZTag)1 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)1 MailException (com.zimbra.cs.mailclient.MailException)1 Body (com.zimbra.cs.mailclient.imap.Body)1 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)1 MailboxName (com.zimbra.cs.mailclient.imap.MailboxName)1 ResponseText (com.zimbra.cs.mailclient.imap.ResponseText)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1