in reply to Re^2: Outlook OLE Delete Attachments
in thread Outlook OLE Delete Attachments
This morning I realized that you are deleting elements of an array that you are looping over. So the foreach loop approach I suggested is not a good idea.
Then I found this node from ten years ago where you were deleting attachments in Outlook using a method called Remove(). Did that not work for this?
Your code:
my $count = $msg->{Attachments}->Count; if ($count > 0) { for (my $i = $count; $i > 0; $i--) { if (defined($msg->{Attachments}->Items($i))) { $msg->{Attachments}->Items($i)->Delete; } } print UnixDate($msgdate,"%Y-%m-%d %i:%M:%S %p")," ",substr +($msg->{Subject},0,30)."... $count attachments deleted\n"; }
One thing I notice here is that you are setting $count before the for loop and then assuming it should decrement each time you call delete. However you are decrementing $count each time whether or not you delete! This is the problem and some print statements would have clearly shown this.
|
|---|