Update 2013/Mar/18: released v1.2: added support for use of CRLF line endings communicating with server (for e.g. hotmail)
It does not happen often, but sometimes my computer crashes. Unfortunately, but such is the live of a computer user. Most programs and their data are fine after, however, Thunderbird is not one of those. Sometimes after the crash, the popstate.dat file is either corrupted, empty or missing. See also Thunderbird bug #263142
This causes Thunderbird to retrieve all the email messages that were kept at the server to be downloaded again. After another one of those incidents I decided to try and find a work-around for it. Luckily the format of the popstate.dat file is pretty straightforward. Retrieving the UIDL list for the emails stored at the server is key to the solution.
To make things easy, I have written a simple PHP script that will rebuild Thunderbird's popstate.dat file based on the emails stored at the server. Usage is pretty straightfoward.
usage: rebuild_popstate.php [-c] [-d] [-i n] [-s] [-v] [-f file] server [ port ] -c CRLF flag, use when talking to Windows servers -d debug flag -f output filename -i ignore the last n messages (for if you don't have them yet) -s use for secure POP3 (SSL/TLS) -v verbose flag
You can find the script at github: rebuild_thunderbird_popstate
I hope it helps, and if so it would be nice if you could share your experiences here, thanks!
13 Responses to Fixing a corrupted Thunderbird popstate.dat file
Great! this is excactly what I was looking for!
Saved me a lot of bandwidth. Worked fine, just out of the box.
It should be implemented as feature of thunderbird.
thank you so much!
Posted on Wed March 14, 2012 at 11:49
Really great script, many times popstate.dat crashes during a power failure.
Posted on Wed March 21, 2012 at 18:26
Hi,
Your solution is very good. Just one minor issue: The script is suppose to work only if we keep messages on the server. If we delete messages from the server after download, nothing will happen. Am I correct?
Thanks.
Marcelo
Posted on Thu April 26, 2012 at 15:22
Hello Luis Marcelo,
Indeed, if you delete the messages from the mail server when downloading, the messages are not available for reconstructing the popstate.dat file. However, the idea of the script is to prevent re-downloading all messages from the server when the popstate.dat file has been corrupted or removed. So, when there are no already downloaded messages at the mail server this problem does not occur and does not need fixing.
PS: Sorry for the late response, I was on holiday.
Posted on Mon April 30, 2012 at 10:28
Hi,
can you please tell me how to make the script work? I have no idea what to do with the sourcecode.
Please help me.
I have a windows 8 if this helps.
Thanks so much
Posted on Sat March 9, 2013 at 13:41
Hi Simone,
The script is a shell script. It was written to be run on linux/unix like systems, not for windows.
However, there might be a solution called Cygwin that could make the script run on windows.
If you try it and it works let me know and if it doesn't let me know also so I can possibly fix it to run on windows using Cygwin as well. Thanks.
[Edit 2013/Mar/13]
Oops, I did not look into it but it's a PHP script of course, so cygwin is not a requirement.
Posted on Sun March 10, 2013 at 12:43
Hi Jeroen,
Thanks for your reply. It does not work with windows through the shell cygwin. I renamed the script file to 123.sh. I get the errors:
simon@ubuntu:/mnt/hgfs/win/1$ sh ./123.sh
: No such file/123.sh: cannot open ?php
: not found: ./123.sh: /**
./123.sh: 4: ./123.sh: 123.php: not found
./123.sh: 305: ./123.sh: Syntax error: "(" unexpected
Dont get the exact problem here. I am a bloody beginner. Please help me ;-)
Thanks in advance
Posted on Tue March 12, 2013 at 16:20
Hi Sorry for the last quiet stupid post. I am a liite further now.
The following "error" shows up. What do in need to do to fix that?
simon@ubuntu:/mnt/hgfs/win/1$ /usr/bin/php /mnt/hgfs/win/1/rebuild_popstate.php [-d] pop3.live.com [995]
rebuild_popstate.php/1.1 Copyright (c) 2011 Jeroen Derks, Apache License 2.0
PHP Warning: fsockopen() expects parameter 2 to be long, string given in /mnt/hgfs/win/1/rebuild_popstate.php on line 116
I need your help please.
Thanks a lot!
2013-03-12 12:06:41: rebuild_popstate.php: failed to connect to [-d]:pop3.live.com
Posted on Tue March 12, 2013 at 20:59
Hi Simone,
Please use the following command:
/usr/bin/php /mnt/hgfs/win/1/rebuild_popstate.php -v -s pop3.live.com
Good luck!
Posted on Thu March 14, 2013 at 02:50
Hi Jeroen,
Thanks so much for your help. It works well with gmx, web and gmail. There is a connection problem with hotmail. Your script says:
simon@ubuntu:~$ /usr/bin/php /mnt/hgfs/win/1/rebuild_popstate.php -v -s pop3.live.com
rebuild_popstate.php/1.1 Copyright (c) 2011 Jeroen Derks, Apache License 2.0
2013-03-14 03:16:04 connected to pop3.live.com:995 [using SSL]
2013-03-14 03:16:04 logging in
username: realstar15@hotmail.com
2013-03-14 03:17:14: rebuild_popstate.php: failed to read from server
Can you sort out what the problem is? I can't even put in the password.
Thanks you man.
Posted on Thu March 14, 2013 at 11:21
Hi,
i tried it with pop3.live.com, but the connection is not possible. It says connection failed. Do you have any idea why?
please help me!
Thanks
Posted on Sat March 16, 2013 at 23:57
Hi Simon,
Windows POP3 servers were not supported so I've added that support by adding a new flag to the program:
-c that makes it uses Windows-style line-endings. Please download the v1.2 at
https://github.com/Magentron/rebuild_thunderbird_popstate
and use the following command:
/usr/bin/php /mnt/hgfs/win/1/rebuild_popstate.php -v -c -s pop3.live.com
Please let me know if it works now. Also, it should properly output messages, so it should be more readable.
Good luck!
Posted on Tue March 19, 2013 at 00:13
Thank you! rebuild_popstate.php worked perfectly today, Sep 1, 2016 (and yes, the problem with Thunderbird apparently still continues, as I found out this morning...).
Posted on Thu September 1, 2016 at 23:41