Search in sources :

Example 6 with CommandFailedException

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

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

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

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

Example 10 with CommandFailedException

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

the class ImapFolderSync method fetchMessages.

private void fetchMessages(String seq) throws ServiceException, IOException {
    final Map<Long, MessageData> flagsByUid = connection.uidFetch(seq, "(FLAGS INTERNALDATE)");
    removeDeleted(flagsByUid);
    final Set<Long> uidSet = flagsByUid.keySet();
    if (uidSet.isEmpty())
        return;
    FetchResponseHandler handler = new FetchResponseHandler() {

        @Override
        public void handleFetchResponse(MessageData md) throws Exception {
            long uid = md.getUid();
            IOExceptionHandler.getInstance().trackSyncItem(mailbox, uid);
            try {
                handleFetch(md, flagsByUid, true);
                clearError(uid);
            } catch (OutOfMemoryError e) {
                Zimbra.halt("Out of memory", e);
            } catch (Exception e) {
                if (!IOExceptionHandler.getInstance().isRecoverable(mailbox, uid, "Exception syncing UID " + uid + " in folder " + remoteFolder.getPath(), e)) {
                    syncFailed("Fetch failed for uid " + uid, e);
                    SyncErrorManager.incrementErrorCount(ds, remoteId(uid));
                }
            }
            uidSet.remove(uid);
        }
    };
    // Try fetching group of messages first
    LOG.debug("Fetching messages for sequence: " + seq);
    try {
        connection.uidFetch(getSequence(uidSet), "BODY.PEEK[]", handler);
    } catch (CommandFailedException e) {
        String msg = "UID FETCH failed: " + e.toString();
        checkCanContinue(msg, e);
        LOG.warn(msg, e);
    }
    if (uidSet.isEmpty())
        return;
    LOG.info("Fetching remaining messages one at a time for UIDs: " + uidSet);
    for (long uid : getOrderedUids(uidSet)) {
        try {
            LOG.info("Fetching message for uid: " + uid);
            MessageData md = connection.uidFetch(uid, "BODY.PEEK[]");
            if (md == null) {
                //FLAGS returned data for UID but BODY.PEEK[] is not; server error; provide more meaningful error than NPE
                throw ServiceException.FAILURE("Server returned no response for UID FETCH " + uid + " BODY.PEEK[]", null);
            }
            handler.handleFetchResponse(md);
        } catch (Exception e) {
            String msg = "Error while fetching message for UID " + uid;
            checkCanContinue(msg, e);
            LOG.warn(msg, e);
        }
    }
    if (!uidSet.isEmpty()) {
        LOG.error("Unable to fetch messages for uids: " + uidSet);
    }
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) FetchResponseHandler(com.zimbra.cs.mailclient.imap.FetchResponseHandler) MailException(com.zimbra.cs.mailclient.MailException) ServiceException(com.zimbra.common.service.ServiceException) SQLException(java.sql.SQLException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException)

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