You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Brett Hoffman <bh...@unifiedcs.com> on 2007/07/19 17:08:14 UTC
Parsing attachments
Hi,
I ran across the script (pasted below, and watch wrapping) on this list
about a year ago or so. I use it to parse attachments "forwarded as
attachments" from MS Outlook. It worked very well until I upgraded to
SpamAssassin 3.2.1
I imagine they changed something in the way that the find_parts works,
but for the life of me I can't figure out why the script doesn't work
anymore. Essentially what happens is it returns a 0 byte message after
it parses the message.
Any pointers or suggestions would be much appreciated.
#!/usr/bin/perl
use strict;
use warnings;
my @message = <STDIN>;
my $path = "/tmp/spam/";
use Mail::SpamAssassin::Message;
use Data::UUID;
my $msg = Mail::SpamAssassin::Message->new(
{
'message' => \@message,
}
) || die "Message error?";
foreach my $p ($msg->find_parts(qr/^message\b/i, 0)) {
eval {
no warnings ;
my $type = $p->{'type'};
my $ug = new Data::UUID;
my $uuid1 = $ug->create_str();
my $attachname = $path . $uuid1 . ".eml";
open OUT, ">", "$attachname" || die "Can't write file
$attachname:$!";
binmode OUT;
print OUT $p->decode();
};
}
Thanks,
Brett
RE: Parsing attachments
Posted by Bret Miller <br...@wcg.org>.
> I ran across the script (pasted below, and watch wrapping) on
> this list about a year ago or so. I use it to parse
> attachments "forwarded as attachments" from MS Outlook. It
> worked very well until I upgraded to SpamAssassin 3.2.1
>
> I imagine they changed something in the way that the
> find_parts works, but for the life of me I can't figure out
> why the script doesn't work anymore. Essentially what happens
> is it returns a 0 byte message after it parses the message.
>
> Any pointers or suggestions would be much appreciated.
I'll take a stab at this since I had to fix my script recently too. I'm
not sure I know exactly what I'm doing, but I'll point out the
differences below:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my @message = <STDIN>;
> my $path = "/tmp/spam/";
>
> use Mail::SpamAssassin::Message;
> use Data::UUID;
>
> my $msg = Mail::SpamAssassin::Message->new(
> {
> 'message' => \@message,
> }
> ) || die "Message error?";
Mine says:
my $msg = Mail::SpamAssassin::Message->new({
message => \@message,
parsenow => 1,
subparse => 1
}) || die "Message error?";
>
> foreach my $p ($msg->find_parts(qr/^message\b/i, 0)) {
Mine says:
foreach my $p ($msg->find_parts(qr/^message\b/i, 0, 0)) {
I don't have an eval statement. I don't use $p->{'type'} though I
suspect it would still work. And the rest looks fine to me. I'd post my
script, but it uses IMAP to re-store the forwarded messages in the mail
server, not in the file system.
> eval {
> no warnings ;
> my $type = $p->{'type'};
> my $ug = new Data::UUID;
> my $uuid1 = $ug->create_str();
> my $attachname = $path . $uuid1 . ".eml";
> open OUT, ">", "$attachname" || die "Can't write
> file $attachname:$!";
> binmode OUT;
> print OUT $p->decode();
> };
> }
HTH,
Bret