e932a5c258221c207296b497bf47d5bbf7d4fc94
[claws.git] / tools / filter_conv.pl
1 #!/usr/bin/perl
2
3 #  * Copyright 2001 Paul Mangan <claws@thewildbeast.co.uk>
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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 #  *
19
20 chdir;
21 chdir '.sylpheed' || die("You don't appear to have Sylpheed installed");
22
23 open(FOLDERLIST, "<folderlist.xml") || warn("Can't find folderlist.xml, guessing that you use 'Mail'");
24 @folderlist = <FOLDERLIST>;
25 close FOLDERLIST;
26
27 foreach $folderlist (@folderlist) {
28         if ($folderlist =~ m/<folder type="mh"/) {
29                 if ($folderlist =~ m/name="Mailbox"/) {
30                         $TOPBOXIS = "Mailbox";
31                 } else {
32                         $TOPBOXIS = "Mail";
33                 }
34         }
35 }
36
37 if (!$TOPBOXIS) {
38         $TOPBOXIS = "Mail";
39 }
40
41 open (FILTERRC, "<filterrc") || die("Can't find your old filter rules");
42 @input_file = <FILTERRC>;
43 close FILTERRC;
44
45 $WRITE_THIS = "";
46 $COUNT      = "0";
47
48 foreach $input_file (@input_file) {
49 $COUNT++;
50 @split_lines = split("\t", $input_file);
51 if (($split_lines[3]) && ($split_lines[0] eq "To")) {
52 $WRITE_THIS .= "to_or_cc match \"$split_lines[1]\"";
53 } elsif ($split_lines[0] eq "To") {
54 $WRITE_THIS .= "to match \"$split_lines[1]\"";
55 } elsif ($split_lines[0] eq "Reply-To") {
56 $WRITE_THIS .= "inreplyto match \"$split_lines[1]\"";
57 } elsif ($split_lines[0] eq "Subject") {
58 $WRITE_THIS .= "subject match \"$split_lines[1]\"";
59 } elsif (($split_lines[0] eq "From") || ($split_lines[0] eq "Sender")){
60 $WRITE_THIS .= "from match \"$split_lines[1]\"";
61 }
62 if (!$split_lines[5]) {
63 $WRITE_THIS .= " delete";
64 } elsif ($split_lines[8] == "m"){
65 $WRITE_THIS .= " move \"\#mh/$TOPBOXIS/$split_lines[5]\"";
66 }
67 $WRITE_THIS .= "\n";
68
69 @split_lines = "";
70 }
71
72 open (FILTERINGRC, ">filteringrc");
73 print FILTERINGRC $WRITE_THIS;
74 close FILTERINGRC;
75
76 print "\nYou have sucessfully converted $COUNT filtering rules\n\n";
77 exit;
78