Search in sources :

Example 1 with RedoException

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

the class CreateMessage method redo.

@Override
public void redo() throws Exception {
    int mboxId = getMailboxId();
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(mboxId);
    OperationContext octxt = getOperationContext();
    if (mTags == null && mTagIds != null) {
        mTags = TagUtil.tagIdStringToNames(mbox, octxt, mTagIds);
    }
    DeliveryContext dctxt = new DeliveryContext(mShared, Arrays.asList(mboxId));
    if (mMsgBodyType == MSGBODY_LINK) {
        Blob blob = StoreIncomingBlob.fetchBlob(mPath);
        if (blob == null)
            throw new RedoException("Missing link source blob " + mPath + " (digest=" + mDigest + ")", this);
        dctxt.setIncomingBlob(blob);
        ParsedMessage pm = null;
        try {
            ParsedMessageOptions opt = new ParsedMessageOptions().setContent(blob.getFile()).setReceivedDate(mReceivedDate).setAttachmentIndexing(mbox.attachmentsIndexingEnabled()).setSize(mMsgSize).setDigest(mDigest);
            pm = new ParsedMessage(opt);
            mbox.addMessage(octxt, pm, getDeliveryOptions(), dctxt);
        } catch (MailServiceException e) {
            if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
                mLog.info("Message " + mMsgId + " is already in mailbox " + mboxId);
                return;
            } else {
                throw e;
            }
        } finally {
            if (pm != null) {
                ByteUtil.closeStream(pm.getBlobInputStream());
            }
        }
    } else {
        // mMsgBodyType == MSGBODY_INLINE
        // Just one recipient.  Blob data is stored inline.
        InputStream in = null;
        try {
            in = mData.getInputStream();
            if (mData.getLength() != mMsgSize) {
                in = new GZIPInputStream(in);
            }
            mbox.addMessage(octxt, in, mMsgSize, mReceivedDate, getDeliveryOptions(), dctxt);
        } catch (MailServiceException e) {
            if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
                mLog.info("Message " + mMsgId + " is already in mailbox " + mboxId);
                return;
            } else {
                throw e;
            }
        } finally {
            ByteUtil.closeStream(in);
        }
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) GZIPInputStream(java.util.zip.GZIPInputStream) Blob(com.zimbra.cs.store.Blob) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) RedoException(com.zimbra.cs.redolog.RedoException)

Example 2 with RedoException

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

the class CreateMailbox method redo.

@Override
public void redo() throws Exception {
    int opMboxId = getMailboxId();
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(mAccountId, false);
    if (mbox == null) {
        Account account = Provisioning.getInstance().get(AccountBy.id, mAccountId);
        if (account == null) {
            throw new RedoException("Account " + mAccountId + " does not exist", this);
        }
        mbox = MailboxManager.getInstance().createMailbox(getOperationContext(), account);
        if (mbox == null) {
            //something went really wrong
            throw new RedoException("unable to create mailbox for accountId " + mAccountId, this);
        }
    }
    int mboxId = mbox.getId();
    if (opMboxId == mboxId) {
        mLog.info("Mailbox " + opMboxId + " for account " + mAccountId + " already exists");
        return;
    } else {
        throw new MailboxIdConflictException(mAccountId, opMboxId, mboxId, this);
    }
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxIdConflictException(com.zimbra.cs.redolog.MailboxIdConflictException) RedoException(com.zimbra.cs.redolog.RedoException)

Aggregations

Mailbox (com.zimbra.cs.mailbox.Mailbox)2 RedoException (com.zimbra.cs.redolog.RedoException)2 Account (com.zimbra.cs.account.Account)1 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 OperationContext (com.zimbra.cs.mailbox.OperationContext)1 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)1 ParsedMessageOptions (com.zimbra.cs.mime.ParsedMessageOptions)1 MailboxIdConflictException (com.zimbra.cs.redolog.MailboxIdConflictException)1 Blob (com.zimbra.cs.store.Blob)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1