Search in sources :

Example 16 with AppendResult

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

the class SharedImapTests method copyFromSharedFolderViaHome.

@Test(timeout = 100000)
public void copyFromSharedFolderViaHome() throws IOException, ServiceException, MessagingException {
    TestUtil.createAccount(SHAREE);
    ZMailbox shareeZmbox = TestUtil.getZMailbox(SHAREE);
    connection = connectAndSelectInbox();
    String sharedFolderName = String.format("INBOX/%s-shared", testId);
    connection.create(sharedFolderName);
    connection.setacl(sharedFolderName, SHAREE, "lrswickxteda");
    String subject = String.format("%s-missiveSubject", testInfo.getMethodName());
    String bodyStr = String.format("test message body for %s", testInfo.getMethodName());
    String part1 = simpleMessage(subject, bodyStr);
    String part2 = "more text\r\n";
    AppendMessage am = new AppendMessage(null, null, literal(part1), literal(part2));
    AppendResult res = connection.append(sharedFolderName, am);
    assertNotNull(String.format("Append result to folder %s", sharedFolderName), res);
    doSelectShouldSucceed(sharedFolderName);
    doFetchShouldSucceed(connection, "1:*", "(ENVELOPE)", Lists.newArrayList(subject));
    connection.logout();
    connection = null;
    String remFolder = String.format("/home/%s/%s", USER, sharedFolderName);
    String copyToFolder = "INBOX/copy-to";
    otherConnection = connectAndSelectInbox(SHAREE);
    doCopy(otherConnection, shareeZmbox, remFolder, copyToFolder, subject);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Test(org.junit.Test)

Example 17 with AppendResult

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

the class SharedImapTests method doMultiappend.

private void doMultiappend(ImapConnection conn) throws Exception {
    assertTrue(conn.hasCapability("MULTIAPPEND"));
    assertTrue(conn.hasCapability("UIDPLUS"));
    AppendMessage msg1 = new AppendMessage(null, null, literal("test 1"));
    AppendMessage msg2 = new AppendMessage(null, null, literal("test 2"));
    AppendResult res = conn.append("INBOX", msg1, msg2);
    assertNotNull("Result of multi-append", 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)

Example 18 with AppendResult

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

the class SharedImapTests method testAppendAndCount.

@Test(timeout = 100000)
public void testAppendAndCount() throws Exception {
    connection = connectAndSelectInbox();
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(100000);
    try {
        MailboxInfo mi;
        mi = new StatusExecutor(connection).execShouldSucceed("Sent", "MESSAGES", "UIDNEXT", "UIDVALIDITY", "UNSEEN", "HIGHESTMODSEQ");
        long oldCount = mi.getExists();
        AppendResult res = connection.append("SENT", null, date, msg);
        assertNotNull("result of append command should not be null", res);
        mi = new StatusExecutor(connection).execShouldSucceed("Sent", "MESSAGES", "UIDNEXT", "UIDVALIDITY", "UNSEEN", "HIGHESTMODSEQ");
        long newCount = mi.getExists();
        assertEquals("message count should have increased by one", oldCount, newCount - 1);
    } finally {
        msg.dispose();
    }
}
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 19 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, 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 20 with AppendResult

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

the class SharedImapTests method doAppendThenOtherAppendReferencingFirst.

private void doAppendThenOtherAppendReferencingFirst(ImapConnection conn, String folder1, String folder2) throws IOException {
    assertTrue(conn.hasCapability("CATENATE"));
    assertTrue(conn.hasCapability("UIDPLUS"));
    String msg1 = simpleMessage("message to exercise ImapURL");
    AppendResult res1 = conn.append(folder1, 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(folder1, res1), literal(s1), literal(s2));
    /* This append command expands into the following (most of the work being done inside AppendMessage)
         *     APPEND INBOX CATENATE (URL "/INBOX;UIDVALIDITY=1/;UID=257" TEXT {12+}
         *     first part
         *      TEXT {13+}
         *     second part
         *     )
         *
         * The URL in the above ends up being processed by the ImapURL class server side.
         */
    AppendResult res2 = conn.append(folder2, am);
    conn.select(folder2);
    byte[] b2 = getBody(fetchMessage(conn, res2.getUid()));
    String newMsg = new String(b2, "UTF-8");
    assertEquals("Content of message not as expected", msg2, newMsg);
}
Also used : AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) 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