Search in sources :

Example 1 with ZSearchFolder

use of com.zimbra.client.ZSearchFolder in project zm-mailbox by Zimbra.

the class SharedImapTests method savedSearch.

@Test(timeout = 100000)
public void savedSearch() throws ServiceException, IOException, MessagingException {
    ZMailbox mbox = TestUtil.getZMailbox(USER);
    String subjectPrefix = String.format("%s test message ", testId);
    TestUtil.addMessage(mbox, subjectPrefix + "1", ZFolder.ID_INBOX);
    TestUtil.addMessage(mbox, subjectPrefix + "2", ZFolder.ID_DRAFTS);
    TestUtil.addMessage(mbox, subjectPrefix + "3 - does not match search", ZFolder.ID_SENT);
    String folderName = "searchFolderInDraftsOrInOnbox";
    ZSearchFolder srchFolder = mbox.createSearchFolder(ZFolder.ID_USER_ROOT, folderName, "in:drafts or in:inbox", ZSearchParams.TYPE_CONVERSATION, SearchSortBy.nameAsc, ZFolder.Color.ORANGE);
    assertNotNull("SearchFolder in Response to CreateSearchFolderRequest should not be null", srchFolder);
    connection = this.connectAndLogin(USER);
    List<ListData> listResult;
    // LIST "" "mountpointName"
    doListShouldSucceed(connection, "", folderName, Lists.newArrayList(folderName), "Just search folder");
    listResult = connection.list("", "*");
    assertNotNull("list result 'list \"\" \"*\"' should not be null", listResult);
    boolean seenIt = false;
    for (ListData listEnt : listResult) {
        if (folderName.equals(listEnt.getMailbox())) {
            seenIt = true;
            break;
        }
    }
    assertTrue(String.format("'%s' mailbox not in result of 'list \"\" \"*\"'", folderName), seenIt);
    connection.select(folderName);
    Map<Long, MessageData> mdMap = connection.fetch("1:*", "(ENVELOPE)");
    assertEquals("Size of map returned by fetch", 2, mdMap.size());
    Iterator<MessageData> iter = mdMap.values().iterator();
    while (iter.hasNext()) {
        MessageData md = iter.next();
        assertNotNull("MessageData", md);
        Envelope env = md.getEnvelope();
        assertNotNull("Envelope", env);
        assertTrue(String.format("Message subject was '%s' expected to contain '%s'", env.getSubject(), subjectPrefix), env.getSubject().contains(subjectPrefix));
    }
    connection.logout();
    connection = null;
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) MessageData(com.zimbra.cs.mailclient.imap.MessageData) Envelope(com.zimbra.cs.mailclient.imap.Envelope) ZSearchFolder(com.zimbra.client.ZSearchFolder) ListData(com.zimbra.cs.mailclient.imap.ListData) Test(org.junit.Test)

Example 2 with ZSearchFolder

use of com.zimbra.client.ZSearchFolder in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doDumpFolder.

private void doDumpFolder(ZFolder folder, boolean recurse) {
    String path;
    if (folder instanceof ZSearchFolder) {
        path = String.format("%s (%s)", folder.getPath(), ((ZSearchFolder) folder).getQuery());
    } else if (folder instanceof ZMountpoint) {
        ZMountpoint mp = (ZMountpoint) folder;
        path = String.format("%s (%s:%s)", folder.getPath(), mp.getOwnerDisplayName(), mp.getRemoteId());
    } else if (folder.getRemoteURL() != null) {
        path = String.format("%s (%s)", folder.getPath(), folder.getRemoteURL());
    } else {
        path = folder.getPath();
    }
    stdout.format("%10.10s  %4.4s  %10d  %10d  %s%n", folder.getId(), folder.getDefaultView().name(), folder.getUnreadCount(), folder.getMessageCount(), path);
    if (recurse) {
        for (ZFolder child : folder.getSubFolders()) {
            doDumpFolder(child, recurse);
        }
    }
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) ZFolder(com.zimbra.client.ZFolder) ZSearchFolder(com.zimbra.client.ZSearchFolder)

Example 3 with ZSearchFolder

use of com.zimbra.client.ZSearchFolder in project zm-mailbox by Zimbra.

the class ImapPath method isValidImapPath.

/**
     * Mostly checking that the path doesn't clash with any paths we don't want to expose via IMAP.
     * Separated out from isVisible() to aid IMAP LSUB command support.
     */
