Parsing Multiple MIME Parts 
Author Message
 Parsing Multiple MIME Parts

Quote:

> I am using the MIME-tools module.  After I parse the mail message I
> cannot figure out how to seperate each of the entities in the message.
> It is a multipart mail message with text in the body and an attached
> text file and an attached gif file.  This is the code I am currently
> using:

(snip)

Nothing wrong with your code, as far as I can see.
Notice, BTW, that you are using output_to_core(),
which you may or may not want to do.  If you want
everything to "hit disk", you could say:

    $parser->output_to_core('NONE');

Then, if you have a multipart message, you could do this
(off the top of my head) with the $entity that the
parser returns:

    my $part;


        if (lc($part->mime_type) eq 'image/gif') {
            print "GIF file is in ", $part->body->path;
        }
        else {
            print "Misc part: ", $part->mime_type;
        }
    }

Then, when you're all done and want the files to go away:

    $entity->purge()

HTH.  Let me know if it doesn't.

--

 / _ \| '_| | | |/ _ ' /  Hughes STX, NASA/Goddard Space Flight Cntr.
|  __/| | | |_| | |_| |   http://www.*-*-*.com/ ~eryq
 \___||_|  \__, |\__, |___/\  Visit STREETWISE, Chicago's newspaper by/
           |___/    |______/ of the homeless: http://www.*-*-*.com/



Tue, 11 Jan 2000 03:00:00 GMT  
 Parsing Multiple MIME Parts

I am using the MIME-tools module.  After I parse the mail message I
cannot figure out how to seperate each of the entities in the message.
It is a multipart mail message with text in the body and an attached
text file and an attached gif file.  This is the code I am currently
using:

    # Create a new parser object:
    my $parser = new MIME::Parser;

    # Set up output directory for files:
    $ENV_HOME = $ENV{HOME};
    $parser->output_dir("$ENV{HOME}/mimemail");
    print "Home  : ", $ENV_HOME, "\n";

    # Set up the prefix for files with auto-generated names:
    $parser->output_prefix("part");

    # If content length is this or below, write to in-core scalar;
    # Else, write to a disk file (the default action):
    $parser->output_to_core(20000);

    # Parse an input stream:
    $entity = $parser->read($pop->Body($i)) || die "couldn't parse
MIME stream";

    # Congratulations: you now have a (possibly multipart) MIME
    # entity!
    $entity->dump_skeleton;          # for debugging

    print "Head:", $entity->head, "\n\n";

    $body = $entity->bodyhandle;
    $message = "";

    # Compute content-lengths for singleparts based on bodies:
    $entity->sync_headers(Length=>'COMPUTE');

    # Output!
    print "Entity: ", $entity->print(\*STDOUT), "\n\n";
    print "Mime-Type:", $entity->mime_type, "\n\n";

    print "Parts : ", $entity->parts(), "\n";

    if ($entity->mime_type eq "text/plain") {
        $message = $pop->Body($i);
        print "Message:", $message, "\n\n";
    }
    else {
        # Read data from the body:
        $IO = $body->open("r")      || die "open body: $!";
        while (defined($_ = $IO->getline)) {
           # do stuff
            $message = $_;
            print "Message:", $_, "\n\n";
        }
        $IO->close                  || die "close I/O handle: $!";
    }

Any help would be greatly appreciated.

Lennie



Tue, 11 Jan 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mime-Tools Parsing multiple mails (newbie)

2. MIME::Parse and MIME::Entity

3. ANNOUNCE: MIME:: modules for parsing MIME streams

4. manipulating MIME parts in a file

5. How to get only Content-Type: text/plain part from MIME mail

6. Getting the names of the files for each MIME:Entity part

7. Send multi-part MIME with BLAT for NT ?

8. Extract parts of a Mime mail ...

9. manipulating MIME parts in a file

10. checking for string in multiple line scalar (part II)

11. Parsing DSP files with perl, part II

12. Help Parsing ASCII File, Part 2

 

 
Powered by phpBB® Forum Software