Search in sources :

Example 6 with Literal

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

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

the class TestImapThrottle method uidfetch.

@Test
public void uidfetch() 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.uidFetch("1:*", new String[] { "FLAGS", "UID" });
    }
    try {
        connection.uidFetch("1:*", new String[] { "FLAGS", "UID" });
        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 8 with Literal

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

the class TestImapThrottle method store.

@Test
public void store() 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.store("1:3", "FLAGS", new String[] { "FOO", "BAR" });
    }
    try {
        connection.store("1:3", "FLAGS", new String[] { "FOO", "BAR" });
        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 9 with Literal

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

the class TestImapThrottle method fetch.

@Test
public void fetch() 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.fetch(1, new String[] { "FLAGS", "UID" });
    }
    try {
        connection.fetch(1, new String[] { "FLAGS", "UID" });
        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 10 with Literal

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

the class TestImap method message.

private static Literal message(int size) throws IOException {
    File file = File.createTempFile("msg", null);
    file.deleteOnExit();
    FileWriter out = new FileWriter(file);
    try {
        out.write(simpleMessage("test message"));
        for (int i = 0; i < size; i++) {
            out.write('X');
            if (i % 72 == 0) {
                out.write("\r\n");
            }
        }
    } finally {
        out.close();
    }
    return new Literal(file, true);
}
Also used : FileWriter(java.io.FileWriter) Literal(com.zimbra.cs.mailclient.imap.Literal) File(java.io.File)

Aggregations

Literal (com.zimbra.cs.mailclient.imap.Literal)17 Flags (com.zimbra.cs.mailclient.imap.Flags)12 Test (org.junit.Test)12 Date (java.sql.Date)11 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)9 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)6 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)4 File (java.io.File)3 ServiceException (com.zimbra.common.service.ServiceException)2 MessageData (com.zimbra.cs.mailclient.imap.MessageData)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Date (java.util.Date)2 MessagingException (javax.mail.MessagingException)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 ZTag (com.zimbra.client.ZTag)1 ZSharedFileInputStream (com.zimbra.common.zmime.ZSharedFileInputStream)1 MailException (com.zimbra.cs.mailclient.MailException)1 Body (com.zimbra.cs.mailclient.imap.Body)1