#! perl -w use strict; use Win32::OLE; my ($in, $to)=@ARGV; my $mail = new Win32::OLE('Outlook.Application'); my $ns = $mail->GetNamespace("MAPI"); my $inbox = $ns->GetDefaultFolder(6); ## the Inbox my $infolder = $inbox->Folders($in); my $tofolder = $inbox->Folders($to); my $count = $infolder->Items->Count; print "There are $count messages in the $in folder\n"; my $i=0; while($i <= $count){ #the original, which worked, but I didn't particularly care for #the way the iteration was carried out #my $itm = $infolder->Items($i); ## the below line works (it returns a reference to something, but... my $itms = $infolder->Items; for (@$itms){ ## for some reason $itms is not an array reference ## so. . . what is it? my $bdy = $_->Body; #the original line, which worked #my $bdy = $itm->Body; print "$bdy\n"; my $atm = $_->Attachments(1); #original line below #my $atm = $itm->Attachments(1); my $atmname = $atm->FileName; $_->Attachments(1)->SaveAsFile("H:\\erepts\\$i.$atmname"); $_->Move($tofolder); #below worked fine, saved to a folder on the network #$itm->Attachments(1)->SaveAsFile("H:\\erepts\\$i.$atmname"); #$itm->Move($tofolder); } $i++; } $mail->Quit();