use of com.zimbra.cs.mime.ParsedMessageDataSource in project zm-mailbox by Zimbra.
the class Mailbox method updateChat.
public Chat updateChat(OperationContext octxt, ParsedMessage pm, int id) throws IOException, ServiceException {
if (pm == null) {
throw ServiceException.INVALID_REQUEST("null ParsedMessage when updating chat " + id + " in mailbox " + mId, null);
}
// write the chat 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();
SaveChat redoRecorder = new SaveChat(mId, id, digest, size, -1, 0, null);
boolean success = false;
try {
beginTransaction("saveChat", octxt, redoRecorder);
SaveChat redoPlayer = (SaveChat) currentChange().getRedoPlayer();
redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
Chat chat = (Chat) getItemById(id, MailItem.Type.CHAT);
if (!chat.isMutable()) {
throw MailServiceException.IMMUTABLE_OBJECT(id);
}
if (!checkItemChangeID(chat)) {
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);
// update the content and increment the revision number
chat.setContent(staged, pm);
// NOTE: msg is now uncached (will this cause problems during commit/reindex?)
index.add(chat);
success = true;
return chat;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
use of com.zimbra.cs.mime.ParsedMessageDataSource in project zm-mailbox by Zimbra.
the class Mailbox method createChat.
public Chat createChat(OperationContext octxt, ParsedMessage pm, int folderId, int flags, String[] tags) throws IOException, ServiceException {
if (pm == null) {
throw ServiceException.INVALID_REQUEST("null ParsedMessage when adding chat to mailbox " + mId, null);
}
// write the chat 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();
CreateChat redoRecorder = new CreateChat(mId, digest, size, folderId, flags, tags);
boolean success = false;
try {
beginTransaction("createChat", octxt, redoRecorder);
Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
CreateChat redoPlayer = (octxt == null ? null : (CreateChat) octxt.getPlayer());
redoRecorder.setMessageBodyInfo(new ParsedMessageDataSource(pm), size);
int itemId = getNextItemId(redoPlayer == null ? ID_AUTO_INCREMENT : redoPlayer.getMessageId());
Chat chat = Chat.create(itemId, getFolderById(folderId), pm, staged, false, flags, ntags);
redoRecorder.setMessageId(chat.getId());
MailboxBlob mblob = sm.link(staged, this, itemId, getOperationChangeID());
markOtherItemDirty(mblob);
// when we created the Chat, we used the staged locator/size/digest;
// make sure that data actually matches the final blob in the store
chat.updateBlobData(mblob);
index.add(chat);
success = true;
return chat;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
use of com.zimbra.cs.mime.ParsedMessageDataSource 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