Search in sources :

Example 31 with Flags

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

the class SharedImapNotificationTests method testRenameTagNotificationCachedFolder.

@Test
public void testRenameTagNotificationCachedFolder() throws Exception {
    String folderName1 = "TestRemoteImapNotifications-folder1";
    String folderName2 = "TestRemoteImapNotifications-folder2";
    String tagName = "TestRemoteImapNotifications-tag";
    String newTagName = "TestRemoteImapNotifications-tag2";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName1);
    TestUtil.createFolder(zmbox, folderName2);
    ZTag tag = zmbox.createTag(tagName, Color.blue);
    zmbox.addMessage(folder.getId(), null, tag.getId(), 0, TestUtil.getTestMessage(subject), true);
    connection = connect();
    connection.login(PASS);
    MailboxInfo info = connection.select(folderName1);
    Flags flags = info.getPermanentFlags();
    assertTrue(flags.contains(new Atom(tagName)));
    info = connection.select(folderName2);
    MailboxOperation renameTag = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.renameTag(tag.getId(), newTagName);
        }

        @Override
        protected String checkResult() throws Exception {
            MailboxInfo info = connection.select(folderName1);
            Flags flags = info.getPermanentFlags();
            if (flags.contains(new Atom(tagName))) {
                return String.format("Flags should NOT contain %s", tagName);
            }
            if (!flags.contains(new Atom(newTagName))) {
                return String.format("Flags should contain %s", newTagName);
            }
            return null;
        }
    };
    runOp(renameTag, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ZTag(com.zimbra.client.ZTag) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Flags(com.zimbra.cs.mailclient.imap.Flags) Atom(com.zimbra.cs.mailclient.imap.Atom) Test(org.junit.Test)

Example 32 with Flags

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

the class SharedImapTests method appendInvalidFlag.

private void appendInvalidFlag(String flag) throws IOException {
    connection = connectAndSelectInbox();
    Literal msg = message(10);
    Flags flags = Flags.fromSpec("afs");
    flags.set(flag);
    Date date = new Date(System.currentTimeMillis());
    try {
        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) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Example 33 with Flags

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

the class SharedImapTests method testCopyThrottle.

@Test(timeout = 100000)
public void testCopyThrottle() 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");
    for (int i = 0; i < LOOP_LIMIT; i++) {
        connection.copy("1:3", "FOO");
    }
    try {
        connection.copy("1:3", "FOO");
        fail("should have been rejected");
    } catch (CommandFailedException e) {
        assertTrue("expecting connection to be closed", connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 34 with Flags

use of com.zimbra.cs.mailclient.imap.Flags 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)

Example 35 with Flags

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

the class SharedImapTests method testSortThrottle.

@Test(timeout = 100000)
public void testSortThrottle() 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();
        }
    }
    for (int i = 0; i < LOOP_LIMIT; i++) {
        connection.newRequest("SORT (DATE REVERSE SUBJECT) UTF-8 ALL").sendCheckStatus();
    }
    try {
        connection.newRequest("SORT (DATE REVERSE SUBJECT) UTF-8 ALL").sendCheckStatus();
        fail("should have been rejected");
    } catch (CommandFailedException e) {
        assertTrue("expecting connection to be closed", connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Aggregations

Flags (com.zimbra.cs.mailclient.imap.Flags)44 Test (org.junit.Test)35 Literal (com.zimbra.cs.mailclient.imap.Literal)26 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)21 MessageData (com.zimbra.cs.mailclient.imap.MessageData)16 Date (java.sql.Date)14 Date (java.util.Date)14 ZMailbox (com.zimbra.client.ZMailbox)12 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)11 ZTag (com.zimbra.client.ZTag)10 ZFolder (com.zimbra.client.ZFolder)8 ServiceException (com.zimbra.common.service.ServiceException)7 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)7 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)7 IOException (java.io.IOException)7 Atom (com.zimbra.cs.mailclient.imap.Atom)6 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)6 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)5 MessagingException (javax.mail.MessagingException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2