Copy messages from a Thunderbird mbox file to a MySQL table using php
Written by: Maciej Grajcarek
July 1, 2008
If for some reason you would like to copy your messages from Thunderbird to a MySQL database, here you can find a simple PHP script which will do it for you! All you have to do is to set some variables in the php class and create a proper database table. Let’s start with the class.
var $file_name = 'some_mbox_file'; var $file_path = '/path/to/file/'; var $db_user = 'user'; var $db_password = 'pass'; var $db_host = 'localhost'; var $db_name = 'mbox';
$file_name is the name of the thunderbird mbox file and $file_path points to the folder it is located (deafult path in Windows looks sth like this: C:\\Documents and Settings\\%user%\\Application Data\\Thunderbird\\Profiles).
You should also define the database connection variables.
Next thing is to create a database table:
CREATE TABLE `messages` ( `id` int(10) unsigned NOT NULL auto_increment, `from` varchar(255) collate latin1_general_ci NOT NULL, `to` varchar(255) collate latin1_general_ci NOT NULL, `subject` varchar(255) collate latin1_general_ci NOT NULL, `date` varchar(255) collate latin1_general_ci NOT NULL, `message` text collate latin1_general_ci NOT NULL, `received_ip` varchar(15) collate latin1_general_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
As you can see, this script will read: from, to, subject, date, received_ip and message fields for each of messages. It will not copy attachments!
It supports also processing of big files. We have used it to parse files bigger than 3GB.
Posted in



July 28th, 2009 at 1:53 pm
Hi Maciej Grajcarek,
I’m one of these people who for some kind of reason I want to convert all my Thunderbird emails to MySQL table. The problem is on the link, (it doesn’t work).
Do you have the original file mboxreader.php?
I will aprecciate your help because I tried Mbox class from phpclasses and it doesn’t work very well with the mbox Thunderbird files.
Thanks in advance!!
Diego Marcos
July 28th, 2009 at 4:17 pm
hi Marcos, we changed our svn server. sorry! you can access with u: anon, p: anon directly connecting with some svn client to svn.devayd.com
regards, daniel
July 28th, 2009 at 4:55 pm
Oh! Thanks Daniel!!
I will check it out, thanks for all!
August 27th, 2009 at 9:27 am
Hi Daniel,
I tried to access at your svn server using TortoiseSVN but username and password seems does not exist…
I’m using “anon” as username and “anon” as password..
Please help me
Thanks, alessio.
September 8th, 2009 at 4:26 am
hey Daniel,
after getting on your svn server, I cant seem to find the php script under any of the sub-directories. is it still there?
thanks,
DGT.
September 8th, 2009 at 5:18 pm
hey Marcos,
I used a svn client to get on your server but I cant find this script under any of the sub-directories. is it still there?
thanks
DT
September 9th, 2009 at 1:14 am
hey Daniel,
I cant seem to find the script when I go on your svn server. what sub-directory is it under?
sent this message before, but it did’nt post -sorry for the resend.
thanks
DT
September 9th, 2009 at 7:57 am
Cant get this page
http://websvn.devayd.com/wsvn/public/scripts/mboxreader.php
I dont have SVN either.
September 10th, 2009 at 11:31 pm
hi,
the exact command to get this file is:
svn export svn://anon:anon@svn.devayd.com/cake/scripts/mboxreader.php
you must have a svn client installed. there is no other way at the moment.
regards
daniel
August 5th, 2010 at 10:55 am
file is not exist T_T
anyone can send me that file “mboxreader.php” ?
send to h312u_kurniawan at yahoo.com
thanks
September 6th, 2010 at 12:05 pm
Hi Maciej,
It’s seems to be a very nice tool for thunderbird mbox file!
Could you send me please the php file (mboxreader.php) by email, please.
It’s not possible to download it by http or svn …
Thank you very much,
Samba
September 7th, 2010 at 6:27 pm
hi, I will try to upload it to github soon. please watch http://github.com/danielzzz
February 6th, 2011 at 2:55 pm
Found it here:
https://github.com/danielzzz/mboxreader/blob/master/mboxreader.php
July 29th, 2012 at 6:12 am
Thanks you very much for this piece of code it worked like a charm.
I “imported” 15k bounces emails and now I can do a proper analysis.
How can pay you a beer :D?