[ale] Parsing attachments out of email

Jay Loden jloden at toughguy.net
Fri Dec 8 21:39:09 EST 2006


>> In this case, what I need is to do a search and replace pattern across the entire set of
>> lines. I assume there must be some way to do this with a special command through sed or a
>> special perl script, but it's beyond me knowledge of either. Anyone happen to know how i
>> can do either?

In case anyone is interested, I managed to get this going with a simple procmail rule and 
a tiny perl script. The perl code is as follows:

#!/usr/bin/perl -w

use strict;

my @stdin;
my @message;
getStdin(\@stdin);
my $stdinstring = join("", @stdin);
if($stdinstring =~ /X-MS-Has-Attach: yes/ims){
                 $stdinstring =~ s/^X-MimeOLE.*X-MimeOLE/X-MimeOLE/ims;
}
print $stdinstring;

#subroutines
sub getStdin{
         my $line;
         my $lines = shift;
         while ($line = <>) {
                 #print;
                 push(@$lines, $line);
         }
}

And the procmail rule just pipes my incoming mail through that small script to rip out all 
the junk I didnt need. So Christopher Fowler was right, Perl was the answer ;)

-Jay



More information about the Ale mailing list