Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone.

Today I'm trying to delete some emails from my email account and for some reason it's not deleting them. I'm using Mail::POP3 to connect and everything looks good except for deleting emails. It does connect and prints out the header and body of my emails so I know it's making contact with the server.

foreach my $to_delete (@ids) { $to_delete =~ s/Message\-id:\s+//i; $to_delete =~ s/<//g; $to_delete =~ s/>//g; print "trying to delete $to_delete<br>"; $pop->Delete($to_delete); } $pop->Close();
Below is what I get on my output. The first two lines are what is read from the script. I have two emails in my email account with the IDs it mentions. The second two lines are the ouput of what it is trying to delete. After every time I run the script the email IDs stay the same but the emails never delete.

I did some hacking by removing the Message-ID: from the message-id line pulled back by the module. I also removed the <>s just in case. None of these had any affect on the deletion of emails.
Message-ID: <0016e646069637dafe049ec66ea8@google.com> Message-ID: <90e6ba3fd257d1d9da049ec67ca9@google.com> trying to delete 0016e646069637dafe049ec66ea8@google.com trying to delete 90e6ba3fd257d1d9da049ec67ca9@google.com
Can someone help me?

Replies are listed 'Best First'.
Re: Can't delete emails from server
by Eliya (Vicar) on Mar 18, 2011 at 20:14 UTC

    I think the delete method (which is just a thin wrapper around the POP3 "DELE" command) expects a sequential message number, not the Message-ID.  For example, "2" to delete the second message in your account.

      You are right! That did the trick and now everything works the way it should. Thank you! Thank you! You saved me a lot of frustration!