luckypower has asked for the wisdom of the Perl Monks concerning the following question:

hellow monks

i want to find that whether text in MIME mail is attachment or mail content.

using MIME::Entity module.

when i try to read the content-type, disposition, etc fields of an text attachment, it looks same as the content of mail.

here is the content of mail

Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
This is simple mail for testing.

and this is text attachment

Content-Type: text/plain;
name="123.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="123.txt"
1
2
3
4
5


any help..???
  • Comment on how to find text file in MIME mail is attachment or content of mail??

Replies are listed 'Best First'.
Re: how to find text file in MIME mail is attachment or content of mail??
by McD (Chaplain) on Nov 04, 2008 at 13:46 UTC
    You wrote:

    i want to find that whether text in MIME mail is attachment or mail content.

    As you've discovered, there's effectively no difference. A text attachment will usually have a filename suggested in the content-disposition, but not always. The "content" or mail body will typically be the first entity - but again, not always.

    If you describe what you're trying to do more specifically, maybe we can suggest another way to do it.
      Hi McD
      Actually i want to compress mail attachments(not the mail contents).
      if the attachments are in BASE64 encoding, its easy to find out the attachments and compress it. but if the attachments are text file so its encoding is 7bit.

      so i want to detach the text file and compress it.

      Thanks.
        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!
Re: how to find text file in MIME mail is attachment or content of mail??
by Anonymous Monk on Nov 04, 2008 at 13:23 UTC
    when i try to read the content-type, disposition, etc fields of an text attachment, it looks same as the content of mail.
    Show your code (and complete message, like multi-simple.msg), otherwise see examples/mimedump it shows how.
Re: how to find text file in MIME mail is attachment or content of mail??
by Anonymous Monk on Nov 04, 2008 at 12:57 UTC
    Why didn't you use code tags?