use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class TestImapClient method testSelect.
@Test
public void testSelect() throws Exception {
login();
MailboxInfo mb = connection.getMailboxInfo();
assertNotNull(mb);
assertTrue(mb.isReadWrite());
assertTrue(mb.getUidValidity() > 0);
assertTrue(mb.getUidNext() > 0);
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo 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());
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class TestImap method testStoreTags.
@Test
public void testStoreTags() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER);
List<ZTag> tags = mbox.getAllTags();
assertTrue(tags == null || tags.size() == 0);
String tagName = "T1";
ZTag tag = mbox.getTag(tagName);
if (tag == null) {
tag = mbox.createTag(tagName, Color.blue);
}
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String folderName = "newfolder1";
ZFolder folder = mbox.createFolder(Mailbox.ID_FOLDER_USER_ROOT + "", folderName, ZFolder.View.message, ZFolder.Color.DEFAULTCOLOR, null, null);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", tag.getId(), System.currentTimeMillis(), simpleMessage("foo1"), true);
mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo2"), true);
MailboxInfo info = connection.select("INBOX");
assertTrue("INBOX does not contain expected flag " + tagName, info.getFlags().isSet(tagName));
Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
assertEquals(2, data.size());
Iterator<Long> it = data.keySet().iterator();
Long seq = it.next();
assertTrue("flag not set on first message", data.get(seq).getFlags().isSet(tagName));
seq = it.next();
assertFalse("flag unexpectedly set on second message", data.get(seq).getFlags().isSet(tagName));
connection.store(seq + "", "+FLAGS", tagName);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE in INBOX", data.get(seq).getFlags().isSet(tagName));
mbox.addMessage(folder.getId(), "u", "", System.currentTimeMillis(), simpleMessage("bar"), true);
info = connection.select(folderName);
assertFalse(folderName + " contains unexpected flag " + tagName, info.getFlags().isSet(tagName));
data = connection.fetch("*", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertFalse("flag unexpectedly set on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
connection.store(seq + "", "+FLAGS", tagName);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
info = connection.select(folderName);
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
String tagName2 = "T2";
connection.store(seq + "", "+FLAGS", tagName2);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
info = connection.select(folderName);
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName2));
//should not have created T2 as a visible tag
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
String tagName3 = "T3";
connection.store(seq + "", "FLAGS", tagName3);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName));
assertFalse("flag unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName2));
assertTrue("flag not set after STORE on message in " + folderName, data.get(seq).getFlags().isSet(tagName3));
info = connection.select(folderName);
assertTrue("new tag not set in new folder", info.getFlags().isSet(tagName3));
assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName));
assertFalse("old tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
//should not have created T2 or T3 as a visible tag
tags = mbox.getAllTags();
assertTrue(tags != null && tags.size() == 1);
assertEquals("T1", tags.get(0).getName());
connection.store(seq + "", "-FLAGS", tagName3);
data = connection.fetch(seq + "", "FLAGS");
assertEquals(1, data.size());
seq = data.keySet().iterator().next();
assertTrue("flags unexpectedly set after STORE on message in " + folderName, data.get(seq).getFlags().isEmpty());
info = connection.select("INBOX");
assertTrue("old tag not set in new folder", info.getFlags().isSet(tagName));
assertFalse("new tag unexpectedly set in new folder", info.getFlags().isSet(tagName2));
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class ImapAppender method appendSlow.
// Slow APPEND for servers lacking UIDPLUS capability
private long appendSlow(MessageInfo mi, Literal lit) throws IOException, MessagingException {
MailboxInfo mb = connection.getMailboxInfo();
if (mdf == null) {
mdf = new MailDateFormat();
}
if (mb == null || !mailbox.equals(mb.getName())) {
connection.select(mailbox);
}
long startUid = getUidNext();
connection.append(mailbox, mi.flags, mi.date, lit);
if (mi.mm.getSentDate() == null || mi.mm.getMessageID() == null) {
// "Date" and "Message-ID" headers are required to find message
return -1;
}
// Check new messages for the one we just appended
try {
//exchange doesn't give accurate UIDNEXT unless mbox is selected again.
connection.select(mailbox);
long endUid = getUidNext() - 1;
if (startUid <= endUid) {
List<Long> found = findUids(startUid + ":" + endUid, mi);
if (found.size() == 1) {
return found.get(0);
}
}
// If not found then server must have de-duped the message. This
// is certainly possible with GMail. Search through the entire mailbox
// for matching message and hope this is not too slow.
List<Long> uids;
try {
// bug 45385: Temporarily increase timeout to 10 minutes in case of slow search.
// Not pretty, but hopefully we never get here since most servers now support
// UIDPLUS or don't de-dup messages.
// bug 64062 : let's try 2 minutes. hopefully search shouldn't take too long now that we use msg id rather than subject
connection.setReadTimeout(2 * 60);
uids = connection.uidSearch(getSearchParams(mi));
} finally {
connection.setReadTimeout(connection.getConfig().getReadTimeout());
}
Iterator<Long> it = uids.iterator();
while (it.hasNext()) {
List<Long> found = findUids(nextSeq(it, 5), mi);
if (found.size() > 0) {
if (found.size() > 1) {
ZimbraLog.imap_client.warn("found more than one (%d)" + "matching UID during appendSlow. Probably a leftover dupe from earlier bugs?", found.size());
if (ZimbraLog.imap_client.isDebugEnabled()) {
ZimbraLog.imap_client.debug("potential duplicate ids = %s", Joiner.on(',').join(found));
}
}
return found.get(0);
}
}
} catch (Exception e) {
//if this is a real exception (e.g. network went down) next command will fail regardless.
//otherwise, don't allow appendSlow to create loop
ZimbraLog.imap_client.warn("Dedupe search in appendSlow failed.", e);
}
//this usually is OK, and actually the way Exchange has been working due to size check in matches()
//we delete the local tracker and allow next sync to get the current version of message
ZimbraLog.imap_client.warn("append slow failed to find appended message id");
// If still not found, then give up :(
return -1;
}
use of com.zimbra.cs.mailclient.imap.MailboxInfo in project zm-mailbox by Zimbra.
the class RemoteFolder method status.
public MailboxInfo status() throws IOException {
MailboxInfo mi = connection.status(path, "UIDVALIDITY", "UIDNEXT", "MESSAGES");
// Bug 35554: If server does not provide UIDVALIDITY, then assume a value of 1
if (mi.getUidValidity() <= 0) {
mi.setUidValidity(1);
}
if (!path.equals(mi.getName())) {
path = mi.getName();
}
if (mi.getExists() == -1) {
debug("Server did not provide MESSAGES");
mi.setExists(1);
}
return mi;
}
Aggregations