Hey Win,
I did almost exactly this recently...this script takes a folder that you want to search, a folder you want to move processed mail items to, and a regex to search on the subject line.
The datestamping could use work, I was just lazy b/c it was just for me.
#! perl -w
use strict;
use Win32::OLE qw(in valof with OVERLOAD);
my $infolder;
my $tstamp = &getDateString;
my ($in, $to, $submatch)=@ARGV;
my $mail = new Win32::OLE('Outlook.Application');
my $ns = $mail->GetNamespace("MAPI");
my $inbox = $ns->GetDefaultFolder(6);
if ($in !~ /inbox/i){
$infolder = $inbox->Folders($in);
}
else {
$infolder = $inbox;
}
my $tofolder = $inbox->Folders($to);
my $count = $infolder->Items->Count;
print "There are $count messages in the $in folder\n";
my $i=0;
my $result = &saveAttachments($submatch);
sub saveAttachments(){
my ($sub) = @_;
foreach my $item(in $infolder->Items){
#my $bdy = $item->Body;
my $subject = $item->Subject;
#print "$subject\n";
#print "$bdy\n";
if ($subject =~ /$sub/i){
foreach my $atm(in $item->Attachments){
my $atmname = $atm->FileName;
$tstamp = &getDateString;
print "\nSaving $tstamp.$atmname...";
$atm->SaveAsFile("H:\\erepts\\$tstamp.$atmname");
(-e "H:\\erepts\\$tstamp.$atmname") or print "Could not sa
+ve $tstamp.$atmname\n";
}
$item->Move($tofolder);
}
}
}
sub getDateString(){
my @fields=localtime();
$fields[5] += 1900;
$fields[4]++;
for (@fields){
$_ = sprintf ("%01d", $_) if length($_) gt 2;
}
my $time_stamp = join "-", reverse @fields[0..5];
return $time_stamp;
}
#$mail->Quit();