CPAN::Forum
Mail-Webmail-Gmail - Automatically removing SPAM messages from Gmail
| Posted on Sun Jul 17 13:51:43 2005 by szabgab |
| Automatically removing SPAM messages from Gmail |
|
#!/usr/bin/perl -w
use strict;
# remove SPAM messages without human interaction
# Due to some bug of deep recursion it seems we cannot delete all the SPAM messages at once so this
# script removes them in batches of 200 starting from the oldest SPAM message
# BUG: it seems the total number of SPAM messages this script sees is slightly larger than
# what I see in my Gmail account.
# Hence if I give it a limit of 50,000 It went down to about 48,800
usage() if not @ARGV == 4;
use Mail::Webmail::Gmail;
my ( $gmail ) = Mail::Webmail::Gmail->new(
username => $ARGV[0],
password => $ARGV[1],
);
my $SPAM = $ARGV[2];
my $limit = $ARGV[3];
while ($SPAM > $limit) {
remove($SPAM);
$SPAM -= 200;
}
sub remove {
my ($from) = @_;
print "Called with $from\n";
my $messages = $gmail->get_messages(
label => $Mail::Webmail::Gmail::FOLDERS{ 'SPAM' },
start => $from );
return if not $messages;
print "Retrieved: " . @$messages . "\n";
return if not @$messages;
my @msgids = map {$_->{ 'id' }} @$messages;
$gmail->delete_message( msgid => \@msgids, search => 'spam', del_message => 1 );
if ( $gmail->error() ) {
print $gmail->error_msg();
} else {
print "Deleted " . @msgids . " Messages\n";
}
}
sub usage {
print "\nUsage: $0 username password SPAM limit\n";
print " SPAM = Number of SPAM that you have now\n";
print " limit = Number that you want to keep\n";
exit;
}
|
| Write a response |
(2)
]