Remove wrong initialization from max_message_size
[claws.git] / tools / kmail2claws-mail.pl
blob681fdf2af97857b1acc04a8e765e122be6efa89c
1 #!/usr/bin/perl
3 # * Copyright 2002 Paul Mangan <paul@claws-mail.org>
4 # *
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 3 of the License, or
8 # * (at your option) any later version.
9 # *
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.
14 # *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 ## script name : kmail2claws-mail.pl
21 ## script purpose : convert a Kmail addressbook into a Claws Mail addressbook
23 use Getopt::Long;
25 $kmailfile = '';
27 GetOptions("kmailfile=s" => \$kmailfile);
29 $time = time;
31 $claws_addr = "<?xml version=\"1.0\" encoding=\"US-ASCII\" ?>\n";
32 $claws_addr .= "<address-book name=\"Kmail Address Book\" >\n";
34 chdir;
36 opendir(CLAWS, ".claws-mail") || die("Can't open .claws-mail directory\n");
37 push(@cached,(readdir(CLAWS)));
38 closedir(CLAWS);
40 foreach $cached (@cached) {
41 if ($cached =~ m/^addrbook/ && $cached =~ m/[0-9].xml$/) {
42 push(@addr, "$cached");
46 @sorted = sort {$a cmp $b} @addr;
47 $last_one = pop(@sorted);
48 $last_one =~ s/^addrbook-//;
49 $last_one =~ s/.xml$//;
50 $last_one++;
51 $new_addrbk = "addrbook-"."$last_one".".xml";
53 open (KFILE, "<$kmailfile") || die("Can't find the kmail file\n");
54 @kmaillines = <KFILE>;
55 close KFILE;
57 $dross = shift(@kmaillines);
59 foreach $kmailline (@kmaillines) {
60 (@kmaildata) = split(/,/,$kmailline);
61 foreach $kmaildata (@kmaildata) {
62 $kmaildata =~ s/^"//;
63 $kmaildata =~ s/"$//;
64 $kmaildata =~ s/"/&quot;/g;
65 $kmaildata =~ s/&/&amp;/g;
66 $kmaildata =~ s/'/&apos;/g;
67 $kmaildata =~ s/</&lt;/g;
68 $kmaildata =~ s/>/&gt;/g;
70 $claws_addr .= " <person uid=\"$time\" first-name=\"$kmaildata[0]\""
71 ." last-name=\"$kmaildata[1]\" nick-name=\"$kmaildata[7]\""
72 ." cn=\"$kmaildata[0] $kmaildata[1]\" >\n"
73 ." <address-list>\n";
74 $time++;
75 $claws_addr .= " <address uid=\"$time\" alias=\"\" email=\"$kmaildata[6]\""
76 ." remarks=\"$kmaildata[8]\" />\n"
77 ." </address-list>\n";
78 if ($kmaildata[13] ne "" || $kmaildata[9] ne "" || $kmaildata[21] ne "" ||
79 $kmaildata[16] ne "" || $kmaildata[5] ne "" || $kmaildata[24] ne "" ||
80 $kmaildata[19] ne "" || $kmaildata[12] ne "" || $kmaildata[10] ne "" ||
81 $kmaildata[4] ne "" || $kmaildata[2] ne "" || $kmaildata[11] ne "" ||
82 $kmaildata[3] ne "" || $kmaildata[14] ne "" || $kmaildata[22] ne "" ||
83 $kmaildata[17] ne "" || $kmaildata[20] ne "" || $kmaildata[15] ne "" ||
84 $kmaildata[23] ne "" || $kmaildata[18] ne "") {
85 $claws_addr .= " <attribute-list>\n";
87 if ($kmaildata[3] ne "" || $kmaildata[2] ne "") {
88 $time++;
89 $claws_addr .= " <attribute uid=\"$time\" name=\"Full Name\" >"
90 ."$kmaildata[3] $kmaildata[0] $kmaildata[2] $kmaildata[1]</attribute>\n";
92 if ($kmaildata[15] ne "") {
93 $time++;
94 $claws_addr .= " <attribute uid=\"$time\" name=\"Home Street Address\" >"
95 ."$kmaildata[15]</attribute>\n";
97 if ($kmaildata[16] ne "") {
98 $time++;
99 $claws_addr .= " <attribute uid=\"$time\" name=\"Home City Address\" >"
100 ."$kmaildata[16]</attribute>\n";
102 if ($kmaildata[17] ne "") {
103 $time++;
104 $claws_addr .= " <attribute uid=\"$time\" name=\"Home State Address\" >"
105 ."$kmaildata[17]</attribute>\n";
107 if ($kmaildata[18] ne "") {
108 $time++;
109 $claws_addr .= " <attribute uid=\"$time\" name=\"Home Zip Address\" >"
110 ."$kmaildata[18]</attribute>\n";
112 if ($kmaildata[19] ne "") {
113 $time++;
114 $claws_addr .= " <attribute uid=\"$time\" name=\"Home Country Address\" >"
115 ."$kmaildata[19]</attribute>\n";
117 if ($kmaildata[10] ne "") {
118 $time++;
119 $claws_addr .= " <attribute uid=\"$time\" name=\"Home Phone\" >"
120 ."$kmaildata[10]</attribute>\n";
122 if ($kmaildata[12] ne "") {
123 $time++;
124 $claws_addr .= " <attribute uid=\"$time\" name=\"Home Fax\" >"
125 ."$kmaildata[12]</attribute>\n";
127 if ($kmaildata[11] ne "") {
128 $time++;
129 $claws_addr .= " <attribute uid=\"$time\" name=\"Mobile Phone\" >"
130 ."$kmaildata[11]</attribute>\n";
132 if ($kmaildata[14] ne "") {
133 $time++;
134 $claws_addr .= " <attribute uid=\"$time\" name=\"Pager\" >"
135 ."$kmaildata[14]</attribute>\n";
137 if ($kmaildata[5] ne "") {
138 $time++;
139 $claws_addr .= " <attribute uid=\"$time\" name=\"Company\" >"
140 ."$kmaildata[5]</attribute>\n";
142 if ($kmaildata[4] ne "") {
143 $time++;
144 $claws_addr .= " <attribute uid=\"$time\" name=\"Job Title\" >"
145 ."$kmaildata[4]</attribute>\n";
147 if ($kmaildata[20] ne "") {
148 $time++;
149 $claws_addr .= " <attribute uid=\"$time\" name=\"Business Street Address\" >"
150 ."$kmaildata[20]</attribute>\n";
152 if ($kmaildata[21] ne "") {
153 $time++;
154 $claws_addr .= " <attribute uid=\"$time\" name=\"Business City Address\" >"
155 ."$kmaildata[21]</attribute>\n";
157 if ($kmaildata[22] ne "") {
158 $time++;
159 $claws_addr .= " <attribute uid=\"$time\" name=\"Business State Address\" >"
160 ."$kmaildata[22]</attribute>\n";
162 if ($kmaildata[23] ne "") {
163 $time++;
164 $claws_addr .= " <attribute uid=\"$time\" name=\"Business Zip Address\" >"
165 ."$kmaildata[23]</attribute>\n";
167 if ($kmaildata[24] ne "") {
168 $time++;
169 $claws_addr .= " <attribute uid=\"$time\" name=\"Business Country Address\" >"
170 ."$kmaildata[24]</attribute>\n";
172 if ($kmaildata[9] ne "") {
173 $time++;
174 $claws_addr .= " <attribute uid=\"$time\" name=\"Business Phone\" >"
175 ."$kmaildata[9]</attribute>\n";
177 if ($kmaildata[13] ne "") {
178 $time++;
179 $claws_addr .= " <attribute uid=\"$time\" name=\"Business Fax\" >"
180 ."$kmaildata[13]</attribute>\n";
182 $claws_addr .= " </attribute-list>\n";
184 $claws_addr .= " </person>\n";
185 $time++;
187 $claws_addr .= "</address-book>\n";
189 open (NEWADDR, ">.claws-mail/$new_addrbk");
190 print NEWADDR $claws_addr;
191 close NEWADDR;
193 open (ADDRIN, "<.claws-mail/addrbook--index.xml") || die("can't open addrbook--index.xml");
194 @addrindex_file = <ADDRIN>;
195 close ADDRIN;
197 foreach $addrindex_line (@addrindex_file) {
198 if ($addrindex_line =~ m/<\/book_list>/) {
199 $rewrite_addrin .= " <book name=\"Kmail Address Book\" file=\"$new_addrbk\" />\n"
200 ." </book_list>\n";
201 } else {
202 $rewrite_addrin .= "$addrindex_line";
206 open (NEWADDRIN, ">.claws-mail/addrbook--index.xml");
207 print NEWADDRIN "$rewrite_addrin";
208 close NEWADDRIN;
210 print "\nYou have sucessfully converted your Kmail addressbook\n";
211 exit;