C
cayenne
Hello all,
I'm trying to learn Perl, and do something fairly difficult at the
same time for work. I'm trying to use the MIME tools modules...and
the examples there on the docs are kinda sparse...and I'm confused how
to decode things to a directory on my harddrive.
At this point, just to learn how it works...I'm sending the perl
script a simple email with text message...and one .jpg image that is
encoded in base64. I'm trying to write these out to a spot on my
harddrive. I'm posting just the part where it is looping through the
mime message, and trying to split off the plain text part (which does
work), but, blows up on messages with a base64 attachment.
Code snippet:
foreach $part ($entity->parts_DFS) {
$head = MIME::Head->new;
$head = $part->head;
$rec_filename = $head->recommended_filename;
$encode_type = $head->get('Content-Transfer-Encoding',0);
$encode_type =~ tr/A-Z/a-z/;
$encode_type =~ s/\s+$//;
my $mimetype = $part->mime_type();
if ($mimetype eq 'text/plain'){
$msg_body = $part->as_string;
$filename = $subject;
open (outfile,">$dir_path/$dir_name/$filename");
print outfile "$msg_body\n";
close (outfile);
} else {
$msg_body = new MIME:
ecoder 'base64' or die 'unsupported';
$filename = $rec_filename;
open (outfile,">$dir_path/$dir_name/$filename");
$msg_body->decode ($part,outfile);
close (outfile);
}
I'm using :
use MIME:
arser;
use MIME::Head;
use MIME::Body;
use MIME:
ecoder;
And the dir_path, dir_name are all being set correctly earlier in the
code..but, I'm having difficulty in decoding the attachment to the
disk...
Can someone give me an example or describe what I'm doing wrong
here...? I think it is the output part writing out the base64
part...but, I'm not sure what is wrong here...all the examples I've
seen are going to STDOUT rather than to a file on the harddrive...
Oh, one last thing probably important I'm doing this all in 'core'
which I am guessing means just all in memory rather that a temp spot
on the disk:
$parser->output_to_core(1);
Thanks in advance for any advice, pointers, links...
chilecayenne
I'm trying to learn Perl, and do something fairly difficult at the
same time for work. I'm trying to use the MIME tools modules...and
the examples there on the docs are kinda sparse...and I'm confused how
to decode things to a directory on my harddrive.
At this point, just to learn how it works...I'm sending the perl
script a simple email with text message...and one .jpg image that is
encoded in base64. I'm trying to write these out to a spot on my
harddrive. I'm posting just the part where it is looping through the
mime message, and trying to split off the plain text part (which does
work), but, blows up on messages with a base64 attachment.
Code snippet:
foreach $part ($entity->parts_DFS) {
$head = MIME::Head->new;
$head = $part->head;
$rec_filename = $head->recommended_filename;
$encode_type = $head->get('Content-Transfer-Encoding',0);
$encode_type =~ tr/A-Z/a-z/;
$encode_type =~ s/\s+$//;
my $mimetype = $part->mime_type();
if ($mimetype eq 'text/plain'){
$msg_body = $part->as_string;
$filename = $subject;
open (outfile,">$dir_path/$dir_name/$filename");
print outfile "$msg_body\n";
close (outfile);
} else {
$msg_body = new MIME:
$filename = $rec_filename;
open (outfile,">$dir_path/$dir_name/$filename");
$msg_body->decode ($part,outfile);
close (outfile);
}
I'm using :
use MIME:
use MIME::Head;
use MIME::Body;
use MIME:
And the dir_path, dir_name are all being set correctly earlier in the
code..but, I'm having difficulty in decoding the attachment to the
disk...
Can someone give me an example or describe what I'm doing wrong
here...? I think it is the output part writing out the base64
part...but, I'm not sure what is wrong here...all the examples I've
seen are going to STDOUT rather than to a file on the harddrive...
Oh, one last thing probably important I'm doing this all in 'core'
which I am guessing means just all in memory rather that a temp spot
on the disk:
$parser->output_to_core(1);
Thanks in advance for any advice, pointers, links...
chilecayenne