3 # * Copyright 2002 Ricardo Mones Lastra <mones@aic.uniovi.es>
5 # * This file is free software; you can redistribute it and/or modify it
6 # * under the terms of the GNU General Public License as published by
7 # * the Free Software Foundation; either version 2 of the License, or
8 # * (at your option) any later version.
10 # * This program is distributed in the hope that it will be useful, but
11 # * WITHOUT ANY WARRANTY; without even the implied warranty of
12 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # * General Public License for more details.
15 # * You should have received a copy of the GNU General Public License
16 # * along with this program; if not, write to the Free Software
17 # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # outlook2sylpheed.pl -- perl script to convert an Outlook generated
20 # contact list into a Sylpheed XML address book.
22 # This script is based on:
23 # out2syl.sh by Rafael Lossurdo <mugas@via-rs.net>
24 # kmail2sylpheed.pl by Paul Mangan <claws@thewildbeast.co.uk>
26 # See README file for details and usage.
29 # parse required parameter
30 die "Required filename missing\nSyntax: $0 fullpathname\n" unless (defined($ARGV[0]));
31 $outl_file = $ARGV[0];
33 $sylconf = ".sylpheed";
34 $indexname = "$sylconf/addrbook--index.xml";
36 # the next is mostly Paul's code
40 opendir(SYLPHEED, $sylconf) || die("can't open $sylconf directory\n");
41 push(@cached,(readdir(SYLPHEED)));
44 foreach $cached (@cached) {
45 if ($cached =~ m/^addrbook/ && $cached =~ m/[0-9].xml$/) {
46 push(@addr, "$cached");
50 @sorted = sort {$a cmp $b} @addr;
51 $last_one = pop(@sorted);
52 $last_one =~ s/^addrbook-//;
53 $last_one =~ s/.xml$//;
55 $new_book = "/addrbook-"."$last_one".".xml";
57 # ok, was enough, do some more bit bashing now
58 open(OUTL, $outl_file)
59 or die "can't open $outl_file for reading\n";
60 open(NEWB, '>', "$sylconf/$new_book")
61 or die "can't open $new_book for writting\n";
63 $_ = <OUTL>; # skip first line
66 print NEWB "<?xml version=\"1.0\" encoding=\"US-ASCII\" ?>\n";
67 print NEWB "<address-book name=\"Outlook Address Book\" >\n";
70 if (/\s+[0-9]+\s+(.+)/) { $_ = $1; }
71 else { $count += 2 and die "wrong format at line $count \n"; }
72 @field = split(';',$_); # first is name, second mail addr
73 print NEWB "<person uid=\"", $time, "\" first-name=\"\"";
74 print NEWB "last-name=\"\" nick-name=\"\" cn=\"", $field[0];
75 print NEWB "\" >\n<address-list>\n";
77 $field[1] =~ s/\r//; # beware, dangerous chars inside ;)
78 print NEWB "<address uid=\"", $time, "\" alias=\"\" email=\"", $field[1];
79 print NEWB "\" /> \n</address-list>\n</person>\n";
83 print NEWB "</address-book>\n";
88 # update index (more Paul's code :)
90 open(INDX, $indexname)
91 or die "can't open $indexname for reading\n";
95 foreach $index_line (@index_file) {
96 if ($index_line =~ m/<\/book_list>/) {
97 $new_index .= " <book name=\"Outlook Address Book\" file=\"$new_book\" />\n"." </book_list>\n"; } else {
98 $new_index .= "$index_line";
101 open (INDX, '>', $indexname)
102 or die "can't open $indexname for writting\n";
103 print INDX "$new_index";
106 print "Done. $count address(es) converted successfully.\n";