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());
}
}
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());
}
}
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());
}
}
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());
}
}
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);
}
}
Aggregations