Thursday, October 23, 2008

Pidgin log file to Adium log converter

Because I'm a business owner, need to keep in touch with many of my clients, partners and employees with all different kinds of IMs(MSN, Yahoo, AIM, GTalk, Jabber, etc.). I have been using Pidgin(both Windows and Linux) to work as my All-in-one IM clients for many many years, and accumulated tons of log files through Pidgin's html log plugin. And those logs are invaluable asset to me and my business.

I switched to Mac in the past year and use Adium (http://www.adiumx.com/) to handle my multiple IM accounts. But I was never able to find a way to convert my Pidgin logs to Adium.

So I finally decided to write one myself. The script is written in PHP, you need to modify some configuration parameters before it is executed:

$srcDir= Where the original Pidgin log files and folders are located
$destDir= Where to save converted Adium log files to
$masterAlias=array("Li","Li Ma","马力");//List all Alias names you ever used in all different IM accounts and in history. Very important to make conversions right

Once the script is configured, you can run it by:

php adium_convert.php

A log file will also be created when error occurs.

You also need to copy converted Adium logs to where your current Adium's log folder, which is normally:

~/Library/Application\ Support/Adium\ 2.0/Users/Default/Logs/

The complete code is:

The script was designed to resolve my issues first. Since we have to convert Pidgin log from html format, which is not very well formatted all the time, this converter might not work 100% for your case. It took me many days to make it work for all my log files. So please make sure you verify the converted log files after you run the script. Also make sure you keep the origina log files just in case.




Anonymous said...


cvelo said...

Thanks for the hard work!

Gabe! said...

Thank you very much for the script; no-one else seems to have anything that works. All of the other google results are bug reports. Unfortunately, it didn't work for me, probably because I have extended timestamps. I modified the script so that it would work, and the modified version is as follows:
A quick changelog: I removed $chatYear and changed the first-line-of-file regex to accept buddy names with spaces in them. I also modified the time regex (line 136 in the pastie) so it'd accept my logs' timestamps. Again, thanks very much for the script.

Li Ma said...

Hi Gabe!,

Thank you very much for your comments and most importantly for your adjustment to the code.
I already copied your code over, so everybody will download the latest version from you from my link.

I'm glad you liked my work.

Thanks again!


Gabe! said...

Hi again.
I rewrote the script (in ruby this time) because I got some odd results with the PHP script, especially for non-standard status messages like the ones that Gaim-Encryption throws up. If you'd like to take a look, it's on http://people.brandeis.edu/~gbw/code
Again, thank you for creating this, it's been an enormous help.

Plamen said...

Hello Li,
Thank you for the script.
Here (http://pastie.org/321353) I've made some changes:
1) Renamed the class SrcHTMLFileParse to SrcFileParser
2) Renamed the method parseFile to parseFileHTML
3) Added new method parseFileTXT
4) Changed function convert() to handle also files with txt extension
5) Added new service name - icq

Now the script converts successfully both HTML and TXT formats of Pidgin.
And I successfully migrated from Pidgin to Adium.


paCkeT said...

Thanks for the initial attempt in writing this script. It saved me lots of time in getting my logs imported.

I have made some modifictions to what Plamen worked on.

I have posted my changes to pastbin site: http://pastie.org/349614

Changes I have made:

* Changes made by Jeffery Fernandez <jeffery@fernandez.net.au>
* @since 2008-12-27
* Added Jabber Service Mapping
* Fixed Yahoo Service Mapping
* Fixed Chat conversation times
* Fixed XMl validity for chat messages
* Added work around for jabber protocol aliases
* Removed unwanted new lines in XML message (breaks Adium Transcipts view)
* Fixed Service Directory name
* Fixed regex for txt chat file
* Converting HTML pidgin messages are a pain. Syntax doesn't always match up with
* the current regex. I used the perl script below to convert all my html messages to
* text format before importing them into Adium. You will need to have cpan to install
* certain modules to get it to work.
* @link http://search.cpan.org/src/MSCHILLI/Gaim-Log-Parser-0.14/eg/gaimlog-html2text

Anonymous said...

Just wanted to say thank you for this! Worked like a charm.

Anonymous said...

Thanks a lot for your work Gabel.

Is there a way to use your script to import Trillian logs into Adium?

Thanks in advance for your reply.


Li Ma said...


I'm glad this script can be useful to you.
Since I don't use Trillian, so I don't know if it can do any help.


Noah said...

Thanks for this script! I tried both Plamen and PaCkeT's versions, and both correctly create all the Adium log files themselves, but I'm left with just an empty parent < chat > node in the resulting XML. I'm using Pidgin's HTML log format.

Any thoughts? Thanks!

Li Ma said...


