[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] MIME parse



Last week I posted a request about sending and receiving mail
attachments and am writing to report the (mostly) good news:).

First, thanks to Paul S. I found the needed modules at CPAN under author
"Eryq." The code for a simple parsing program follows...it searches a
directory and reads the first 20 lines of each file, looking to see if
it is MIME multi-part/mixed. Then it parses each MIME file.

One problem is that each part is extracted and renamed with a "/" in
front of it...not terribly (mac) friendly. I'll look into how this could
be changed. 

This script seems to suffer slightly from a memory issue, (see my next
posting!!!) but mostly runs consistently.

Thanks to all and take care :)

##########

use MIME::Parser;

##########

$dir="daffners:Desktop Folder:6.9:";

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

    # Set up output directory for files:
    $parser->output_dir("$dir");

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

    # If content length is <= 20000 bytes, store each msg as in-core
scalar;
    # Else, write to a disk file (the default action):
    $parser->output_to_core(20000);

        opendir(DIR1,"$dir") ;       
        @filelist = readdir(DIR1) ;       
        closedir(DIR1);

foreach $file_d (@filelist){

$count="0";

open (FILE, "$file_d");
@lines=<FILE>;
close(FILE);

foreach $e (@lines){

++$count;

if ($count <= 20 && $e =~/mixed/i){
@mimelist= (@mimelist , "$file_d");}
}
}

foreach $file_m (@mimelist){

print "FILE: $file_m is a mime file!!\n";

open (DAFF, "$file_m");
    # Parse an input stream:
    $entity = $parser->read(\*DAFF) or die "couldn't parse MIME stream";
close(DAFF);

    $entity->dump_skeleton;          # for debugging 

}


###end of program

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch