Search in sources :

Example 16 with Flags

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

the class TestImapThrottle method search.

@Test
public void search() throws IOException {
    Flags flags = Flags.fromSpec("afs");
    for (int i = 0; i < 3; i++) {
        Date date = new Date(System.currentTimeMillis());
        Literal msg = message(1000 + i * 1000);
        try {
            connection.append("INBOX", flags, date, msg);
        } finally {
            msg.dispose();
        }
    }
    for (int i = 0; i < LOOP_LIMIT; i++) {
        connection.search((Object[]) new String[] { "TEXT", "\"XXXXX\"" });
    }
    try {
        connection.search((Object[]) new String[] { "TEXT", "\"XXXXX\"" });
        Assert.fail("should have been rejected");
    } catch (CommandFailedException e) {
        Assert.assertTrue(connection.isClosed());
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 17 with Flags

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

the class TestImapThrottle method append.

@Test
public void append() throws Exception {
    assertTrue(connection.hasCapability("UIDPLUS"));
    Date date = new Date(System.currentTimeMillis());
    Flags flags = Flags.fromSpec("afs");
    for (int i = 0; i < LOOP_LIMIT; i++) {
        Literal msg = message(100000);
        try {
            connection.append("INBOX", flags, date, msg);
        } finally {
            msg.dispose();
        }
    }
    Literal msg = message(100000);
    try {
        connection.append("INBOX", flags, date, msg);
        Assert.fail("expected exception here...");
    } catch (Exception e) {
        Assert.assertTrue(connection.isClosed());
    } finally {
        msg.dispose();
    }
}
Also used : Literal(com.zimbra.cs.mailclient.imap.Literal) Flags(com.zimbra.cs.mailclient.imap.Flags) Date(java.sql.Date) IOException(java.io.IOException) ServiceException(com.zimbra.common.service.ServiceException) CommandFailedException(com.zimbra.cs.mailclient.CommandFailedException) Test(org.junit.Test)

Example 18 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 19 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 20 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)

Aggregations

Flags (com.zimbra.cs.mailclient.imap.Flags)21 Test (org.junit.Test)14 Date (java.sql.Date)13 Literal (com.zimbra.cs.mailclient.imap.Literal)12 CommandFailedException (com.zimbra.cs.mailclient.CommandFailedException)10 MessageData (com.zimbra.cs.mailclient.imap.MessageData)5 AppendResult (com.zimbra.cs.mailclient.imap.AppendResult)4 ImapRequest (com.zimbra.cs.mailclient.imap.ImapRequest)4 ImapResponse (com.zimbra.cs.mailclient.imap.ImapResponse)4 MailboxInfo (com.zimbra.cs.mailclient.imap.MailboxInfo)4 ServiceException (com.zimbra.common.service.ServiceException)3 IOException (java.io.IOException)3 ZFolder (com.zimbra.client.ZFolder)2 ZMailbox (com.zimbra.client.ZMailbox)2 ZTag (com.zimbra.client.ZTag)2 ResponseHandler (com.zimbra.cs.mailclient.imap.ResponseHandler)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Body (com.zimbra.cs.mailclient.imap.Body)1 FetchResponseHandler (com.zimbra.cs.mailclient.imap.FetchResponseHandler)1 MailboxName (com.zimbra.cs.mailclient.imap.MailboxName)1