Can you send me a sample HTML file you have, so I can have a look?


Noah said...

Thanks. I'd send it, but your email address isn't anywhere on your site. ;)

I think it's an issue with the regex on line 170 of paCkeT's version, and may have to do with my date format.

If you want a copy of the HTML, go to the website listed in my Blogger profile; my contact info is there.


Gabe! said...

Hi Li,
I'm planning to create a Ruby gem to allow for wide distribution of my version of this program, but I'd like to see how you feel since it is originally based strongly on your program. This post appears to be the best (only) way for me to contact you about this.

Li Ma said...


Yes, any improvement is more than welcome! So feel free to post your code.

Actually since I posted this code, I never had time to refine it further.

If you or anyone could make a better script or even a GUI that can make the conversion even smoother, I would be very very happy to see.


Gabe! said...

Thank you. The project is at http://rubyforge.org/projects/pidgin2adium/

Anonymous said...

I want something to do the reverse, convert Adium logs to gaim.
Does anybody know of any tool for this?

mjr2k said...

I tried to run it after modifying the variables for Source and Destination and I got:

Parse error: syntax error, unexpected T_VARIABLE in /Users/Mike/adium_convert.php on line 3

paCkeT said...

that error is a parse error. Paste your code somewhere and I can tell you what is wrong.

mjr2k said...

Packet - I don't know where I can leave you a long comment. What's your email address, I'll email you the code that I used.

paCkeT said...

put the code on pastebin.com

mjr2k said...

Packet, try this: http://pastebin.com/embed_js.php?i=nbuLkddC

paCkeT said...

you are missing a semi-colon on the second line. It should be:


mjr2k said...

Packet, though it let it run, there was a whole slew of errors that I'm not going to bother with. I was looking through many of the logs and they are either one-liners or stuff that I don't need. I think since I'm not using Pidgin anymore, I'm just going to archive the useful ones away. Thanks for your help - it's amazing how a semicolon can screw the whole thing up.

Anonymous said...

Thanks very much for this script, converted my logs perfectly! Having come over to the Mac from Linux a few days ago, I already feel right at home.

Feel it's worth mentioning in case anyone else has this problem; the script initially did not work for me (got an exception to do with the timezone) until I put "date_default_timezone_set('Europe/London');" at the top of the file after googling around (php is pretty foreign to me, I mainly use BASH and Obj-C)

Might just be a strange quirk of my system and / or log files though :P

Thanks again! :-)

piloro said...

excuse me for the maybe stupid question but.. I'm a very beginner..
How do I run this script in my mac?

Li Ma said...


Simply make changes in the code to reflect your folder structure, then run:
php adium_convert.php

Of course, please first make sure you get PHP installed.

Good luck and Happy New Year!


piloro said...

excuse me, be patient.. I think I'm a bit hard in understanding...
I miss the passage "then run:
php adium_convert.php"..

Here's what i did: i copied the script, whit the changes for my folders path, in Automator, and I run it. The process seems to be successfully completed, but nothing appears in the destination folder...

I probably miss something basic...
Happy new year to you too!

Anonymous said...

piloro, execute the script via the "Terminal.app" Application

piloro said...

ok.. When I say that I am a beginner I am even too optimistic..

I still miss or misunderstand some steps.. Here's what I did: I created a document called "adium_convert.php" with the code inside. And I wrote in the terminal "...path../adium_convert.php"
But the answer is "permission denied", even if I write the command as "root".

In automator, the command seems to be completed, but nothing appears in the folder that I created to host the new logs. Maybe I wrote something wrong in the "$masterAlias=array"...
I think I'm stuck in a basic and stupid mistake..

Excuse me for my insistence (and for my bad english), tell me if I bother you too much I just quit trying..


Anonymous said...

make sure the folder you are writing to is writeable. For example when logged in as root user:

chmod 774 [Path to Folder Name]

should make it writeable by you and anyone who belongs to your group.

Similarly make sure your php script is executable:

chmod 664 [Path to Script name]

Both the above commands to be executed via the terminal Application.

niz said...

I used paCkeT's mods and added the date_default_timezone_set() function to the top of the script. I used PHP 5.3.2 from the command line.

stephs said...

Wow! I'm pretty sure that this caught up plenty of people's attention, Thumbs up for your work and Good writing skills!

i am jayne and i am a freelance writer..
see my related post here ------> Men Suit

SEO tools said...

Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

Anonymous said...

excellent script!! just what i needed as i wanted to save my chat history from pidgin days now to adium on my new mac. thanks very much worked excellent.

Anonymous said...

rubyforge is down now, was the project migrated somewhere?

Gabe said...

Pidgin2adium is on GitHub now: https://github.com/gabebw/pidgin2adium