Skip to content

Commit

Permalink
Add heuristic to map inline image attachment CID to Content-ID
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrussler committed May 31, 2024
1 parent 0be1b54 commit a0439a6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/mimeparser/MimeMessageConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,18 @@ public static void convertToPdf(String emailFilePath, String pdfOutputPath, bool
htmlBody = StringReplacer.replace(htmlBody, IMG_CID_REGEX, new StringReplacerCallback() {
@Override
public String replace(Matcher m) throws Exception {
MimeObjectEntry<String> base64Entry = inlineImageMap.get("<" + m.group(1) + ">");
String cid = m.group(1);
MimeObjectEntry<String> base64Entry = inlineImageMap.get("<" + cid + ">");

// heuristic to find entry with in eml cid=X and Content-ID=<X@...>
if (base64Entry == null) {
for (String key : inlineImageMap.keySet()) {
if (key.startsWith("<" + cid + "@") && key.endsWith(">")) {
base64Entry = inlineImageMap.get(key);
break;
}
}
}

// found no image for this cid, just return the matches string as it is
if (base64Entry == null) {
Expand Down

0 comments on commit a0439a6

Please sign in to comment.