In: , ,
On: 2005 / 01 / 08
Shorter URL for this post: http://ozh.in/3y

I have a few alternative mail accounts, mostly used when I need to register with a site I don't trust and thus when I'm expecting spam. Checking last night, I noticed that 3 accounts were filled up with a grand total of 3500 spams, so I wrote a small Perl script, using Net::POP3, to delete all mails in an account.

  1. #!/usr/bin/perl
  2. use Net::POP3;
  3. if (@ARGV < 2) {
  4.     print "Usage : $0 <login> <pass>\n";
  5.     exit 0;
  6. }
  7.  
  8. print "Going to delete ALL mail from account $ARGV[0] ! ctrl-c to abort\n";
  9.  
  10. sleep 3;
  11. $pop = Net::POP3->new('pop.free.fr');
  12. die "Couldn’t log on to server" unless $pop;
  13.  
  14. $total = $pop->login($ARGV[0],$ARGV[1]);
  15. die "No mails or couldn’t connect !" unless $total;
  16.  
  17. print("Deleting $total mails ...\n");
  18.  
  19. for($i = 0; $i<$tot; $i++) {
  20.     $pop->delete($i);
  21. }
  22.  
  23. $pop->quit();
  24.  
  25. exit 1;

Shorter URL

Want to share or tweet this post? Please use this short URL: http://ozh.in/3y

Metastuff

This entry "Deleting all mails with a simple Perl script" was posted on 08/01/2005 at 2:36 pm and is tagged with , ,
Watch this discussion : Comments RSS 2.0.

5 Blablas

  1. dju` says:

    cool. perhaps adding the POP server as a third argument would be a good idea…

  2. ralf says:

    Nice script, but has a little error:
    for($i = 0; $i

  3. Ozh says:

    Hmm, what is the error then ? Works fine for me :)

  4. Brian says:

    The error is that the for loop variable is "$tot" where it should be "$total"

  5. Mike says:

    Hi I had an error with this script. If you only have 1 Mail and you will begin ($i = 0; $i<$tot; $i++) my msg index starts with 1 and not with 0 so no emails will deleted because there is no MSG with the index 0.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Gravatars: Curious about the little images next to each commenter's name ? Go to Gravatar and sign for a free account
Spam: Various spam plugins may be activated. I'll put pins in a Voodoo doll if you spam me.

Read more ?