#!perl use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::Const 'Microsoft Outlook'; use Data::Dumper; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use IO::File; use Win32::OLE::Variant; my $outlook; eval { $outlook = Win32::OLE->GetActiveObject('Outlook.Application') }; if ($@ || !defined($outlook)) { $outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;}) or die("Cannot create outlook\n"); } my $namespace = $outlook->GetNamespace('MAPI'); # get the proper pst file my $folder = $namespace->{'Folders'}{'somepst'}; # now get the folder within the pst file my $folder2 = $folder->{'Folders'}{"dailyfolder"}; # get all the messages my $msgs = $folder2->{Items}; my $ncon = $msgs->{Count}; print "number of contacts - $ncon\n\n"; # this works my $app = new Win32::OLE('Redemption.SafeMailItem'); my $con; my $at; my $fn; my $obase = 'C:\strawberry\perl\daily\\'; my $out; my $po = {}; foreach my $ii (1 .. $ncon) { $con = $msgs->Item($ii); $app->{'Item'} = $con; #print_body($app->{Body}); #find_data($app->{Body},$ii,$t); $at = $app->{'Attachments'}; print "\n\n Attachment count\n"; print $at->{Count} . "\n"; $fn = $at->Item(1)->{FileName}; print "filename is $fn\n" if $fn; $out = $obase . $fn; if(!-e $out) { $at->Item(1)->SaveAsFile($out); print "SAVING ATTACHMENT TO $out\n"; } $po->{$out}++; } my $z = Archive::Zip->new(); my $i = 1; my $fh; my $fl; my $exf = {}; my $he = 0; foreach my $zf (keys %$po) { warn("processing $zf\n"); unless( $z->read($zf) == AZ_OK) { die("ERROR READING $zf\n"); } foreach my $m ($z->memberNames()) { warn("processing member $m\n"); if(! -e "$obase$m") { $fh = IO::File->new("$obase$m",">") or die($!); $fl = $z->memberNamed($m); $fl->extractToFileHandle($fh); $fh->close() if $fh; if($m =~ /\.xls$/) { $exf->{"$obase$m"}++; $he++; } next; } } }