WHAT IT DOES
This perl script will convert an exported Kmail addressbook into a
- Sylpheed addressbook.
+ Sylpheed addressbook. If your version of Kmail is 1.37 or greater
+ and/or your version of KAddressBook is 3.1beta1 or greater, or
+ this script mixes up your definitions and their related data, use
+ 'kmail2sylpheed_v2.pl' instead.
HOW TO USE IT
-----------------------------------------------------------------------
+* kmail2sylpheed_v2.pl
+
+ This script has been tested with Kmail 1.37 and KAddressBook 3.1beta1
+
+ WHAT IT DOES
+
+ This perl script will convert a Kmail addressbook that has been
+ exported in csv format into a Sylpheed addressbook.
+
+ HOW TO USE IT
+
+ (You must run sylpheed at least once before running this script.)
+
+ Open Kmail's Addressbook, /File/Address Book
+ In Kmail's Addressbook choose '/File/Export/Export List...'. This
+ will allow you to export your Kmail addressbook data to a *.csv file.
+
+ If Sylpheed is running, close it.
+
+ From the command line, execute the following:
+
+ perl kmail2sylpheed_v2.pl --kmailfile=/path/to/addressbook.csv
+
+ You can also use --help to see usage instructions.
+
+ Your Kmail addressbook data will now be contained in Sylpheed's
+ addressbook, under the name 'Kmail address book'.
+
+ Any questions, comments or problems, contact Paul <claws@thewildbeast.co.uk>
+
+-----------------------------------------------------------------------
+
* newscache_clean.pl
WHAT IT DOES AND WHY IT DOES IT
--- /dev/null
+#!/usr/bin/perl
+
+# * Copyright © 2002 Paul Mangan <claws@thewildbeast.co.uk>
+# *
+# * This file is free software; you can redistribute it and/or modify it
+# * under the terms of the GNU General Public License as published by
+# * the Free Software Foundation; either version 2 of the License, or
+# * (at your option) any later version.
+# *
+# * This program is distributed in the hope that it will be useful, but
+# * WITHOUT ANY WARRANTY; without even the implied warranty of
+# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# * General Public License for more details.
+# *
+# * You should have received a copy of the GNU General Public License
+# * along with this program; if not, write to the Free Software
+# * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## script name : kmail2sylpheed_v2.pl
+
+## script purpose : convert an exported Kmail addressbook csv file
+## into a Sylpheed addressbook
+
+## tested with Kmail 1.37 and KAddressBook 3.1beta1
+
+use Getopt::Long;
+
+$kmailfile = '';
+$iNeedHelp = '';
+
+GetOptions("kmailfile=s" => \$kmailfile,
+ "help" => \$iNeedHelp);
+
+if ($kmailfile eq "" || $iNeedHelp) {
+ if (!$iNeedHelp) {
+ print "No filename given\n";
+ }
+ print "Use the following format:\n";
+ print "\tkmail2sylpheed_v2.pl --kmailfile=/path/to/addressbook.csv\n";
+ exit;
+}
+
+$sylph_dir = ".sylpheed";
+$addr_index = "$sylph_dir/addrbook--index.xml";
+$new_addressbook = "Kmail address book";
+
+$time = time;
+
+chdir;
+
+opendir(SYLPHEED, $sylph_dir) || die("Can't open $sylph_dir directory\n");
+ push(@cached,(readdir(SYLPHEED)));
+closedir(SYLPHEED);
+
+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";
+
+open (KFILE, "<$kmailfile") || die("Can't open the kmail file [$kmailfile]\n");
+ @kmaillines = <KFILE>;
+close KFILE;
+
+$count = 0;
+$defs = shift(@kmaillines);
+@extra_def = (3,4,5,7 ... 27,29 ... 32,34 ... 42);
+
+(@kmaildefs) = split(/,/,$defs);
+
+$sylph_addr = "<?xml version=\"1.0\" encoding=\"US-ASCII\" ?>\n";
+$sylph_addr .= "<address-book name=\"Kmail address book\" >\n";
+
+foreach $kmailline (@kmaillines) {
+ (@kmaildata) = split(/,/,$kmailline);
+ foreach $kmaildata (@kmaildata) {
+ $kmaildata =~ s/^"//;
+ $kmaildata =~ s/"$//;
+ $kmaildata =~ s/"/"/g;
+ $kmaildata =~ s/&/&/g;
+ $kmaildata =~ s/'/'/g;
+ $kmaildata =~ s/</</g;
+ $kmaildata =~ s/>/>/g;
+ $kmaildata =~ s/\\n/, /g;
+ chomp $kmaildata;
+ }
+ $sylph_addr .= " <person uid=\"$time\" first-name=\"$kmaildata[2]\""
+ ." last-name=\"$kmaildata[1]\" nick-name=\"$kmaildata[6]\""
+ ." cn=\"$kmaildata[2] $kmaildata[1]\" >\n"
+ ." <address-list>\n";
+ $time++;
+ $sylph_addr .= " <address uid=\"$time\" alias=\"\" email=\"$kmaildata[28]\""
+ ." remarks=\"$kmaildata[33]\" />\n"
+ ." </address-list>\n";
+
+ foreach $extra_def (@extra_def) {
+ if ($kmaildata[$extra_def] ne "") {
+ push (@def_exist, $extra_def);
+ }
+ }
+ if ($def_exist[0]) {
+ $sylph_addr .= " <attribute-list>\n";
+ }
+ foreach $def_exist (@def_exist) {
+ $kmaildefs[$def_exist] =~ s/^"//;
+ $kmaildefs[$def_exist] =~ s/"$//;
+ $kmaildefs[$def_exist] =~ s/'/'/g;
+
+ $time++;
+ $sylph_addr .= " <attribute uid=\"$time\" name=\"$kmaildefs[$def_exist]\" >"
+ ."$kmaildata[$def_exist]</attribute>\n";
+ $attribs = 1;
+ }
+ if ($attribs == 1) {
+ $sylph_addr .= " </attribute-list>\n";
+ }
+ $sylph_addr .= " </person>\n";
+ $time++;
+ $count++;
+}
+$sylph_addr .= "</address-book>\n";
+
+open (NEWADDR, ">$sylph_dir/$new_addrbk");
+print NEWADDR $sylph_addr;
+close NEWADDR;
+
+open (ADDRIN, "<$addr_index")
+ || die("can't open $addr_index for reading");
+ @addrindex_file = <ADDRIN>;
+close ADDRIN;
+
+foreach $addrindex_line (@addrindex_file) {
+ if ($addrindex_line =~ m/<\/book_list>/) {
+ $rw_addrindex .= " <book name=\"$new_addressbook\" file=\"$new_addrbk\" />\n"
+ ." </book_list>\n";
+ } else {
+ $rw_addrindex .= "$addrindex_line";
+ }
+}
+
+open (NEWADDRIN, ">$addr_index")
+ || die("Can't open $addr_index for writing");
+print NEWADDRIN "$rw_addrindex";
+close NEWADDRIN;
+
+print "Done. $count address(es) converted successfully.\n";
+
+exit;
+