Search in sources :

Example 1 with MailboxBlobDataSource

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);
}
Also used : SMTPMessage(com.sun.mail.smtp.SMTPMessage) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) SMTPMessage(com.sun.mail.smtp.SMTPMessage) MimeMessage(javax.mail.internet.MimeMessage) MailboxBlob(com.zimbra.cs.store.MailboxBlob) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MimeMultipart(javax.mail.internet.MimeMultipart) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MailboxBlobDataSource(com.zimbra.cs.mime.MailboxBlobDataSource) Config(com.zimbra.cs.account.Config) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) DataHandler(javax.activation.DataHandler) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 2 with MailboxBlobDataSource

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);
}
Also used : ContentType(com.zimbra.common.mime.ContentType) ContentDisposition(com.zimbra.common.mime.ContentDisposition) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MailboxBlobDataSource(com.zimbra.cs.mime.MailboxBlobDataSource) DataHandler(javax.activation.DataHandler) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Example 3 with MailboxBlobDataSource

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);
}
Also used : ContentType(com.zimbra.common.mime.ContentType) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MailboxBlobDataSource(com.zimbra.cs.mime.MailboxBlobDataSource) DataHandler(javax.activation.DataHandler) ZMimeBodyPart(com.zimbra.common.zmime.ZMimeBodyPart) MimeBodyPart(javax.mail.internet.MimeBodyPart)

Aggregations

ZMimeBodyPart (com.zimbra.common.zmime.ZMimeBodyPart)3 MailboxBlobDataSource (com.zimbra.cs.mime.MailboxBlobDataSource)3 DataHandler (javax.activation.DataHandler)3 MimeBodyPart (javax.mail.internet.MimeBodyPart)3 ContentType (com.zimbra.common.mime.ContentType)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 Message (com.zimbra.cs.mailbox.Message)2 MimeMessage (javax.mail.internet.MimeMessage)2 SMTPMessage (com.sun.mail.smtp.SMTPMessage)1 ContentDisposition (com.zimbra.common.mime.ContentDisposition)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 ZMimeMultipart (com.zimbra.common.zmime.ZMimeMultipart)1 Config (com.zimbra.cs.account.Config)1 MailboxBlob (com.zimbra.cs.store.MailboxBlob)1 MimeMultipart (javax.mail.internet.MimeMultipart)1