get mail by POP3Client?

J

jck11

hi all
I want to get my mail from gmail account.
The code below got it.
But I also want the mail reserve one copy in the mail server.
How can I modify the code to match the function.
Thanks for any information.

use MIME::parser;
use Mail::pOP3Client;
use IO::Socket::SSL;

my $pop3=Mail::pOP3Client->new(
USER=>'xxxxxxxx',
PASSWORD=>'xxxxxxxx',
HOST=>'pop.gmail.com',
PORT=>'995',
USESSL=>'true',
DEBUG=>0,
)or die "can't connect the server.\n";

if(($pop3->Count()) < 1){
print "No messages...\n";
exit;
}
print $pop3->Count() ." messages found!\n";

for($i=1; $i<=$pop3->Count(); $i++){
print $i, "\n";
my $msg=$pop3->Retrieve($i);
my $parser=new MIME::parser;
$parser->output_dir('c:\\mail');
my $entity=$parser->parse_data($msg);
}

$pop3->Close();
 
B

Brian McCauley

I want to get my mail from gmail account.
The code below got it.
But I also want the mail reserve one copy in the mail server.

What do you mean "reserve one copy"?

The POP3 protocol does not delete anything from the server unless you
do so explicitly.
 
J

jck11

Brian McCauley said:
What do you mean "reserve one copy"?

The POP3 protocol does not delete anything from the server unless you
do so explicitly.

The code below download the mail from the server and delete the mail from
the server.
I don't know why it delete the mail but it 's ture.
Because why I run the code second tims, I can't get any mail.



use MIME::parser;
use Mail::pOP3Client;
use IO::Socket::SSL;

my $pop3=Mail::pOP3Client->new(
USER=>'xxxxxxxx',
PASSWORD=>'xxxxxxxx',
HOST=>'pop.gmail.com',
PORT=>'995',
USESSL=>'true',
DEBUG=>0,
)or die "can't connect the server.\n";

if(($pop3->Count()) < 1){
print "No messages...\n";
exit;
}
print $pop3->Count() ." messages found!\n";

for($i=1; $i<=$pop3->Count(); $i++){
my $msg=$pop3->HeadAndBody($i);
my $parser=new MIME::parser;
$parser->output_dir();
my $entity=$parser->parse_data($msg);
my @parts=$entity->parts;
foreach my $part(@parts){
my $path=($part->bodyhandle)?$part->bodyhandle->path: undef;
next unless $path;
print "path: ", $path, "\n";
}
}

$pop3->Close();
 
S

Simon Andrews

jck11 said:
The code below download the mail from the server and delete the mail from
the server.
I don't know why it delete the mail but it 's ture.
Because why I run the code second tims, I can't get any mail.

Odd. The docs for POP3Client suggest that you need to do a
$pop3->Delete() to remove a message. Maybe your POP3 server
automatically flags any read message to be deleted? If so then add:

$pop3->Reset()

before
$pop3->Close();

and see if that works.

Simon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top