Search in sources :

Example 26 with Flags

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

the class TestImap method testAppend.

@Test
public void testAppend() throws Exception {
    assertTrue(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(res);
        byte[] b = fetchBody(res.getUid());
        assertArrayEquals("content mismatch", msg.getBytes(), b);
    } finally {
        msg.dispose();
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) AppendResult(com.zimbra.cs.mailclient.imap.AppendResult) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) Test(org.junit.Test)

Example 27 with Flags

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

the class ImapFolderSync method updateImapTrashFolderId.

private void updateImapTrashFolderId(ListData ld) throws ServiceException {
    Flags flags = ld.getFlags();
    if (flags.isSet("\\Trash") && ds.getImapTrashFolderId() != localFolder.getId()) {
        Map<String, Object> attrs = new HashMap<String, Object>();
        attrs.put(Provisioning.A_zimbraDataSourceImapTrashFolderId, localFolder.getId());
        ds.getProvisioning().modifyDataSource(ds.getAccount(), ds.getId(), attrs);
    }
}
Also used : HashMap(java.util.HashMap) Flags(com.zimbra.cs.mailclient.imap.Flags)

Example 28 with Flags

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

the class ImapSync method getLocalPath.

/*
     * Returns the path to the Zimbra folder that stores messages for the given
     * IMAP folder. The Zimbra folder has the same path as the IMAP folder,
     * but is relative to the root folder specified by the DataSource.
     */
String getLocalPath(ListData ld) throws ServiceException {
    String remotePath = ld.getMailbox();
    char localDelimiter = ld.getDelimiter();
    String relativePath = ld.getMailbox();
    Flags flags = ld.getFlags();
    if (localDelimiter != '/' && (remotePath.indexOf(localDelimiter) >= 0 || remotePath.indexOf('/') >= 0)) {
        // Change remote path to use our separator
        String[] parts = remotePath.split("\\" + localDelimiter);
        for (int i = 0; i < parts.length; i++) {
            // TODO Handle case where separator is not valid in Zimbra folder name
            parts[i] = parts[i].replace('/', localDelimiter);
        }
        relativePath = StringUtil.join("/", parts);
    }
    relativePath = ILLEGAL_FOLDER_CHARS.matcher(relativePath).replaceAll("_");
    if (dataSource.ignoreRemotePath(relativePath, flags)) {
        // Do not synchronize folder
        return null;
    }
    String localPath = joinPath(localRootFolder.getPath(), coalesce(dataSource.mapRemoteToLocalPath(relativePath, flags), relativePath));
    if (isUniqueLocalPathNeeded(localPath)) {
        int count = 1;
        for (; ; ) {
            String path = String.format("%s-%d", localPath, count++);
            if (LocalFolder.fromPath(mbox, path) == null) {
                return path;
            }
        }
    } else {
        return localPath;
    }
}
Also used : Flags(com.zimbra.cs.mailclient.imap.Flags)

Example 29 with Flags

use of com.zimbra.cs.mailclient.imap.Flags 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 30 with Flags

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

the class SharedImapNotificationTests method testRenameTagNotificationActiveFolder.

@Test
public void testRenameTagNotificationActiveFolder() throws Exception {
    String folderName = "TestRemoteImapNotifications-folder";
    String tagName = "TestRemoteImapNotifications-tag";
    String newTagName = "TestRemoteImapNotifications-tag2";
    String subject = "TestRemoteImapNotifications-testMessage";
    ZMailbox zmbox = TestUtil.getZMailbox(USER);
    ZFolder folder = TestUtil.createFolder(zmbox, folderName);
    ZTag tag = zmbox.createTag(tagName, Color.blue);
    zmbox.addMessage(folder.getId(), null, tag.getId(), 0, TestUtil.getTestMessage(subject), true);
    connection = connect();
    connection.login(PASS);
    MailboxInfo info = connection.select(folderName);
    Flags flags = info.getPermanentFlags();
    assertTrue(flags.contains(new Atom(tagName)));
    MailboxOperation renameTag = new MailboxOperation() {

        @Override
        protected void run(ZMailbox zmbox) throws Exception {
            zmbox.renameTag(tag.getId(), newTagName);
        }

        @Override
        protected String checkResult() throws Exception {
            MailboxInfo info = connection.select(folderName);
            Flags flags = info.getPermanentFlags();
            if (flags.contains(new Atom(tagName))) {
                return String.format("Permanent flags should not contain %s", tagName);
            }
            if (!flags.contains(new Atom(newTagName))) {
                return String.format("Permanent flags should contain %s", newTagName);
            }
            return null;
        }
    };
    runOp(renameTag, zmbox, folder);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder) ZTag(com.zimbra.client.ZTag) MailboxInfo(com.zimbra.cs.mailclient.imap.MailboxInfo) Flags(com.zimbra.cs.mailclient.imap.Flags) Atom(com.zimbra.cs.mailclient.imap.Atom) Test(org.junit.Test)

Aggregations

Flags (com.zimbra.cs.mailclient.imap.Flags)44 Test (org.junit.Test)35 Literal (com.zimbra.cs.mailclient.imap.Literal)26 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)21 MessageData (com.zimbra.cs.mailclient.imap.MessageData)16 Date (java.sql.Date)14 Date (java.util.Date)14 ZMailbox (com.zimbra.client.ZMailbox)12 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)11 ZTag (com.zimbra.client.ZTag)10 ZFolder (com.zimbra.client.ZFolder)8 ServiceException (com.zimbra.common.service.ServiceException)7 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)7 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)7 IOException (java.io.IOException)7 Atom (com.zimbra.cs.mailclient.imap.Atom)6 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)6 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)5 MessagingException (javax.mail.MessagingException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2