A perl programming solution to deleting Yahoo Email messages quickly...

In Yahoo mail it's impossible to mass-delete emails from a folder - and you can't delete the folder when there are any messages in it. When you have 1000's of read and unread emails in a folder then this perl script will delete them for you. It's dangerous because once gone you cant get the mails back.
You have to install perl - and I'm assuming here that you've got yourself a windows PC
1) download Perl from http://www.activestate.com/activeperl/downloads
2) install in default place which is C:\perl - this takes quite a while
3) open a command window Start->Run... cmd then run the following commands
3.1) cd C:\perl\bin
3.2) ppm install Mail-IMAPClient

4) create a new directory called c:\perl\test

5) create file called deleteyahoomail.pl in c:\perl\test
5.1) edit deleteyahoomail.pl and add these lines


use strict;
use warnings;
use IO::Socket::SSL;
use Mail::IMAPClient;

if ($#ARGV != 2)
{
  print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
  print "  USE WITH CARE  USE WITH CARE  USE WITH CARE  USE WITH CARE  \n";
  print "\n This program will delete your yahoo email. Make sure you   ";
  print "\n supply the correct name for the folder you wish to purge   \n";
  print "\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n";
  print "\nUsage c:\\perl\\bin\\perl deleteyahoomail.pl username (including the \@yahoo.com bit) password (if you have odd characters in your password try putting the \\ symbol before them) folder to delete all the messages from (and BE CAREFUL) \n";
  print "\nExample 1 : c:\\perl\\bin\\perl deleteyahoomail.pl myusername\@yahoo.com mypassword1234 ebaystuff\t - logs on to myusername\@yahoo.com with the given password and deletes messages in ebaystuff\n";
  print "\nExample 2 : c:\\perl\\bin\\perl deleteyahoomail.pl myusername\@yahoo.com pw\\\"\\*\\\"pw123 ebaystuff\t - logs on to myusername\@yahoo.com with the password  pw\"\*\"pw123 and deletes messages in ebaystuff\n";
  print "\nExample 3 : c:\\perl\\bin\\perl deleteyahoomail.pl myusername\@yahoo.com pw123xyz \"my old stuff\"\t - logs on to myusername\@yahoo.com with the password  pw123xyz and deletes messages in the folder called   my old stuff\n";

  die "\n";
}

{
  my $socket = IO::Socket::SSL->new(
    PeerAddr => 'imap.mail.yahoo.com',
    PeerPort => 993,
    SSL_verify_mode => SSL_VERIFY_NONE,
  )
  or die "socket error - Internet connection OK? Or yahoo mail not accepting connections";

  my $imapc;
  my $user = $ARGV[0];
  my $password = $ARGV[1];
  my $foldertodelete = $ARGV[2];

  print "\nUser     --> $user\n";
  print "Password --> $password\n";
  print "Folder   --> $foldertodelete\n\n";


  $imapc = Mail::IMAPClient->new( Socket => $socket,
    User => $user,
    Password => $password)
  or die "User and or Password error, Internet connection error or permissions error";

  if ($imapc->IsAuthenticated()) {
    print "\nLogged in OK.\n";
  }
  else
  {
    die "\nSome problem logging in :( \n";
  }

  $imapc->select($foldertodelete) or die "Not a valid folder name -->   $foldertodelete\n";

  my $m = $imapc->message_count($foldertodelete);
  my $moretodelete = 1;
  if (int($m) != 0)
  {
    print "\n $m messages total found\n";
    while ($moretodelete == 1)
    {
      my @r_msgs = $imapc->messages;

      if (int(@r_msgs) == 0)
      {
        print "\nNo more messages to delete.\n";
        $moretodelete = 0;
      }
      else
      {
        # truncate array
        print "Number of messages = ";
        print int(@r_msgs);
        print "\n";
        my $maxrsize = int(@r_msgs);
        if ($maxrsize > 1000) { $maxrsize = 1000; }

        my @subset = splice(@r_msgs, 0, $maxrsize);

        $imapc->delete_message(\@subset) or die "Could not delete the messages - reasons unknown\n";
        print int(@subset);
        print " messages deleted\n";
        $imapc->expunge($foldertodelete) or die "Some problem committing the delete action: $@\n";
      }
    }
  }
  else
  {
    print "No messages to delete\n";
  }

  sleep(2);
  $imapc->logout();

} 

5.2) Change the email addresses and password to your information

6) in the cmd window type
6.1) cd c:\perl\test
6.2) c:\perl\bin\perl deleteyahoomail.pl ==> this will give you the help page
6.3) Example : c:\perl\bin\perl deleteyahoomail.pl myusername@yahoo.com mypassword1234 ebaystuff
The example here logs on to myusername@yahoo.com using the password mypassword1234 and deletes all the messages in the folder named ebaystuff.
Obviously you need to provide your own login, password and folder name information. It only works on Yahoo mail!

mike