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