[Dovecot] Check if a message has attachments
Hi all,
my question is not specific to Dovecot but to the IMAP protocol in general.
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?
Thanks in advance,
Antoine Nguyen
Quoting Antoine Nguyen ngu.antoine@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
2011/1/14 Michael M. Slusarz slusarz@curecanti.org
You should only need the structure for each message, which you can get with BODYSTRUCTURE command.
Indeed I should be able to achieve what I'm looking for with this 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
Ok, I understand. It seems I need to think my code as flexible as possible because I would certainly have to add unsupported combinations in the future... By the way, thanks for your answer.
Antoine
participants (2)
-
Antoine Nguyen
-
Michael M. Slusarz