root/trunk/licq/bin/licq.micqconvert

Revision 4586, 4.8 kB (checked in by erijo, 2 years ago)

Close input and output files before trying to move them around, as this apparently causes troubles on FreeBSD softupdates filesystem.
Closes #175.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3# ------------------------------------------------------------------------
4#
5# Objectives:
6# To make the life easier for people switching from MICQ to LICQ.
7# Convert MICQ contacts list to LICQ one.
8#
9# Usage: micq2licq.pl micq_rc_file licq_home_directory
10# Example: micq2licq.pl ~/.micqrc ~/.licq
11#
12# It is quick hack initially done for personal needs. The code
13# is released to the public under GPL.
14#
15# Any comments, hints, suggestions direct them to me:
16#
17# atanas argirov
18# e-mail: aa@boza.org
19# http://www.boza.org/~aa
20#
21# You can find the original script at the following URL:
22# http://www.boza.org/~aa/src/micq2licq.pl
23#
24# ------------------------------------------------------------------------
25
26use strict;
27
28
29print STDERR <<EOF if $#ARGV < 1;
30
31Convert MICQ U*IX client contacts list to LICQ contacts list.
32
33Usage: micq2licq.pl micq_rc_file licq_home_directory
34   
35Example: micq2licq.pl ~/.micqrc ~/.licq
36   
37EOF
38   
39exit 1 if $#ARGV < 1;
40
41# Global variables
42
43my $rc;
44my $contacts_counted = 0;
45my $directory;
46my $absolute_path;
47my $initial_users = 0;
48my @contact;
49my @contacts_list;
50
51$directory = $ARGV[1];
52
53
54sub fill_out_content {
55   
56    print OUT "[user]" . "\n";
57    print OUT "History = default" . "\n";
58    print OUT "Groups.System = 0" . "\n";
59    print OUT "Groups.User = 0" . "\n";
60    print OUT "Ip = " . "\n";
61    print OUT "Port = 0" . "\n";
62    print OUT "NewMessages = 0" . "\n";
63    print OUT "LastOnline = 977755483" . "\n";
64    print OUT "LastSent = 977755431" . "\n";
65    print OUT "LastRecv = 0" . "\n";
66    print OUT "LastCheckedAR = 0" . "\n";
67    print OUT "AutoAccept = 0" . "\n";
68    print OUT "StatusToUser = 65535" . "\n";
69    print OUT "CustomAutoRsp = " . "\n";
70    print OUT "SendRealIp = 0" . "\n";
71    print OUT "Alias = " . $contact[1] . "\n";;
72    print OUT "FirstName = " . "\n";
73    print OUT "LastName = " . "\n";
74    print OUT "Email1 = " . "\n";
75    print OUT "Email2 = " . "\n";
76    print OUT "EmailO = " . "\n";
77    print OUT "City = " . "\n";
78    print OUT "State = " . "\n";
79    print OUT "PhoneNumber = " . "\n";
80    print OUT "FaxNumber = " . "\n";
81    print OUT "Address = " . "\n";
82    print OUT "CellularNumber = " . "\n";
83    print OUT "Zipcode = " . "\n";
84    print OUT "Country = 0" . "\n";
85    print OUT "Timezone = -100" . "\n";
86    print OUT "Authorization = 0" . "\n";
87    print OUT "HideEmail = 0" . "\n";
88    print OUT "Age = 65535" . "\n";
89    print OUT "Gender = 0" . "\n";
90    print OUT "Homepage = " . "\n";
91    print OUT "BirthYear = 0" . "\n";
92    print OUT "BirthMonth = 0" . "\n";
93    print OUT "BirthDay = 0" . "\n";
94    print OUT "Language1 = 0" . "\n";
95    print OUT "Language2 = 0" . "\n";
96    print OUT "Language3 = 0" . "\n";
97    print OUT "CompanyCity = " . "\n";
98    print OUT "CompanyState = " . "\n";
99    print OUT "CompanyPhoneNumber = " . "\n";
100    print OUT "CompanyFaxNumber = " . "\n";
101    print OUT "CompanyAddress = " . "\n";
102    print OUT "CompanyName = " . "\n";
103    print OUT "CompanyDepartment = " . "\n";
104    print OUT "CompanyPosition = " . "\n";
105    print OUT "CompanyHomepage = " . "\n";
106}   
107
108sub update_users_conf {
109    my $j;
110    my @users;
111    my $system_commands;
112    my $filename  =  $ARGV[1] . "/" . "users.conf";
113    my $filename_tmp  =  $ARGV[1] . "/" . "users.conf.tmp";
114    open (IN, "$filename") or die "Can't open requested file $!";
115    open (TMP, "+>$filename_tmp") or die "Can't open requested file $!";
116   
117    print "\nUpdating $filename... ";
118   
119    while (<IN>) {
120    $rc = index($_, "NumOfUsers");
121    if ($rc >= 0) {
122        @users = split("=");
123        $initial_users = $users[1];
124        print TMP "NumOfUsers = " . ($initial_users + $contacts_counted - 1) . "\n";
125    } else {
126        print TMP $_;
127    }   
128    }
129   
130    for ($j=0; $j < ($contacts_counted-1); $j++) {
131    print TMP "User" . ($j + $initial_users + 1) . " = " . $contacts_list[$j] . "\n";
132    }   
133   
134    close (IN);
135    close (TMP);
136
137    $system_commands = "cp $filename_tmp $filename; rm $filename_tmp";
138    system($system_commands) == 0 or die "system() call failed: $?";
139   
140    print "Done.\n\n";
141}
142
143
144# Ignition point
145# try to open .micqrc
146
147open (STREAM, $ARGV[0]) or die "Can't open requested file $!";
148
149while (<STREAM>) {
150   
151    if ($contacts_counted >= 1) {
152    chop;
153    @contact = split (" ");
154    $contact[0] =~ s/\*//g;
155    $contact[0] =~ s/\~//g;
156    $contacts_list[$contacts_counted-1] = $contact[0];
157    $absolute_path = $directory . "/users/" . $contact[0] . ".uin";
158    open (OUT, ">$absolute_path") or die "Can't open requested file $!";
159    &fill_out_content();
160    close (OUT);
161    print "Contact #" . $contacts_counted . ": " . "uin: " . $contact[0] . " -> " . "alias: " . $contact[1] . " processed\n";
162    $contacts_counted++;
163       
164    } 
165   
166    else {
167   
168    $rc = index ($_, "Contacts");
169    if ($rc >= 0) {
170        $contacts_counted = 1;
171    }
172    }
173}
174
175
176# let update users.conf also
177
178&update_users_conf();
179
180# let's clean
181
182close (STREAM);
Note: See TracBrowser for help on using the browser.