use of com.zimbra.cs.store.BlobInputStream in project zm-mailbox by Zimbra.
the class ZimbraLmtpBackend method deliver.
@Override
public void deliver(LmtpEnvelope env, InputStream in, int sizeHint) throws UnrecoverableLmtpException {
CopyInputStream cis = null;
Blob blob = null;
try {
int bufLen = Provisioning.getInstance().getLocalServer().getMailDiskStreamingThreshold();
cis = new CopyInputStream(in, sizeHint, bufLen, bufLen);
in = cis;
// MimeParserInputStream mpis = null;
// if (ZMimeMessage.usingZimbraParser()) {
// mpis = new MimeParserInputStream(in);
// in = mpis;
// }
Rfc822ValidationInputStream validator = null;
if (LC.zimbra_lmtp_validate_messages.booleanValue()) {
validator = new Rfc822ValidationInputStream(in, LC.zimbra_lmtp_max_line_length.longValue());
in = validator;
}
try {
blob = StoreManager.getInstance().storeIncoming(in);
} catch (IOException ioe) {
throw new UnrecoverableLmtpException("Error in storing incoming message", ioe);
}
if (validator != null && !validator.isValid()) {
try {
StoreManager.getInstance().delete(blob);
} catch (IOException e) {
ZimbraLog.lmtp.warn("Error in deleting blob %s", blob, e);
}
setDeliveryStatuses(env.getRecipients(), LmtpReply.INVALID_BODY_PARAMETER);
return;
}
BufferStream bs = cis.getBufferStream();
byte[] data = bs.isPartial() ? null : bs.getBuffer();
BlobInputStream bis = null;
MimeMessage mm = null;
try {
deliverMessageToLocalMailboxes(blob, bis, data, mm, env);
} catch (Exception e) {
ZimbraLog.lmtp.warn("Exception delivering mail (temporary failure)", e);
setDeliveryStatuses(env.getLocalRecipients(), LmtpReply.TEMPORARY_FAILURE);
}
try {
deliverMessageToRemoteMailboxes(blob, data, env);
} catch (Exception e) {
ZimbraLog.lmtp.warn("Exception delivering remote mail", e);
setDeliveryStatuses(env.getRemoteRecipients(), LmtpReply.TEMPORARY_FAILURE);
}
} catch (ServiceException e) {
ZimbraLog.lmtp.warn("Exception delivering mail (temporary failure)", e);
setDeliveryStatuses(env.getRecipients(), LmtpReply.TEMPORARY_FAILURE);
} finally {
if (cis != null) {
cis.release();
}
if (blob != null) {
try {
// clean up the incoming blob
StoreManager.getInstance().delete(blob);
} catch (IOException e) {
ZimbraLog.lmtp.warn("Error in deleting blob %s", blob, e);
}
}
}
}
Aggregations