/usr/share/doc/claws-mail/tools/tb2claws-mail is in claws-mail-tools 3.16.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | #!/usr/bin/perl
# Script name : tb2claws-mail
# Script version: 1.0.2
# Script based on : script kmail2claws-mail.pl
# Script purpose : convert The Bat! addressbook into Claws Mail addressbook
# Author : Aleksandar Urosevic aka Urke MMI <urke@gmx.net>
# Licence : GPL
#
# Thanks goes to : Paul Mangan <paul@claws-mail.org>
#
# Usage: Export The Bat! Address Book to CSV file format
# with all fields selected to YES and then start:
# tb2claws-mail --tbfile=/full/path/to/thebat/addressbook.csv
#
# Change Log:
#
# 18-12-2003 v 1.0.2
# - bugfix: added missing attribute-list start
#
# 01-01-2003 v 1.0.1
# - bugfix: no more empty Business Homepage entry
# - bugfix: no more \0D\0A´s in Notes entry
# - bugfix: no more double space in Full Name entry
# - code utilization
# - add info about number of converted addresses
#
# 15-08-2002 v 1.0.0
# - first public release
#
# TODO:
#
# * Add switch for Full Name entry on atrybute part
#
use Getopt::Long;
GetOptions("tbfile=s" => \$tbfile);
#$tbfile = '/home/urke/bin/claws-mail/tb2ldif/thebat-addressbook.csv';
$total_addresses = 0;
chdir;
# check is Claws-Mail instrtalled
opendir(CLAWS, ".claws-mail/addrbook") || die("Can't open Claws Mail directory! Conversion aborted\n");
push(@cached, (readdir(CLAWS)));
closedir(CLAWS);
# get last existing addressbook filename
# to set filename for newest addressbook
# get all existing addressbook filenames
foreach $cached (@cached) {
if ($cached =~ m/^addrbook/ && $cached =~ m/[0-9].xml$/) {
push(addr, "$cached");
}
}
# sort filenames, get last and set newest filename
@sorted = sort {$a cmp $b} @addr;
$last_one = pop(@sorted);
$last_one =~ s/^addrbook-//;
$last_one =~ s/.xml$//;
$last_one++;
$new_addrbk = "addrbook-"."$last_one".".xml";
# open thebat file to stack
open (TBFILE, "<$tbfile") || die("Specified Address Book file does not exist.\n\033[5m\033[31mYou must specify full path to input file!\033[0m\nConversion aborted.\n");
@tblines = <TBFILE>;
close TBFILE;
# shift firs line from file because this is field names
$dross = shift(@tblines);
# set time mark and header of addressbook
$time = time;
$claws_addr = "<?xml version=\"1.0\" encoding=\"ISO-8859-2\" ?>\n";
$claws_addr .= "<address-book name=\"The Bat! Address Book\" >\n";
# create addressbook entry from The Bat! addressbook
foreach $tbline (@tblines) {
$total_addresses += 1;
(@tbdata) = split(/,/,$tbline);
foreach $tbdata (@tbdata) {
# fix nonacceptable characters
$tbdata =~ s/^"//;
$tbdata =~ s/"$//;
$tbdata =~ s/"/"/g;
$tbdata =~ s/&/&/g;
$tbdata =~ s/'/'/g;
$tbdata =~ s/</</g;
$tbdata =~ s/>/>/g;
$tbdata =~ s/\\2C\ /, /g;
$tbdata =~ s/(\\0D\\0A){1,}/, /g;
$tbdata =~ s/\ {2,}/ /g;
}
# set addressbook field values
$claws_addr .= " <person uid=\"$time\" first-name=\"$tbdata[1]\""
." last-name=\"$tbdata[2]\" nick-name=\"$tbdata[5]\""
." cn=\"$tbdata[0]\" >\n"
." <address-list>\n";
$time++;
$claws_addr .= " <address uid=\"$time\" alias=\"$tbdata[5]\" email=\"$tbdata[4]\""
." remarks=\"\" />\n"
." </address-list>\n";
# find is need to make entry attributes
$check = 0;
for($i=6; $i<=31; $i++) {
$tbdata[$i] =~ s/^\s+//;
$tbdata[$i] =~ s/\s+$//;
if ($tbdata[$i] ne "") { $check += 1; }
}
if ($check > 0) {
$claws_addr .= " <attribute-list>\n";
if ($tbdata[1] ne "" || $tbdata[2] ne "") {
$time++;
if($tbdata[29] ne "" && $tbdata[1] ne "") { $full_name = "$tbdata[29] $tbdata[1]"; } else { $full_name = "$tbdata[1]"; }
if($tbdata[3] ne "") { $full_name .= " $tbdata[3]"; }
if($tbdata[2] ne "") { $full_name .= " $tbdata[2]"; }
if($tbdata[28] ne "") { $full_name .= " $tbdata[28]"; }
$claws_addr .= " <attribute uid=\"$time\" name=\"Full Name\" >"
."$full_name</attribute>\n";
}
if ($tbdata[15] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home Street Address\" >"
."$tbdata[15]</attribute>\n";
}
if ($tbdata[16] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home City Address\" >"
."$tbdata[16]</attribute>\n";
}
if ($tbdata[17] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home State Address\" >"
."$tbdata[17]</attribute>\n";
}
if ($tbdata[18] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home Zip Address\" >"
."$tbdata[18]</attribute>\n";
}
if ($tbdata[19] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home Country Address\" >"
."$tbdata[19]</attribute>\n";
}
if ($tbdata[9] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home Phone\" >"
."$tbdata[9]</attribute>\n";
}
if ($tbdata[10] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Home Fax\" >"
."$tbdata[10]</attribute>\n";
}
if ($tbdata[11] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Mobile Phone\" >"
."$tbdata[11]</attribute>\n";
}
if ($tbdata[30] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Personal Homepage\" >"
."$tbdata[30]</attribute>\n";
}
if ($tbdata[14] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Pager\" >"
."$tbdata[14]</attribute>\n";
}
if ($tbdata[7] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Bussines Company\" >"
."$tbdata[7]</attribute>\n";
}
if ($tbdata[8] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Bussines Job Title\" >"
."$tbdata[8]</attribute>\n";
}
if ($tbdata[20] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Department\" >"
."$tbdata[20]</attribute>\n";
}
if ($tbdata[21] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Office\" >"
."$tbdata[21]</attribute>\n";
}
if ($tbdata[22] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Street Address\" >"
."$tbdata[22]</attribute>\n";
}
if ($tbdata[23] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business City Address\" >"
."$tbdata[23]</attribute>\n";
}
if ($tbdata[24] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business State Address\" >"
."$tbdata[24]</attribute>\n";
}
if ($tbdata[25] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Zip Address\" >"
."$tbdata[25]</attribute>\n";
}
if ($tbdata[26] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Country Address\" >"
."$tbdata[26]</attribute>\n";
}
if ($tbdata[12] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Phone\" >"
."$tbdata[12]</attribute>\n";
}
if ($tbdata[13] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Fax\" >"
."$tbdata[13]</attribute>\n";
}
if ($tbdata[31] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Business Homepage\" >"
."$tbdata[31]</attribute>\n";
}
if ($tbdata[27] ne "") {
$time++;
$claws_addr .= " <attribute uid=\"$time\" name=\"Notes\" >"
."$tbdata[27]</attribute>\n";
}
$claws_addr .= " </attribute-list>\n";
}
# if ( $check > 0 ) {
# $claws_addr .= "</attribute-list>\n";
# }
$claws_addr .= " </person>\n";
$time++;
}
$claws_addr .= "</address-book>\n";
# print new addressbook to file
open (NEWADDR, ">.claws-mail/addrbook/$new_addrbk");
print NEWADDR $claws_addr;
close NEWADDR;
# add new addressbook to index
open (ADDRIN, "<.claws-mail/addrbook/addrbook--index.xml") || die("Can't open addrbook--index.xml");
@addrindex_file = <ADDRIN>;
close ADDRIN;
foreach $addrindex_line (@addrindex_file) {
if ($addrindex_line =~ m/<\/book_list>/) {
$rewrite_addrin .= " <book name=\"The Bat! Address Book\" file=\"$new_addrbk\" />\n"
." </book_list>\n";
} else {
$rewrite_addrin .= "$addrindex_line";
}
}
open (NEWADDRIN, ">.claws-mail/addrbook/addrbook--index.xml");
print NEWADDRIN "$rewrite_addrin";
close NEWADDRIN;
print "You have sucessfully converted your The Bat! addressbook\n";
print "New addressbook file name: $new_addrbk\n";
print "Total addresses converted: $total_addresses\n";
exit;
|