use of com.zimbra.cs.mime.MailboxBlobDataSource in project zm-mailbox by Zimbra.
the class SpamHandler method sendReport.
private void sendReport(SpamReport sr) throws ServiceException, MessagingException {
Config config = Provisioning.getInstance().getConfig();
String isSpamString = sr.isSpam ? config.getSpamReportTypeSpam() : config.getSpamReportTypeHam();
SMTPMessage out = new SMTPMessage(JMSession.getSmtpSession());
Mailbox mbox = MailboxManager.getInstance().getMailboxById(sr.mailboxId);
Message msg = mbox.getMessageById(null, sr.messageId);
MimeMultipart mmp = new ZMimeMultipart("mixed");
MimeBodyPart infoPart = new ZMimeBodyPart();
infoPart.setHeader("Content-Description", "Zimbra spam classification report");
String body = String.format("Classified-By: %s\r\n" + "Classified-As: %s\r\n" + "Action: %s\r\n" + "Source-Folder: %s\r\n" + "Destination-Folder: %s\r\n" + "Destination-Mailbox: %s\r\n", Strings.nullToEmpty(sr.accountName), isSpamString, Strings.nullToEmpty(sr.action), Strings.nullToEmpty(sr.sourceFolder), Strings.nullToEmpty(sr.destFolder), Strings.nullToEmpty(sr.destAccountName));
infoPart.setText(body);
mmp.addBodyPart(infoPart);
MailboxBlob blob = msg.getBlob();
MimeBodyPart mbp = new ZMimeBodyPart();
mbp.setDataHandler(new DataHandler(new MailboxBlobDataSource(blob)));
mbp.setHeader("Content-Type", MimeConstants.CT_MESSAGE_RFC822);
mbp.setHeader("Content-Disposition", Part.ATTACHMENT);
mmp.addBodyPart(mbp);
out.setContent(mmp);
out.addHeader(config.getSpamReportSenderHeader(), sr.accountName);
out.addHeader(config.getSpamReportTypeHeader(), isSpamString);
if (config.isSmtpSendAddOriginatingIP() && sr.origIp != null)
out.addHeader(MailSender.X_ORIGINATING_IP, MailSender.formatXOrigIpHeader(sr.origIp));
out.setRecipient(javax.mail.Message.RecipientType.TO, sr.reportRecipient);
out.setEnvelopeFrom(config.getSpamReportEnvelopeFrom());
out.setSubject(config.getSpamTrainingSubjectPrefix() + " " + sr.accountName + ": " + isSpamString);
Transport.send(out);
ZimbraLog.misc.info("Sent " + sr);
}
use of com.zimbra.cs.mime.MailboxBlobDataSource in project zm-mailbox by Zimbra.
the class ParseMimeMessage method attachDocument.
private static void attachDocument(MimeMultipart mmp, Document doc, String contentID, ParseMessageContext ctxt) throws MessagingException, ServiceException {
ctxt.incrementSize("attached document", (long) (doc.getSize() * 1.33));
ContentType ct = new ContentType(doc.getContentType());
if (MimeConstants.isZimbraDocument(ct.getContentType())) {
ct = new ContentType(MimeConstants.CT_TEXT_HTML);
}
MimeBodyPart mbp = new ZMimeBodyPart();
mbp.setDataHandler(new DataHandler(new MailboxBlobDataSource(doc.getBlob(), ct.getContentType())));
mbp.setHeader("Content-Type", ct.cleanup().setParameter("name", doc.getName()).setCharset(ctxt.defaultCharset).toString());
mbp.setHeader("Content-Disposition", new ContentDisposition(Part.ATTACHMENT).setParameter("filename", doc.getName()).toString());
mbp.setContentID(contentID);
mmp.addBodyPart(mbp);
}
use of com.zimbra.cs.mime.MailboxBlobDataSource in project zm-mailbox by Zimbra.
the class ParseMimeMessage method attachMessage.
@SuppressWarnings("unchecked")
private static void attachMessage(MimeMultipart mmp, ItemId iid, String contentID, ParseMessageContext ctxt, boolean attachMessageFromCache) throws MessagingException, ServiceException {
if (!iid.isLocal()) {
attachRemoteItem(mmp, iid, contentID, ctxt, Collections.EMPTY_MAP, new ContentType(MimeConstants.CT_MESSAGE_RFC822));
return;
}
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(iid.getAccountId());
Message msg = mbox.getMessageById(ctxt.octxt, iid.getId());
ctxt.incrementSize("attached message", msg.getSize());
MimeBodyPart mbp = new ZMimeBodyPart();
if (attachMessageFromCache && mbox.getAccount().isFeatureSMIMEEnabled() && (Mime.isEncrypted(msg.getMimeMessage(false).getContentType()) || Mime.isPKCS7Signed(msg.getMimeMessage(false).getContentType()))) {
MimeMessage cachedMimeMessage = msg.getMimeMessage(true);
mbp.setContent(cachedMimeMessage, MimeConstants.CT_MESSAGE_RFC822);
} else {
mbp.setDataHandler(new DataHandler(new MailboxBlobDataSource(msg.getBlob())));
mbp.setHeader("Content-Type", MimeConstants.CT_MESSAGE_RFC822);
mbp.setHeader("Content-Disposition", Part.ATTACHMENT);
}
mbp.setContentID(contentID);
mmp.addBodyPart(mbp);
}
Aggregations