Search in sources :

Example 1 with MimeVisitor

use of com.zimbra.cs.mime.MimeVisitor in project zm-mailbox by Zimbra.

the class SendMsg method parseUploadedMessage.

static MimeMessage parseUploadedMessage(ZimbraSoapContext zsc, String attachId, MimeMessageData mimeData, boolean needCalendarSentByFixup) throws ServiceException {
    boolean anySystemMutators = MimeVisitor.anyMutatorsRegistered();
    Upload up = FileUploadServlet.fetchUpload(zsc.getAuthtokenAccountId(), attachId, zsc.getAuthToken());
    if (up == null) {
        throw MailServiceException.NO_SUCH_UPLOAD(attachId);
    }
    (mimeData.uploads = new ArrayList<Upload>(1)).add(up);
    try {
        // if we may need to mutate the message, we can't use the "updateHeaders" hack...
        if (anySystemMutators || needCalendarSentByFixup) {
            MimeMessage mm = new ZMimeMessage(JMSession.getSession(), up.getInputStream());
            if (anySystemMutators) {
                return mm;
            }
            OutlookICalendarFixupMimeVisitor.ICalendarModificationCallback callback = new OutlookICalendarFixupMimeVisitor.ICalendarModificationCallback();
            MimeVisitor mv = new OutlookICalendarFixupMimeVisitor(getRequestedAccount(zsc), getRequestedMailbox(zsc)).needFixup(true).setCallback(callback);
            try {
                mv.accept(mm);
            } catch (MessagingException e) {
            }
            if (callback.wouldCauseModification()) {
                return mm;
            }
        }
        // ... but in general, for most installs this is safe
        return new ZMimeMessage(JMSession.getSession(), up.getInputStream()) {

            @Override
            protected void updateHeaders() throws MessagingException {
                setHeader("MIME-Version", "1.0");
                if (getMessageID() == null)
                    updateMessageID();
            }
        };
    } catch (MessagingException e) {
        throw MailServiceException.MESSAGE_PARSE_ERROR(e);
    } catch (IOException e) {
        throw ServiceException.FAILURE("IOException when parsing upload", e);
    }
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) MimeVisitor(com.zimbra.cs.mime.MimeVisitor) Upload(com.zimbra.cs.service.FileUploadServlet.Upload) IOException(java.io.IOException)

Aggregations

ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 MimeVisitor (com.zimbra.cs.mime.MimeVisitor)1 Upload (com.zimbra.cs.service.FileUploadServlet.Upload)1 IOException (java.io.IOException)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1