#!/usr/bin/perl # dumpmsn - Pretty up MSN Messenger chat logs. # # Usage: dumpmsn *.xml # # This will create a folder named "html" and put the files there. Give it chat # logs from Windows Live Messenger 2011 or similar (no guarantees it # will work with other versions). # # --Kirsle # http://sh.kirsle.net/ use 5.14.0; use strict; use warnings; use XML::Simple; if (!-d "html") { mkdir("html") or die "Can't create folder 'html': $@"; } foreach my $file (@ARGV) { say "Dumping $file..."; my $xml = XMLin($file, ForceArray => 1); my $html = $file; $html =~ s/\.xml$//g; open (my $fh, ">:utf8", "./html/$html.html"); print {$fh} < Conversation Log EOF if (ref($xml->{Message}) ne "ARRAY") { warn "Not an array for $file"; next; } foreach my $Message (@{$xml->{Message}}) { my $to = $Message->{To}->[0]->{User}->[0]->{FriendlyName}; my $from = $Message->{From}->[0]->{User}->[0]->{FriendlyName}; my $time = $Message->{Date} . " " . $Message->{Time}; my ($text,$style); if (ref($Message->{Text}->[0])) { $text = $Message->{Text}->[0]->{content}; $style = $Message->{Text}->[0]->{Style}; } else { $text = $Message->{Text}->[0]; } $style //= ""; $style = " style=\"$style\"" if length $style > 0; print {$fh} "$time
\n" . "$from says:\n" . "$text\n" . "
\n\n"; } print {$fh} "\n"; close($fh); }