connwrap - initialize gnutls session in cw_connect
[centerim.git] / misc / cimconv
blob0718285f5c341cf2377e0df34e252667a758099d
1 #!/usr/bin/env perl
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 $
13 use Time::Local;
15 my $ourUIN = 0;
18 # cicq_adduser
20 # Adds a user to contact list.
21 # One arguments: user's UIN.
24 sub cicq_adduser {
25 local ($uin) = @_;
26 system("mkdir -p $ENV{HOME}/.centerim/$uin");
30 # cicq_addhistoryitem
32 # Adds a message to a user's events history.
33 # Requires the following parameters to be passed:
35 # to_UIN
36 # Uin of the receiver.
37 # from_UIN
38 # Sender's uin.
39 # timestamp
40 # UNIX timestamp (seconds since 1980).
41 # text
42 # Message text.
45 sub cicq_addhistoryitem {
46 local ($touin, $fromuin, $timestamp, $text) = @_;
48 if($ourUIN) {
49 $histuin = ($touin == $ourUIN) ? $fromuin : $touin;
51 if(open(UF, ">>$ENV{HOME}/.centerim/$histuin/history")) {
52 print UF "\f\n";
53 print UF ($touin == $ourUIN) ? "IN" : "OUT", "\nMSG\n";
54 print UF "$timestamp\n$timestamp\n";
55 print UF "$text\n\n";
56 close UF;
59 if(open(UF, ">$ENV{HOME}/.centerim/$histuin/lastread")) {
60 print UF "$timestamp\n";
61 close UF;
67 # LICQ specific functions
70 sub licq_conv_history {
71 local ($uin) = @_;
73 local $uto = 0;
74 local $ufrom = 0;
75 local $utimestamp = 0;
76 local $text = "";
78 if(open(HF, "<$ENV{HOME}/.licq/history/$uin.history")) {
79 while(<HF>) {
80 chomp;
81 $buf = $_;
83 if($buf =~ m/\[ (.?) .+ ([0-9]+) \]$/) {
84 if($text ne "") {
85 cicq_addhistoryitem($uto, $ufrom, $timestamp, $text);
86 $text = "";
89 $timestamp = $2;
91 if($1 eq "R") {
92 $ufrom = $uin;
93 $uto = $ourUIN;
94 } elsif($1 eq "S") {
95 $ufrom = $ourUIN;
96 $uto = $uin;
98 } else {
99 $buf = substr($buf, 1) if substr($buf, 0, 1) eq ":";
100 $text .= $buf;
104 cicq_addhistoryitem($uto, $ufrom, $timestamp, $text)
105 if $text ne "";
107 close HF;
111 sub licq {
112 if(open(F, "<$ENV{HOME}/.licq/owner.uin")) {
113 while(<F>) {
114 chomp; $buf = $_;
116 if($buf =~ m/^Uin = ([0-9]+)$/) {
117 $ourUIN = $1;
118 last;
122 close F;
125 open(F, "<$ENV{HOME}/.licq/users.conf")
126 or die "cannot find licq users file $ENV{HOME}/.licq/users.conf";
128 while(<F>) {
129 chomp; $buf = $_;
131 if($buf =~ m/^User[0-9]+ = ([0-9]+)$/) {
132 cicq_adduser($1);
133 licq_conv_history($1);
137 close F;
141 # micq specific functions
144 sub micq {
145 $contsection = 0;
146 $fname = "$ENV{HOME}/.micq/micqrc";
148 open(F, "<$fname")
149 or die "cannot find micq config file $fname";
151 while(<F>) {
152 chomp;
153 s/#.*//;
154 s/^\s+//;
155 next unless length;
156 $buf = $_;
157 if($contsection) {
158 if($buf =~ m/^([0-9]+)\s.+$/) {
159 cicq_adduser($1);
161 } else {
162 $contsection = $buf =~ m/^\[Contacts\]$/;
166 close F;
170 # GnomeICU specific functions
173 sub gnomeicu {
174 $contsection = 0;
175 $fname = "$ENV{HOME}/.gnome/GnomeICU";
177 open(F, "<$fname")
178 or die "cannot find GnomeICU config file $fname";
180 while(<F>) {
181 chomp;
182 $buf = $_;
184 if($contsection) {
185 if($buf =~ m/^([0-9]+)=.+$/) {
186 cicq_adduser($1);
188 } else {
189 $contsection = $buf =~ m/^\[NewContacts\]$/;
193 close F;
197 # KXicq2 specific functions
200 sub kxicq2 {
201 if(open(F, "<$ENV{HOME}/.kde/share/config/kxicq2rc")) {
202 while(<F>) {
203 chomp; $buf = $_;
204 if($buf =~ m/^UIN=([0-9]+)$/) {
205 $ourUIN = $1;
206 last;
210 close F;
213 $fname = "$ENV{HOME}/.kde/share/apps/kxicq2/contacts.kxicq";
215 open(F, "<$fname")
216 or die "cannot find kxicq2 contacts file $fname";
218 while(<F>) {
219 chomp; $buf = $_;
221 if($buf =~ m/^UIN=([0-9]+)$/) {
222 cicq_adduser($1);
226 close F;
229 # Now convert messages history
232 $fname = "$ENV{HOME}/.kde/share/apps/kxicq2/messages.kxicq2";
234 local $uto = 0;
235 local $ufrom = 0;
236 local $utimestamp = 0;
237 local $text = "";
238 local $msgmode = "R";
240 if(open(F, "<$fname")) {
241 while(<F>) {
242 chomp; $buf = $_;
244 if($buf =~ m/^\[Message [0-9]+\]$/) {
245 cicq_addhistoryitem($uto, $ufrom, $timestamp, $text)
246 if $text ne "";
247 $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") {
252 $ufrom = $1;
253 $uto = $ourUIN;
254 } else {
255 $ufrom = $ourUIN;
256 $uto = $1;
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=(.+)$/) {
261 $text = $1;
262 $text =~ s/\\r//g;
263 $text =~ s/\\n/\n/g;
267 cicq_addhistoryitem($uto, $ufrom, $timestamp, $text)
268 if $text ne "";
270 close F;
274 # Trillian specific functions
276 sub create_account_irc {
277 local $OUTPUT_DIR = "$ENV{HOME}/.centerim/";
278 local $buddy_dir = $OUTPUT_DIR."i".$_[0];
280 mkdir($buddy_dir);
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];
288 mkdir($buddy_dir);
289 open(INFO_FP,">".$buddy_dir."/info");
290 print INFO_FP $buddy_mail[0]."\n\n\n".$_[0]."\n";
291 close(INFO_FP);
294 sub trillian {
295 open(TRILLIAN_XML,"Buddies.xml") or
296 die "Can not open Buddies.xml";
297 @lines = <TRILLIAN_XML>;
298 close(TRILLIAN_XML);
300 foreach(@lines){
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\>/) {
309 $buddy_irc = $2;
310 $buddy_irc =~ s/%([0-9A-Za-z]{2})/pack("H2",$1)/ge;
311 create_account_irc($buddy_irc);
316 sub usage {
318 print <<EOF
319 Centerim contact list and history convertor usage:
320 $0 <client>
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";
346 } else {
347 usage;