Yeah, you probably really want to be using a module to parse the MIME structure of the message, but you can probably still do some quick and dirty things.

You should search for Content-Type: headers. You can do something fancy or something crude. Something crude would be to catch it wherever it appears in the message, but this means you would catch it even if it appears as part of the text of the message (well, how likely is that??). You can get fancy and try to catch it only when it appears in MIME body part headers and not in bodies themselves, but the fancier you get the close you get to reinventing a preexisting MIME parser module such as the one you suggest -- so try to get one installed instead :-)

Once you are collecting Content-Type:s, you should whitelist the ones you will accept:

Anything else, like image/* and application/* is likely to be what should be considered an attachment.

Once you get a proper MIME parsing module installed and begin using it, you can use the same technique of whitelisting text/* but you won't have to worry about message/* and multipart/* because those will probably be dealt with by the module.

There is another header, called Content-Disposition: which specifies unambiguously whether a body part is inline or is an attachment, but you probably cannot use that because it is not always present.


In reply to Re: establishing the existance of an email attachment by Celada
in thread establishing the existance of an email attachment by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.