Search in sources :

Example 31 with MessageData

use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.

the class RemoteFolder method getFlags.

/*
     * Fetch message flags for specific UID sequence. Exclude messages which
     * have been flagged \Deleted.
     */
public List<MessageData> getFlags(long startUid, long endUid) throws IOException {
    final List<MessageData> mds = new ArrayList<MessageData>();
    String end = endUid > 0 ? String.valueOf(endUid) : "*";
    connection.uidFetch(startUid + ":" + end, "FLAGS", new FetchResponseHandler() {

        public void handleFetchResponse(MessageData md) {
            Flags flags = md.getFlags();
            if (flags != null && !flags.isDeleted()) {
                mds.add(md);
            }
        }
    });
    // result.
    if (endUid <= 0 && mds.size() == 1 && mds.get(0).getUid() < startUid) {
        return Collections.emptyList();
    }
    return mds;
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) ArrayList(java.util.ArrayList) FetchResponseHandler(com.zimbra.cs.mailclient.imap.FetchResponseHandler) Flags(com.zimbra.cs.mailclient.imap.Flags)

Example 32 with MessageData

use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.

the class ImapTestBase method doAppend.

protected AppendResult doAppend(ImapConnection conn, String folderName, String subject, String body, Flags flags, boolean fetchResult) {
    checkConnection(conn);
    assertTrue("expecting UIDPLUS capability", conn.hasCapability("UIDPLUS"));
    String msg = simpleMessage(subject, body);
    Date date = new Date(System.currentTimeMillis());
    AppendMessage am = new AppendMessage(flags, date, literal(msg));
    try {
        AppendResult res = conn.append(folderName, am);
        assertNotNull("result of append command should not be null", res);
        if (fetchResult) {
            doSelectShouldSucceed(conn, folderName);
            MessageData md = fetchMessage(conn, res.getUid());
            byte[] b = getBody(md);
            assertArrayEquals("FETCH content not same as APPENDed content", msg.getBytes(), b);
        }
        return res;
    } catch (IOException e) {
        ZimbraLog.test.info("Exception thrown trying to append", e);
        fail("Exception thrown trying to append:" + e.getMessage());
    }
    return null;
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) AppendMessage(com.zimbra.cs.mailclient.imap.AppendMessage) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) IOException(java.io.IOException) Date(java.util.Date)

Example 33 with MessageData

use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.

the class SharedImapTests method doCopy.

private void doCopy(ImapConnection imapConn, ZMailbox shareeZmbox, String fromFolderName, String toFolderName, String srcMsgSubject) throws IOException, ServiceException, MessagingException {
    imapConn.list("", "*");
    imapConn.create(toFolderName);
    // This loop is to create some distance between the IDs in the from and to mailboxes
    for (int cnt = 1; cnt < 10; cnt++) {
        TestUtil.addMessage(shareeZmbox, String.format("inbox msg %s", cnt));
    }
    doSelectShouldSucceed(imapConn, fromFolderName);
    CopyResult copyResult = imapConn.copy("1", toFolderName);
    assertNotNull("copyResult.getFromUids()", copyResult.getFromUids());
    assertNotNull("copyResult.getToUids()", copyResult.getToUids());
    assertEquals("Number of fromUIDs", 1, copyResult.getFromUids().length);
    assertEquals("Number of toUIDs", 1, copyResult.getToUids().length);
    MailboxInfo selectMboxInfo = imapConn.select(toFolderName);
    assertNotNull(String.format("Select result for folder=%s", toFolderName), selectMboxInfo);
    assertEquals("Select result Folder Name folder", toFolderName, selectMboxInfo.getName());
    assertEquals(String.format("Number of exists for folder=%s after copy", toFolderName), 1, selectMboxInfo.getExists());
    Map<Long, MessageData> mdMap = this.doFetchShouldSucceed(imapConn, "1:*", "(ENVELOPE)", Lists.newArrayList(srcMsgSubject));
    MessageData md = mdMap.values().iterator().next();
    assertNull("Internal date was NOT requested and should be NULL", md.getInternalDate());
    BodyStructure bs = md.getBodyStructure();
    assertNull("Body Structure was not requested and should be NULL", bs);
    Body[] body = md.getBodySections();
    assertNull("body sections were not requested and should be null", body);
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) BodyStructure(com.zimbra.cs.mailclient.imap.BodyStructure) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Body(com.zimbra.cs.mailclient.imap.Body) CopyResult(com.zimbra.cs.mailclient.imap.CopyResult)

Example 34 with MessageData

use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.

the class SharedImapTests method testAppendFlags.

@Test(timeout = 100000)
public void testAppendFlags() throws Exception {
    connection = connectAndSelectInbox();
    assertTrue("expecting UIDPLUS capability", connection.hasCapability("UIDPLUS"));
    Flags flags = Flags.fromSpec("afs");
    Date date = new Date(System.currentTimeMillis());
    Literal msg = message(100000);
    try {
        AppendResult res = connection.append("INBOX", flags, date, msg);
        assertNotNull("result of append command should not be null", res);
        MessageData md = fetchMessage(connection, res.getUid());
        Flags msgFlags = md.getFlags();
        assertTrue("expecting isAnswered flag", msgFlags.isAnswered());
        assertTrue("expecting isFlagged flag", msgFlags.isFlagged());
        assertTrue("expecting isSeen flag", msgFlags.isSeen());
        byte[] b = getBody(md);
        assertArrayEquals("content mismatch", msg.getBytes(), b);
    } finally {
        msg.dispose();
    }
}
Also used : MessageData(com.zimbra.cs.mailclient.imap.MessageData) Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.util.Date) Test(org.junit.Test)

Example 35 with MessageData

use of com.zimbra.cs.mailclient.imap.MessageData in project zm-mailbox by Zimbra.

the class SharedImapTests method testStoreInvalidSystemFlag.

@Test(timeout = 100000)
public void testStoreInvalidSystemFlag() throws Exception {
    connection = connectAndSelectInbox();
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    mbox.addMessage(Mailbox.ID_FOLDER_INBOX + "", "u", "", System.currentTimeMillis(), simpleMessage("foo"), true);
    connection.select("INBOX");
    Map<Long, MessageData> data = connection.fetch("1:*", "FLAGS");
    assertEquals(1, data.size());
    Iterator<Long> it = data.keySet().iterator();
    Long seq = it.next();
    storeInvalidFlag("\\Bulk", seq);
    storeInvalidFlag("\\Unread", seq);
    storeInvalidFlag("\\Forwarded", seq);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Test(org.junit.Test)

Aggregations

MessageData (com.zimbra.cs.mailclient.imap.MessageData)47 Test (org.junit.Test)33 ZMailbox (com.zimbra.client.ZMailbox)28 ZFolder (com.zimbra.client.ZFolder)19 Flags (com.zimbra.cs.mailclient.imap.Flags)16 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)14 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)11 ZTag (com.zimbra.client.ZTag)10 Body (com.zimbra.cs.mailclient.imap.Body)9 BodyStructure (com.zimbra.cs.mailclient.imap.BodyStructure)8 Envelope (com.zimbra.cs.mailclient.imap.Envelope)8 Literal (com.zimbra.cs.mailclient.imap.Literal)8 IOException (java.io.IOException)8 Date (java.util.Date)8 ServiceException (com.zimbra.common.service.ServiceException)7 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)6 MailException (com.zimbra.cs.mailclient.MailException)5 RemoteServiceException (com.zimbra.common.service.RemoteServiceException)4 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)4 Atom (com.zimbra.cs.mailclient.imap.Atom)4