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

Hi I tried to write some easy scipt which can check my pop3 mailbox and copy message haeders into array. I decide to use NET:Pop3 Lib. I can create new object, log into the server (which returned to me number of messages) But I am not able to get working methods which using MSGNUM parameter. Did anybody know what is this parameter? I tried something like this

$mail = $pop->top( $i ); and then use it as reference to array (as is in documentation) but @$mail doesn't work.

$pop->last(); (highest MSGNUM) returned me 0 (but I have 2 mail in my box)

Please can anybody know how to get this work? Thanks. Litin

Replies are listed 'Best First'.
Re: net::pop3 usage
by arhuman (Vicar) on Mar 07, 2001 at 15:54 UTC
    use the list method.

    From the cookbook (slightly modified):
    %msgs= $pop->list(); for $msg (keys %msgs) { print "the message $msg is $msgs{$msg} bytes long.\n"; $msgnum++; } print "\nthere is $msgnum messages\n"
      Many THX but this was "last()" method not "list"....

      from doc... last() - Returns the highest MSGNUM of all the messages accessed. So how can return me 0 value if I have 2 mails in my box?

      And "top(MSGNUM) return should return me:

      from doc Get the header and the first NUMLINES of the body for the message MSGNUM. Returns a reference to an array which contains the lines of text read from the server.

      but when I try to acess array by @$ notation nothing happend. I will look at cook book for some more info, but if you know why this happened.... THX. Litin

        Isn't last() supposed to gives you the highest MSGNUM of your accessed messages ?
      I am sorry I tried this and get only

      Starting script
      conecting to POP3 server....
      Conected.
      Receiving mails...
      the message HASH(0x1b4440c) is bytes long.
      there is 1 messages
      Done.

      This was only one what I get from your code... Login is correct I checking it on my local instlation of mail server:

      Wed 2001-03-07 12:22:29: 60:8 Accepting POP connection from 10.0.0.75
      Wed 2001-03-07 12:22:29: 60:8 +OK xxx.cz POP MDaemon ready using UNREGISTERED SOFTWARE 3.5.4
      Wed 2001-03-07 12:22:29: 60:8 USER xxxxxx
      Wed 2001-03-07 12:22:29: 60:8 +OK xxxxx... Recipient ok
      Wed 2001-03-07 12:22:29: 60:8 PASS ******
      Wed 2001-03-07 12:22:29: 60:8 +OK xxxxx@xxxxx.cz's mailbox has 2 total messages (20354 octets).
      Wed 2001-03-07 12:22:29: 60:8 STAT
      Wed 2001-03-07 12:22:29: 60:8 +OK 2 20354
      Wed 2001-03-07 12:22:29: 60:8 LAST
      Wed 2001-03-07 12:22:29: 60:8 +OK 0
      Wed 2001-03-07 12:22:29: 60:8 LIST
      Wed 2001-03-07 12:22:29: 60:8 +OK 2 20354
      Wed 2001-03-07 12:22:29: 60:8 1 18831
      Wed 2001-03-07 12:22:29: 60:8 2 1523
      Wed 2001-03-07 12:22:29: 60:8 .
      Wed 2001-03-07 12:22:29: 60:8 QUIT
      Wed 2001-03-07 12:22:29: 60:8 +OK xxxxx@xxxxx.cz xxxxx.cz POP Server signing off (2 messages left)
      Wed 2001-03-07 12:22:29: 60:8 POP session complete, 0 bytes transferred!

      But as you can see scripts list mail corectly but code cannot take results. Debbuger message:

      Reference found where even-sized list expected at c:\windows\TEMP\DzTemp.pl line 53.
      Use of uninitialized value in concatenation (.) at c:\windows\TEMP\DzTemp.pl line 55.

        From the errors your getting, it looks like list() returns a hash-ref, not a list. Change the first line of arhuman's code to: %msgs = %{$pop->list()};

        and it should work.

        HTH

        bbfu
        Seasons don't fear The Reaper.
        Nor do the wind, the sun, and the rain.
        We can be like they are.

Re: net::pop3 usage
by dmistretta (Beadle) on Mar 07, 2001 at 19:44 UTC
    Here's my understanding.

    - As stated previously $pop->last() returns the last message number that <bold>you<bold> previously accessed. If you haven't downloaded any messages yet, it will return 0. If you have downloaded messages from the current set and it still returns 0 then maybe your POP3 server is not configured correctly.
    - in my use of $pop->top(), I needed to add the number of additional lines past the header to grab. This seemed to be more of a 'function' of my POP3 server. You can test this out by doing the commands manually.
    Like this:
    Telnet popserver 110
    user username
    pass password
    top msg# --- this did not work for me
    top msg# 0 --- this showed me the message headers for msg#

    while you are there, try the list and last commands.
    quit --- end your session

    ok, now for my code that worked against yahoo's POP servers

    #!d:\perl\bin\perl -w use Net::POP3; use strict; my $host = 'popserver'; my $mailbox = 'username'; my $password = 'password'; my ($item,$message,$line); my $pop = Net::POP3->new($host) or die "$!\n"; $pop->login($mailbox,$password) or die "$!\n"; my $message_list = $pop->list; foreach $item (keys %$message_list) { my $message = $pop->top($item, 0); foreach $line (@$message){ print "$item = $line"; } }

    Hope this helps.

Re: net::pop3 usage
by tomhukins (Curate) on Mar 07, 2001 at 15:53 UTC

    Without seeing your code, it's hard to tell what is wrong. Are you calling die or warn if any of your calls to $pop fail? Maybe your login is failing, so you're not seeing any messages.

    If your code seems fine, read up on how to debug with libnet in Net::libnetFAQ.