use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class RemoteFolder method select.
public MailboxInfo select() throws IOException {
MailboxInfo mi = connection.select(path);
// Bug 35554: If server does not provide UIDVALIDITY, then assume a value of 1
if (mi.getUidValidity() <= 0) {
mi.setUidValidity(1);
}
if (mi.getExists() == -1) {
debug("Server did not provide EXISTS");
mi.setExists(1);
}
return mi;
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class TestImap method testAppendTags.
@Test
public void testAppendTags() throws Exception {
Flags flags = Flags.fromSpec("afs");
//new tag; does not exist in mbox
String tag1 = "APPENDTAG1";
flags.set(tag1);
Date date = new Date(System.currentTimeMillis());
Literal msg = message(10);
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag1));
} finally {
msg.dispose();
}
//should not have created a visible tag
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue("APPEND created new visible tag", tags == null || tags.size() == 0);
//now create a visible tag, add it to a message in inbox then try append to message in different folder
String tag2 = "APPENDTAG2";
ZTag tag = mbox.getTag(tag2);
if (tag == null) {
tag = mbox.createTag(tag2, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals(tag2, tags.get(0).getName());
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tag2, info.getFlags().isSet(tag2));
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
info = connection.select(folderName);
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tag2));
msg = message(10);
flags = Flags.fromSpec("afs");
flags.set(tag2);
try {
AppendResult res = connection.append(folderName, flags, date, msg);
MessageData data = connection.uidFetch(res.getUid(), "FLAGS");
assertTrue(data.getFlags().isSet(tag2));
} finally {
msg.dispose();
}
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tag2));
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class TestImapClient method testAppend.
@Test
public void testAppend() throws Exception {
login();
MailboxInfo mb = connection.select("INBOX");
long exists = mb.getExists();
Date date = new Date((System.currentTimeMillis() / 1000) * 1000);
Flags flags = Flags.fromSpec("fs");
AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), date, new Literal(Ascii.getBytes(MESSAGE)));
assertNotNull(res);
mb = connection.select("INBOX");
assertEquals(1, mb.getExists() - exists);
MessageData md = connection.uidFetch(res.getUid(), "(FLAGS BODY.PEEK[] INTERNALDATE)");
assertNotNull(md);
assertEquals(date, md.getInternalDate());
assertEquals(res.getUid(), md.getUid());
assertEquals(flags, md.getFlags());
Body[] parts = md.getBodySections();
assertNotNull(parts);
assertEquals(1, parts.length);
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo 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);
// Start IDLE...
connection.idle(new ResponseHandler() {
@Override
public void handleResponse(ImapResponse res) {
System.out.println("XXX res = " + res);
if (res.getCCode() == CAtom.EXISTS) {
synchronized (exists) {
exists.set(res.getNumber());
}
}
}
});
assertTrue(connection.isIdling());
// Send test message
sendTestMessage();
// Wait for message delivery...
synchronized (exists) {
while (exists.get() <= 0) {
exists.wait();
}
}
// Stop IDLE...
connection.stopIdle();
// Check mailbox status
MailboxInfo mb = connection.getMailboxInfo();
assertEquals(mb.getExists(), exists.get());
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class TestImapClient method testDelete.
@Test
public void testDelete() throws Exception {
login();
MailboxInfo mb = connection.select("INBOX");
long exists = mb.getExists();
AppendResult res = connection.append("INBOX", Flags.fromSpec("fs"), new Date(System.currentTimeMillis()), new Literal(Ascii.getBytes(MESSAGE)));
assertNotNull(res);
mb = connection.select("INBOX");
assertEquals(exists, mb.getExists() - 1);
connection.uidStore(String.valueOf(res.getUid()), "+FLAGS.SILENT", Flags.fromSpec("d"));
mb = connection.select("INBOX");
assertEquals(exists, mb.getExists() - 1);
connection.expunge();
mb = connection.select("INBOX");
assertEquals(exists, mb.getExists());
}
Aggregations