Search in sources :

Example 6 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class Mailbox method addMessage.

public Message addMessage(OperationContext octxt, InputStream in, long sizeHint, Long receivedDate, DeliveryOptions dopt, DeliveryContext dctxt, ItemData id) throws IOException, ServiceException {
    int bufLen = Provisioning.getInstance().getLocalServer().getMailDiskStreamingThreshold();
    CopyInputStream cs = new CopyInputStream(in, sizeHint, bufLen, bufLen);
    in = cs;
    Blob blob = null;
    try {
        BufferStream bs = cs.getBufferStream();
        ParsedMessage pm = null;
        Rfc822ValidationInputStream validator = null;
        if (LC.zimbra_lmtp_validate_messages.booleanValue()) {
            validator = new Rfc822ValidationInputStream(cs, LC.zimbra_lmtp_max_line_length.longValue());
            in = validator;
        }
        blob = StoreManager.getInstance().storeIncoming(in);
        if (id != null && id.ud != null && id.ud.getBlobDigest() != null && !id.ud.getBlobDigest().isEmpty()) {
            blob.setDigest(id.ud.getBlobDigest());
        }
        if (validator != null && !validator.isValid()) {
            StoreManager.getInstance().delete(blob);
            throw ServiceException.INVALID_REQUEST("Message content is invalid.", null);
        }
        pm = new ParsedMessage(new ParsedMessageOptions(blob, bs.isPartial() ? null : bs.getBuffer(), receivedDate, attachmentsIndexingEnabled()));
        cs.release();
        if (dctxt == null) {
            dctxt = new DeliveryContext();
        }
        dctxt.setIncomingBlob(blob);
        return addMessage(octxt, pm, dopt, dctxt);
    } finally {
        cs.release();
        StoreManager.getInstance().quietDelete(blob);
    }
}
Also used : BufferStream(com.zimbra.common.util.BufferStream) StoreIncomingBlob(com.zimbra.cs.redolog.op.StoreIncomingBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) Blob(com.zimbra.cs.store.Blob) ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) CopyInputStream(com.zimbra.common.util.CopyInputStream) Rfc822ValidationInputStream(com.zimbra.common.mime.Rfc822ValidationInputStream) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Example 7 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class VerifyStoreManager method testStore.

private void testStore() throws Exception {
    ParsedMessage pm = getMessage(1024);
    byte[] mimeBytes = readInputStream(pm.getRawInputStream());
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(AccountTestUtil.getAccount(USER_NAME));
    StoreManager sm = StoreManager.getInstance();
    Blob blob = sm.storeIncoming(pm.getRawInputStream());
    assertEquals("blob size = message size", pm.getRawData().length, blob.getRawSize());
    assertTrue("blob content = mime content", bytesEqual(mimeBytes, readInputStream(blob.getInputStream())));
    StagedBlob staged = sm.stage(blob, mbox);
    assertEquals("staged size = blob size", blob.getRawSize(), staged.getSize());
    MailboxBlob mblob = sm.link(staged, mbox, 0, 0);
    assertEquals("link size = staged size", staged.getSize(), mblob.getSize());
    assertTrue("link content = mime content", bytesEqual(mimeBytes, readInputStream(mblob.getLocalBlob().getInputStream())));
    mblob = sm.getMailboxBlob(mbox, 0, 0, staged.getLocator());
    assertEquals("mblob size = staged size", staged.getSize(), mblob.getSize());
    assertTrue("mailboxblob content = mime content", bytesEqual(mimeBytes, readInputStream(mblob.getLocalBlob().getInputStream())));
    sm.delete(mblob);
}
Also used : Blob(com.zimbra.cs.store.Blob) MailboxBlob(com.zimbra.cs.store.MailboxBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) StagedBlob(com.zimbra.cs.store.StagedBlob) Mailbox(com.zimbra.cs.mailbox.Mailbox) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) StoreManager(com.zimbra.cs.store.StoreManager)

Example 8 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class StoreManagerBasedTempBlobStore method store.

// BlobStore API
@Override
public StoredBlob store(IncomingBlob ib, String id, int version) throws IOException, ServiceException {
    IncomingBlob myIb = ib;
    synchronized (incomingBlobs) {
        IncomingBlob existingBlob = incomingBlobs.remove(myIb.getId());
        if (existingBlob == null) {
            // because the underlying file is gone
            throw ServiceException.INVALID_REQUEST("Cannot accept incoming blob " + myIb.getId(), null);
        }
        assert existingBlob == myIb : "Wrong blob removed: " + myIb.getId();
    }
    Blob blob = myIb.getBlob();
    StoredBlob sb = new StoredBlob(id, blob, myIb.getContext(), blob.getRawSize());
    if (storedCached) {
        synchronized (storedBlobs) {
            TreeMap<Integer, StoredBlob> versionMap = storedBlobs.get(id);
            if (versionMap == null) {
                versionMap = new TreeMap<Integer, StoredBlob>();
                storedBlobs.put(id, versionMap);
            }
            Integer versionInt = Integer.valueOf(version);
            assert !versionMap.containsKey(versionInt) : "Version " + version + " already exists";
            versionMap.put(versionInt, sb);
        }
    }
    return sb;
}
Also used : Blob(com.zimbra.cs.store.Blob) IncomingBlob(com.zimbra.cs.store.IncomingBlob) IncomingBlob(com.zimbra.cs.store.IncomingBlob)

Example 9 with Blob

use of com.zimbra.cs.store.Blob in project zm-mailbox by Zimbra.

the class NativeFormatter method saveCallback.

@Override
public void saveCallback(UserServletContext context, String contentType, Folder folder, String filename) throws IOException, ServiceException, UserServletException {
    if (filename == null) {
        Mailbox mbox = folder.getMailbox();
        try {
            ParsedMessage pm = new ParsedMessage(context.getPostBody(), mbox.attachmentsIndexingEnabled());
            DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(true);
            mbox.addMessage(context.opContext, pm, dopt, null);
            return;
        } catch (ServiceException e) {
            throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, "error parsing message");
        }
    }
    InputStream is = context.getRequestInputStream();
    try {
        Blob blob = StoreManager.getInstance().storeIncoming(is);
        saveDocument(blob, context, contentType, folder, filename, is);
    } finally {
        is.close();
    }
}
Also used : Blob(com.zimbra.cs.store.Blob) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) UserServletException(com.zimbra.cs.service.UserServletException) PushbackInputStream(java.io.PushbackInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MemoryCacheImageInputStream(javax.imageio.stream.MemoryCacheImageInputStream) InputStream(java.io.InputStream) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions)

Example 10 with Blob

use of com.zimbra.cs.store.Blob 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)

Aggregations

Blob (com.zimbra.cs.store.Blob)27 MailboxBlob (com.zimbra.cs.store.MailboxBlob)18 Mailbox (com.zimbra.cs.mailbox.Mailbox)14 StagedBlob (com.zimbra.cs.store.StagedBlob)13 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)12 IOException (java.io.IOException)11 StoreManager (com.zimbra.cs.store.StoreManager)10 ServiceException (com.zimbra.common.service.ServiceException)9 InputStream (java.io.InputStream)7 Test (org.junit.Test)6 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)4 StoreIncomingBlob (com.zimbra.cs.redolog.op.StoreIncomingBlob)4 Rfc822ValidationInputStream (com.zimbra.common.mime.Rfc822ValidationInputStream)3 CopyInputStream (com.zimbra.common.util.CopyInputStream)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)3 ParsedMessageOptions (com.zimbra.cs.mime.ParsedMessageOptions)3 AbstractStoreManagerTest (com.zimbra.cs.store.AbstractStoreManagerTest)3 BlobInputStream (com.zimbra.cs.store.BlobInputStream)3