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

Hi, Ive been using a script to retrieve messages & process them, & delete messages ok.. it works fine, Im now transfering the code over to a new script.... however it now gets the message correctly, But it refuses to delete the message afterwards. Is there a 'debug' thing for pop3 commands ? a summary of commands i'm using are :-
use Net::POP3; # This debug flag will print debugging code to your browser, depending + on its value # Set this to 1 to send debug code to your browser. Set it to 0 to tu +rn it off. my $DEBUG = 1; if($DEBUG) { $| = 1; open(STDERR, ">&STDOUT"); } # Set this variable to your POP3 server name my $ServerName = "my.server.com"; # Create a new POP3 object my $pop3 = Net::POP3->new($ServerName, Debug => 0) or die "Couldn't lo +g on to server"; # Initiate the mail transaction my $UserName = "username"; my $Password = "password"; my $Num_Messages = $pop3->login($UserName, $Password); # Get the list of messages my $Messages; my $msg_id; $Messages = $pop3->list(); # Parse each message header for "From" and "Subject" fields foreach $msg_id (keys(%$Messages)) { if ($msg_id <$end){ next; } my $MsgContent = $pop3->top($msg_id, 50); PrintList($msg_id,@$MsgContent); my $delete = $pop3->delete($msg_id);
------------- END QUOTE MY WORDS :- ok, Printlist does the main processing of the message - & it works.. & ive verified that $msg_id is still correct - But it wont delete...

Ive even put the delete funcrtion immediatly after the message - eg :-
my $MsgContent = $pop3->top($msg_id, 50); my $delete = $pop3->delete($msg_id); PrintList($msg_id,@$MsgContent);
Even if I delete before it gets processed - It still processes the message, However it doesnt delete.

Can someone advise

Thankyou

Replies are listed 'Best First'.
Re: POP3 Delete ?
by virtualsue (Vicar) on Mar 25, 2003 at 13:54 UTC
    In a private message, I pointed Gordonisnz to POP3 mailbox cleaner, since it is a self-contained snippet which demonstrates how to delete POP3 messages. He looked at it, and determined that his problem was due to the fact that he wasn't using the quit method, which is what actually closes the mailbox and preserves the changes. Problem solved, he says.
Re: POP3 Delete ?
by Mr. Muskrat (Canon) on Mar 25, 2003 at 14:19 UTC

    Is there a 'debug' thing for pop3 commands ?
    Change:
    my $pop3 = Net::POP3->new($ServerName, Debug => 0) or die "Couldn't log on to server";
    to:
    my $pop3 = Net::POP3->new($ServerName, Debug => 1) or die "Couldn't log on to server";.

Re: POP3 Delete ?
by shotgunefx (Parson) on Mar 25, 2003 at 13:33 UTC
    It is probably timing out. I had this happen and made a wrapper around POP3 to keep track of the deleted msg_ids and check to see if the connection was lost before the destructor and if so, reconnect and delete them again. I didn't get around yet to putting it up on CPAN but perhaps I can clean it up for general use and posted it later this week.

    -Lee

    "To be civilized is to deny one's nature."
FIXED: Re: POP3 Delete ?
by Gordonisnz (Initiate) on Mar 25, 2003 at 14:12 UTC
    I found out I wasnt using a ->quit(); command

    Its working now.
      Duh, I missed that. I would still caution the that if you are doing anything slow when processing, beware timing out.

      I had this happen with a cron job that after a year the data feed grew substantially. I noticed later that day when Eudora said "Downloading 1 of 4082 messages"... Whooops! Needless to say that after that I always put in several redunadant checks to make sure that messages are indeed deleted.

      -Lee

      "To be civilized is to deny one's nature."
Re: POP3 Delete ?
by dbush (Deacon) on Mar 25, 2003 at 13:57 UTC

    Not a perl solution but tcpTrace would allow you to view the interaction between the client script and the POP server.

    Regards,
    Dom.

Re: POP3 Delete ?
by tachyon (Chancellor) on Mar 25, 2003 at 23:14 UTC

    Mail::POP3Client works reliably and has a pretty good interface.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print