Aziz Saleh am Montag, 23. September 2013 - 22:06:
> What Niklaus wishes for is a way to detect if an email message
contains an
> attachment by just reading the headers (correct me if I am wrong).
Yes, that's what I'm seeking :-)

> This isn't really a PHP issue. In any language you can't really figure
> if an email has an attachment by just looking at the headers, you need
> check the body. You can try to infer by using the content-type or the
> but that isn't 100% valid.

That's like radio Eriwan: In principle you are right!

BUT: I want not show the whole MIME-structure in the mailbox overview!
That whould be absurd, and indeed could only be done by reading the

Nevertheless we have in the primary header of any MIME compliant message
the line "Content-Type". (We have it also in the headers of the attached
parts, but that is not intresting now)

In this primary header (fetched by "imap_fetchbody($mailbox, $msg_no,
0)) the leading part of the MIME-type description can have only two
values: "text" or "multipart". Right? I'm sure you will never find other
values in the _primary_ header.

That's the first decision for your script. "text: no attachment",
"multipart: attachment". No matter the subtype-value after the slash,
you have what I want! And ONLY by looking on the header. And this ist
100% valid, because it follows logically from the imap- and MIME-rfc's.

About malformed messages violating the protocols we discuss next year,
you agree? :-)

You may evaluate the subtype after the slash. If the type is multipart,
you will find "mixed", "alternative", "related" or "digest", if the type
is "text", you will have "plain" or "html" as subtype.

May be there are more subtypes on the way, but all these are optional
for the primary job, a decent mailbox overview must do: tell the user,
whether there are attachments or not.

My own webmail client does this job pretty good, but it violates my own
standard of good practice. Whether "imap_fetch-overview()" nor
"imap_headerinfo" are reading the "Content-Type"-line while parsing much
other header lines of minor importance. My script must refetch the
mailheaders to do that! This is an ugly overhead I wish to avoid.

BTW: the "squirrelmail"-staff, leading in the PHP-webmail-world, just
ignores the whole imap-extension of PHP. Instead, they talk low level
with the server. But this way is a little bit too hard for me...

Therefore my pledge to all involved into the development of the fabulous
PHP framework, section imap:
Please ad the primary MIME-type to the objects returned by
fetch_overview and headerinfo! It's so ridiculous simple: read the
"Content-Type"-line in the primary mailheader as I must do afterwards,
only because you do not!



PHP General Mailing List (
To unsubscribe, visit:

Reply via email to