[Dovecot] Check if a message has attachments
Michael M. Slusarz
slusarz at curecanti.org
Fri Jan 14 23:00:38 EET 2011
Quoting Antoine Nguyen <ngu.antoine at gmail.com>:
> I'm working on a web based software that provides a simple webmail (
> http://modoboa.org/). I'm wondering what would an efficient way to detect if
> a message (or a group of messages) has attachments. I know it certainly
> consists in checking for specific MIME constructions but how to achieve that
> without fetching the whole body for each message?
You should only need the structure for each message, which you can get
with BODYSTRUCTURE command.
But beware that determination of what is an "attachment" is not so
straight-forward. The Content-Disposition header (RFC 2183), if it
even exists, is often not useful.
Take these examples:
* Message with a single application/pdf part. Is this an attachment?
Many users would say yes. But what if Content-Disposition does exist
and is set to 'inline'.
* multipart/mixed part, with a single text/plain child part. This is
most likely not an attachment, at least by an end user definition, and
shows that you can't just search for 'multipart' in the Content-Type
field.
* multipart/related part with two embedded parts, text and HTML.
Again, most likely users would not expect this to be an attachment.
* multipart/related part with two embedded parts, one text and one
PDF. If PDF can't be displayed in the MUA, should it be considered an
attachment, even though it lives in a multipart/related part? (e.g.
the text part is intended to be displayed as a quick view of the PDF,
but loses all of the formatting contained in the PDF.)
And so on.
michael
More information about the dovecot
mailing list