Parse INLINE attachments without ID as regular attachments when converting
fauvetg opened this issue · comments
fauvetg commented
Hello,
Apparently some mailer clients can send emails that contain one or multiple inline attachment, without any contentId :
From: Test <test@example.com>
Content-Type: multipart/mixed;
boundary="Apple-Mail=_DF026BAA-42B1-476C-A89F-A2B2D388A362"
Subject: test PJ
Message-ID: <87B0499D-EFFC-424C-8B68-45B6CBDDBA29@resabase.com>
Date: Thu, 15 Jun 2017 09:52:02 +0200
To: Test <test@example.com>
X-Mailer: Apple Mail (2.3273)
MIME-Version: 1.0
--Apple-Mail=_DF026BAA-42B1-476C-A89F-A2B2D388A362
Content-Disposition: inline;
filename="ALERTE SOCIALE 12 juin 2017.pdf"
Content-Type: application/pdf;
x-unix-mode=0644;
name="ALERTE SOCIALE 12 juin 2017.pdf"
Content-Transfer-Encoding: base64
...
--Apple-Mail=_DF026BAA-42B1-476C-A89F-A2B2D388A362
Content-Disposition: inline;
filename="ALERTE SOCIALE 12 juin 2017.pdf"
Content-Type: application/pdf;
x-unix-mode=0644;
name="ALERTE SOCIALE 12 juin 2017.pdf"
Content-Transfer-Encoding: base64
...
--Apple-Mail=_DF026BAA-42B1-476C-A89F-A2B2D388A362--
In this case, the email contains 2 attachments, but the MimeMessageParser's cidMap
contains only one, with a null
key.
A way to fix this would be to handle an INLINE Content-Disposition without contentID just as a standard attachment :
final DataSource ds = createDataSource(part);
// 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(parseResourceName(part.getContentID(), part.getFileName()), ds);
} else if (Part.INLINE.equalsIgnoreCase(part.getDisposition())) {
if (part.getContentID() != null) {
this.cidMap.put(part.getContentID(), ds);
} else {
// Missing contentID : treated as standard attachment
this.attachmentList.put(parseResourceName(null, part.getFileName()), ds);
}
} else {
throw new IllegalStateException("invalid attachment type");
}
Sincerely,
Benny Bottema commented
Thanks for the report. I'll look into it.
Benny Bottema commented
Related to smiley22/S22.Imap#81.
Benny Bottema commented
Released in 4.3.0.