bbottema/simple-java-mail

Bug: MimeMessageParser rejects attachments with duplicate names

nicolasbelisle opened this issue · 6 comments

MimeMessageParser uses a Map for the attachments:

484 : public Map<String, DataSource> getAttachmentList()

However an email can have 2 attachments with the same name. The Map will just replace any existing attachment.

Is this a real use case?

Yes. Real email that went through MimeMessageParser (v. 5.1.7).

Essentially replacing the Map with a List<Map.Entry) does the job
It's already called "attachmentList" ;-)
parsedComponents.attachmentList.put(cid, cidEntry.getValue());
to
parsedComponents.attachmentList.add(new AbstractMap.SimpleEntry(cid, cidEntry.getValue()));

BTW, you can add attachments with the same name in Gmail.
Reference nicolasbelisle@47a47f3 (There's a few other fixes in this commit however).

Ok, you made a convincing case. If you feel up to it, I'll accept a PR on master! Or else I'll pick it up in due time.

Fixed and released in 5.2.1!

Seems to be still there in Simple Java Mail 6.5.0:
package org.simplejavamail.converter.internal.mimemessage;
MimeMessageParser :
Line 508 : public Map<String, DataSource> getAttachmentList() {
return this.attachmentList;
}

WIll not work with two attachments named e.g.:
TSOL0038
TSOL0038.AUF

i.e. no suffix in one case.
This case is used for electronic billing for healthcare in Germany.
Works fine with different suffixes.

#249