use of com.zimbra.common.mailbox.SearchFolderStore in project zm-mailbox by Zimbra.
the class ImapHandler method getFolderAttrs.
private String getFolderAttrs(ImapPath path, byte returnOptions, Map<ImapPath, ItemId> paths, Set<String> subscriptions, boolean isMounted) throws ServiceException {
StringBuilder attrs = new StringBuilder();
ItemId iid = paths.get(path);
if (iid == null) {
attrs.append(attrs.length() == 0 ? "" : " ").append("\\NonExistent");
}
try {
if ((returnOptions & RETURN_SUBSCRIBED) != 0 && isPathSubscribed(path, subscriptions)) {
attrs.append(attrs.length() == 0 ? "" : " ").append("\\Subscribed");
}
} catch (NoSuchItemException nsie) {
ZimbraLog.imap.debug("Subscribed path \"%s\" is not available on server.", path.asImapPath());
}
if (iid == null) {
return attrs.toString();
}
boolean noinferiors = (iid.getId() == Mailbox.ID_FOLDER_SPAM);
if (noinferiors) {
attrs.append(attrs.length() == 0 ? "" : " ").append("\\NoInferiors");
}
if (!path.isSelectable()) {
attrs.append(attrs.length() == 0 ? "" : " ").append("\\NoSelect");
}
if (!noinferiors && (returnOptions & RETURN_CHILDREN) != 0) {
String prefix = path.asZimbraPath().toUpperCase() + '/';
boolean children = false;
for (ImapPath other : paths.keySet()) {
if (other.asZimbraPath().toUpperCase().startsWith(prefix) && other.isVisible()) {
children = true;
break;
}
}
attrs.append(attrs.length() == 0 ? "" : " ").append(children ? "\\HasChildren" : "\\HasNoChildren");
}
// we also keep support for non-standard XLIST attributes for legacy clients that may still use them
if (!isMounted && (DebugConfig.imapForceSpecialUse || (returnOptions & RETURN_XLIST) != 0) && path.belongsTo(credentials)) {
// return deprecated XLIST attrs if requested
boolean returnXList = (returnOptions & RETURN_XLIST) != 0;
switch(iid.getId()) {
case Mailbox.ID_FOLDER_INBOX:
if (returnXList) {
attrs.append(attrs.length() == 0 ? "" : " ").append("\\Inbox");
}
break;
case Mailbox.ID_FOLDER_DRAFTS:
attrs.append(attrs.length() == 0 ? "" : " ").append("\\Drafts");
break;
case Mailbox.ID_FOLDER_TRASH:
attrs.append(attrs.length() == 0 ? "" : " ").append("\\Trash");
break;
case Mailbox.ID_FOLDER_SENT:
attrs.append(attrs.length() == 0 ? "" : " ").append("\\Sent");
break;
case Mailbox.ID_FOLDER_SPAM:
attrs.append(attrs.length() == 0 ? "" : " ").append(returnXList ? "\\Spam" : "\\Junk");
break;
default:
String query = path.getFolder() instanceof SearchFolderStore ? ((SearchFolderStore) path.getFolder()).getQuery() : null;
if (query != null) {
if (query.equalsIgnoreCase("is:flagged")) {
attrs.append(attrs.length() == 0 ? "" : " ").append(returnXList ? "\\Starred" : "\\Flagged");
} else if (query.equalsIgnoreCase("is:local")) {
attrs.append(attrs.length() == 0 ? "" : " ").append(returnXList ? "\\AllMail" : "\\All");
}
}
break;
}
}
return attrs.toString();
}
use of com.zimbra.common.mailbox.SearchFolderStore in project zm-mailbox by Zimbra.
the class ImapSessionManager method cacheKey.
private String cacheKey(FolderStore folder, boolean active) {
MailboxStore mbox = folder.getMailboxStore();
int modseq = folder instanceof SearchFolderStore ? mbox.getLastChangeID() : folder.getImapMODSEQ();
int uvv = folder instanceof SearchFolderStore ? mbox.getLastChangeID() : ImapFolder.getUIDValidity(folder);
String acctId = null;
try {
acctId = mbox.getAccountId();
} catch (ServiceException e) {
acctId = "<unknown>";
}
if (active) {
// use '_' as separator
return String.format("%s_%d_%d_%d", acctId, folder.getFolderIdInOwnerMailbox(), modseq, uvv);
} else {
// use ':' as a separator
return String.format("%s:%d:%d:%d", acctId, folder.getFolderIdInOwnerMailbox(), modseq, uvv);
}
}
use of com.zimbra.common.mailbox.SearchFolderStore in project zm-mailbox by Zimbra.
the class ImapSessionManager method openFolder.
protected FolderDetails openFolder(ImapPath path, byte params, ImapHandler handler) throws ServiceException {
ZimbraLog.imap.debug("opening folder: %s", path);
if (!path.isSelectable()) {
throw ServiceException.PERM_DENIED("cannot select folder: " + path);
}
if ((params & ImapFolder.SELECT_CONDSTORE) != 0) {
handler.activateExtension(ImapExtension.CONDSTORE);
}
FolderStore folder = path.getFolder();
String folderIdAsString = folder.getFolderIdAsString();
int folderId = folder.getFolderIdInOwnerMailbox();
MailboxStore mbox = folder.getMailboxStore();
ImapMailboxStore imapStore = ImapMailboxStore.get(mbox);
// don't have a session when the folder is loaded...
OperationContext octxt = handler.getCredentials().getContext();
List<ImapMessage> i4list = null;
// *always* recalculate the contents of search folders
if (folder instanceof SearchFolderStore) {
i4list = loadVirtualFolder(octxt, (SearchFolderStore) folder);
} else {
waitForWaitSetNotifications(imapStore, folder);
}
mbox.lock(true);
try {
// need mInitialRecent to be set *before* loading the folder so we can determine what's \Recent
if (!(folder instanceof ZSharedFolder)) {
folder = mbox.getFolderById(octxt, folderIdAsString);
if (folder == null) {
throw MailServiceException.NO_SUCH_FOLDER(path.asImapPath());
}
}
int recentCutoff = imapStore.getImapRECENTCutoff(folder);
if (i4list == null) {
List<ImapListener> listners = imapStore.getListeners(folder);
// first option is to duplicate an existing registered session
// (could try to just activate an inactive session, but this logic is simpler for now)
i4list = duplicateExistingSession(folderId, listners);
// no matching session means we next check for serialized folder data
if (i4list == null) {
i4list = duplicateSerializedFolder(folder);
} else if (CONSISTENCY_CHECK) {
Collections.sort(i4list);
// sort only if using list from duplicated session which may be out of order
// if loaded from serialized folder order _should_ already be OK since no changes have occurred
}
// do the consistency check, if requested
if (CONSISTENCY_CHECK) {
i4list = consistencyCheck(i4list, imapStore, octxt, folder);
}
// no matching serialized session means we have to go to the DB to get the messages
if (i4list == null) {
ItemIdentifier ident;
if (folder instanceof MountpointStore) {
ident = ((MountpointStore) folder).getTargetItemIdentifier();
} else {
ident = folder.getFolderItemIdentifier();
}
i4list = imapStore.openImapFolder(octxt, ident);
}
}
Collections.sort(i4list);
// check messages for imapUid <= 0 and assign new IMAP IDs if necessary
renumberMessages(octxt, mbox, i4list);
ImapFolder i4folder = new ImapFolder(path, params, handler);
// don't rely on the <code>Folder</code> object being updated in place
if (!(folder instanceof ZSharedFolder)) {
folder = mbox.getFolderById(octxt, folderIdAsString);
}
// can't set these until *after* loading the folder because UID renumbering affects them
InitialFolderValues initial = new InitialFolderValues(folder);
for (ImapMessage i4msg : i4list) {
i4folder.cache(i4msg, i4msg.imapUid > recentCutoff);
if (initial.firstUnread == -1 && (i4msg.flags & Flag.BITMASK_UNREAD) != 0) {
initial.firstUnread = i4msg.sequence;
}
}
i4folder.setInitialSize();
ZimbraLog.imap.debug("ImapSessionManager.openFolder. Folder with id=%s added message list %s", folderIdAsString, i4list);
ImapListener session = null;
try {
session = imapStore.createListener(i4folder, handler);
session.register();
sessions.put(session, session);
imapStore.registerWithImapServerListener(session);
return new FolderDetails(session, initial);
} catch (ServiceException e) {
if (session != null) {
session.unregister();
}
throw e;
}
} finally {
mbox.unlock();
}
}
Aggregations