Search in sources :

Example 1 with ParsedMessageDataSource

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);
    }
}
Also used : ParsedMessageDataSource(com.zimbra.cs.mime.ParsedMessageDataSource) StagedBlob(com.zimbra.cs.store.StagedBlob) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) SaveChat(com.zimbra.cs.redolog.op.SaveChat) CreateChat(com.zimbra.cs.redolog.op.CreateChat) SaveChat(com.zimbra.cs.redolog.op.SaveChat) 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)

Example 2 with ParsedMessageDataSource

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);
    }
}
Also used : StagedBlob(com.zimbra.cs.store.StagedBlob) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) MailboxBlob(com.zimbra.cs.store.MailboxBlob) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) CopyInputStream(com.zimbra.common.util.CopyInputStream) InputStream(java.io.InputStream) 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) ParsedMessageDataSource(com.zimbra.cs.mime.ParsedMessageDataSource) CreateChat(com.zimbra.cs.redolog.op.CreateChat) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) SaveChat(com.zimbra.cs.redolog.op.SaveChat) CreateChat(com.zimbra.cs.redolog.op.CreateChat) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag)

Example 3 with ParsedMessageDataSource

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);
    }
}
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)3 CopyInputStream (com.zimbra.common.util.CopyInputStream)3 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)3 ParsedMessageDataSource (com.zimbra.cs.mime.ParsedMessageDataSource)3 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)3 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)3 StagedBlob (com.zimbra.cs.store.StagedBlob)3 StoreManager (com.zimbra.cs.store.StoreManager)3 InputStream (java.io.InputStream)3 CreateChat (com.zimbra.cs.redolog.op.CreateChat)2 SaveChat (com.zimbra.cs.redolog.op.SaveChat)2 ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 DbTag (com.zimbra.cs.db.DbTag)1 ImapMessage (com.zimbra.cs.imap.ImapMessage)1 NormalizedTags (com.zimbra.cs.mailbox.Tag.NormalizedTags)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 Pop3Message (com.zimbra.cs.pop3.Pop3Message)1 AlterItemTag (com.zimbra.cs.redolog.op.AlterItemTag)1 CreateMessage (com.zimbra.cs.redolog.op.CreateMessage)1