get mail by POP3Client?

Discussion in 'Perl Misc' started by jck11, May 26, 2007.

  1. jck11

    jck11 Guest

    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();
     
    jck11, May 26, 2007
    #1
    1. Advertising

  2. On 26 May, 04:33, "jck11" <> wrote:

    > 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.
     
    Brian McCauley, May 26, 2007
    #2
    1. Advertising

  3. jck11

    jck11 Guest

    "Brian McCauley" <>
    ???????:...
    > On 26 May, 04:33, "jck11" <> wrote:
    >
    > 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();
     
    jck11, May 30, 2007
    #3
  4. jck11 wrote:
    > "Brian McCauley" <>
    > ???????:...
    >> On 26 May, 04:33, "jck11" <> wrote:
    >>
    >> 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.


    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.
     
    Simon Andrews, May 31, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Snoxell

    Mail::POP3Client

    Jeff Snoxell, Oct 8, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    136
    Sisyphus
    Oct 9, 2003
  2. A Ymous

    Mail::POP3Client

    A Ymous, Jun 15, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    92
    Ben Morrow
    Jun 15, 2004
  3. Paul
    Replies:
    4
    Views:
    181
    A. Sinan Unur
    Jul 11, 2005
  4. Replies:
    1
    Views:
    225
  5. Replies:
    1
    Views:
    137
Loading...

Share This Page