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

Let me show the example first:
If you have an email:
From test@gmail.com Tue Nov 21 02:29:28 2006 Return-Path: test.gmail.com Received: from test@gmail.com (gmail.com [172.27.220.34]) for test@gmail.com; Tue, 21 Nov 2006 02:29:28 GMT Message-Id: <200611210229.kAL2TS3D013057@gmail.com> Received: from grpm_dom-MTA by gmail.com with Novell_GroupWise; Tue, 21 Nov 2006 02:29:28 +0000 Received: from localhost.localdomain (gmail.com [172.27.30.200]) by gmail.com with ESMTP; Tue, 21 Nov 2006 02:29:01 +0000 Content-Transfer-Encoding: binary Content-Type: multipart/related; boundary="_----------=_11640761411305 +30" MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; T1.16; A1.67; B3.05; Q3.03) Date: Tue, 21 Nov 2006 02:29:01 UT From: test.team.email@gmail.com To: test@gmail.com Subject: Notification - This call has been assigned to you. (Task ID:1 +29244) This is a multi-part message in MIME format. --_----------=_1164076141130530 Content-Disposition: inline Content-Length: 1668 Content-Transfer-Encoding: binary Content-Type: text/html <body> <table> </table> </body> --_----------=_1164076141130530--
when we try to read the email box with Mail::Box::Mbox
# Set mbox object. my $mb = Mail::Box::Mbox->new( folder => "/var/spool/mail/root", access => 'rw', remove_when_empty => 0, lock_wait => 10, lock_method => 'DOTLOCK', ); use Data::Dumper; for my $msg ($mb->messages) { print Dumper($msg->string); }
the message is:
Return-Path: test.gmail.com Received: from test@gmail.com (gmail.com [172.27.220.34]) for test@gmail.com; Tue, 21 Nov 2006 02:29:28 GMT Message-Id: <200611210229.kAL2TS3D013057@gmail.com> Received: from grpm_dom-MTA by gmail.com with Novell_GroupWise; Tue, 21 Nov 2006 02:29:28 +0000 Received: from localhost.localdomain (gmail.com [172.27.30.200]) by gmail.com with ESMTP; Tue, 21 Nov 2006 02:29:01 +0000 Content-Transfer-Encoding: binary Content-Type: multipart/related; boundary="_----------=_11640761411305 +30" MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; T1.16; A1.67; B3.05; Q3.03) Date: Tue, 21 Nov 2006 02:29:01 UT From: test.team.email@gmail.com To: test@gmail.com Subject: Notification - This call has been assigned to you. (Task ID:1 +29244) This is a multi-part message in MIME format. --_----------=_1164076141130530 Content-Disposition: inline Content-Length: 1668 Content-Transfer-Encoding: binary Content-Type: text/html <body> <table> </table> </body> --_----------=_1164076141130530 --_----------=_1164076141130530--
strange line:
--_----------=_1164076141130530
is added to the email and it is causing me big problems.
Thanks in advance for everyone who can help.
Ivan

Replies are listed 'Best First'.
Re: Mail::Box::Mbox adds a strange boundary when read email
by jettero (Monsignor) on Dec 19, 2006 at 11:49 UTC

    Hrm, that's pretty standard stuff....

    Content-Type: multipart/related; boundary="_----------=_11640761411305 +30"

    That is a MIME header that says your document is broken up into peices, divided by your "strange line." Mail::Box definitely knows how to read MIME messages, so I suspect you're not using the module to its full potential. It's possible the mail is damaged in some way. It looks acceptable to my tired eyes though.

    -Paul

