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);
}
}
Aggregations