Search in sources :

Example 1 with ImapMaximumSizeExceededException

use of com.zimbra.cs.imap.ImapParseException.ImapMaximumSizeExceededException 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;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) ImapMaximumSizeExceededException(com.zimbra.cs.imap.ImapParseException.ImapMaximumSizeExceededException) ArrayList(java.util.ArrayList) SearchFolderStore(com.zimbra.common.mailbox.SearchFolderStore) FolderStore(com.zimbra.common.mailbox.FolderStore) ZClientUploadSizeLimitExceededException(com.zimbra.common.zclient.ZClientException.ZClientUploadSizeLimitExceededException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Aggregations

FolderStore (com.zimbra.common.mailbox.FolderStore)1 SearchFolderStore (com.zimbra.common.mailbox.SearchFolderStore)1 ServiceException (com.zimbra.common.service.ServiceException)1 ZClientUploadSizeLimitExceededException (com.zimbra.common.zclient.ZClientException.ZClientUploadSizeLimitExceededException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 ImapMaximumSizeExceededException (com.zimbra.cs.imap.ImapParseException.ImapMaximumSizeExceededException)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ArrayList (java.util.ArrayList)1