Okay, I think I get it. You want to compress "attachments", but not the "mail body" and text attachments are throwing you because they look like the mail body.

That's going to be tricky - don't forget that MIME entities can nest, you often have to process them recursively. (Think of a MIME message which has an attached MIME message, like a mail forward...)

There are also semantic considerations - such as what the effects might be of compressing parts of an entity of type multipart/related, you might break the composite entity.

But speaking in terms of a quick-and-dirty solution that works 90% of the time, I'd say go ahead and key off the presence of a suggested file name. Process the message entity by entity, and if there's a filename suggestion (in content-type or content-disposition, as you saw) then assume it's an attachment and replace it with a compressed version of itself.

You can throw in some heuristics to make it little more robust, like never compressing the first text entity you come across, never compressing a single-part message (only one entity), and not descending inside of multipart/alternative entities (which often contain the text/html and text/plain versions of the "message body").

Good luck!

In reply to Re^3: how to find text file in MIME mail is attachment or content of mail?? by McD
in thread how to find text file in MIME mail is attachment or content of mail?? by luckypower

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.