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.
- #!/usr/bin/perl
- use Net::POP3;
- if (@ARGV < 2) {
- print "Usage : $0 <login> <pass>\n";
- exit 0;
- }
- print "Going to delete ALL mail from account $ARGV[0] ! ctrl-c to abort\n";
- sleep 3;
- $pop = Net::POP3->new('pop.free.fr');
- die "Couldn’t log on to server" unless $pop;
- $total = $pop->login($ARGV[0],$ARGV[1]);
- die "No mails or couldn’t connect !" unless $total;
- print("Deleting $total mails ...\n");
- for($i = 0; $i<$tot; $i++) {
- $pop->delete($i);
- }
- $pop->quit();
- exit 1;
Shorter URL
Want to share or tweet this post? Please use this short URL: http://ozh.in/3y
cool. perhaps adding the POP server as a third argument would be a good idea…
Nice script, but has a little error:
for($i = 0; $i
Hmm, what is the error then ? Works fine for me :)
The error is that the for loop variable is "$tot" where it should be "$total"
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.