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

I've got a simple script to download emails w/ attachments from Gmail. What is happening is that the message count is set to zero after I do a read. That's fine & what I would expect. But I'd like to know if there's some way to avoid clearing the message count, so I could download messages again if needed. $pop->reset() doesn't make a difference... ========================
$pop = new Mail::POP3Client( USER => $USER, PASSWORD => $PW, HOST => $SERVER, USESSL => 'true', # DEBUG => 1, PORT => 995 ); print "Status: ". $pop->State()." unread emails:". $pop->Count()."\n"; $count=$pop->Count(); #<<<set to zero after download if($count < 0 ){ print "Error: Gmail returned ".$pop->Message()."\n"; exit; } elsif ($count == 0){ print "No messages for $USER\n"; exit; } for( $i = 1; $i <= $count; $i++ ) { foreach( $pop->Head( $i ) ) { /^(From|Subject):\s+/i && print $_, "\n"; } $body=$pop->HeadAndBody($i); $stripper=Email::MIME::Attachment::Stripper->new($body); $msg=$stripper->message; @attachments=$stripper->attachments; foreach $attachment (@attachments){ # print "$#attachments found\n"; # add code to save attachments here # structure # $attachments[$i] # 0 HASH # 'content_type' => 'text/xml' # 'filename' => 'foo.xml' # 'payload' => "<attachment> # } } $pop->Reset(); $pop->Close();

Replies are listed 'Best First'.
Re: Gmail message count reset
by Anonymous Monk on Mar 26, 2009 at 06:28 UTC
    But I'd like to know if there's some way to avoid clearing the message count, so I could download messages again if needed. $pop->reset() doesn't make a difference...

    POP3 servers do not keep information regarding read/unread status.

Re: Gmail message count reset
by Anonymous Monk on Apr 30, 2009 at 05:53 UTC
    I'm having this problem as well - I download a message using the same sort of script and gmail marks them as read; I log back into the gmail account, mark them as unread and the POP3 interface still refuses to find them. POP3 may not take into account READ/UNREAD, but gmail does.
      You're seeking relief in the wrong venue. Contact GMAIL for help.