| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # ICQ99b contact list converter |
|---|
| 4 | # (tested with build 2569) |
|---|
| 5 | # |
|---|
| 6 | # (c)1999 Erwin Aitenbichler <eait@gmx.at> |
|---|
| 7 | # This program is released under the terms of the GPL. |
|---|
| 8 | # |
|---|
| 9 | |
|---|
| 10 | $path=(getpwuid($<))[7]."/.licq/"; |
|---|
| 11 | $pathUsers=$path."users/"; |
|---|
| 12 | $fnOwner=$path."owner.uin"; |
|---|
| 13 | $fnUsers=$path."users.conf"; |
|---|
| 14 | $verbose=1; |
|---|
| 15 | $|=1; |
|---|
| 16 | |
|---|
| 17 | @fieldNames=("UIN","MyDefinedHandle","NickName","FirstName","LastName","PrimaryEmail"); |
|---|
| 18 | @values=(); |
|---|
| 19 | |
|---|
| 20 | foreach $arg (@ARGV) |
|---|
| 21 | { |
|---|
| 22 | if ($arg eq "-q") |
|---|
| 23 | { $verbose=0; } |
|---|
| 24 | elsif ($arg eq "-v") |
|---|
| 25 | { $verbose=2; } |
|---|
| 26 | else |
|---|
| 27 | { $fn=$arg; } |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | if (!defined($fn)) |
|---|
| 31 | { |
|---|
| 32 | print STDERR "\nsyntax: licq.winconvert99b-2000 [options] <your_uin>.dat\n"; |
|---|
| 33 | print STDERR "Extracts all UINs out of an ICQ99b/2000 database and creates licq .uin files.\n"; |
|---|
| 34 | print STDERR "(tested with build 2569)\n"; |
|---|
| 35 | print STDERR "\nThe .dat-file is usually located in: <your_win_drive>/Program Files/icq/Db99b/\n"; |
|---|
| 36 | print STDERR "\noptions:\n"; |
|---|
| 37 | print STDERR " -q quiet\n"; |
|---|
| 38 | print STDERR " -v verbose\n"; |
|---|
| 39 | print STDERR "\n"; |
|---|
| 40 | exit 0; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | # get owner uin |
|---|
| 44 | |
|---|
| 45 | open(INFH, "<$fnOwner") || die "canŽt open Ž$fnOwnerŽ.\n"; |
|---|
| 46 | while(<INFH>) |
|---|
| 47 | { |
|---|
| 48 | if ($_=~/Uin = (\d+)/) |
|---|
| 49 | { |
|---|
| 50 | $own_uin=$1; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | close(INFH); |
|---|
| 54 | die "canŽt determine owner uin.\n" if (!defined($own_uin)); |
|---|
| 55 | print "owner uin: $own_uin\n\n" if $verbose>=2; |
|---|
| 56 | |
|---|
| 57 | # read users from users.conf |
|---|
| 58 | |
|---|
| 59 | %uins=(); |
|---|
| 60 | if (open(INFH, "<$fnUsers")) |
|---|
| 61 | { |
|---|
| 62 | while (<INFH>) |
|---|
| 63 | { |
|---|
| 64 | $uins{$1}=1 if ($_=~/User\d+ = (\d+)/); |
|---|
| 65 | } |
|---|
| 66 | close(INFH); |
|---|
| 67 | } |
|---|
| 68 | else |
|---|
| 69 | { |
|---|
| 70 | print "Ž$fnUsersŽ not found - will create a new one.\n" if $verbose>=1; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | # import users |
|---|
| 74 | |
|---|
| 75 | $count=0; |
|---|
| 76 | readFile($fn); |
|---|
| 77 | |
|---|
| 78 | # write new users.conf |
|---|
| 79 | |
|---|
| 80 | open(OUTFH, ">$fnUsers") || die "canŽt open Ž$fnUsersŽ for writing.\n"; |
|---|
| 81 | @list=sort {$a <=> $b} (keys %uins); |
|---|
| 82 | print OUTFH "[users]\nNumOfUsers = ", $#list+1, "\n"; |
|---|
| 83 | $i=1; |
|---|
| 84 | foreach $key (@list) |
|---|
| 85 | { |
|---|
| 86 | print OUTFH "User", $i++, " = ", $key, "\n"; |
|---|
| 87 | } |
|---|
| 88 | close(OUTFH); |
|---|
| 89 | |
|---|
| 90 | print "$count users add.\n" if $verbose>=1; |
|---|
| 91 | |
|---|
| 92 | if ($verbose>=1) |
|---|
| 93 | { |
|---|
| 94 | print "NOTE: This script doesn't support all user information fields.\n"; |
|---|
| 95 | print "Select 'Users/Update All Users' in licq to get full user information.\n"; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | sub readFile() |
|---|
| 99 | { |
|---|
| 100 | my $fn=shift; |
|---|
| 101 | open(INFH, "<$fn") || die "can't open file '$fn'\n"; |
|---|
| 102 | binmode INFH; # for M$... |
|---|
| 103 | $key=""; |
|---|
| 104 | $pos=0; |
|---|
| 105 | print "reading" if $verbose==1; |
|---|
| 106 | nextChar(); |
|---|
| 107 | while (nextPair()) |
|---|
| 108 | { |
|---|
| 109 | if ($field==0) |
|---|
| 110 | { |
|---|
| 111 | if ($values[0]!=$own_uin && ($values[1] || $values[2])) |
|---|
| 112 | { |
|---|
| 113 | if (!$uins{$values[0]}) |
|---|
| 114 | { |
|---|
| 115 | $uins{$values[0]}=1; |
|---|
| 116 | $count++; |
|---|
| 117 | } |
|---|
| 118 | writeRecord(); |
|---|
| 119 | } |
|---|
| 120 | @values=(); |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | close(INFH); |
|---|
| 124 | print "\n" if $verbose==1; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | sub nextPair() |
|---|
| 128 | { |
|---|
| 129 | do |
|---|
| 130 | { |
|---|
| 131 | nextKey(); |
|---|
| 132 | return 0 if (eof(INFH)); |
|---|
| 133 | } |
|---|
| 134 | while (!$key); |
|---|
| 135 | if ($c eq "k") |
|---|
| 136 | { |
|---|
| 137 | nextChar(); |
|---|
| 138 | readString(); |
|---|
| 139 | } |
|---|
| 140 | elsif ($c eq "i") |
|---|
| 141 | { |
|---|
| 142 | read(INFH, $buffer, 4); |
|---|
| 143 | $value=unpack("V", $buffer); |
|---|
| 144 | nextChar(); |
|---|
| 145 | } |
|---|
| 146 | $values[$field]=$value; |
|---|
| 147 | return 1; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | sub nextKey() |
|---|
| 151 | { |
|---|
| 152 | while (ord($c)!=0) { nextChar(); } |
|---|
| 153 | nextChar(); |
|---|
| 154 | my $s=""; |
|---|
| 155 | while (ord($c)!=0) |
|---|
| 156 | { |
|---|
| 157 | $s.=$c; |
|---|
| 158 | nextChar(); |
|---|
| 159 | } |
|---|
| 160 | for ($i=0; $i<=$#fieldNames; $i++) |
|---|
| 161 | { |
|---|
| 162 | if ($fieldNames[$i] eq $s) |
|---|
| 163 | { |
|---|
| 164 | nextChar(); # type |
|---|
| 165 | $key=$s; |
|---|
| 166 | $field=$i; |
|---|
| 167 | return 1; |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | $key=""; |
|---|
| 171 | return 0; |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | sub nextChar() |
|---|
| 175 | { |
|---|
| 176 | $c=getc(INFH); |
|---|
| 177 | print "." if ($verbose==1 && $pos%10000==0); |
|---|
| 178 | $pos++; |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | sub readString() |
|---|
| 182 | { |
|---|
| 183 | $value=""; |
|---|
| 184 | my $len=ord($c); |
|---|
| 185 | nextChar(); |
|---|
| 186 | return 0 if $c!=0; |
|---|
| 187 | nextChar(); |
|---|
| 188 | return 1 if ($len==0); |
|---|
| 189 | my $i; |
|---|
| 190 | for ($i=0; $i<$len-1; $i++) |
|---|
| 191 | { |
|---|
| 192 | return 0 if (ord($c)==0); |
|---|
| 193 | $value.=$c; |
|---|
| 194 | nextChar(); |
|---|
| 195 | } |
|---|
| 196 | return 0 if $c!=0; |
|---|
| 197 | return 1; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | sub writeRecord() |
|---|
| 201 | { |
|---|
| 202 | if ($verbose>=2) |
|---|
| 203 | { |
|---|
| 204 | print "uin : $values[0]\n"; |
|---|
| 205 | print "display name : $values[1]\n"; |
|---|
| 206 | print "nick name : $values[2]\n"; |
|---|
| 207 | print "first name : $values[3]\n"; |
|---|
| 208 | print "last name : $values[4]\n"; |
|---|
| 209 | print "email : $values[5]\n\n"; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | my $fnUIN=$pathUsers.$values[0].".uin"; |
|---|
| 213 | if (!-f $fnUIN) |
|---|
| 214 | { |
|---|
| 215 | open(OUTFH, ">$fnUIN") || die "can't open '$fnUIN' for writing.\n"; |
|---|
| 216 | print OUTFH "[user]\n"; |
|---|
| 217 | print OUTFH "Alias = ", $values[1] ne "" ? $values[1] : $values[2]; |
|---|
| 218 | print OUTFH "\nFirstName = $values[3]\n"; |
|---|
| 219 | print OUTFH "LastName = $values[4]\n"; |
|---|
| 220 | print OUTFH "EMail = $values[5]\n"; |
|---|
| 221 | print OUTFH "History = default\n"; |
|---|
| 222 | print OUTFH "Authorization =\n"; |
|---|
| 223 | print OUTFH "OnlineNotify =\n"; |
|---|
| 224 | print OUTFH "NewUser =\n"; |
|---|
| 225 | print OUTFH "NewMessages =\n"; |
|---|
| 226 | print OUTFH "Group =\n"; |
|---|
| 227 | print OUTFH "City =\n"; |
|---|
| 228 | print OUTFH "State =\n"; |
|---|
| 229 | print OUTFH "Homepage =\n"; |
|---|
| 230 | print OUTFH "Age =\n"; |
|---|
| 231 | print OUTFH "Sex =\n"; |
|---|
| 232 | print OUTFH "About =\n"; |
|---|
| 233 | print OUTFH "PhoneNumber =\n"; |
|---|
| 234 | print OUTFH "Country =\n"; |
|---|
| 235 | print OUTFH "VisibleList =\n"; |
|---|
| 236 | print OUTFH "InvisibleList =\n"; |
|---|
| 237 | close(OUTFH); |
|---|
| 238 | } |
|---|
| 239 | } |
|---|