4 # * Copyright 2002 Paul Mangan <claws@thewildbeast.co.uk>
6 # * Reimplemented by Torsten Schoenfeld <kaffeetisch@web.de>
8 # * This file is free software; you can redistribute it and/or modify it
9 # * under the terms of the GNU General Public License as published by
10 # * the Free Software Foundation; either version 2 of the License, or
11 # * (at your option) any later version.
13 # * This program is distributed in the hope that it will be useful, but
14 # * WITHOUT ANY WARRANTY; without even the implied warranty of
15 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # * General Public License for more details.
18 # * You should have received a copy of the GNU General Public License
19 # * along with this program; if not, write to the Free Software
20 # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 chdir($ENV{ HOME } . "/.sylpheed") or die("You don't appear to have Sylpheed installed\n");
25 ###############################################################################
27 my $normal_headers = qr/^(?:Subject|From|To|Cc)$/;
29 my @new_filters = ("[global]\n");
31 ###############################################################################
35 open(FOLDERLIST, "<folderlist.xml") or die("Can't find 'folderlist.xml'\n");
36 while (<FOLDERLIST>) {
37 if (m/<folder type="mh" name="([^"]+)" path="[^"]+"/) {
44 ###############################################################################
46 open(FILTERRC, "<filterrc") or die("Can't find your old filter rules ('filterrc')\n");
58 $action) = split(/\t/);
60 $value_one =~ s/\"/\\\"/g ;
61 $value_two =~ s/\"/\\\"/g ;
62 $action = $action eq "m" ? "move" : "delete";
63 $destination = $destination =~ m!^\#mh/! ?
65 "#mh/$mailbox/$destination";
73 ###########################################################################
75 if ($mode_one % 2 == 0) {
83 $match_type_one = "matchcase";
86 $match_type_one = "regexpcase";
89 ###########################################################################
91 if ($mode_two % 2 == 0) {
99 $match_type_two = "matchcase";
102 $match_type_two = "regexpcase";
105 ###########################################################################
107 if ($header_one eq "To" && $header_two eq "Cc" ||
108 $header_one eq "Cc" && $header_two eq "To" and
109 $value_one eq $value_two and
110 $mode_one eq $mode_two and
112 if ($action eq "move") {
113 $new_filter = $predicate_one . qq(to_or_cc $match_type_one "$value_one" move "$destination"\n);
116 $new_filter = $predicate_one . qq(to_or_cc $match_type_one "$value_one" delete\n);
120 if ($header_one =~ m/$normal_headers/) {
121 $new_filter .= $predicate_one . lc($header_one) . qq( $match_type_one "$value_one");
124 $new_filter .= $predicate_one . qq(header "$header_one" $match_type_one "$value_one");
128 if ($header_two =~ m/$normal_headers/) {
129 $new_filter .= qq( $op ) . $predicate_two . lc($header_two) . qq( $match_type_two "$value_two");
132 $new_filter .= qq( $op ) . $predicate_two . qq(header "$header_two" $match_type_two "$value_two");
136 if (defined($new_filter)) {
137 if ($action eq "move") {
138 $new_filter .= qq( move "$destination"\n);
141 $new_filter .= qq(delete\n);
146 ###########################################################################
148 push(@new_filters, $new_filter) if (defined($new_filter));
152 ###############################################################################
154 open(MATCHERRC, ">>matcherrc");
155 print MATCHERRC @new_filters;
158 rename("filterrc", "filterrc.old");
160 ###############################################################################
162 print "Converted $#new_filters filters\n";
163 print "Renamed your old filter rules ('filterrc' to 'filterrc.old')\n";