This is a Perl 5 script for reading a Yahoo Messenger archive file and saving 
it as a Kopete 0.11.1 archive file.

It's simplistic, poorly documented, and probably way out of date since it 
converts to kopete-history version="0.9"  but it works for me and might be a 
starting point for someone who wants to make a better version.

Unfortunately, email has probably truncated some of the lines below, make sure 
to unwrap any line that isn't a comment and doesn't end with a { or ;.

I don't read the list so please email questions, sorry.

Brian


Syntax:  yahoo-dat.pl /path/filename.dat
The destination will be 
$HOME/.kde/share/apps/kopete/logs/YahooProtocol/$myname/$theirname.$year$month.xml

If the file exists, it will add a number before .xml to avoid overwriting 
existing data.


#!/usr/bin/perl

require "ctime.pl";

foreach $inputfile (@ARGV) {
# source file example command line:
#      /mnt/laptop/c/Program 
Files/Yahoo!/Messenger/Profiles/myname/Archive/Messages/theirname25.20090727-myname.dat
#  print "$file\n";
  ($theirname, $year, $month, 
$myname)=$inputfile=~/.*\/(.*)\/(\d\d\d\d)(\d\d).*-(.*).dat/;
#  print "$theirname\n";
#  print "$myname\n";

  open(INPUT, $inputfile);
  for 
($outputfile="$ENV{HOME}/.kde/share/apps/kopete/logs/YahooProtocol/$myname/$theirname.$year$month.xml",$i=1;-e
 $outputfile;$i++){
    
$outputfile="$ENV{HOME}/.kde/share/apps/kopete/logs/YahooProtocol/$myname/$theirname.$year$month\($i\).xml";
  }
print $outputfile,"\n";
  open(OUTPUT, ">".$outputfile);
  $i=0;
  $keylen=length($myname);

  print OUTPUT "<!DOCTYPE Kopete-History>\n";
  print OUTPUT "<kopete-history version=\"0.9\" >\n";
  print OUTPUT " <head>\n";
  print OUTPUT "  <date month=\"$month\" year=\"$year\" />\n";
  print OUTPUT "  <contact contactId=\"$myname\" type=\"myself\" />\n";
  print OUTPUT "  <contact contactId=\"$theirname\" />\n";
  print OUTPUT " </head>\n";


# 4 bytes date
# 4 bytes pad
# 1 byte direction
# 3 bytes pad
# 4 byte length
# message
# 4 bytes pad/terminator


  while(read(INPUT,$timebyte,1)){
  #bindly assume that if first byte exists, the whole line will
  #damage from truncated files is no more than an extra empty line of xml 
    $timestamp=ord($timebyte);
    read(INPUT,$timebyte,1);
    $timestamp=$timestamp+ord($timebyte)*256;
    read(INPUT,$timebyte,1);
    $timestamp=$timestamp+ord($timebyte)*65536;
    read(INPUT,$timebyte,1);
    $timestamp=$timestamp+ord($timebyte)*16777216;
#  print"timestamp:$timestamp\n";
    $timestamp= &ctime($timestamp);
    ($timestamp)=$timestamp=~/... ... (.*) 2[0-9][0-9][0-9]\n$/;
    read(INPUT,$pad,4);
    read(INPUT,$direction,1);
    $direction=ord($direction);
  #print"direction:$direction\n";
    if ($direction==0) { print OUTPUT " <msg nick=\"",$myname,"\" in=\"0\" 
from=\"",$myname,"\" time=\"",$timestamp,"\" >"; }
    elsif ($direction==1) { print OUTPUT " <msg nick=\"\" in=\"1\" 
from=\"",$theirname,"\" time=\"",$timestamp,"\" >"; }
    else { print OUTPUT "<msg nick=\"unknown\" in=\"",$direction,"\" 
from=\"unknown\" time=\"",$timestamp,"\" >"; }
    read(INPUT,$pad,3);
    read(INPUT,$lengthbyte,1);
    $length=ord($lengthbyte);
    read(INPUT,$lengthbyte,1);
    $length=$length+ord($lengthbyte)*256;
    read(INPUT,$lengthbyte,1);
    $length=$length+ord($lengthbyte)*65536;
    read(INPUT,$lengthbyte,1);
    $length=$length+ord($lengthbyte)*16777216;
#    print"length:$length\n";
    read(INPUT,$encrypted,$length);
#  print"encrypted:$encrypted\n";
    read(INPUT,$pad,4);
    $i=0;
    $decrypted="";
    #one character at a time
    foreach $encryptedchar (split(//,$encrypted)){
      #next character from username, repeat as needed.
      $key=substr($myname,$i,1);
      # this is the key of the decryption, XOR with the username
      $decryptedchar=$encryptedchar ^ $key;
      #next offset into key ($myname).  reset when longer than $myname.
      $i=($i+1) % $keylen;
#      print $decryptedchar;
#      print ord($decryptedchar),"~",$decryptedchar,":";
      $decrypted=$decrypted.$decryptedchar;
      #strip fonts
      $decrypted=~ s#<font face=\".*\" size=\"[0-9]*\">(.*)</font>#$1#gi || 
$decrypted;
      #strip italics
      $decrypted=~ s#<i>(.*)</i>#$1#gi || $decrypted;
      #strip bold
      $decrypted=~ s#<b>(.*)</b>#$1#gi || $decrypted;
      #strip escape[#NNNNNNm codes
      $decrypted=~ 
s#(.*)\x1b\[\#[0-9][0-9][0-9][0-9][0-9][0-9][a-z](.*)#$1$2#gi || $decrypted;
    }
    print OUTPUT $decrypted,"</msg>\n";
  }
  print OUTPUT "</kopete-history>\n";
  close(OUTPUT);
  close(INPUT);
}


      
_______________________________________________
kopete-devel mailing list
kopete-devel@kde.org
https://mail.kde.org/mailman/listinfo/kopete-devel

Reply via email to