Search in sources :

Example 1 with MailboxInfo

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;
}
Also used : MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo)

Example 2 with MailboxInfo

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));
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) ZTag(com.zimbra.client.ZTag) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) ZFolder(com.zimbra.client.ZFolder) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) Test(org.junit.Test)

Example 3 with MailboxInfo

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);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Body(com.zimbra.cs.mailclient.imap.Body) Date(java.util.Date) Test(org.junit.Test)

Example 4 with MailboxInfo

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());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ResponseHandler(com.zimbra.cs.mailclient.imap.ResponseHandler) ImapResponse(com.zimbra.cs.mailclient.imap.ImapResponse) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Test(org.junit.Test)

Example 5 with MailboxInfo

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());
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)15 Test (org.junit.Test)10 MessageData (com.zimbra.cs.mailclient.imap.MessageData)6 ZFolder (com.zimbra.client.ZFolder)4 ZMailbox (com.zimbra.client.ZMailbox)4 Flags (com.zimbra.cs.mailclient.imap.Flags)4 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)4 Literal (com.zimbra.cs.mailclient.imap.Literal)4 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)4 IOException (java.io.IOException)4 ZTag (com.zimbra.client.ZTag)3 ServiceException (com.zimbra.common.service.ServiceException)3 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)3 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)3 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Date (java.sql.Date)2 Date (java.util.Date)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 MessagingException (javax.mail.MessagingException)2