Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/main/java/org/codemonkey/simplejavamail/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,12 @@ private static BodyPart getBodyPartFromDatasource(final AttachmentResource resou
final BodyPart attachmentPart = new MimeBodyPart();
final DataSource ds = resource.getDataSource();
// setting headers isn't working nicely using the javax mail API, so let's do that manually
String contentId= resource.getName();
String fileName = ds.getName() != null ? ds.getName() : contentId;
attachmentPart.setDataHandler(new DataHandler(resource.getDataSource()));
attachmentPart.setFileName(resource.getName());
attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName());
attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName()));
attachmentPart.setFileName(fileName);
attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + fileName + "; name=" + fileName);
attachmentPart.setHeader("Content-ID", String.format("<%s>", contentId));
attachmentPart.setDisposition(dispositionType + "; size=0");
return attachmentPart;
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/codemonkey/simplejavamail/email/Email.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,21 @@ private void fillEmailFromMimeMessage(MimeMessageParser parser) throws Messaging
this.setText(parser.getPlainContent());
this.setTextHTML(parser.getHtmlContent());
for (Map.Entry<String, DataSource> cid : parser.getCidMap().entrySet()) {
this.addEmbeddedImage(cid.getKey(), cid.getValue());
this.addEmbeddedImage(beautifyCID(cid.getKey()), cid.getValue());
}
for (Map.Entry<String, DataSource> attachment : parser.getAttachmentList().entrySet()) {
this.addAttachment(attachment.getKey(), attachment.getValue());
this.addAttachment(beautifyCID(attachment.getKey()), attachment.getValue());
}
}

private String beautifyCID(String cid){
int len1 = 0;
if(cid == null || (len1 = cid.length() - 1) < 0){
return cid;
}
if(cid.charAt(0) == '<' && cid.charAt(len1) == '>' ){
return cid.substring(1, len1);
}
return cid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ protected void parse(final MimePart part)
}
} else {
final DataSource ds = createDataSource(part);
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
this.attachmentList.put(part.getFileName(), ds);
// If the diposition is not provided, the part should be treat as attachment
if (part.getDisposition() == null || Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
this.attachmentList.put(part.getContentID(), ds);
} else if (Part.INLINE.equalsIgnoreCase(part.getDisposition())) {
this.cidMap.put(part.getFileName(), ds);
this.cidMap.put(part.getContentID(), ds);
} else {
throw new IllegalStateException("invalid attachment type");
}
Expand Down