Search in sources :

Example 1 with CommandFailedException

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

the class SmtpConnection method readHelloReplies.

/**
     * Reads replies to {@code EHLO} or {@code HELO}.
     * <p>
     * Returns the reply code.  Handles multiple {@code 250} responses.
     *
     * @param command the command name
     * @param firstReply the first reply line returned from sending {@code EHLO} or {@code HELO}
     */
private int readHelloReplies(String command, Reply firstReply) throws IOException {
    Reply reply = firstReply;
    int line = 1;
    serverExtensions.clear();
    serverAuthMechanisms.clear();
    while (true) {
        if (reply.text == null) {
            throw new CommandFailedException(command, "Invalid server response at line " + line + ": " + reply);
        }
        if (reply.code != 250) {
            return reply.code;
        }
        if (line > 1) {
            // Parse server extensions.
            Matcher matcher = PAT_EXTENSION.matcher(reply.text);
            if (matcher.matches()) {
                String extName = matcher.group(1).toUpperCase();
                serverExtensions.add(extName);
                if (extName.equals(AUTH)) {
                    // Parse auth mechanisms.
                    Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings();
                    for (String mechanism : splitter.split(matcher.group(2))) {
                        serverAuthMechanisms.add(mechanism.toUpperCase());
                    }
                }
            }
        }
        if (reply.last) {
            // Last 250 response.
            mailIn.trace();
            return 250;
        } else {
            // Multiple response lines.
            reply = Reply.parse(mailIn.readLine());
        }
        line++;
    }
}
Also used : Splitter(com.google.common.base.Splitter) Matcher(java.util.regex.Matcher) CharMatcher(com.google.common.base.CharMatcher) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

Example 2 with CommandFailedException

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

the class ImapRequest method failed.

public CommandFailedException failed(String error, Throwable cause) {
    CommandFailedException cfe = new CommandFailedException(cmd.getName(), error);
    try {
        cfe.setRequest(toString());
    } catch (Exception e) {
    }
    cfe.initCause(cause);
    return cfe;
}
Also used : CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) ParseException(com.zimbra.cs.mailclient.ParseException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) MailException(com.zimbra.cs.mailclient.MailException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 3 with CommandFailedException

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

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

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

Aggregations

CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)13 Flags (com.zimbra.cs.mailclient.imap.Flags)7 Literal (com.zimbra.cs.mailclient.imap.Literal)7 Date (java.sql.Date)7 Test (org.junit.Test)6 IOException (java.io.IOException)3 ServiceException (com.zimbra.common.service.ServiceException)2 MailException (com.zimbra.cs.mailclient.MailException)2 ParseException (com.zimbra.cs.mailclient.ParseException)2 CharMatcher (com.google.common.base.CharMatcher)1 Splitter (com.google.common.base.Splitter)1 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)1 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Message (com.zimbra.cs.mailbox.Message)1 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)1 FetchResponseHandler (com.zimbra.cs.mailclient.imap.FetchResponseHandler)1 IDInfo (com.zimbra.cs.mailclient.imap.IDInfo)1 ImapConfig (com.zimbra.cs.mailclient.imap.ImapConfig)1 ImapConnection (com.zimbra.cs.mailclient.imap.ImapConnection)1