If Outlook is available you may be better off using that.
This is a skeleton of something I've used. You'd need to adjust the mailbox name.
#!/usr/bin/perl
use v5.12.2;
use warnings;
use strict;
use Win32::OLE;
my $mail = parse_inbox();
sub parse_inbox{
# use existing instance if Outlook is already running, or launce a n
+ew one
my $ol;
eval {$ol = Win32::OLE->GetActiveObject('Outlook.Application')};
die "Outlook not installed" if $@;
unless (defined $ol) {
$ol = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;})
or die "Oops, cannot start Outlook";
}
my $mailbox = seekFolder(
$ol->Session,
'Mailbox - John Sharpe'
); # adjust to suit
my $folder = seekFolder(
$mailbox,
'Inbox'
);
my (%table);
for (my $i = 1; $i <= $folder->Items->Count; $i++) {
my $sender_name = $folder->Items->Item($i)->SenderName;
my $subject = $folder->Items->Item($i)->Subject;
my $body = $folder->Items->Item($i)->Body;
say $subject;
# process
# store something in table
}
return \%table;
}
sub seekFolder {
my $obj = shift;
my $target = shift;
for (my $i = 1; $i <= $obj->Folders->Count; $i++) {
if ($obj->Folders->Item($i)->Name eq $target) {
return $obj->Folders->Item($i);
}
}
return;
}
Tested with Outlook 2003. There is a snag in that after the script is started Outlook complains that something is trying to look at the contact list. You need to click a checkbox and OK.