Search in sources :

Example 1 with SaveDraft

use of com.zimbra.cs.redolog.op.SaveDraft in project zm-mailbox by Zimbra.

the class Mailbox method saveDraft.

/**
     * Saves draft.
     *
     * @param autoSendTime time at which the draft needs to be auto-sent. Note that this method does not schedule
     *                     the task for auto-sending the draft. It just persists this time for tracking purposes.
     * @see com.zimbra.cs.service.mail.SaveDraft#handle(com.zimbra.common.soap.Element, java.util.Map)
     */
public Message saveDraft(OperationContext octxt, ParsedMessage pm, int id, String origId, String replyType, String identityId, String accountId, long autoSendTime) throws IOException, ServiceException {
    Message.DraftInfo dinfo = null;
    if ((replyType != null && origId != null) || identityId != null || accountId != null || autoSendTime != 0) {
        dinfo = new Message.DraftInfo(replyType, origId, identityId, accountId, autoSendTime);
    }
    if (id == ID_AUTO_INCREMENT) {
        // special-case saving a new draft
        return addMessage(octxt, pm, ID_FOLDER_DRAFTS, true, Flag.BITMASK_DRAFT | Flag.BITMASK_FROM_ME, null, ID_AUTO_INCREMENT, ":API:", dinfo, null, null);
    }
    // write the draft content directly to the mailbox's blob staging area
    StoreManager sm = StoreManager.getInstance();
    StagedBlob staged;
    InputStream is = pm.getRawInputStream();
    try {
        staged = sm.stage(is, this);
    } finally {
        ByteUtil.closeStream(is);
    }
    String digest = staged.getDigest();
    int size = (int) staged.getSize();
    SaveDraft redoRecorder = new SaveDraft(mId, id, digest, size);
    InputStream redoStream = null;
    boolean success = false;
    try {
        beginTransaction("saveDraft", octxt, redoRecorder);
        SaveDraft redoPlayer = (SaveDraft) currentChange().getRedoPlayer();
        Message msg = getMessageById(id);
        if (!msg.isTagged(Flag.FlagInfo.DRAFT)) {
            throw MailServiceException.IMMUTABLE_OBJECT(id);
        }
        if (!checkItemChangeID(msg)) {
            throw MailServiceException.MODIFY_CONFLICT();
        }
        // content changed, so we're obliged to change the IMAP uid
        int imapID = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getImapId());
        redoRecorder.setImapId(imapID);
        redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
        msg.setDraftAutoSendTime(autoSendTime);
        if (dinfo != null) {
            if (replyType != null) {
                msg.setDraftReplyType(replyType);
            }
            if (origId != null) {
                msg.setDraftOrigId(origId);
            }
            if (identityId != null) {
                msg.setDraftIdentityId(identityId);
            }
            if (accountId != null) {
                msg.setDraftAccountId(accountId);
            }
            if (autoSendTime != 0) {
                msg.setDraftAutoSendTime(autoSendTime);
            }
        }
        // update the content and increment the revision number
        msg.setContent(staged, pm);
        index.add(msg);
        success = true;
        try {
            Notification.getInstance().interceptIfNecessary(this, pm.getMimeMessage(), "save draft", msg.getFolder());
        } catch (ServiceException e) {
            ZimbraLog.mailbox.error("Unable to send lawful intercept message.", e);
        }
        return msg;
    } finally {
        endTransaction(success);
        ByteUtil.closeStream(redoStream);
        sm.quietDelete(staged);
    }
}
Also used : ParsedMessageDataSource(com.zimbra.cs.mime.ParsedMessageDataSource) StagedBlob(com.zimbra.cs.store.StagedBlob) ImapMessage(com.zimbra.cs.imap.ImapMessage) Pop3Message(com.zimbra.cs.pop3.Pop3Message) MimeMessage(javax.mail.internet.MimeMessage) CreateMessage(com.zimbra.cs.redolog.op.CreateMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) SaveDraft(com.zimbra.cs.redolog.op.SaveDraft) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) StoreManager(com.zimbra.cs.store.StoreManager)

Aggregations

Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)1 ServiceException (com.zimbra.common.service.ServiceException)1 CopyInputStream (com.zimbra.common.util.CopyInputStream)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 ImapMessage (com.zimbra.cs.imap.ImapMessage)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 ParsedMessageDataSource (com.zimbra.cs.mime.ParsedMessageDataSource)1 Pop3Message (com.zimbra.cs.pop3.Pop3Message)1 CreateMessage (com.zimbra.cs.redolog.op.CreateMessage)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)1 SaveDraft (com.zimbra.cs.redolog.op.SaveDraft)1 StagedBlob (com.zimbra.cs.store.StagedBlob)1 StoreManager (com.zimbra.cs.store.StoreManager)1 InputStream (java.io.InputStream)1 MimeMessage (javax.mail.internet.MimeMessage)1