This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository faxtomail. See http://git.codelutin.com/faxtomail.git commit 60a69ed926434eb528a3d3c88f90286baf442f48 Author: Kevin Morin <morin@codelutin.com> Date: Thu Nov 12 16:58:56 2015 +0100 concaténation des différentes partie text/html de l'email pour la génération du pdf (fixes #7716) --- .../faxtomail/services/service/EmailService.java | 4 +- .../services/service/EmailServiceImpl.java | 81 ++++++++++++---------- .../faxtomail/web/job/MailFilterJob.java | 2 +- 3 files changed, 49 insertions(+), 38 deletions(-) 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 f8352a8..0005165 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 @@ -155,7 +155,7 @@ public interface EmailService extends FaxToMailService { * @param part the part to decompose * @throws Exception */ - String decomposeMultipartEmail(List<Attachment> attachments, Part part) throws Exception; + List<String> decomposeMultipartEmail(List<Attachment> attachments, Part part) throws Exception; /** * Retourne un input stream sur une piece jointe convertie ou pas. @@ -187,5 +187,5 @@ public interface EmailService extends FaxToMailService { * @return image attachment or {@code null} if content can't be converted * @throws IOException */ - Attachment convertHTMLToPdf(List<Attachment> attachments, String content, String name) throws IOException; + Attachment convertHTMLToPdf(List<Attachment> attachments, List<String> content, String name) throws IOException; } 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 e3aa7d6..a007a99 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 @@ -1840,12 +1840,12 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe } @Override - public String decomposeMultipartEmail(List<Attachment> attachments, Part part) throws Exception { + public List<String> decomposeMultipartEmail(List<Attachment> attachments, Part part) throws Exception { return decomposeMultipartEmail(attachments, part, 0); } - protected String decomposeMultipartEmail(List<Attachment> attachments, Part part, int decomposingForwardedEmail) throws Exception { - String result = null; + 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); @@ -1875,12 +1875,15 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe } } else { - result = content; + if (result == null) { + result = new ArrayList<String>(); + } + result.add(content); } // if it is multipart part, decompose it } else if (bp.isMimeType("multipart/*")) { - String htmlContent = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); + List<String> htmlContent = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); if (htmlContent != null) { result = htmlContent; } @@ -1890,8 +1893,8 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe Attachment attachment = null; String fileName = t("faxtomail.email.content.attachment.forwardedFileName", decomposingForwardedEmail) + ".pdf"; try { - String content = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); - if (StringUtils.isNotBlank(content)) { + List<String> content = decomposeMultipartEmail(attachments, bp, decomposingForwardedEmail); + if (content != null) { attachment = convertHTMLToPdf(attachments, content, fileName); } @@ -2083,44 +2086,52 @@ public class EmailServiceImpl extends FaxToMailServiceSupport implements EmailSe } @Override - public Attachment convertHTMLToPdf(List<Attachment> attachments, String content, String name) throws IOException { + public Attachment convertHTMLToPdf(List<Attachment> attachments, List<String> contentList, String name) throws IOException { Attachment result = null; ByteArrayOutputStream os = new ByteArrayOutputStream(); Collection<File> fileToDelete = new ArrayList<File>(); + try { - 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); + 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(); + } - // 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"); + // get file content + AttachmentFile attachmentFile = attachment.getOriginalFile(); + File file = attachmentFile.getFile(); + fileToDelete.add(file); - if (log.isDebugEnabled()) { - log.debug("Mapping attachment id " + key + " to file " + file.toURI()); + // 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()); + } } - } - // 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:.*?([\"'])", ""); + + contents.add(content); + } - Html2Image html2Image = Html2Image.fromHtml(content); + Html2Image html2Image = Html2Image.fromHtml(StringUtils.join(contents, "<hr/>")); ImageRenderer imageRenderer = html2Image.getImageRenderer().setWidth((int) PageSize.A4.getWidth()); org.w3c.dom.Document doc = html2Image.getParser().getDocument(); 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 7867b3c..05d0e41 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 @@ -476,7 +476,7 @@ public class MailFilterJob extends AbstractFaxToMailJob { if (message.isMimeType("multipart/*")) { // manage boundary id - String htmlContent = emailService.decomposeMultipartEmail(attachments, message); + List<String> htmlContent = emailService.decomposeMultipartEmail(attachments, message); if (htmlContent != null) { if (log.isDebugEnabled()) { log.debug("Converting html content to pdf : " + message.getSubject()); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.