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