Skip to content

Commit

Permalink
fixed mail parsing error related to inline images. close #2669
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Nov 16, 2024
1 parent c606346 commit 92fb076
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
-Dsonar.organization=jlawyerorg
-Dsonar.projectKey=jlawyerorg_j-lawyer-org
-Dsonar.projectName=j-lawyer-org
-Dsonar.projectVersion=2.6.0
-Dsonar.projectVersion=3.1-dev
-Dsonar.java.binaries=.
-Dsonar.java.source=11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,24 @@ private Map<String, MimeMessageObject> getInlinedImage(Part part) throws Excepti
walkMimeStructure(part, 0, (p, level) -> {
String[] header = p.getHeader(CONTENT_ID);
if (p.isMimeType(IMAGE_TYPE) && nonNull(header)) {
if (p.getContent() != null && !(p.getContent() instanceof BASE64DecoderStream)) {
log.warn("inline image has content of instance " + p.getContent().getClass().getName());
} else {
try {
String imageBase64 = Base64.getEncoder().encodeToString(IOUtils.toByteArray((BASE64DecoderStream) p.getContent()));
result.put(header[0], new MimeMessageObject(imageBase64, new ContentType(p.getContentType())));
} catch (Throwable t) {
log.error("unable to get content of inline image - skipping", t);

Object contentObject=null;
try {
contentObject=p.getContent();
} catch (Throwable t) {
log.error("Unable to extract content", t);
}

if (contentObject != null) {
if (!(contentObject instanceof BASE64DecoderStream)) {
log.warn("inline image has content of instance " + contentObject.getClass().getName());
} else {
try {
String imageBase64 = Base64.getEncoder().encodeToString(IOUtils.toByteArray((BASE64DecoderStream) contentObject));
result.put(header[0], new MimeMessageObject(imageBase64, new ContentType(p.getContentType())));
} catch (Throwable t) {
log.error("unable to get content of inline image - skipping", t);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
package com.jdimension.jlawyer.client.utils.convert;

import static com.jdimension.jlawyer.client.utils.convert.Helper.DEFAULT_HTML_NAME;
import static com.jdimension.jlawyer.client.utils.convert.Helper.DEFAULT_PDF_NAME;
import static com.jdimension.jlawyer.client.utils.convert.Helper.EMAIL_HEADER_ID;
import static com.jdimension.jlawyer.client.utils.convert.Helper.HEADER_TEMPLATE_CONTAINER;
import static com.jdimension.jlawyer.client.utils.convert.Helper.TEMP_DIR;
import static com.jdimension.jlawyer.client.utils.convert.Helper.UNKNOWN;
import static com.jdimension.jlawyer.client.utils.convert.Helper.readTemplate;
import static com.jdimension.jlawyer.client.utils.convert.Helper.writeToFile;
import com.lowagie.text.DocumentException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
//import org.simplejavamail.api.email.AttachmentResource;
//import org.simplejavamail.converter.EmailConverter;

import javax.mail.MessagingException;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.ArrayList;
import static java.util.Objects.isNull;
import static java.util.Optional.ofNullable;
import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
Expand Down

0 comments on commit 92fb076

Please sign in to comment.