From 10e9faa3f815d021bbfe325904b9092826e13bf0 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Tue, 10 Sep 2002 08:33:04 +0000 Subject: [PATCH] add The Bat! addressbook conversion script --- tools/Makefile.am | 1 + tools/README | 24 +++++ tools/tb2sylpheed | 241 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 tools/tb2sylpheed diff --git a/tools/Makefile.am b/tools/Makefile.am index ed91ebcab..51b3c762b 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -11,6 +11,7 @@ EXTRA_TOOLS = \ sylpheed-switcher \ sylprint.pl \ sylprint.rc \ + tb2sylpheed \ update-po \ uudec diff --git a/tools/README b/tools/README index 6dd852f35..6d617f1ba 100644 --- a/tools/README +++ b/tools/README @@ -262,6 +262,30 @@ ----------------------------------------------------------------------- +* tb2sylpheed + + WHAT IT DOES + + This perl script will convert an addressbook exported from The Bat! into + a Sylpheed addressbook. + + HOW TO USE IT + + (You must run sylpheed at least once before running this script.) + + If Sylpheed is running, close it. + + 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 + + The Bat! addressbook data will now be contained in Sylpheed's + addressbook, under the name 'The Bat! Address Book'. + + Any questions, comments or problems, contact Urke MMI + +----------------------------------------------------------------------- * update-po WHAT IT DOES diff --git a/tools/tb2sylpheed b/tools/tb2sylpheed new file mode 100644 index 000000000..a425674ea --- /dev/null +++ b/tools/tb2sylpheed @@ -0,0 +1,241 @@ +#!/usr/bin/perl + +# Script name : tb2sylpheed.pl +# Script based on : script kmail2sylpheed.pl +# Script purpose : convert The Bat! addressbook into a Sylpheed addressbook +# Author : Aleksandar Urosevic aka Urke MMI +# Licence : GPL +# +# Thanks goes to : Paul Mangan +# +# 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 + +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"; + +chdir; + +# check is Sylpheed instrtalled + +opendir(SYLPHEED, ".sylpheed") || die("Can't oen sylpheed directory\n"); + push(@cached, (readdir(SYLPHEED))); +closedir(SYLPHEED); + +# get last existing addressbook filename to set filename for newest addressbook + +foreach $cached (@cached) { + if ($cached =~ m/^addrbook/ && $cached =~ m/[0-9].xml$/) { + push(addr, "$cached"); + } +} + +@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"; + +# opening thebat file in to stack + +open (TBFILE, "<$tbfile") || die("Can't find the thebat file\n"); + @tblines = ; +close TBFILE; + +$dross = shift(@tblines); + +# create addressbook entry from The Bat! addressbook + +foreach $tbline (@tblines) { + (@tbdata) = split(/,/,$tbline); + foreach $tbdata (@tbdata) { + $tbdata =~ s/^"//; + $tbdata =~ s/"$//; + $tbdata =~ s/"/"/g; + $tbdata =~ s/&/&/g; + $tbdata =~ s/'/'/g; + $tbdata =~ s//>/g; + } + $sylph_addr .= " \n" + ." \n"; + $time++; + $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"; + + if ($tbdata[1] ne "" || $tbdata[2] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[29] $tbdata[1] $tbdata[3] $tbdata[2] $tbdata[28]\n"; + } + if ($tbdata[15] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[15]\n"; + } + if ($tbdata[16] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[16]\n"; + } + if ($tbdata[17] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[17]\n"; + } + if ($tbdata[18] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[18]\n"; + } + if ($tbdata[19] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[19]\n"; + } + if ($tbdata[9] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[9]\n"; + } + if ($tbdata[10] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[10]\n"; + } + if ($tbdata[11] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[11]\n"; + } + if ($tbdata[30] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[30]\n"; + } + if ($tbdata[14] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[14]\n"; + } + if ($tbdata[7] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[7]\n"; + } + if ($tbdata[8] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[8]\n"; + } + if ($tbdata[20] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[20]\n"; + } + if ($tbdata[21] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[21]\n"; + } + if ($tbdata[22] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[22]\n"; + } + if ($tbdata[23] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[23]\n"; + } + if ($tbdata[24] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[24]\n"; + } + if ($tbdata[25] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[25]\n"; + } + if ($tbdata[26] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[26]\n"; + } + if ($tbdata[12] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[12]\n"; + } + if ($tbdata[13] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[13]\n"; + } + if ($tbdata[31] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[31]\n"; + } + if ($tbdata[27] ne "") { + $time++; + $sylph_addr .= " " + ."$tbdata[27]\n"; + } + $sylph_addr .= " \n"; + } + $sylph_addr .= " \n"; + $time++; +} +$sylph_addr .= "\n"; + +open (NEWADDR, ">.sylpheed/$new_addrbk"); +print NEWADDR $sylph_addr; +close NEWADDR; + +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" + ." \n"; + } else { + $rewrite_addrin .= "$addrindex_line"; + } +} + +open (NEWADDRIN, ">.sylpheed/addrbook--index.xml"); +print NEWADDRIN "$rewrite_addrin"; +close NEWADDRIN; + +print "\nYou have sucessfully converted your The Bat! addressbook\n"; +exit; -- 2.25.1