use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.
the class TestImapClient method testIdle.
@Test
public void testIdle() throws Exception {
login();
assertFalse(connection.isIdling());
final AtomicLong exists = new AtomicLong(-1);
final CountDownLatch doneSignal = new CountDownLatch(1);
// Start IDLE...
connection.idle(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) {
System.out.println("XXX res = " + res);
if (res.getCCode() == CAtom.EXISTS) {
exists.set(res.getNumber());
doneSignal.countDown();
}
}
});
assertTrue(connection.isIdling());
// Send test message
TestUtil.addMessage(TestUtil.getZMailbox(USER), "TestImapClient testIdle");
// Wait for message delivery...
try {
doneSignal.await(5, TimeUnit.SECONDS);
} catch (Exception e) {
fail("Wait interrupted. ");
}
// Stop IDLE...
connection.stopIdle();
// Check mailbox status
MailboxInfo mb = connection.getMailboxInfo();
assertEquals(String.format("got wrong number of messages. mb.getExists(): %d. exists.get(): %d", mb.getExists(), exists.get()), mb.getExists(), exists.get());
}
use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.
the class TestImap method testOverflowNotAppend.
@Test
public void testOverflowNotAppend() throws Exception {
int oldReadTimeout = connection.getConfig().getReadTimeout();
try {
connection.setReadTimeout(10);
Flags flags = Flags.fromSpec("afs");
Date date = new Date(System.currentTimeMillis());
ImapRequest req = connection.newRequest(CAtom.FETCH, "1:*");
req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "+}");
ImapResponse resp = req.send();
assertTrue(resp.isNO() || resp.isBAD());
} finally {
connection.setReadTimeout(oldReadTimeout);
}
}
use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.
the class TestImap method testAppendTagsDirty.
@Test
public void testAppendTagsDirty() throws Exception {
Flags flags = Flags.fromSpec("afs");
//new tag; does not exist in mbox
final String tag1 = "NEWDIRTYTAG";
MailboxInfo info = connection.select("INBOX");
assertFalse("INBOX contains unexpected flag " + tag1, info.getFlags().isSet(tag1));
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
ImapRequest req = connection.newRequest("APPEND", "INBOX", flags, date, msg);
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(tag1));
}
}
});
req.sendCheckStatus();
} finally {
msg.dispose();
}
}
use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.
the class TestImap method testOverflowAppend.
@Test
public void testOverflowAppend() throws Exception {
assertTrue(connection.hasCapability("UIDPLUS"));
int oldReadTimeout = connection.getConfig().getReadTimeout();
try {
connection.setReadTimeout(10);
Flags flags = Flags.fromSpec("afs");
Date date = new Date(System.currentTimeMillis());
ImapRequest req = connection.newRequest(CAtom.APPEND, new MailboxName("INBOX"));
req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "+}");
ImapResponse resp = req.send();
assertTrue(resp.isNO() || resp.isBAD());
req = connection.newRequest(CAtom.APPEND, new MailboxName("INBOX"));
req.addParam("{" + ((long) (Integer.MAX_VALUE) + 1) + "}");
resp = req.send();
assertTrue(resp.isNO() || resp.isBAD());
} finally {
connection.setReadTimeout(oldReadTimeout);
}
}
use of com.zimbra.cs.mailclient.imap.ImapResponse in project zm-mailbox by Zimbra.
the class TestImapClient method testFetch.
@Test
public void testFetch() throws Exception {
connect();
login();
MailboxInfo mb = connection.select("INBOX");
final AtomicLong count = new AtomicLong(mb.getExists());
connection.uidFetch("1:*", "(FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY BODY.PEEK[])", new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) throws Exception {
if (res.getCCode() != CAtom.FETCH)
return;
MessageData md = (MessageData) res.getData();
assertNotNull(md);
Envelope env = md.getEnvelope();
assertNotNull(env);
assertNotNull(env.getSubject());
assertNotNull(md.getUid());
assertTrue(md.getRfc822Size() != -1);
assertNotNull(md.getInternalDate());
BodyStructure bs = md.getBodyStructure();
assertNotNull(bs);
if (bs.isMultipart()) {
BodyStructure[] parts = bs.getParts();
for (BodyStructure part : parts) {
assertNotNull(part.getType());
assertNotNull(part.getSubtype());
}
} else {
assertNotNull(bs.getType());
assertNotNull(bs.getSubtype());
}
Body[] body = md.getBodySections();
assertNotNull(body);
assertEquals(1, body.length);
// assertNotNull(body[0].getBytes());
count.decrementAndGet();
System.out.printf("Fetched uid = %s\n", md.getUid());
}
});
assertEquals(0, count.longValue());
}
Aggregations