use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.
the class ImapHandler method doUNSUBSCRIBE.
private boolean doUNSUBSCRIBE(String tag, ImapPath path) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
try {
if (path.belongsTo(credentials)) {
try {
FolderStore folder = path.getFolder();
if (folder.isIMAPSubscribed()) {
path.getOwnerMailbox().flagFolderAsUnsubscribed(getContext(), folder);
}
} catch (NoSuchItemException e) {
}
}
// always check for remote subscriptions -- the path might be an old mountpoint...
credentials.unsubscribe(path);
} catch (MailServiceException.NoSuchItemException nsie) {
ZimbraLog.imap.info("UNSUBSCRIBE failure skipped: no such folder: %s", path);
} catch (ServiceException e) {
ZimbraLog.imap.warn("UNSUBSCRIBE failed", e);
sendNO(tag, "UNSUBSCRIBE failed");
return canContinue(e);
}
sendNotifications(true, false);
sendOK(tag, "UNSUBSCRIBE completed");
return true;
}
use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.
the class ImapListener method handleModify.
protected void handleModify(int changeId, Change chg, AddedItems added) {
if (chg.what instanceof ZimbraTag && (chg.why & Change.NAME) != 0) {
mFolder.handleTagRename(changeId, (ZimbraTag) chg.what, chg);
} else {
boolean isFolder = (chg.what instanceof BaseItemInfo && ((BaseItemInfo) chg.what).getMailItemType() == MailItemType.FOLDER);
boolean isMsgOrContact = false;
BaseItemInfo item = null;
if (chg.what instanceof BaseItemInfo) {
item = (BaseItemInfo) chg.what;
isMsgOrContact = (item.getMailItemType() == MailItemType.MESSAGE || item.getMailItemType() == MailItemType.CONTACT);
}
try {
if (isFolder && ((BaseFolderInfo) chg.what).getFolderIdInOwnerMailbox() == folderId.id) {
FolderStore folder = (FolderStore) chg.what;
// here we assume that the FolderStore object also implements BaseItemInfo
if ((chg.why & Change.FLAGS) != 0 && (((BaseItemInfo) folder).getFlagBitmask() & Flag.BITMASK_DELETED) != 0) {
// mailbox accessed by sending a untagged BYE response."
if (handler != null) {
handler.close();
}
} else if ((chg.why & (Change.FOLDER | Change.NAME)) != 0) {
mFolder.handleFolderRename(changeId, folder, chg);
}
} else if (isMsgOrContact) {
boolean inFolder = mIsVirtual || item.getFolderIdInMailbox() == folderId.id;
if (!inFolder && (chg.why & Change.FOLDER) == 0) {
return;
}
mFolder.handleItemUpdate(changeId, chg, added);
}
} catch (ServiceException e) {
ZimbraLog.imap.warn("error handling modified items for changeId %s", changeId, e);
return;
}
}
}
use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.
the class ImapHandler method doGETACL.
private boolean doGETACL(String tag, ImapPath path) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
StringBuilder i4acl = new StringBuilder("ACL ").append(path.asUtf7String());
try {
// make sure the requester has sufficient permissions to make the request
if ((path.getFolderRights() & ACL.RIGHT_ADMIN) == 0) {
ZimbraLog.imap.info("GETACL failed: user does not have admin access: %s", path);
sendNO(tag, "GETACL failed");
return true;
}
// the target folder's owner always has full rights
Account owner = path.getOwnerAccount();
if (owner != null) {
i4acl.append(" \"").append(owner.getName()).append("\" ").append(IMAP_CONCATENATED_RIGHTS);
}
// write out the grants to all users and groups
Short anyoneRights = null;
FolderStore folderStore = path.getFolder();
if (null != folderStore) {
for (ACLGrant grant : folderStore.getACLGrants()) {
GrantGranteeType gType = grant.getGrantGranteeType();
short rights = ACL.stringToRights(grant.getPermissions());
if (gType == GrantGranteeType.pub || gType == GrantGranteeType.all) {
anyoneRights = (short) ((anyoneRights == null ? 0 : anyoneRights) | rights);
} else if (gType == GrantGranteeType.usr || gType == GrantGranteeType.grp) {
NamedEntry entry = FolderAction.lookupGranteeByZimbraId(grant.getGranteeId(), gType.asByte());
if (entry != null) {
i4acl.append(" \"").append(entry.getName()).append("\" ").append(exportRights(rights));
}
}
}
}
// aggregate all the "public" and "auth user" grants into the "anyone" IMAP ACL
if (anyoneRights != null) {
i4acl.append(" anyone ").append(exportRights(anyoneRights));
}
} catch (ServiceException e) {
if (e.getCode().equals(ServiceException.PERM_DENIED)) {
ZimbraLog.imap.info("GETACL failed: permission denied on folder: %s", path);
} else if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("GETACL failed: no such folder: %s", path);
} else {
ZimbraLog.imap.warn("GETACL failed", e);
}
sendNO(tag, "GETACL failed");
return true;
}
sendUntagged(i4acl.toString());
sendNotifications(true, false);
sendOK(tag, "GETACL completed");
return true;
}
use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.
the class ImapHandler method doAPPEND.
private boolean doAPPEND(String tag, ImapPath path, List<AppendMessage> appends) throws IOException, ImapException {
checkCommandThrottle(new AppendCommand(path, appends));
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
ImapMailboxStore mboxStore = null;
List<Integer> createdIds = new ArrayList<Integer>(appends.size());
StringBuilder appendHint = extensionEnabled("UIDPLUS") ? new StringBuilder() : null;
OperationContext octxt = getContextOrNull();
try {
if (!path.isVisible()) {
throw ImapServiceException.FOLDER_NOT_VISIBLE(path.asImapPath());
} else if (!path.isWritable(ACL.RIGHT_INSERT)) {
throw ImapServiceException.FOLDER_NOT_WRITABLE(path.asImapPath());
}
mboxStore = path.getOwnerImapMailboxStore();
mboxStore.checkAppendMessageFlags(octxt, appends);
FolderStore folderStore = path.getFolder();
// Append message parts and check message content size
for (AppendMessage append : appends) {
append.checkContent();
}
for (AppendMessage append : appends) {
int id = append.storeContent(mboxStore, folderStore);
if (id > 0) {
createdIds.add(id);
}
}
int uvv = folderStore.getUIDValidity();
if (appendHint != null && uvv > 0) {
appendHint.append("[APPENDUID ").append(uvv).append(' ').append(ImapFolder.encodeSubsequence(createdIds)).append("] ");
}
} catch (ZClientUploadSizeLimitExceededException zcusle) {
ZimbraLog.imap.debug("upload limit hit", zcusle);
throw new ImapMaximumSizeExceededException(tag, "message");
} catch (ServiceException e) {
for (AppendMessage append : appends) {
append.cleanup();
}
if (null != mboxStore) {
mboxStore.deleteMessages(octxt, createdIds);
}
String msg = "APPEND failed";
if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("APPEND failed: no such folder: " + path);
// of the text of the tagged NO response."
if (path.isCreatable()) {
msg = "[TRYCREATE] APPEND failed: no such mailbox";
}
} else if (e.getCode().equals(MailServiceException.INVALID_NAME)) {
ZimbraLog.imap.info("APPEND failed: " + e.getMessage());
} else if (e.getCode().equals(ImapServiceException.FOLDER_NOT_VISIBLE)) {
ZimbraLog.imap.info("APPEND failed: folder not visible: " + path);
} else if (e.getCode().equals(ImapServiceException.FOLDER_NOT_WRITABLE)) {
ZimbraLog.imap.info("APPEND failed: folder not writable: " + path);
} else if (e.getCode().equals(MailServiceException.QUOTA_EXCEEDED)) {
ZimbraLog.imap.info("APPEND failed: quota exceeded");
} else {
ZimbraLog.imap.warn("APPEND failed", e);
}
sendNO(tag, msg);
return canContinue(e);
}
sendNotifications(true, false);
sendOK(tag, (appendHint == null ? "" : appendHint.toString()) + "APPEND completed");
return true;
}
use of com.zimbra.common.mailbox.FolderStore in project zm-mailbox by Zimbra.
the class ImapHandler method doRENAME.
private boolean doRENAME(String tag, ImapPath oldPath, ImapPath newPath) throws IOException {
if (!checkState(tag, State.AUTHENTICATED)) {
return true;
}
try {
Account source = oldPath.getOwnerAccount();
Account target = newPath.getOwnerAccount();
if (source == null || target == null) {
ZimbraLog.imap.info("RENAME failed: no such account for %s or %s", oldPath, newPath);
sendNO(tag, "RENAME failed: no such account");
return true;
} else if (!source.getId().equalsIgnoreCase(target.getId())) {
ZimbraLog.imap.info("RENAME failed: cannot move folder between mailboxes");
sendNO(tag, "RENAME failed: cannot rename mailbox to other user's namespace");
return true;
} else if (!newPath.isCreatable()) {
ZimbraLog.imap.info("RENAME failed: hidden folder or parent: %s", newPath);
sendNO(tag, "RENAME failed");
return true;
} else if (!oldPath.isVisible()) {
throw MailServiceException.NO_SUCH_FOLDER(oldPath.asZimbraPath());
}
MailboxStore mboxStore = oldPath.getOwnerMailbox();
if (null != mboxStore) {
FolderStore pathFolder = oldPath.getFolder();
if (pathFolder.isInboxFolder()) {
throw ImapServiceException.CANT_RENAME_INBOX();
}
mboxStore.renameFolder(getContext(), pathFolder, "/" + newPath.asResolvedPath());
} else {
ZimbraLog.imap.info("RENAME failed: cannot get mailbox for path: " + oldPath);
sendNO(tag, "RENAME failed");
return true;
}
} catch (ServiceException e) {
if (e.getCode().equals(ImapServiceException.CANT_RENAME_INBOX)) {
ZimbraLog.imap.info("RENAME failed: RENAME of INBOX not supported");
sendNO(tag, "RENAME failed: RENAME of INBOX not supported");
return true;
} else if (e.getCode().equals(MailServiceException.NO_SUCH_FOLDER)) {
ZimbraLog.imap.info("RENAME failed: no such folder: %s", oldPath);
} else if (e.getCode().equals(MailServiceException.IMMUTABLE_OBJECT)) {
ZimbraLog.imap.info("RENAME failed: cannot rename system folder: %s", oldPath);
} else if (e.getCode().equals(MailServiceException.CANNOT_CONTAIN)) {
ZimbraLog.imap.info("RENAME failed: invalid target folder: %s", newPath);
} else {
ZimbraLog.imap.warn("RENAME failed", e);
}
sendNO(tag, "RENAME failed");
return canContinue(e);
}
// note: if ImapFolder contains a pathname, we may need to update mSelectedFolder
sendNotifications(true, false);
sendOK(tag, "RENAME completed");
return true;
}
Aggregations