Hi! Thunderbird downloaded all my Yahoo! Mail messages and deleted them from the server. This was not good, as now I could not search the messages either.

Fortunately I know Perl, and wrote a script to restore the mail from my local Thunderbird file back to Yahoo! Inbox.

You will need to stop Thunderbird deleting mail from the server. This is under Account Settings... > Server Settings > Leave messages on server . Make sure this is ticked as well as Until I delete them

Now you will want to Exit Thunderbird to stop the application downloading more email while you restore the mail.

Find your Thunderbird mail location :: something of the sort Users/YOUR_USER_NAME/AppData/Roaming/Thunderbird/Profiles/THE_PROFILE_DIRECTORY/Mail . Make a directory tmp under that directory.

Save the script below as RestorePOP3.pl to the new tmp directory. Now you will need to edit the file to place in your details. You will need to put in your email address in the my $emailAddress = "username@yahoo.co.uk"; variable on line ~35. You will also need to change $smtp->auth('LOGIN','myUserNameWithoutAtSymbol','YourNormalPassword'); touse your username and password respectively.

Use the cpan command to ensure you have the requirements

install Mail::MboxParser

install Net::SMTP_auth

. These have requirements of their own, so I suggest installing them too.

Now you should be ready to cd Users/YOUR_USER_NAME/AppData/Roaming/Thunderbird/Profiles/THE_PROFILE_DIRECTORY/Mail/tmp and execute perl RestorePOP3.pl

See the Caveats below.


  • You should know Perl reasonably well

  • The server you are trying to restore to may have a daily limit. Yahoo! Mail had a limit of 300 messages per day. So if you have slurped 3000 messages off the server, it will take you 10 days to restore it.

  • Do not keep running the script again and again, you will simply get the same 300 top messages resent. Alter line 12: my $startIndex=$numMessages-1; To use the index that was printed out once the mail server overflowed

  • If you have touble, try changing line 28 to enable debugging of the SMTP server response

  • You may need the Yahoo! Plus paid-for-account to be able to use the SMTP

use Mail::MboxParser;
use Net::SMTP_auth;my $mb = Mail::MboxParser->new('../Local Folders/Inbox',
decode     => 'NEVER', #Yahoo! client should do the escaping
parseropts => $parseropts);my $numMessages = $mb->nmsgs;
my $endIndex = 0;
my $startIndex=$numMessages-1;

my $sleepInterval=5;

print "# Working from ".($startIndex+1)." to $endIndex of $numMessages messages\n";
#for my $idx ($startIndex .. $endIndex-1) {
for (my $idx=$startIndex; $idx >=$endIndex; $idx--){

my $msg = $mb->get_message($idx);

print "Working on [$idx]:: --->'".$msg->header->{subject}, "'<--- [".$msg->header->{"Date"}."]\n";

# Constructors
$smtp = Net::SMTP_auth->new('smtp.mail.yahoo.co.uk',
Hello => 'terry.internal',
Timeout => 30,
#                Debug   => 1,

#print "SMTP server supports: '".$smtp->auth_types()."'\n";

my $emailAddress = "username@yahoo.co.uk";
$smtp->mail($emailAddress); #don't worry, the message will write in the correct sender

my $success = $smtp->data();

if(! $success) {
die "Server error at index [$idx]. Restart later";

my $payload = $msg->as_string;
#    print "Sending: \n".$payload."\n#---\n";
#    $smtp->dataend();


print "Done [$idx].\n";

print "Slept $sleepInterval s.\n";

print ("---* ENDE *---");