------------------------------------------------
On Fri, 21 Feb 2003 11:13:06 -0600, "Dan Muey" <[EMAIL PROTECTED]> wrote:

> Sweet!! Thanks a million!!!
> 
> Any ideas how to get the text/plain section of the message into an array or scalar?
> 

This goes back to the everything in the body before the first boundary is the text 
content (known as the preamble). So you can pull the boundary from the MIME header in 
the main message in the case of a multipart, and look until you run into the boundary 
(in the case that you don't run into the boundary then it is not multipart and you 
want the whole body anyways.)  Of course all of this is messy, you could also try the 
Mail::Box module which handles all of this beautifully if you are working your way to 
anything complex.

Mail::Box does have a fair amount of overhead all things considering, but then, mail 
is probably one of the most complex things on the internet.

For example:

#!/usr/local/bin/perl
#
# $Id$
use strict;
use warnings;

use 5.6.1;

use Mail::Box::Manager;

my $filename = '/tmp/smtp-raw-2003';

my $mgr    = Mail::Box::Manager->new;
my $folder = $mgr->open($filename);
my $message = $folder->message(0);

my $subject = $message->get('subject');
print "Subject: ",$subject || '<no subject>', "\n";
print "From: ",$message->get('From') || '<no from>', "\n";
print "To: ",$message->get('To') || '<no to>', "\n";
print "Date: ",$message->get('Date') || '<no date>', "\n";
print "Content-type: ",$message->get('content-type') || '<no mime type>', "\n";
print "Content-Transfer-Encoding: ",$message->get('content-transfer-encoding') || '<no 
encoding type>', "\n";

print "\n";

if ($message->isMultipart()) {

    print "This message has ", scalar($message->parts()), " parts.\n";

    my $count = 0;
    foreach my $part ($message->parts()) {

        print "Part #$count.......\n";

        my $contenttype = $part->get('content-type');
        print "Part content type: $contenttype\n";

        my $contentenc = $part->get('content-transfer-encoding');
        print "Part content encoding: $contentenc\n";

        if ($contenttype =~ /text/i) {
            print "Text attachment...\n";
        }
        elsif ($contenttype =~ /html/i) {
            print "Html attachment...\n";
        }
        else {
            my $file = "/tmp/attachment-$count.out";

            my $ATTACHMENT;
            open($ATTACHMENT,">$file") or die "Can't open attachment temp file: $!\n";
            $part->decoded()->print($ATTACHMENT);
            close($ATTACHMENT) or die "Not able to close attachment temp file: $!\n";

        }
        print "\n";
        $count++;
    }
}
else {
}

$folder->close;

__END__


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to