boolean isValidImapPath() throws ServiceException {
    if (mCredentials != null) {
        if (mCredentials.isHackEnabled(ImapCredentials.EnabledHack.WM5)) {
            String lcname = mPath.toLowerCase();
            if (lcname.startsWith("sent items") && (lcname.length() == 10 || lcname.charAt(10) == '/'))
                return false;
        }
    }
    try {
        // you cannot access your own mailbox via the /home/username mechanism
        if (mOwner != null && belongsTo(mCredentials))
            return false;
        getFolder();
        if (mFolder instanceof Folder) {
            Folder folder = (Folder) mFolder;
            // hide all system folders and the user root folder
            if (folder.getId() == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
                return false;
            }
            // hide spam folder unless anti-spam feature is enabled.
            if (folder.getId() == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
                return false;
            }
            boolean isMailFolders = Provisioning.getInstance().getLocalServer().isImapDisplayMailFoldersOnly();
            if (!isVisible(folder.getDefaultView(), isMailFolders)) {
                return false;
            }
            // hide subfolders of trashed mountpoints
            if (mReferent != this && folder.inTrash() && !((Mountpoint) folder).getTarget().equals(mReferent.asItemId())) {
                return false;
            }
            // hide other users' mountpoints and mountpoints that point to the same mailbox
            if (folder instanceof Mountpoint && mReferent == this && mScope != Scope.UNPARSED) {
                return false;
            }
            // search folder visibility depends on an account setting
            if (folder instanceof SearchFolder) {
                return ((SearchFolder) folder).isImapVisible() && ImapFolder.getTypeConstraint((SearchFolder) folder).size() > 0;
            }
        } else {
            ZFolder zfolder = (ZFolder) mFolder;
            int folderId = asItemId().getId();
            // the mailbox root folder is not visible
            if (folderId == Mailbox.ID_FOLDER_USER_ROOT && mScope != Scope.REFERENCE) {
                return false;
            }
            // hide spam folder unless anti-spam feature is enabled.
            if (folderId == Mailbox.ID_FOLDER_SPAM && !getOwnerAccount().isFeatureAntispamEnabled()) {
                return false;
            }
            // calendars, briefcases, etc. are not surfaced in IMAP
            ZFolder.View view = zfolder.getDefaultView();
            if (view == ZFolder.View.appointment || view == ZFolder.View.task || view == ZFolder.View.wiki || view == ZFolder.View.document) {
                return false;
            }
            // hide other users' mountpoints and mountpoints that point to the same mailbox
            if (zfolder instanceof ZMountpoint && mReferent == this && mScope != Scope.UNPARSED) {
                return false;
            }
            // hide all remote searchfolders
            if (zfolder instanceof ZSearchFolder) {
                return false;
            }
        }
    } catch (NoSuchItemException ignore) {
    // 6.3.9.  LSUB Command
    //   The server MUST NOT unilaterally remove an existing mailbox name from the subscription list even if a
    //   mailbox by that name no longer exists.
    } catch (AccountServiceException ase) {
        if (!AccountServiceException.NO_SUCH_ACCOUNT.equals(ase.getCode())) {
            throw ase;
        }
    } catch (ServiceException se) {
        if (ServiceException.PERM_DENIED.equals(se.getCode())) {
            // Path probably OK.  For subscriptions, don't disallow path for possibly temporary permissions issue
            return true;
        }
        throw se;
    }
    return mReferent == this ? true : mReferent.isValidImapPath();
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) ZSearchFolder(com.zimbra.client.ZSearchFolder) ZFolder(com.zimbra.client.ZFolder) SearchFolder(com.zimbra.cs.mailbox.SearchFolder) Folder(com.zimbra.cs.mailbox.Folder) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZFolder(com.zimbra.client.ZFolder) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZSearchFolder(com.zimbra.client.ZSearchFolder)

Example 4 with ZSearchFolder

use of com.zimbra.client.ZSearchFolder in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doCreateSearchFolder.

private void doCreateSearchFolder(String[] args) throws ServiceException {
    ZSearchFolder csf = mMbox.createSearchFolder(lookupFolderId(args[0], true), ZMailbox.getBasePath(args[0]), args[1], typesOpt(), searchSortByOpt(), folderColorOpt());
    stdout.println(csf.getId());
}
Also used : ZSearchFolder(com.zimbra.client.ZSearchFolder)

Example 5 with ZSearchFolder

use of com.zimbra.client.ZSearchFolder in project zm-mailbox by Zimbra.

the class TestZClient method doCreateSearchFolder.

private ZSearchFolder doCreateSearchFolder(ZMailbox zmbox, String parentId, String name, String query, String types, SearchSortBy sortBy, ZFolder.Color color) throws ServiceException {
    try {
        ZSearchFolder sf = zmbox.createSearchFolder(parentId, name, query, types, sortBy, color);
        assertNotNull(String.format("createSearchFolder failed for '%s' returned null ZSearchFolder", name), sf);
        assertEquals("Name of folder created by createSearchFolder", name, sf.getName());
        assertEquals("Query of folder created by createSearchFolder", query, sf.getQuery());
        if (null != color) {
            assertEquals("Color of folder created by createSearchFolder", color, sf.getColor());
        }
        if (null != sortBy) {
            assertEquals("SortBy of folder created by createSearchFolder", sortBy, sf.getSortBy());
        }
    } catch (Exception e) {
        fail(String.format("createSearchFolder failed for '%s'", name));
    }
    return null;
}
Also used : SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) AuthTokenException(com.zimbra.cs.account.AuthTokenException) ZClientException(com.zimbra.common.zclient.ZClientException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) MessagingException(javax.mail.MessagingException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ZSearchFolder(com.zimbra.client.ZSearchFolder)

Aggregations

ZSearchFolder (com.zimbra.client.ZSearchFolder)5 ZFolder (com.zimbra.client.ZFolder)2 ZMountpoint (com.zimbra.client.ZMountpoint)2 ServiceException (com.zimbra.common.service.ServiceException)2 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 ZMailbox (com.zimbra.client.ZMailbox)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 ZClientException (com.zimbra.common.zclient.ZClientException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 Folder (com.zimbra.cs.mailbox.Folder)1 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)1 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)1 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)1 Envelope (com.zimbra.cs.mailclient.imap.Envelope)1 ListData (com.zimbra.cs.mailclient.imap.ListData)1 MessageData (com.zimbra.cs.mailclient.imap.MessageData)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1