From d6b3b54223203254814973c1df73d01bc94d5088 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Thu, 2 Jan 2003 18:03:25 +0000 Subject: [PATCH] fixes and improvements to tb2sylpheed --- ChangeLog.claws | 5 + tools/tb2sylpheed | 245 ++++++++++++++++++++++++++-------------------- 2 files changed, 142 insertions(+), 108 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index 01262cfcc..46f3eb6f1 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,8 @@ +2003-01-02 [paul] + + * tools/tb2sylpheed + fixes and improvements by Urke MMI + 2003-01-02 [thorsten] 0.8.8claws40 * src/procmsg.c diff --git a/tools/tb2sylpheed b/tools/tb2sylpheed index a425674ea..05082eb61 100644 --- a/tools/tb2sylpheed +++ b/tools/tb2sylpheed @@ -1,8 +1,9 @@ #!/usr/bin/perl -# Script name : tb2sylpheed.pl +# Script name : tb2sylpheed +# Script version: 1.0.1 # Script based on : script kmail2sylpheed.pl -# Script purpose : convert The Bat! addressbook into a Sylpheed addressbook +# Script purpose : convert The Bat! addressbook into Sylpheed addressbook # Author : Aleksandar Urosevic aka Urke MMI # Licence : GPL # @@ -11,38 +12,48 @@ # Usage: Export The Bat! Address Book to CSV file format # with all fields selected to YES and then start: # tb2sylpheed --tbfile=/full/path/to/thebat/addressbook.csv +# +# Change Log: +# +# 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; -$tbfile = ''; - GetOptions("tbfile=s" => \$tbfile); -$time = time; - -# $tbfile = 'thebat-addressbook.csv'; - -$sylph_addr = "\n"; -$sylph_addr .= "\n"; - -# $new_addrbk = "addrbook-000013.xml"; +#$tbfile = '/home/urke/bin/sylpheed/tb2ldif/thebat-addressbook.csv'; +$total_addresses = 0; chdir; # check is Sylpheed instrtalled - -opendir(SYLPHEED, ".sylpheed") || die("Can't oen sylpheed directory\n"); - push(@cached, (readdir(SYLPHEED))); +opendir(SYLPHEED, ".sylpheed") || die("Can't open Sylpheed directory! Conversion abroted\n"); + push(@cached, (readdir(SYLPHEED))); closedir(SYLPHEED); -# get last existing addressbook filename to set filename for newest addressbook +# 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"); - } + 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-//; @@ -50,163 +61,178 @@ $last_one =~ s/.xml$//; $last_one++; $new_addrbk = "addrbook-"."$last_one".".xml"; -# opening thebat file in to stack - -open (TBFILE, "<$tbfile") || die("Can't find the thebat file\n"); - @tblines = ; +# 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 = ; close TBFILE; +# shift firs line from file because this is field names $dross = shift(@tblines); -# create addressbook entry from The Bat! addressbook +# set time mark and header of addressbook +$time = time; +$sylph_addr = "\n"; +$sylph_addr .= "\n"; +# create addressbook entry from The Bat! addressbook foreach $tbline (@tblines) { + $total_addresses += 1; (@tbdata) = split(/,/,$tbline); - foreach $tbdata (@tbdata) { - $tbdata =~ s/^"//; - $tbdata =~ s/"$//; - $tbdata =~ s/"/"/g; - $tbdata =~ s/&/&/g; - $tbdata =~ s/'/'/g; - $tbdata =~ s//>/g; - } + foreach $tbdata (@tbdata) { + # fix nonacceptable characters + $tbdata =~ s/^"//; + $tbdata =~ s/"$//; + $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 $sylph_addr .= " \n" - ." \n"; + ." last-name=\"$tbdata[2]\" nick-name=\"$tbdata[5]\"" + ." cn=\"$tbdata[0]\" >\n" + ." \n"; $time++; - $sylph_addr .= "
\n" + $sylph_addr .= "
\n" ." \n"; - if ($tbdata[6] ne "" || $tbdata[7] ne "" || $tbdata[8] ne "" || - $tbdata[9] ne "" || $tbdata[10] ne "" || $tbdata[11] ne "" || - $tbdata[12] ne "" || $tbdata[13] ne "" || $tbdata[14] ne "" || - $tbdata[15] ne "" || $tbdata[16] ne "" || $tbdata[17] ne "" || - $tbdata[18] ne "" || $tbdata[19] ne "" || $tbdata[20] ne "" || - $tbdata[21] ne "" || $tbdata[22] ne "" || $tbdata[23] ne "" || - $tbdata[24] ne "" || $tbdata[25] ne "" || $tbdata[26] ne "" || - $tbdata[27] ne "" || $tbdata[30] ne "" || $tbdata[31] ne "") { - $sylph_addr .= " \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) { if ($tbdata[1] ne "" || $tbdata[2] ne "") { - $time++; - $sylph_addr .= " " - ."$tbdata[29] $tbdata[1] $tbdata[3] $tbdata[2] $tbdata[28]\n"; + $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]"; } + + $sylph_addr .= " " + ."$full_name\n"; } if ($tbdata[15] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[15]\n"; } if ($tbdata[16] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[16]\n"; } if ($tbdata[17] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[17]\n"; } if ($tbdata[18] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[18]\n"; } if ($tbdata[19] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[19]\n"; } if ($tbdata[9] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[9]\n"; } if ($tbdata[10] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[10]\n"; } if ($tbdata[11] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[11]\n"; } if ($tbdata[30] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[30]\n"; } if ($tbdata[14] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[14]\n"; } if ($tbdata[7] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[7]\n"; } if ($tbdata[8] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[8]\n"; } if ($tbdata[20] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[20]\n"; } if ($tbdata[21] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[21]\n"; } if ($tbdata[22] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[22]\n"; } if ($tbdata[23] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[23]\n"; } if ($tbdata[24] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[24]\n"; } if ($tbdata[25] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[25]\n"; } if ($tbdata[26] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[26]\n"; } if ($tbdata[12] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[12]\n"; } if ($tbdata[13] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[13]\n"; } if ($tbdata[31] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[31]\n"; } if ($tbdata[27] ne "") { - $time++; - $sylph_addr .= " " + $time++; + $sylph_addr .= " " ."$tbdata[27]\n"; } $sylph_addr .= " \n"; @@ -216,26 +242,29 @@ foreach $tbline (@tblines) { } $sylph_addr .= "\n"; +# print new addressbook to file open (NEWADDR, ">.sylpheed/$new_addrbk"); -print NEWADDR $sylph_addr; + print NEWADDR $sylph_addr; close NEWADDR; -open (ADDRIN, "<.sylpheed/addrbook--index.xml") || die("can't open addrbook--index.xml"); - @addrindex_file = ; +# add new addressbook to index +open (ADDRIN, "<.sylpheed/addrbook--index.xml") || die("Can't open addrbook--index.xml"); + @addrindex_file = ; close ADDRIN; foreach $addrindex_line (@addrindex_file) { - if ($addrindex_line =~ m/<\/book_list>/) { - $rewrite_addrin .= " \n" + if ($addrindex_line =~ m/<\/book_list>/) { + $rewrite_addrin .= " \n" ." \n"; - } else { - $rewrite_addrin .= "$addrindex_line"; - } + } else { + $rewrite_addrin .= "$addrindex_line"; + } } open (NEWADDRIN, ">.sylpheed/addrbook--index.xml"); -print NEWADDRIN "$rewrite_addrin"; + print NEWADDRIN "$rewrite_addrin"; close NEWADDRIN; - -print "\nYou have sucessfully converted your The Bat! addressbook\n"; +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; -- 2.25.1