Search in sources :

Example 36 with Flags

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

the class SharedImapTests method testStoreTagsDirty.

@Test(timeout = 100000)
public void testStoreTagsDirty() throws Exception {
    connection = connectAndSelectInbox();
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    List<ZTag> tags = mbox.getAllTags();
    assertTrue(tags == null || tags.size() == 0);
    String tagName = "T1";
    final String tagName2 = "T2";
    ZTag tag = mbox.getTag(tagName);
    if (tag == null) {
        tag = mbox.createTag(tagName, Color.blue);
    }
    tags = mbox.getAllTags();
    assertTrue(tags != null && tags.size() == 1);
    assertEquals("T1", tags.get(0).getName());
    String folderName = "newfolder1";
    mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
    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 " + tagName, info.getFlags().isSet(tagName));
    assertFalse("INBOX contain unexpected flag " + tagName2, info.getFlags().isSet(tagName2));
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(1, data.size());
    Iterator<Long> it = data.keySet().iterator();
    Long seq = it.next();
    assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
    ImapRequest req = connection.newRequest("STORE", seq + "", "+FLAGS", tagName2);
    req.setResponseHandler(new ResponseHandler() {

        @Override
        public void handleResponse(ImapResponse res) throws Exception {
            if (res.isUntagged() && res.getCCode() == CAtom.FLAGS) {
                Flags flags = (Flags) res.getData();
                assertTrue(flags.isSet(tagName2));
            }
        }
    });
    req.sendCheckStatus();
}
Also used : ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) MessageData(com.zimbra.cs.mailclient.imap.MessageData) ImapRequest(com.zimbra.cs.mailclient.imap.ImapRequest) ZTag(com.zimbra.client.ZTag) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) Flags(com.zimbra.cs.mailclient.imap.Flags) MessagingException(javax.mail.MessagingException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ZMailbox(com.zimbra.client.ZMailbox) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 37 with Flags

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

the class SharedImapTests method testCopy.

@Test(timeout = 100000)
public void testCopy() 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");
    connection.copy("1:3", "FOO");
    connection.select("FOO");
    Map<Long, MessageData> mdMap = connection.fetch("1:3", "(ENVELOPE INTERNALDATE BODY BODY.PEEK[])");
    assertEquals("Size of map returned by fetch", 3, mdMap.size());
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) Test(org.junit.Test)

Example 38 with Flags

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

the class TestImapThrottle method copy.

@Test
public void copy() throws IOException {
    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");
        Assert.fail("should have been rejected");
    } catch (CommandFailedException e) {
        Assert.assertTrue(connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 39 with Flags

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

the class TestImapThrottle method sort.

@Test
public void sort() throws IOException {
    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();
        Assert.fail("should have been rejected");
    } catch (CommandFailedException e) {
        Assert.assertTrue(connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 40 with Flags

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

the class TestImapThrottle method search.

@Test
public void search() throws IOException {
    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.search((Object[]) new String[] { "TEXT", "\"XXXXX\"" });
    }
    try {
        connection.search((Object[]) new String[] { "TEXT", "\"XXXXX\"" });
        Assert.fail("should have been rejected");
    } catch (CommandFailedException e) {
        Assert.assertTrue(connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.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