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;
}
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);
}
}
}
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();
}
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());
}
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;
}
Aggregations