branch feature/8321 created (now 91451be)
This is an automated email from the git hooks/post-receive script. New change to branch feature/8321 in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git at 91451be fixes #8321 PJ mal extraite quand il s'agit d'un email transféré non valide : - factorisation de l'extraction des pj d'un email - meilleure gestion des erreurs dans la transfo du mail texte en texte This branch includes the following new commits: new 91451be fixes #8321 PJ mal extraite quand il s'agit d'un email transféré non valide : - factorisation de l'extraction des pj d'un email - meilleure gestion des erreurs dans la transfo du mail texte en texte The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 91451be4e95705431dba4cb383ef1837516a9747 Author: Kevin Morin <morin@codelutin.com> Date: Tue May 24 23:51:08 2016 +0200 fixes #8321 PJ mal extraite quand il s'agit d'un email transféré non valide : - factorisation de l'extraction des pj d'un email - meilleure gestion des erreurs dans la transfo du mail texte en texte -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/8321 in repository faxtomail. See https://gitlab.nuiton.org/codelutin/faxtomail.git commit 91451be4e95705431dba4cb383ef1837516a9747 Author: Kevin Morin <morin@codelutin.com> Date: Tue May 24 23:51:08 2016 +0200 fixes #8321 PJ mal extraite quand il s'agit d'un email transféré non valide : - factorisation de l'extraction des pj d'un email - meilleure gestion des erreurs dans la transfo du mail texte en texte --- .../faxtomail/services/FaxToMailServiceUtils.java | 32 ++ .../faxtomail/services/service/EmailService.java | 2 + .../services/service/EmailServiceImpl.java | 384 ++++++++++++++------- .../i18n/faxtomail-service_fr_FR.properties | 1 + .../services/service/EmailServiceTest.java | 62 +--- .../ui/swing/actions/OpenReplyAction.java | 15 +- .../ui/swing/content/demande/DemandeUIModel.java | 12 +- .../demande/replies/DemandRepliesUIHandler.java | 31 +- .../faxtomail/web/action/DemandDetailAction.java | 20 +- .../faxtomail/web/job/MailFilterJob.java | 76 +--- 10 files changed, 341 insertions(+), 294 deletions(-) diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java index 34aa7b4..b5b0d63 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailServiceUtils.java @@ -29,14 +29,18 @@ import com.google.common.base.Preconditions; import org.apache.commons.httpclient.URIException; import org.apache.commons.httpclient.util.URIUtil; import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import javax.mail.MessagingException; import javax.mail.Part; import javax.mail.internet.ContentType; +import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeUtility; import java.awt.GraphicsEnvironment; +import java.io.IOException; +import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -169,4 +173,32 @@ public class FaxToMailServiceUtils { return subject; } + + public static String getTextFromMessage(MimeMessage message) throws IOException, MessagingException { + // convertit le contenu texte en PDF + String text; + try { + text = (String) message.getContent(); + + } catch (Exception e) { + if (log.isWarnEnabled()) { + log.warn("Error while getting the text from the message, reading the raw data", e); + } + InputStream inputStream = message.getRawInputStream(); + Charset charset = getCharset(message); + text = getTextFromInputStream(inputStream, charset); + } + return text; + } + + public static String getTextFromPart(Part part) throws Exception { + // convertit le contenu texte en PDF + Charset charset = getCharset(part); + return getTextFromInputStream(part.getInputStream(), charset); + } + + public static String getTextFromInputStream(InputStream inputStream, Charset charset) throws IOException { + return IOUtils.toString(inputStream, charset); + } + } diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java index e76b6aa..0b55ee0 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java @@ -156,6 +156,8 @@ public interface EmailService extends FaxToMailService { */ List<String> decomposeMultipartEmail(List<Attachment> attachments, Part part) throws Exception; + List<Attachment> extractAttachmentsFromMessage(MimeMessage message) throws Exception; + /** * Retourne un input stream sur une piece jointe convertie ou pas. * diff --git a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java index 3ea6148..57af106 100644 --- a/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java +++ b/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java @@ -24,7 +24,51 @@ package com.franciaflex.faxtomail.services.service; * #L% */ -import com.franciaflex.faxtomail.persistence.entities.*; +import com.franciaflex.faxtomail.persistence.entities.AbstractFaxToMailTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Attachment; +import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; +import com.franciaflex.faxtomail.persistence.entities.AttachmentFileImpl; +import com.franciaflex.faxtomail.persistence.entities.AttachmentFileTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.AttachmentImpl; +import com.franciaflex.faxtomail.persistence.entities.AttachmentTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Client; +import com.franciaflex.faxtomail.persistence.entities.DemandStatus; +import com.franciaflex.faxtomail.persistence.entities.DemandType; +import com.franciaflex.faxtomail.persistence.entities.DemandTypeTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.EdiReturn; +import com.franciaflex.faxtomail.persistence.entities.Email; +import com.franciaflex.faxtomail.persistence.entities.EmailFilter; +import com.franciaflex.faxtomail.persistence.entities.EmailGroup; +import com.franciaflex.faxtomail.persistence.entities.EmailGroupTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.EmailTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.ExtensionCommand; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaPersistenceContext; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailUserGroup; +import com.franciaflex.faxtomail.persistence.entities.History; +import com.franciaflex.faxtomail.persistence.entities.HistoryTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.HistoryType; +import com.franciaflex.faxtomail.persistence.entities.MailField; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.MailLock; +import com.franciaflex.faxtomail.persistence.entities.MailLockImpl; +import com.franciaflex.faxtomail.persistence.entities.MailLockTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.OriginalEmail; +import com.franciaflex.faxtomail.persistence.entities.OriginalEmailTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Priority; +import com.franciaflex.faxtomail.persistence.entities.PriorityTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Range; +import com.franciaflex.faxtomail.persistence.entities.RangeRow; +import com.franciaflex.faxtomail.persistence.entities.RangeRowTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.RangeTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.Reply; +import com.franciaflex.faxtomail.persistence.entities.ReplyContent; +import com.franciaflex.faxtomail.persistence.entities.ReplyContentTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.ReplyTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.SearchFilter; +import com.franciaflex.faxtomail.persistence.entities.WaitingState; +import com.franciaflex.faxtomail.persistence.entities.WaitingStateTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import com.franciaflex.faxtomail.services.FaxToMailServiceUtils; import com.franciaflex.faxtomail.services.service.exceptions.AlreadyLockedMailException; @@ -46,6 +90,7 @@ import com.google.common.collect.Collections2; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import com.google.common.io.Files; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Image; @@ -83,6 +128,7 @@ import org.nuiton.topia.persistence.TopiaQueryException; import org.nuiton.topia.persistence.support.TopiaHibernateSupport; import org.nuiton.topia.persistence.support.TopiaSqlSupport; import org.nuiton.topia.persistence.support.TopiaSqlWork; +import org.nuiton.util.FileUtil; import org.nuiton.util.StringUtil; import org.nuiton.util.beans.Binder; import org.nuiton.util.beans.BinderFactory; @@ -1421,17 +1467,7 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe String headerLine = headerLines.nextElement(); emailSource.append(headerLine).append("\n"); } - InputStream inputStream; - try { - inputStream = message.getRawInputStream(); - - } catch (Exception e) { - if (log.isWarnEnabled()) { - log.warn("error while getting the raw input stream"); - } - inputStream = message.getInputStream(); - } - String originalContent = IOUtils.toString(inputStream, charset); + String originalContent = FaxToMailServiceUtils.getTextFromMessage(message); emailSource.append("\n").append(originalContent); OriginalEmail originalEmail = getPersistenceContext().getOriginalEmailDao().newInstance(); @@ -1848,119 +1884,206 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe protected List<String> decomposeMultipartEmail(List<Attachment> attachments, Part part, int decomposingForwardedEmail) throws Exception { List<String> result = null; - DataSource dataSource = part.getDataHandler().getDataSource(); - MimeMultipart mimeMultipart = new MimeMultipart(dataSource); - int multiPartCount = mimeMultipart.getCount(); + if (part.getContent() instanceof MimeMessage) { + + List<Attachment> forwardeEmailAttachments = extractAttachmentsFromMessage((MimeMessage) part.getContent(), + decomposingForwardedEmail + 1); + attachments.addAll(forwardeEmailAttachments); + + } else { + + DataSource dataSource = part.getDataHandler().getDataSource(); + MimeMultipart mimeMultipart = new MimeMultipart(dataSource); + int multiPartCount = mimeMultipart.getCount(); + + for (int j = 0; j < multiPartCount; j++) { + MimeBodyPart bp = (MimeBodyPart) mimeMultipart.getBodyPart(j); + + // if it is a text part, then this is the email content + String disposition = bp.getDisposition(); + if (bp.isMimeType("text/*") && !Part.ATTACHMENT.equals(disposition)) { - for (int j = 0; j < multiPartCount; j++) { - MimeBodyPart bp = (MimeBodyPart) mimeMultipart.getBodyPart(j); + String content = FaxToMailServiceUtils.getTextFromPart(bp); + + if (bp.isMimeType("text/plain")) { + if (StringUtils.isNotBlank(content)) { + String name; + if (decomposingForwardedEmail > 0) { + name = t("faxtomail.email.content.attachment.forwardedFileName", decomposingForwardedEmail); + } else { + name = t("faxtomail.email.content.attachment.plainFileName"); + } + Attachment attachment = convertTextToPdf(content, name); + attachments.add(attachment); + } + + } else { + if (result == null) { + result = new ArrayList<>(); + } + result.add(content); + } - // if it is a text part, then this is the email content - String disposition = bp.getDisposition(); - if (bp.isMimeType("text/*") && !Part.ATTACHMENT.equals(disposition)) { + // if it is multipart part, decompose it + } else if (bp.isMimeType("multipart/*")) { + List<String> htmlContent = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); + if (htmlContent != null) { + result = htmlContent; + } - Charset charset = FaxToMailServiceUtils.getCharset(bp); - String content = IOUtils.toString(bp.getInputStream(), charset); + } else if (bp.isMimeType("message/*")) { + decomposingForwardedEmail++; + Attachment attachment = null; + String fileName = t("faxtomail.email.content.attachment.forwardedFileName", decomposingForwardedEmail); + try { + List<String> content = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); + if (content != null) { + attachment = convertHTMLToPdf(attachments, content, fileName); + } - if (bp.isMimeType("text/plain")) { - if (StringUtils.isNotBlank(content)) { - String name; - if (decomposingForwardedEmail > 0) { - name = t("faxtomail.email.content.attachment.forwardedFileName", decomposingForwardedEmail); - } else { - name = t("faxtomail.email.content.attachment.plainFileName"); + } catch (Exception e) { + String content = FaxToMailServiceUtils.getTextFromPart(bp); + if (StringUtils.isNotBlank(content)) { + attachment = convertTextToPdf(content, FileUtil.basename(fileName, ".pdf", ".PDF")); } - Attachment attachment = convertTextToPdf(content, name); + } + if (attachment != null) { attachments.add(attachment); } + + // else, this is an attachment } else { - if (result == null) { - result = new ArrayList<String>(); + String fileName = bp.getFileName(); + + // parse Content-ID (content identifier in html mail content) + String[] headers = bp.getHeader("Content-ID"); + String contentID = null; + if (headers != null) { + contentID = headers[0]; + contentID = contentID.replaceFirst("^<(.*)>$", "$1"); } - result.add(content); - } - // if it is multipart part, decompose it - } else if (bp.isMimeType("multipart/*")) { - List<String> htmlContent = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); - if (htmlContent != null) { - result = htmlContent; - } + // remove the guillemets between the id - } else if (bp.isMimeType("message/*")) { - decomposingForwardedEmail++; - Attachment attachment = null; - String fileName = t("faxtomail.email.content.attachment.forwardedFileName", decomposingForwardedEmail) + ".pdf"; - try { - List<String> content = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); - if (content != null) { - attachment = convertHTMLToPdf(attachments, content, fileName); + if (fileName == null && contentID == null) { + fileName = t("faxtomail.email.content.attachment.unnamed", attachments.size()); + + } else if (fileName == null) { + fileName = contentID; } - } catch (Exception e) { - Charset charset = FaxToMailServiceUtils.getCharset(bp); - String content = IOUtils.toString(bp.getInputStream(), charset); - if (StringUtils.isNotBlank(content)) { - attachment = convertTextToPdf(content, fileName); + try { + fileName = MimeUtility.decodeText(fileName); + if (log.isDebugEnabled()) { + log.debug("FileName : " + fileName + ", Content-ID : " + contentID); + } + } catch (UnsupportedEncodingException ex) { + // don't care, use filename raw value + if (log.isWarnEnabled()) { + log.warn("Can't debug email file name", ex); + } } - } - if (attachment != null) { - attachments.add(attachment); - } + DataHandler dh = bp.getDataHandler(); - // else, this is an attachment - } else { - String fileName = bp.getFileName(); - - // parse Content-ID (content identifier in html mail content) - String[] headers = bp.getHeader("Content-ID"); - String contentID = null; - if (headers != null) { - contentID = headers[0]; - contentID = contentID.replaceFirst("^<(.*)>$", "$1"); + // create new attachment + Attachment attachment = new AttachmentImpl(); + attachment.setAddedByUser(false); + AttachmentFile attachmentFile = getAttachmentFileFromStream(dh.getInputStream()); + attachmentFile.setFilename(fileName); + attachment.setOriginalFile(attachmentFile); + attachment.setContentId(contentID); + + // convert attachment if defined by admin + convertIfNecessary(attachment); + + // save attachment + attachments.add(attachment); } + } + } + return result; + } - // remove the guillemets between the id + @Override + public List<Attachment> extractAttachmentsFromMessage(MimeMessage message) throws Exception { + List<Attachment> attachments = extractAttachmentsFromMessage(message, 0); + return attachments; + } - if (fileName == null && contentID == null) { - fileName = t("faxtomail.email.content.attachment.unnamed", attachments.size()); + protected List<Attachment> extractAttachmentsFromMessage(MimeMessage message, int decomposingForwardedEmail) throws Exception { - } else if (fileName == null) { - fileName = contentID; + String plainTextFileName = t("faxtomail.email.content.attachment.plainFileName"); + if (decomposingForwardedEmail > 0) { + plainTextFileName += decomposingForwardedEmail; + } + + List<Attachment> attachments = new ArrayList<>(); + if (message.isMimeType("multipart/*")) { + + // manage boundary id + List<String> htmlContent = decomposeMultipartEmail(attachments, message, decomposingForwardedEmail); + if (htmlContent != null) { + if (log.isDebugEnabled()) { + log.debug("Converting html content to pdf : " + message.getSubject()); + } + String htmlFileName = t("faxtomail.email.content.attachment.htmlFileName"); + if (decomposingForwardedEmail > 0) { + htmlFileName += decomposingForwardedEmail; } - try { - fileName = MimeUtility.decodeText(fileName); - if (log.isDebugEnabled()) { - log.debug("FileName : " + fileName + ", Content-ID : " + contentID); - } - } catch (UnsupportedEncodingException ex) { - // don't care, use filename raw value - if (log.isWarnEnabled()) { - log.warn("Can't debug email file name", ex); + Attachment attachment = convertHTMLToPdf(attachments, htmlContent, htmlFileName); + if (attachment != null) { + //remove text plain attachement if exists, to avoid having twice the mail content in the attachments + + for (Attachment a : attachments) { + if (plainTextFileName.equals(a.getOriginalFileName())) { + attachments.remove(a); + break; + } } + attachments.add(attachment); } + } - DataHandler dh = bp.getDataHandler(); + // text email + } else if (message.isMimeType("text/*")) { + String content = FaxToMailServiceUtils.getTextFromMessage(message); - // create new attachment - Attachment attachment = new AttachmentImpl(); - attachment.setAddedByUser(false); - AttachmentFile attachmentFile = getAttachmentFileFromStream(dh.getInputStream()); - attachmentFile.setFilename(fileName); - attachment.setOriginalFile(attachmentFile); - attachment.setContentId(contentID); + if (StringUtils.isNotBlank(content)) { + Attachment attachment = convertTextToPdf(content, plainTextFileName); + attachments.add(0, attachment); + } - // convert attachment if defined by admin - convertIfNecessary(attachment); + //directly an attachment + } else { + String fileName = message.getFileName(); + + try { + fileName = MimeUtility.decodeText(fileName); - // save attachment - attachments.add(attachment); + } catch (UnsupportedEncodingException ex) { + // don't care, use filename raw value } + + DataHandler dh = message.getDataHandler(); + + // create new attachment + Attachment attachment = new AttachmentImpl(); + attachment.setAddedByUser(false); + AttachmentFile attachmentFile = getAttachmentFileFromStream(dh.getInputStream()); + attachmentFile.setFilename(fileName); + attachment.setOriginalFile(attachmentFile); + + // convert attachment if defined by admin + convertIfNecessary(attachment); + + // save attachment + attachments.add(attachment); } - return result; + + return attachments; } @Override @@ -2052,11 +2175,8 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe @Override public Attachment convertTextToPdf(String content, String name) throws IOException, DocumentException { Preconditions.checkArgument(StringUtils.isNotBlank(content)); - //File target = File.createTempFile("faxtomail-", ".tmp"); - //target.deleteOnExit(); Document document = new Document(); - //FileOutputStream fos = new FileOutputStream(target); ByteArrayOutputStream os = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, os); writer.open(); @@ -2079,7 +2199,9 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe attachment.setOriginalFileName(name + ".pdf"); attachment.setAddedByUser(false); - //target.delete(); + File tempFile = File.createTempFile(name, ".pdf"); + tempFile.createNewFile(); + Files.write(attachmentFileNew.getContent(), tempFile); return attachment; } @@ -2094,45 +2216,47 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe List<String> contents = new ArrayList<String>(); - for (String content : contentList) { - content = content.replaceAll("<meta (.*?)>(</meta>)?", ""); - // remove the images whose sources are on the filesystem of the sender (yes, it happens...) - // cf #6996 - content = content.replaceAll("(\\w+)=([\"'])file://.*?([\"'])", ""); - - for (Attachment attachment : attachments) { - String key = attachment.getContentId(); - if (key == null) { - key = attachment.getOriginalFileName(); - } + if (contentList != null) { + for (String content : contentList) { + content = content.replaceAll("<meta (.*?)>(</meta>)?", ""); + // remove the images whose sources are on the filesystem of the sender (yes, it happens...) + // cf #6996 + content = content.replaceAll("(\\w+)=([\"'])file://.*?([\"'])", ""); + + for (Attachment attachment : attachments) { + String key = attachment.getContentId(); + if (key == null) { + key = attachment.getOriginalFileName(); + } - // get file content - AttachmentFile attachmentFile = attachment.getOriginalFile(); - File file = attachmentFile.getFile(); - fileToDelete.add(file); + // get file content + AttachmentFile attachmentFile = attachment.getOriginalFile(); + File file = attachmentFile.getFile(); + fileToDelete.add(file); - // replace the inline attachments with the extracted attachment file url - // match les patterns: - // <td background="cid:bg.gif" height="52"> - // <img border=0 src="cid:bg.gif" /> - // <img src='cid:5e9ef859-ea65-4f9b-a9fa-30d4a2c5837c' - content = content.replaceAll("(\\w+)=([\"'])cid:" + Pattern.quote(key) + "([\"'])", "$1=$2" + file.toURI() + "$3"); + // replace the inline attachments with the extracted attachment file url + // match les patterns: + // <td background="cid:bg.gif" height="52"> + // <img border=0 src="cid:bg.gif" /> + // <img src='cid:5e9ef859-ea65-4f9b-a9fa-30d4a2c5837c' + content = content.replaceAll("(\\w+)=([\"'])cid:" + Pattern.quote(key) + "([\"'])", "$1=$2" + file.toURI() + "$3"); - if (log.isDebugEnabled()) { - log.debug("Mapping attachment id " + key + " to file " + file.toURI()); + if (log.isDebugEnabled()) { + log.debug("Mapping attachment id " + key + " to file " + file.toURI()); + } } - } - // remove the remaining cids whose attachment is not in the email (yes, it happens) - // cf #6996 - content = content.replaceAll("(\\w+)=([\"'])cid:.*?([\"'])", ""); + // remove the remaining cids whose attachment is not in the email (yes, it happens) + // cf #6996 + content = content.replaceAll("(\\w+)=([\"'])cid:.*?([\"'])", ""); - // on reformate les urls pour supprimer les caractères qui vont pas (ex espaces) - // cf #7740 - String defaultImageIfMalformedUrl = serviceContext.getApplicationConfig().getDefaultImageIfMalformedUrl(); - content = FaxToMailServiceUtils.encodeImageSourcesInEmail(content, defaultImageIfMalformedUrl); + // on reformate les urls pour supprimer les caractères qui vont pas (ex espaces) + // cf #7740 + String defaultImageIfMalformedUrl = serviceContext.getApplicationConfig().getDefaultImageIfMalformedUrl(); + content = FaxToMailServiceUtils.encodeImageSourcesInEmail(content, defaultImageIfMalformedUrl); - contents.add(content); + contents.add(content); + } } Html2Image html2Image = Html2Image.fromHtml(StringUtils.join(contents, "<hr/>")); diff --git a/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties b/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties index 23962ee..7a2bb96 100644 --- a/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties +++ b/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties @@ -4,6 +4,7 @@ faxtomail.archives.import.error.persistence=Erreur technique de persistence faxtomail.archives.import.error.readingAttachmentFile=Erreur lors de la lecture de la PJ %s faxtomail.attachment.demand.filename=Détail de la demande faxtomail.email.content.attachment.forwardedFileName=Email transféré %s +faxtomail.email.content.attachment.htmlFileName=Contenu HTML du mail faxtomail.email.content.attachment.plainFileName=Fichier texte faxtomail.email.content.attachment.unnamed=Pièce-jointe %s faxtomail.email.projectReference.default=Votre demande du %s diff --git a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java index b13512b..717ef8f 100644 --- a/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java +++ b/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/EmailServiceTest.java @@ -26,7 +26,6 @@ package com.franciaflex.faxtomail.services.service; import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; -import com.franciaflex.faxtomail.persistence.entities.AttachmentImpl; import com.franciaflex.faxtomail.persistence.entities.DemandStatus; import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.EmailFilter; @@ -42,8 +41,8 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.io.Files; import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.commons.mail.util.MimeMessageUtils; import org.junit.Assert; import org.junit.Before; @@ -52,16 +51,11 @@ import org.nuiton.topia.persistence.TopiaEntities; import org.nuiton.util.pagination.PaginationParameter; import org.nuiton.util.pagination.PaginationResult; -import javax.activation.DataHandler; import javax.mail.Session; import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeUtility; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -77,6 +71,9 @@ import java.util.Set; */ public class EmailServiceTest extends AbstractFaxToMailServiceTest { + /** Logger. */ + private static final Log log = LogFactory.getLog(EmailServiceTest.class); + protected EmailService service; protected ReferentielService referentielService; @@ -327,50 +324,17 @@ public class EmailServiceTest extends AbstractFaxToMailServiceTest { Session session = Session.getInstance(properties); MimeMessage message = MimeMessageUtils.createMimeMessage(session, emailContent); - Charset charset = FaxToMailServiceUtils.getCharset(message); - ArrayList<Attachment> attachments = new ArrayList<>(); - - if (message.isMimeType("multipart/*")) { - - List<String> htmlContent = service.decomposeMultipartEmail(attachments, message); - - Attachment attachment = service.convertHTMLToPdf(attachments, htmlContent, emailId); - Files.copy(attachment.getOriginalFile().getFile(), new File(tempDirectory, emailId + ".pdf")); - - } else if (message.isMimeType("text/*")) { - // convertit le contenu texte en PDF - String content = IOUtils.toString(message.getInputStream(), charset); - if (StringUtils.isNotBlank(content)) { - Attachment attachment = service.convertTextToPdf(content, emailId); - Files.copy(attachment.getOriginalFile().getFile(), new File(tempDirectory, emailId + ".pdf")); - } - } else { - String fileName = message.getFileName(); - try { - fileName = MimeUtility.decodeText(fileName); - - } catch (UnsupportedEncodingException ex) { - // don't care, use filename raw value - } - - DataHandler dh = message.getDataHandler(); - - // create new attachment - Attachment attachment = new AttachmentImpl(); - attachment.setAddedByUser(false); - AttachmentFile attachmentFile = service.getAttachmentFileFromStream(dh.getInputStream()); - attachmentFile.setFilename(fileName); - attachment.setOriginalFile(attachmentFile); - - // convert attachment if defined by admin - service.convertIfNecessary(attachment); - - // save attachment - attachments.add(attachment); - Files.copy(attachment.getOriginalFile().getFile(), new File(tempDirectory, emailId + ".pdf")); + + List<Attachment> attachments = service.extractAttachmentsFromMessage(message); + + for (Attachment attachment : attachments) { + Files.copy(attachment.getOriginalFile().getFile(), new File(tempDirectory, attachment.getOriginalFileName())); } } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Error while handling the email " + emailId, e); + } Assert.fail(e.getMessage()); } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/OpenReplyAction.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/OpenReplyAction.java index cb1b4fa..50cc47e 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/OpenReplyAction.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/actions/OpenReplyAction.java @@ -36,16 +36,14 @@ import com.franciaflex.faxtomail.ui.swing.content.demande.replies.DemandReplyIte import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUI; import com.franciaflex.faxtomail.ui.swing.content.reply.ReplyFormUIModel; import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.mail.util.MimeMessageUtils; -import javax.mail.Message; import javax.mail.internet.MimeMessage; -import javax.swing.*; -import java.awt.*; -import java.nio.charset.Charset; +import javax.swing.JFrame; +import javax.swing.SwingUtilities; +import java.awt.Dimension; import static org.nuiton.i18n.I18n.t; @@ -82,7 +80,7 @@ public class OpenReplyAction extends AbstractFaxToMailAction<DemandeUIModel, Dem frameContent = new ReplyFormUI(getUI()); // TODO echatellier 20140804 : c'est très technique et très bas niveau, ca devrait se trouver dans les services ReplyContent replyContent = reply.getReplyContent(); - Message message = MimeMessageUtils.createMimeMessage(null, replyContent.getSource()); + MimeMessage message = MimeMessageUtils.createMimeMessage(null, replyContent.getSource()); ReplyFormUIModel replyModel = frameContent.getModel(); replyModel.setEditable(editable); replyModel.setOriginalDemand(demand); @@ -99,11 +97,10 @@ public class OpenReplyAction extends AbstractFaxToMailAction<DemandeUIModel, Dem } if (message.isMimeType("multipart/*")) { - handler.decomposeMultipartEmail(message, replyModel, reply.getTopiaId()); + handler.decomposeMultipartEmail(message, replyModel); } else { - Charset charset = FaxToMailServiceUtils.getCharset(message); - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); replyModel.setMessage(content); } } diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java index 76079d0..a2f5018 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/DemandeUIModel.java @@ -46,7 +46,6 @@ import com.franciaflex.faxtomail.ui.swing.util.AbstractFaxToMailBeanUIModel; import com.google.common.collect.Lists; import jaxx.runtime.JAXXUtil; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -61,10 +60,10 @@ import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.Part; import javax.mail.Session; +import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Date; @@ -922,9 +921,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU properties.setProperty("mail.mime.address.strict", "false"); Session session = Session.getInstance(properties); - Message message = MimeMessageUtils.createMimeMessage(session, getOriginalEmailContent()); - - Charset charset = FaxToMailServiceUtils.getCharset(message); + MimeMessage message = MimeMessageUtils.createMimeMessage(session, getOriginalEmailContent()); if (subject == null) { subject = FaxToMailServiceUtils.getDecodedSubject(message.getSubject()); @@ -951,7 +948,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU decomposeMultipartEmail(message); } else if (message.isMimeType("text/*")) { - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); if (plainContents == null) { plainContents = new ArrayList<String>(); } @@ -987,8 +984,7 @@ public class DemandeUIModel extends AbstractFaxToMailBeanUIModel<Email, DemandeU // if it is a text part, the,n this is the email content String disposition = bp.getDisposition(); if (bp.isMimeType("text/*") && !Part.ATTACHMENT.equals(disposition)) { - Charset charset = FaxToMailServiceUtils.getCharset(bp); - String content = IOUtils.toString(bp.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromPart(bp); if (bp.isMimeType("text/plain")) { if (plainContents == null) { diff --git a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java index 4cf08d1..895dddf 100644 --- a/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java +++ b/faxtomail-ui-swing/src/main/java/com/franciaflex/faxtomail/ui/swing/content/demande/replies/DemandRepliesUIHandler.java @@ -43,7 +43,6 @@ import com.franciaflex.faxtomail.ui.swing.util.FaxToMailUIUtil; import com.google.common.collect.Iterables; import jaxx.runtime.JAXXUtil; import jaxx.runtime.validator.swing.SwingValidator; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.mail.util.MimeMessageUtils; @@ -53,11 +52,13 @@ import org.jdesktop.swingx.decorator.HighlighterFactory; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.mail.BodyPart; -import javax.mail.Message; import javax.mail.Part; +import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import javax.mail.internet.MimeUtility; -import javax.swing.*; +import javax.swing.AbstractCellEditor; +import javax.swing.JComponent; +import javax.swing.JTable; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; @@ -67,11 +68,11 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; -import java.awt.*; +import java.awt.Component; +import java.awt.Dimension; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.ByteArrayOutputStream; -import java.nio.charset.Charset; import static org.nuiton.i18n.I18n.t; @@ -200,7 +201,7 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU ReplyFormUI dialogContent = new ReplyFormUI(ui); // TODO echatellier 20140804 : c'est très technique et très bas niveau, ca devrait se trouver dans les services ReplyContent replyContent = reply.getReplyContent(); - Message message = MimeMessageUtils.createMimeMessage(null, replyContent.getSource()); + MimeMessage message = MimeMessageUtils.createMimeMessage(null, replyContent.getSource()); ReplyFormUIModel replyModel = dialogContent.getModel(); replyModel.setEditable(editable); replyModel.setOriginalDemand(ui.getModel()); @@ -208,11 +209,10 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU replyModel.setSubject(t("faxtomail.reply.forwardsubject", message.getSubject())); if (message.isMimeType("multipart/*")) { - decomposeMultipartEmail(message, replyModel, reply.getTopiaId()); + decomposeMultipartEmail(message, replyModel); } else { - Charset charset = FaxToMailServiceUtils.getCharset(message); - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); replyModel.setMessage(content); } @@ -239,7 +239,7 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU * @param part the part to decompose * @throws Exception */ - public void decomposeMultipartEmail(Part part, ReplyFormUIModel reply, String topiaId) throws Exception { + public void decomposeMultipartEmail(Part part, ReplyFormUIModel reply) throws Exception { DataSource dataSource = part.getDataHandler().getDataSource(); MimeMultipart mimeMultipart = new MimeMultipart(dataSource); int multiPartCount = mimeMultipart.getCount(); @@ -250,13 +250,12 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU // if it is a text part, the,n this is the email content String disposition = bp.getDisposition(); if (bp.isMimeType("text/*") && !Part.ATTACHMENT.equals(disposition)) { - Charset charset = FaxToMailServiceUtils.getCharset(bp); - String content = IOUtils.toString(bp.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromPart(bp); reply.setMessage(content); // if it is multipart part, decompose it } else if (bp.isMimeType("multipart/*")) { - decomposeMultipartEmail(bp, reply, topiaId); + decomposeMultipartEmail(bp, reply); // else, this is an attachment } else { @@ -277,12 +276,6 @@ public class DemandRepliesUIHandler extends AbstractToolbarPopupHandler<DemandeU log.debug("FileName : " + fileName); } - /*File dir = new File(FileUtils.getTempDirectory(), topiaId); - if (!dir.exists()) { - dir.mkdir(); - } - File file = new File(dir, fileName);*/ - ByteArrayOutputStream fos = new ByteArrayOutputStream(); DataHandler dh = bp.getDataHandler(); diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java index 755fc1b..2242274 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/DemandDetailAction.java @@ -41,7 +41,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.collect.Ordering; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -69,7 +68,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; @@ -166,13 +164,12 @@ public class DemandDetailAction extends FaxToMailActionSupport { public String dlReplyAttachment() throws Exception { ReplyContent replyContent = emailService.getReplyContent(id); - Message message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); + MimeMessage message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); EmailUIModel replyModel = new EmailUIModel(); if (message.isMimeType("multipart/*")) { decomposeMultipartEmail(message, replyModel); } else { - Charset charset = FaxToMailServiceUtils.getCharset(message); - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); replyModel.setPlainContent(content); } @@ -238,7 +235,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { for (Reply reply : demand.getReplies()) { ReplyContent replyContent = reply.getReplyContent(); - Message message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); + MimeMessage message = new MimeMessage(null, new ByteArrayInputStream(replyContent.getSource())); EmailUIModel replyModel = new EmailUIModel(); replyModel.setId(reply.getTopiaId()); @@ -262,8 +259,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { decomposeMultipartEmail(message, replyModel); } else { - Charset charset = FaxToMailServiceUtils.getCharset(message); - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); replyModel.setPlainContent(content); } @@ -341,7 +337,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { OriginalEmail originalEmail = demand.getOriginalEmail(); String originalEmailContent = originalEmail.getContent(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(originalEmailContent.getBytes(StandardCharsets.UTF_8)); - Message message = new MimeMessage(null, byteArrayInputStream); + MimeMessage message = new MimeMessage(null, byteArrayInputStream); emailUIModel.setSubject(message.getSubject()); List<String> toRecipients = new ArrayList<>(); @@ -366,8 +362,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { decomposeMultipartEmail(message, emailUIModel); } else if (message.isMimeType("text/*")) { - Charset charset = FaxToMailServiceUtils.getCharset(message); - String content = IOUtils.toString(message.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromMessage(message); emailUIModel.setPlainContent(content); } @@ -398,8 +393,7 @@ public class DemandDetailAction extends FaxToMailActionSupport { // if it is a text part, the,n this is the email content String disposition = bp.getDisposition(); if (bp.isMimeType("text/*") && !Part.ATTACHMENT.equals(disposition)) { - Charset charset = FaxToMailServiceUtils.getCharset(bp); - String content = IOUtils.toString(bp.getInputStream(), charset); + String content = FaxToMailServiceUtils.getTextFromPart(bp); if (bp.isMimeType("text/plain")) { emailUIModel.setPlainContent(content); } else { diff --git a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java index c2c7364..9d87a72 100644 --- a/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java +++ b/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java @@ -27,8 +27,6 @@ package com.franciaflex.faxtomail.web.job; import com.franciaflex.faxtomail.FaxToMailApplicationContext; import com.franciaflex.faxtomail.FaxToMailConfiguration; import com.franciaflex.faxtomail.persistence.entities.Attachment; -import com.franciaflex.faxtomail.persistence.entities.AttachmentFile; -import com.franciaflex.faxtomail.persistence.entities.AttachmentImpl; import com.franciaflex.faxtomail.persistence.entities.Client; import com.franciaflex.faxtomail.persistence.entities.DemandStatus; import com.franciaflex.faxtomail.persistence.entities.Email; @@ -49,7 +47,6 @@ import com.franciaflex.faxtomail.services.service.MailFolderService; import com.google.common.base.Function; import com.google.common.collect.Collections2; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -58,7 +55,6 @@ import org.quartz.DisallowConcurrentExecution; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; -import javax.activation.DataHandler; import javax.mail.Address; import javax.mail.Flags; import javax.mail.Folder; @@ -68,8 +64,6 @@ import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Store; import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeUtility; -import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.text.DateFormat; import java.util.ArrayList; @@ -329,8 +323,15 @@ public class MailFilterJob extends AbstractFaxToMailJob { String company = filterFolder.getCompany(); String brand = null; // TODO kmorin 20150320 retirer cette rustine quand la gestion des marques par nom de domaine sera faite - if ("@groupecreal.com".equals(email.getRecipient().substring(email.getRecipient().lastIndexOf("@")))) { - brand = "creal"; + String recipient1 = email.getRecipient(); + if (StringUtils.isNotEmpty(recipient1) && recipient1.lastIndexOf("@") > 0) { + if ("@groupecreal.com".equals(recipient1.substring(recipient1.lastIndexOf("@")))) { + brand = "creal"; + } + } else { + if (log.isErrorEnabled()) { + log.error("Destinataire vide ou sans @ : " + recipient1); + } } Address[] addresses = message.getFrom(); @@ -471,64 +472,7 @@ public class MailFilterJob extends AbstractFaxToMailJob { email.setSubject(FaxToMailServiceUtils.getDecodedSubject(message.getSubject())); - List<Attachment> attachments = new ArrayList<>(); - if (message.isMimeType("multipart/*")) { - - // manage boundary id - List<String> htmlContent = emailService.decomposeMultipartEmail(attachments, message); - if (htmlContent != null) { - if (log.isDebugEnabled()) { - log.debug("Converting html content to pdf : " + message.getSubject()); - } - Attachment attachment = emailService.convertHTMLToPdf(attachments, htmlContent, t("faxtomail.email.content.attachment.htmlFileName")); - if (attachment != null) { - //remove text plain attachement if exists, to avoid having twice the mail content in the attachments - String plainTextFileName = t("faxtomail.email.content.attachment.plainFileName") + ".pdf"; - for (Attachment a : attachments) { - if (plainTextFileName.equals(a.getOriginalFileName())) { - attachments.remove(a); - break; - } - } - attachments.add(attachment); - } - } - - // text email - } else if (message.isMimeType("text/*")) { - // convertit le contenu texte en PDF - String content = IOUtils.toString(message.getInputStream(), charset); - if (StringUtils.isNotBlank(content)) { - Attachment attachment = emailService.convertTextToPdf(content, t("faxtomail.email.content.attachment.plainFileName")); - attachments.add(0, attachment); - } - - //directly an attachment - } else { - String fileName = message.getFileName(); - - try { - fileName = MimeUtility.decodeText(fileName); - - } catch (UnsupportedEncodingException ex) { - // don't care, use filename raw value - } - - DataHandler dh = message.getDataHandler(); - - // create new attachment - Attachment attachment = new AttachmentImpl(); - attachment.setAddedByUser(false); - AttachmentFile attachmentFile = emailService.getAttachmentFileFromStream(dh.getInputStream()); - attachmentFile.setFilename(fileName); - attachment.setOriginalFile(attachmentFile); - - // convert attachment if defined by admin - emailService.convertIfNecessary(attachment); - - // save attachment - attachments.add(attachment); - } + List<Attachment> attachments = emailService.extractAttachmentsFromMessage((MimeMessage) message); emailService.saveEmail(email, attachments, -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm