cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
It works great up until the last if block. When I watch it with the debugger, it seems to be working because it finds the messages with attachments, $attachments->Count does decrement as it goes through the while loop, and the while loop terminates. However when the script finished and I look in Outlook the attachments are still there. What am I doing wrong?use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; my $Folder; my $mailboxname = "Mailbox"; # set up OLE my $Outlook; eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed" if $@; unless (defined $Outlook) { $Outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit +;}) or die "Cannot start Outlook"; } my $ol = Win32::OLE::Const->Load($Outlook); my $namespace = $Outlook->GetNamespace("MAPI"); # open folder if ($ARGV[0]) { $Folder = $namespace->Folders($mailboxname)->Folders($ARGV[0]) || +die "Can't open folder $ARGV[0]\n"; } else { die "Usage: stripattachments.pl foldername\n"; } my $n = $Folder->Items->Count; # analyze messages print "$n messages\n\n"; for my $i (1..$n) { print "Message $i "; my $msg = $Folder->Items($i); my $attachments = $msg->attachments; if ($attachments->Count) { print "removing..."; while ($attachments->Count) { $attachments->Remove(1); } } print "\n"; } undef $Outlook;
TIA.....Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32 Deleting Outlook Attachments
by Roger (Parson) on Jan 13, 2004 at 03:20 UTC | |
|
Re: Win32 Deleting Outlook Attachments
by maa (Pilgrim) on Jan 13, 2004 at 07:41 UTC | |
by cormanaz (Deacon) on Jan 13, 2004 at 14:24 UTC |