axllent / mailpit

An email and SMTP testing tool with API for developers
https://mailpit.axllent.org
MIT License
5.63k stars 139 forks source link

Inline images are listed among the attachments #379

Open tkoop opened 4 days ago

tkoop commented 4 days ago

If an email has an image in it with a disposition of "inline", it shows up in Mailpit as an attachment. The UI will say there is an attachment, but there isn't really.

Other email clients don't consider "inline" files to be attachments, so they shouldn't show up in Mailpit as attachments either.

For example, the html of the email may contain an inline png, like this:

<img src="cid:dc94e944fb73a7d82ed7da8350333ae6@symfony" alt="image">

When it does, there should also be a file included that matches the cid ("Content-id"), like this. (Also notice the Content-Disposition is "inline").

--w9GNgkGw
Content-ID: <dc94e944fb73a7d82ed7da8350333ae6@symfony>
Content-Type: image/png; name="dc94e944fb73a7d82ed7da8350333ae6@symfony"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 name="dc94e944fb73a7d82ed7da8350333ae6@symfony"; filename=embed0.png

iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9
kT1Iw0AcxV9TpVoqDlYo4hCkOlkQFXHUKhShQqgVWnUwufRDaNKQtLg4Cq4FBz8Wqw4uzro6uAqC
4AeIs4OToouU+L+k0CLGg+N+vLv3uHsHCPUS06yOMUDTK2YqERcz2RUx8IogIuhHN4ZkZhmzkpSE
5/i6h4+vdzGe5X3uz9Gj5iwG+ETiGWaYFeJ14qnNisF5nzjMirJKfE48atIFiR+5rrj8xrngsMAz
w2Y6NUccJhYLbay0MSuaGvEkcVTVdMoXMi6rnLc4a6Uqa96TvzCU05eXuE5zEAksYBESRCioYgMl
VBCjVSfFQor24x7+AccvkUsh1wYYOeZRhgbZ8YP/we9urfzEuJsUigOdL7b9MQwEdoFGzba/j227
cQL4n4ErveUv14HpT9JrLS16BPRuAxfXLU3ZAy53gMiTIZuyI/lpCvk88H5G35QF+m6B4KrbW3Mf
pw9AmrpK3gAHh8BIgbLXPN7d1d7bv2ea/f0AaVtyo0qcczMAAAAGYktHRAAAAAAAAPlDu38AAAAJ
cEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfoChgVGzUMtjq8AAAAGXRFWHRDb21tZW50AENyZWF0
ZWQgd2l0aCBHSU1QV4EOFwAAADtJREFUOMtjnLzJ5z8DlQATAxUBC4yR67eFbEMmb/KhvstGiGEs
6IFICOCLqNEIGKAcMBoBdMwBdHMZAFlwC77XoVD6AAAAAElFTkSuQmCC
--w9GNgkGw

When this happens, the web UI shows this as an attachment, but it shouldn't. No other email client considers files like this to be attachments, so Mailpit shouldn't either.

image

image

If we really like the idea of listing all included files in the email, we should at least differentiate between attached files and inline files. Perhaps we could have two lists: a list of "Attachments", and a list of all "Included Files".

For the sake of completeness, this is what an actual attachment looks like. Notice the value of "Content-Disposition".

--frmTiHh9
Content-Type: application/pdf; name="abide.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; name="abide.pdf"; filename="abide.pdf"

JVBERi0xLjQKJcfsj6IKJSVJbnZvY2F0aW9uOiBncyAtc0RFVklDRT1wZGZ3cml0ZSAtZENvbXBh
dGliaWxpdHlMZXZlbD0xLjQgLWRQREZTRVRUSU5HUz0vcHJpbnRlciAtZE5PUEFVU0UgLWRRVUlF
VCAtZEJBVENIIC1zT3V0cHV0RmlsZT0/ID8KNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nH1by65syVEthISsYuBfKMmTc5DuJh+Rr6llC8wAuc2V
GGAzObhlQd2WjD8AIwb8Dp/jz2GtFZl776o6sq6660RUPiLjHZFZv7+FLd4C/83Pj2/Xv/1Vv338
4Rq2Prrlfnv94w8fP1zD7Uvbyq3GFG784z9/e/3+qpX09e+v0YH58fHt9tOvWDrG27h9/f7qu/H/
X/LWyu3rt+u/vF3+4vKz9y9hs25W29vlu/ewldhSy2+Xv+MXJbXWy9vlF+9fUi7bGIWDvvCvNDDh
X4G3vIUw3i5/rZVAcLG3yy81O46Y+9vlP9bCZlj4/h4jgIgpP7z/5us/kEhzImvoW0oNRH79t+vb
...
tkoop commented 4 days ago

Also note this. On the home page, the paper clip icon does show up correctly, only when disposition is "attachment", not when it is "inline".

image

axllent commented 4 days ago

@tkoop Thanks for the details. You are correct, there is a discrepancy between the message list attachment indicator (paper clip) and the message view (Attachment (1)) which I will fix.

Backstory: Unfortunately there are actually huge discrepancies between mail clients, mainly in the generation of messages containing inline images. A number of clients do not actually use the Content-Disposition: inline; / Content-ID attributes - they just attach the file (like a regular attachment) and reference the filename as <img src="cid:<filename>" />. Because of this, many (most?) clients support displaying inline images even when they are attachments (and so does Mailpit).

Originally I catered for this in Mailpit by referring to both attachments and inline images as "attachments" in the web UI as well as the search, however that is wrong and at some point I decided this was a bad idea and changed it to the current behaviour. But, as you pointed out, there is still one artefact from that (...in the current versions of Mailpit, you're using an older version < v1.20.0 based on hour screenshots) - that being the Attachment (1) in the message view in your screenshot.

I need to give this a little more thought as to whether I just exclude inline images from that count, or whether I add a new Inline (1) tag to the message view (eg: a message with one attachment and two inline images could show Attachment (1) and Inlines (2)).