4 # Contact list, history and other stuff conversion script from
5 # various flavours of icq client software to centerim format.
7 # by Konstantin Klyagin <k@thekonst.net>
8 # trillian support by Vassilios Karakoidas <bkarak@aueb.gr>
10 # $Id: cimconv,v 1.9 2003/09/26 07:13:21 konst Exp $
20 # Adds a user to contact list.
21 # One arguments: user's UIN.
26 system("mkdir -p $ENV{HOME}/.centerim/$uin");
32 # Adds a message to a user's events history.
33 # Requires the following parameters to be passed:
36 # Uin of the receiver.
40 # UNIX timestamp (seconds since 1980).
45 sub cicq_addhistoryitem
{
46 local ($touin, $fromuin, $timestamp, $text) = @_;
49 $histuin = ($touin == $ourUIN) ?
$fromuin : $touin;
51 if(open(UF
, ">>$ENV{HOME}/.centerim/$histuin/history")) {
53 print UF
($touin == $ourUIN) ?
"IN" : "OUT", "\nMSG\n";
54 print UF
"$timestamp\n$timestamp\n";
59 if(open(UF
, ">$ENV{HOME}/.centerim/$histuin/lastread")) {
60 print UF
"$timestamp\n";
67 # LICQ specific functions
70 sub licq_conv_history
{
75 local $utimestamp = 0;
78 if(open(HF
, "<$ENV{HOME}/.licq/history/$uin.history")) {
83 if($buf =~ m/\[ (.?) .+ ([0-9]+) \]$/) {
85 cicq_addhistoryitem
($uto, $ufrom, $timestamp, $text);
99 $buf = substr($buf, 1) if substr($buf, 0, 1) eq ":";
104 cicq_addhistoryitem
($uto, $ufrom, $timestamp, $text)
112 if(open(F
, "<$ENV{HOME}/.licq/owner.uin")) {
116 if($buf =~ m/^Uin = ([0-9]+)$/) {
125 open(F
, "<$ENV{HOME}/.licq/users.conf")
126 or die "cannot find licq users file $ENV{HOME}/.licq/users.conf";
131 if($buf =~ m/^User[0-9]+ = ([0-9]+)$/) {
133 licq_conv_history
($1);
141 # micq specific functions
146 $fname = "$ENV{HOME}/.micq/micqrc";
149 or die "cannot find micq config file $fname";
158 if($buf =~ m/^([0-9]+)\s.+$/) {
162 $contsection = $buf =~ m/^\[Contacts\]$/;
170 # GnomeICU specific functions
175 $fname = "$ENV{HOME}/.gnome/GnomeICU";
178 or die "cannot find GnomeICU config file $fname";
185 if($buf =~ m/^([0-9]+)=.+$/) {
189 $contsection = $buf =~ m/^\[NewContacts\]$/;
197 # KXicq2 specific functions
201 if(open(F
, "<$ENV{HOME}/.kde/share/config/kxicq2rc")) {
204 if($buf =~ m/^UIN=([0-9]+)$/) {
213 $fname = "$ENV{HOME}/.kde/share/apps/kxicq2/contacts.kxicq";
216 or die "cannot find kxicq2 contacts file $fname";
221 if($buf =~ m/^UIN=([0-9]+)$/) {
229 # Now convert messages history
232 $fname = "$ENV{HOME}/.kde/share/apps/kxicq2/messages.kxicq2";
236 local $utimestamp = 0;
238 local $msgmode = "R";
240 if(open(F
, "<$fname")) {
244 if($buf =~ m/^\[Message [0-9]+\]$/) {
245 cicq_addhistoryitem
($uto, $ufrom, $timestamp, $text)
248 } elsif($buf =~ m/Options=[0-9]+ [0-9]+ ([0-9]+) [0-9]+$/) {
249 $msgmode = $1 ?
"S" : "R";
250 } elsif($buf =~ m/Uin=([0-9]+)$/) {
251 if($msgmode eq "R") {
258 } elsif($buf =~ m/DateTime=([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+)$/) {
259 $timestamp = timelocal
(0, $5, $4, $1, $2, $3);
260 } elsif($buf =~ m/Message=(.+)$/) {
267 cicq_addhistoryitem
($uto, $ufrom, $timestamp, $text)
274 # Trillian specific functions
276 sub create_account_irc
{
277 local $OUTPUT_DIR = "$ENV{HOME}/.centerim/";
278 local $buddy_dir = $OUTPUT_DIR."i".$_[0];
283 sub create_account_msn
{
284 local $OUTPUT_DIR = "$ENV{HOME}/.centerim/";
285 local @buddy_mail = split("@",$_[0]);
286 local $buddy_dir = $OUTPUT_DIR."m".$buddy_mail[0];
289 open(INFO_FP
,">".$buddy_dir."/info");
290 print INFO_FP
$buddy_mail[0]."\n\n\n".$_[0]."\n";
295 open(TRILLIAN_XML
,"Buddies.xml") or
296 die "Can not open Buddies.xml";
297 @lines = <TRILLIAN_XML
>;
301 if($_ =~ /\<buddy uri=\"ICQ:1%3A(.*)\"\>(.*)\<\/buddy\
>/) {
302 @buddy_icq_array = split("%3A",$1);
303 cicq_adduser
($buddy_icq_array[0]);
304 } elsif($_ =~ /\<buddy uri=\"MSN:1%3A(.*)\"\>(.*)\<\/buddy\
>/) {
305 @buddy_msn_array = split("%3A",$1);
306 $buddy_msn_array[0] =~ s/%([0-9A-Za-z]{2})/pack("H2",$1)/ge;
307 create_account_msn
($buddy_msn_array[0]);
308 } elsif($_ =~ /\<buddy uri=\"IRC:(.*)\"\>(.*)\<\/buddy\
>/) {
310 $buddy_irc =~ s/%([0-9A-Za-z]{2})/pack("H2",$1)/ge;
311 create_account_irc
($buddy_irc);
319 Centerim contact list and history convertor usage:
322 Where <client> is the name of program you can to convert from.
323 Can be: licq, kxicq2, gnomeicu, micq, trillian.
329 my $flavour = $ARGV[0];
331 if($flavour eq "licq") {
332 print "Converting from $flavour.. ";
333 licq
; print "done.\n";
334 } elsif($flavour eq "kxicq2") {
335 print "Converting from $flavour.. ";
336 kxicq2
; print "done.\n";
337 } elsif($flavour eq "gnomeicu") {
338 print "Converting from $flavour.. ";
339 gnomeicu
; print "done.\n";
340 } elsif($flavour eq "micq") {
341 print "Converting from $flavour.. ";
342 micq
; print "done.\n";
343 } elsif($flavour eq "trillian") {
344 print "Converting from $flavour.. ";
345 trillian
; print "done.\n";