/usr/share/doc/claws-mail/tools/mew2claws-mail.pl is in claws-mail-tools 3.14.1-3.
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 | #!/usr/bin/perl
# * Copyright 2007 Jérôme Lelong <jerome.lelong@gmail.com>
# *
# * 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 3 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
## script name : mew2claws-mail.pl
## script purpose : convert a Mew addressbook into a Claws Mail addressbook
## This script assumes your Mew addressbook is Latin-1 encoded and not
## unicode. In this latter case, you will have to hack this script a
## little.
use Getopt::Long;
## Process the command line options
## the program expects one argument: the Mew addressbook file
my $help=0;
my $mewfile='';
GetOptions("mew-addressbook=s" => \$mewfile,
"help" => \$help);
if ($help==1)
{
print("usage : perl mew2claws-mail.pl [--help] [--mew-addressbook=file] \n");
print("\t--help: displays this help\n");
print("\t--mew-addressbook=file : file is the filename of your Mew addressbook\n");
exit 0;
}
if ($mewfile ne '' && !-f $mewfile)
{
print("file $mewfile does not exists\n");
exit 1;
}
$time=time;
$claws_addr='';
$home = glob("~");
$clawsdir=`claws-mail --config-dir`;
chomp($clawsdir);
$clawsdir = $home . '/' . $clawsdir . '/' . 'addrbook/';
opendir(CLAWS, $clawsdir) || die("Can't open $clawsdir directory\n");
push(@cached,(readdir(CLAWS)));
closedir(CLAWS);
## find the first availabel name for a new addressbook in claws-mail
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 (MEWFILE, "<$mewfile") || die("Can't find the Mew addressbook file\n");
@mewentries = <MEWFILE>;
close MEWFILE;
$claws_addr .= "<?xml version=\"1.0\" encoding=\"ISO8859-1\" ?>\n"
. "<address-book name=\"Mew Address Book\" >";
chomp(@mewentries);
foreach $line (@mewentries)
{
$line =~ s/ *\t/ /g;
$line =~ s/ *$//g;
(@fields) = split(/ +/,$line);
$nickname= shift(@fields);
@emails=();
$alias='';
$firstname='';
$lastname='';
while (1)
{
$field = shift(@fields);
if ($field =~ m/@/)
{
$field =~ s/,$//;
push(@emails, $field);
} else
{
unshift(@fields, $field);
last;
}
}
$alias = shift(@fields);
if ($alias eq "\*")
{
print($alias . "\n");
$alias='';
}
$firstname=shift(@fields); $firstname =~ s/"//g;
foreach (@fields)
{
$lastname .= "$_ ";
}
$lastname =~ s/"//g;
$lastname =~ s/ *$//g;
$claws_addr .= " <person uid=\"$time\" first-name=\"$firstname\""
." last-name=\"$lastname\" nick-name=\"$nickname\""
." cn=\"$firstname $lastname\" >\n"
." <address-list>\n";
$time++;
foreach $email (@emails)
{
$claws_addr .= " <address uid=\"$time\" alias=\"$alias\" email=\"$email\""
." remarks=\"\" />\n";
$time++;
}
$claws_addr .= " </address-list>\n"
. " <attribute-list>\n"
. " </attribute-list>\n";
$claws_addr .= " </person>\n";
$time++;
}
$claws_addr .= "</address-book>\n";
open (NEWADDR, ">$clawsdir/$new_addrbk") ;
print NEWADDR ($claws_addr);
close NEWADDR;
open (ADDRIN, "<$clawsdir/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 name=\"Mew Address Book\"/)
{
print("An entry already exists for \"Mew Address Book\", you may duplicate it\n");
print("Continuing anyway...\n");
}
if ($addrindex_line =~ m/<\/book_list>/)
{
$rewrite_addrin .= " <book name=\"Mew Address Book\" file=\"$new_addrbk\" />\n"
." </book_list>\n";
} else
{
$rewrite_addrin .= "$addrindex_line";
}
}
open (NEWADDRIN, ">$clawsdir/addrbook--index.xml");
print NEWADDRIN "$rewrite_addrin";
close NEWADDRIN;
print "\nYou have sucessfully converted your Mew addressbook\n";
exit;
|