Re: Mail::Box::Mbox adds a strange boundary when read email
by jbert (Priest) on Dec 19, 2006 at 13:05 UTC
    The string is a MIME boundary marker. It is used to seperate the different parts of the message. e.g. a message with an attachment might have a multipart/alternative part, containing a text/plain part and a text/html part, followed by an application/octet-stream part. This nested email structure is kept straight by the use of these boundaries.

    You've called ->string on the object, asking for the message as a single string - which is what you've got.

    If you want just some parts of the message, look at some of the other methods in Mail::Box::Message - there is a full selection of methods to pick apart the message, e.g. ->parts pulls apart the message into its constituent body parts.

    Read the docs, have a play with these modules and don't forget to test with emails of different types (with and without attachments, with and without HTML alternatives, etc).

      Yes, you are right, I can use a lot of methods to handle different parts of email message, but in this case I want to get the source of the email.
      My final target is to have all the email separated in an Array and to save them in different files
      If this strange boundary is a part of my target file when I try to open the file from Outlook Express the Email application is adding a non existing Email Attachment.
      In example above the Outlook Express will open an Email with attachment: ATT00002.txt which is wrong the part is just a html body not the attachment.
      I hope you can undestand me.
        I think Outlook is correct. The top-level content type (in the headers) is multipart.

        If you want a plain HTML mail (and you should really send multipart/mixed(text/plain + text/html)) then you should create it that way to start with. The headers suggest that you're creating the mail programatically. If you don't like the way it has been created then my advice would be to take a look at that and do it differently...

Re: Mail::Box::Mbox adds a strange boundary when read email
by dlegia (Initiate) on Dec 20, 2006 at 13:14 UTC
    Hi all
    I found the problem:
    The missing "last" new line in email source:
    From test@gmail.com Tue Nov 21 02:29:28 2006 Return-Path: test.gmail.com Received: from test@gmail.com (gmail.com [172.27.220.34]) for test@gmail.com; Tue, 21 Nov 2006 02:29:28 GMT Message-Id: <200611210229.kAL2TS3D013057@gmail.com> Received: from grpm_dom-MTA by gmail.com with Novell_GroupWise; Tue, 21 Nov 2006 02:29:28 +0000 Received: from localhost.localdomain (gmail.com [172.27.30.200]) by gmail.com with ESMTP; Tue, 21 Nov 2006 02:29:01 +0000 Content-Transfer-Encoding: binary Content-Type: multipart/related; boundary="_----------=_11640761411305 +30" MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; T1.16; A1.67; B3.05; Q3.03) Date: Tue, 21 Nov 2006 02:29:01 UT From: test.team.email@gmail.com To: test@gmail.com Subject: Notification - This call has been assigned to you. (Task ID:1 +29244) This is a multi-part message in MIME format. --_----------=_1164076141130530 Content-Disposition: inline Content-Length: 1668 Content-Transfer-Encoding: binary Content-Type: text/html <body> <table> </table> </body> --_----------=_1164076141130530--
    it has to be:
    From test@gmail.com Tue Nov 21 02:29:28 2006 Return-Path: test.gmail.com Received: from test@gmail.com (gmail.com [172.27.220.34]) for test@gmail.com; Tue, 21 Nov 2006 02:29:28 GMT Message-Id: <200611210229.kAL2TS3D013057@gmail.com> Received: from grpm_dom-MTA by gmail.com with Novell_GroupWise; Tue, 21 Nov 2006 02:29:28 +0000 Received: from localhost.localdomain (gmail.com [172.27.30.200]) by gmail.com with ESMTP; Tue, 21 Nov 2006 02:29:01 +0000 Content-Transfer-Encoding: binary Content-Type: multipart/related; boundary="_----------=_11640761411305 +30" MIME-Version: 1.0 X-Mailer: MIME::Lite 3.01 (F2.72; T1.16; A1.67; B3.05; Q3.03) Date: Tue, 21 Nov 2006 02:29:01 UT From: test.team.email@gmail.com To: test@gmail.com Subject: Notification - This call has been assigned to you. (Task ID:1 +29244) This is a multi-part message in MIME format. --_----------=_1164076141130530 Content-Disposition: inline Content-Length: 1668 Content-Transfer-Encoding: binary Content-Type: text/html <body> <table> </table> </body> --_----------=_1164076141130530-- <the important new line>
    Thanks for all efforts to help me.