use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapHandler method doDELETE.
boolean doDELETE(String tag, ImapPath path) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
try {
if (!path.isVisible()) {
throw ImapServiceException.FOLDER_NOT_VISIBLE(path.asImapPath());
}
// don't want the DELETE to cause *this* connection to drop if the deleted folder is currently selected
if (getState() == State.SELECTED) {
ImapSession i4selected = getCurrentSession();
if (i4selected != null && path.isEquivalent(i4selected.getPath())) {
unsetSelectedFolder(true);
} else if (imapProxy != null && path.isEquivalent(imapProxy.getPath())) {
unsetSelectedFolder(true);
}
}
Object mboxobj = path.getOwnerMailbox();
if (path.useReferent()) {
// when users try to remove mountpoints, the IMAP client hard-deletes the subfolders!
// deal with this by only *pretending* to delete subfolders of mountpoints
credentials.hideFolder(path);
// even pretend-deleting the folder also unsubscribes from it...
credentials.unsubscribe(path);
} else if (mboxobj instanceof Mailbox) {
Mailbox mbox = (Mailbox) mboxobj;
Folder folder = (Folder) path.getFolder();
if (!folder.isDeletable()) {
throw ImapServiceException.CANNOT_DELETE_SYSTEM_FOLDER(folder.getPath());
}
if (!folder.hasSubfolders()) {
mbox.delete(getContext(), folder.getId(), MailItem.Type.FOLDER);
// deleting the folder also unsubscribes from it...
credentials.unsubscribe(path);
} else {
// 6.3.4: "It is permitted to delete a name that has inferior hierarchical
// names and does not have the \Noselect mailbox name attribute.
// In this case, all messages in that mailbox are removed, and the
// name will acquire the \Noselect mailbox name attribute."
mbox.emptyFolder(getContext(), folder.getId(), false);
// FIXME: add \Deleted flag to folder
}
} else if (mboxobj instanceof ZMailbox) {
ZMailbox zmbx = (ZMailbox) mboxobj;
ZFolder zfolder = (ZFolder) path.getFolder();
if (zfolder.getSubFolders().isEmpty()) {
zmbx.deleteFolder(zfolder.getId());
// deleting the folder also unsubscribes from it...
credentials.unsubscribe(path);
} else {
zmbx.emptyFolder(zfolder.getId(), false);
}
} else {
throw AccountServiceException.NO_SUCH_ACCOUNT(path.getOwner());
}
} catch (ServiceException e) {
if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("DELETE failed: no such folder: %s", path);
} else if (e.getCode().equals(AccountServiceException.NO_SUCH_ACCOUNT)) {
ZimbraLog.imap.info("DELETE failed: no such account: %s", path);
} else if (e.getCode().equals(ImapServiceException.FOLDER_NOT_VISIBLE)) {
ZimbraLog.imap.info("DELETE failed: folder not visible: %s", path);
} else if (e.getCode().equals(ImapServiceException.CANT_DELETE_SYSTEM_FOLDER)) {
ZimbraLog.imap.info("DELETE failed: system folder cannot be deleted: %s", path);
} else if (e.getCode().equals(ServiceException.PERM_DENIED)) {
ZimbraLog.imap.info("DELETE failed: permission denied: %s", path);
} else {
ZimbraLog.imap.warn("DELETE failed", e);
}
sendNO(tag, "DELETE failed");
return canContinue(e);
}
sendNotifications(true, false);
sendOK(tag, "DELETE completed");
return true;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapHandler method status.
String status(ImapPath path, byte status) throws ImapException, ServiceException {
StringBuilder data = new StringBuilder("STATUS ").append(path.asUtf7String()).append(" (");
int empty = data.length();
int messages, recent, uidnext, uvv, unread, modseq;
Object mboxobj = path.getOwnerMailbox();
if (mboxobj instanceof Mailbox) {
Mailbox mbox = (Mailbox) mboxobj;
Folder folder = (Folder) path.getFolder();
ImapFolder i4folder = getSelectedFolder();
messages = (int) folder.getItemCount();
if ((status & STATUS_RECENT) == 0) {
recent = -1;
} else if (messages == 0) {
recent = 0;
} else if (i4folder != null && path.isEquivalent(i4folder.getPath())) {
recent = i4folder.getRecentCount();
} else {
recent = mbox.getImapRecent(getContext(), folder.getId());
}
uidnext = folder instanceof SearchFolder ? -1 : folder.getImapUIDNEXT();
uvv = ImapFolder.getUIDValidity(folder);
unread = folder.getUnreadCount();
modseq = folder instanceof SearchFolder ? 0 : folder.getImapMODSEQ();
} else if (mboxobj instanceof ZMailbox) {
ZFolder zfolder = (ZFolder) path.getFolder();
if (zfolder == null) {
throw MailServiceException.NO_SUCH_FOLDER(path.asImapPath());
}
messages = zfolder.getImapMessageCount();
recent = 0;
uidnext = zfolder.getImapUIDNEXT();
uvv = ImapFolder.getUIDValidity(zfolder);
unread = zfolder.getImapUnreadCount();
modseq = zfolder.getImapMODSEQ();
} else {
throw AccountServiceException.NO_SUCH_ACCOUNT(path.getOwner());
}
if (messages >= 0 && (status & STATUS_MESSAGES) != 0) {
data.append(data.length() != empty ? " " : "").append("MESSAGES ").append(messages);
}
if (recent >= 0 && (status & STATUS_RECENT) != 0) {
data.append(data.length() != empty ? " " : "").append("RECENT ").append(recent);
}
// note: we're not supporting UIDNEXT for search folders; see the comments in selectFolder()
if (uidnext > 0 && (status & STATUS_UIDNEXT) != 0) {
data.append(data.length() != empty ? " " : "").append("UIDNEXT ").append(uidnext);
}
if (uvv > 0 && (status & STATUS_UIDVALIDITY) != 0) {
data.append(data.length() != empty ? " " : "").append("UIDVALIDITY ").append(uvv);
}
if (unread >= 0 && (status & STATUS_UNSEEN) != 0) {
data.append(data.length() != empty ? " " : "").append("UNSEEN ").append(unread);
}
if (modseq >= 0 && (status & STATUS_HIGHESTMODSEQ) != 0) {
data.append(data.length() != empty ? " " : "").append("HIGHESTMODSEQ ").append(modseq);
}
return data.append(')').toString();
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class ImapPath method getFolder.
Object getFolder() throws ServiceException {
if (useReferent()) {
return getReferent().getFolder();
}
if (mCredentials != null && mCredentials.isFolderHidden(this)) {
throw MailServiceException.NO_SUCH_FOLDER(asImapPath());
}
if (mFolder == null) {
Object mboxobj = getOwnerMailbox();
if (mboxobj instanceof Mailbox) {
Folder folder = ((Mailbox) mboxobj).getFolderByPath(getContext(), asZimbraPath());
mFolder = folder;
mItemId = new ItemId(folder);
} else if (mboxobj instanceof ZMailbox) {
ZFolder zfolder = ((ZMailbox) mboxobj).getFolderByPath(asZimbraPath());
mFolder = zfolder;
if (zfolder == null) {
throw MailServiceException.NO_SUCH_FOLDER(asImapPath());
}
mItemId = new ItemId(zfolder.getId(), mCredentials == null ? null : mCredentials.getAccountId());
} else {
throw AccountServiceException.NO_SUCH_ACCOUNT(getOwner());
}
}
return mFolder;
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestAccessKeyGrant method dumpGrants.
private void dumpGrants(ZMailbox mbox, String folderId) throws Exception {
ZFolder folder = mbox.getFolderRequestById(folderId);
System.out.println("--------------------");
System.out.println(mbox.getName() + ", folder=" + folderId);
List<ZGrant> grants = folder.getGrants();
for (ZGrant grant : grants) {
System.out.println(" type: " + grant.getGranteeType().toString());
System.out.println(" id: " + grant.getGranteeId());
System.out.println(" name: " + grant.getGranteeName());
System.out.println(" rights: " + grant.getPermissions());
if (grant.getGranteeType() == ZGrant.GranteeType.key)
System.out.println(" accesskey: " + grant.getArgs());
else if (grant.getGranteeType() == ZGrant.GranteeType.guest)
System.out.println(" password: " + grant.getArgs());
else
assertNull(grant.getArgs());
System.out.println();
}
}
use of com.zimbra.client.ZFolder in project zm-mailbox by Zimbra.
the class TestMountpoint method testInvalidMountpoint.
/**
* Tests {@link ZMailbox#getValidFolderIds(String)}.
*/
@Test
public void testInvalidMountpoint() throws Exception {
TestUtil.createAccount(USER_NAME);
TestUtil.createAccount(REMOTE_USER_NAME);
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
ZMailbox remoteMbox = TestUtil.getZMailbox(REMOTE_USER_NAME);
String remoteFolderPath = "/" + NAME_PREFIX + "-testInvalidMountpoint-remote";
ZFolder remoteFolder = TestUtil.createFolder(remoteMbox, remoteFolderPath);
ZMountpoint mountpoint = TestUtil.createMountpoint(remoteMbox, remoteFolderPath, mbox, NAME_PREFIX + "-mountpoint");
// Test valid mountpoint.
Set<String> folderIds = new HashSet<String>();
folderIds.add(mountpoint.getId());
String inboxId = Integer.toString(Mailbox.ID_FOLDER_INBOX);
folderIds.add(inboxId);
String idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
List<String> returnedIds = Arrays.asList(idString.split(","));
Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds", 2, returnedIds.size());
Assert.assertTrue("Returned IDs should contain ID of inbox", returnedIds.contains(inboxId));
Assert.assertTrue("Returned IDs should contain ID of mountpoint", returnedIds.contains(mountpoint.getId()));
Assert.assertEquals("Should be 1 comma in string returned by mbox.getValidFolderIds", 1, getNumCommas(idString));
// Delete remote folder and confirm that the id is no longer returned.
remoteMbox.deleteFolder(remoteFolder.getId());
idString = mbox.getValidFolderIds(StringUtil.join(",", folderIds));
returnedIds = Arrays.asList(idString.split(","));
Assert.assertEquals("Number of return IDs from mbox.getValidFolderIds after mountpoint delete", 1, returnedIds.size());
Assert.assertTrue("Returned IDs should contain ID of inbox after mp delete", returnedIds.contains(inboxId));
Assert.assertEquals("Should no commas in string returned by mbox.getValidFolderIds after mp delete", 0, getNumCommas(idString));
}
Aggregations