there's a problem with the parts_set() function call:
when the function is called with a one part message, it doesn't change
that part but it justs change the content-type.
i'll attach a file that shows the problem.
marco.
Subject: | bugreport.pl |
#!/usr/bin/perl
use strict;
use Email::MIME::Modifier;
my $email = Email::MIME->new( join "", <> );
my @stack;
my $already_html=0;
my $already_txt=0;
# print $email->debug_structure;
#remove_attachments($email);
#&add_image_attachment($email,'logo.png');
#&add_image_attachment($email,'environment.png');
print "######\nBefore\n######\n" . $email->debug_structure;
#&parts_walk($email);
print "######\nAfter\n######\n" . $email->debug_structure;
remove_attachments($email);
#print $email->as_string;
sub remove_attachments {
my $email = shift;
my @keep;
foreach my $part ( $email->parts ) {
push @keep, $part
unless $part->header('Content-Disposition') =~ /^attachment/;
remove_attachments($part)
if $part->content_type =~ /^(?:multipart|message)/;
&add_image_attachment($part,'logo.png');
}
print "######\nIntra\n######\n" . @keep[0]->debug_structure;
$email->parts_set( \@keep );
}
sub file_read {
my $filename = shift;
my $buf;
my $line;
open(MYFILE,"<".$filename);
binmode(MYFILE);
while ($line = <MYFILE>){
$buf.=$line;
}
close(MYFILE);
return $buf
}
sub add_image_attachment {
my @temp;
#my $buf;
#my $line;
my $email = shift; # shift(@_)
my $filename = shift;
my $newpart = Email::MIME->new("");
$newpart->encoding_set('base64');
$newpart->filename_set($filename);
$newpart->name_set($filename);
$newpart->content_type_set('image/png');
$newpart->disposition_set('attachment');
# $newpart->charset_set('ISO-8859-1');
# $buf = &file_read($filename);
#open(LOGO,"<".$filename);
#binmode(LOGO);
#while ($line = <LOGO>){
# $buf.=$line;
#}
#close(LOGO);
$newpart->header_set('Content-ID',''.$filename.'.06060507.09080005@turboden');
$newpart->body_set( &file_read($filename) );
# $newpart->header_set('Content-ID',''.$filename.'.06060507.09080005@turboden');
# $newpart->debug_structure;
@temp = ($newpart);
$email->parts_add( \@temp );
}