#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Net::POP3 deleting emails


    I have a perl script and I can login using Net::POP3 and display each message. However, $pop->delete($msgnum) doesn't work. I am using Ubuntu 13.10 server software and running the perl script on the localhost. After running the script, I expect the mailbox to be empty. However, when I run the script again, I see the same messages. Even if I run the following script that I copied from cpan.org, messages are not deleted. Any suggestions?

    use Net::POP3;

    # Constructors
    $pop = Net::POP3->new('pop3host');
    $pop = Net::POP3->new('pop3host', Timeout => 60);

    if ($pop->login($username, $password) > 0) {
    my $msgnums = $pop->list; # hashref of msgnum => size
    foreach my $msgnum (keys %$msgnums) {
    my $msg = $pop->get($msgnum);
    print @$msg;
    $pop->delete($msgnum);
    }
    }

    $pop->quit;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    Are you using the latest version of the module, which was just released a few days ago?

    I have not used that module, but the starting point would be to enable strictures and debug mode on the object.
    Code:
    use strict;
    use warnings;
    use Net::POP3;
    
    
    my $pop = Net::POP3->new('pop3host', Timeout => 60, Debug => 1);
    
    if ($pop->login($username, $password) > 0) {
        my $msgnums = $pop->list; # hashref of msgnum => size
        foreach my $msgnum (keys %$msgnums) {
            my $msg = $pop->get($msgnum);
            print @$msg;
           $pop->delete($msgnum);
        }
    }
    
    $pop->quit;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Tried your suggestion, emails not deleted.


    FishMonger

    Thanks for the response. I typed the code exactly how you had it, changed the server, username, and password. I noticed that the messages were marked as deleted and stated that the messages were deleted. However, when I run the script again it will display the same messages and the email file is still at /var/mail/username and the text length is the same. Am I wrong in thinking that the text file size would be 0 or something low? Am I also wrong to think when I run the script again that no emails should be displayed?

    I am using modules that are included on the Ubuntu 13.10 64-bit server distribution disk. What module are you referring to and how do I check what version it is?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    You can find out the version by running this command.
    perl -MNet::POP3 -e 'print $Net::POP3::VERSION, $/'

    I would expect the file size to change/lower after running the script.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Version 2.29


    It is version 2.29, again, thanks for the help.

    I believe it is an email server configuration issue and not a perl issue based on the output of the script.

    In the future I am sure people will ask me to post warnings if I am having troubles. I don't want to type everything out. Is there a way I can output the warnings to a text file? That way I would be able to copy and paste in my replies. How would I do that in the example that you provided?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Smile Problem solved


    Thanks again for pointing out that I should use warnings. That helped a lot by showing that the code is working and that the problem is somewhere else.

    As a newbie I need to learn to use the server log files and understand what they mean. I looked in the log file for the email server and found a suggestion that worked.

    I would still like to save warnings to a text file.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,923
    Rep Power
    1225
    There are multiple ways to save the warnings/errors to a file. The 2 most common are:

    1) From the command line you'd use normal I/O redirection, e.g.,
    perl myscript.pl 2> stderr.txt

    2) From inside the script you can use the open function to reopen the STDERR filehandle pointing it to a file.

IMN logo majestic logo threadwatch logo seochat tools logo