X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=tools%2Ffilter_conv.pl;h=74ac353b0dc6944b50c84d936dacc426fdb968e6;hp=a1f5b5ce64c12fdbb6eb83aa16b8f83ed9d331f4;hb=5c3a9ab9d77d2d95bec509607b76cc461360fe18;hpb=8979e742c8c4c5dbf19b6374046feee756ed2979 diff --git a/tools/filter_conv.pl b/tools/filter_conv.pl index a1f5b5ce6..74ac353b0 100644 --- a/tools/filter_conv.pl +++ b/tools/filter_conv.pl @@ -1,7 +1,10 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w +use strict; # * Copyright 2002 Paul Mangan # * +# * Reimplemented by Torsten Schoenfeld +# * # * 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 2 of the License, or @@ -17,67 +20,144 @@ # * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # * -chdir; -chdir '.sylpheed' || die("You don't appear to have Sylpheed installed\n"); +chdir($ENV{ HOME } . "/.sylpheed") or die("You don't appear to have Sylpheed installed\n"); + +############################################################################### + +my $normal_headers = qr/^(?:Subject|From|To|Cc)$/; + +my @new_filters = ("[global]\n"); -open(FOLDERLIST, "; +############################################################################### + +my $mailbox; + +open(FOLDERLIST, ") { + if (m/\n//ig; - $folderlist =~ s/^ +//; - $mailbox = $folderlist; +############################################################################### + +open(FILTERRC, ") { + chomp(); + + my ($header_one, + $value_one, + $op, + $header_two, + $value_two, + $destination, + $mode_one, + $mode_two, + $action) = split(/\t/); + + $value_one =~ s/\"/\\\"/g ; + $value_two =~ s/\"/\\\"/g ; + $action = $action eq "m" ? "move" : "delete"; + $destination = $destination =~ m!^\#mh/! ? + $destination : + "#mh/$mailbox/$destination"; + + my ($predicate_one, + $predicate_two, + $match_type_one, + $match_type_two, + $new_filter); + + ########################################################################### + + if ($mode_one % 2 == 0) { + $predicate_one = "~"; + } + else { + $predicate_one = ""; + } + + if ($mode_one <= 1) { + $match_type_one = "matchcase"; + } + else { + $match_type_one = "regexpcase"; + } + + ########################################################################### + + if ($mode_two % 2 == 0) { + $predicate_two = "~"; + } + else { + $predicate_two = ""; + } + + if ($mode_two <= 1) { + $match_type_two = "matchcase"; + } + else { + $match_type_two = "regexpcase"; + } + + ########################################################################### + + if ($header_one eq "To" && $header_two eq "Cc" || + $header_one eq "Cc" && $header_two eq "To" and + $value_one eq $value_two and + $mode_one eq $mode_two and + $op eq "|") { + if ($action eq "move") { + $new_filter = $predicate_one . qq(to_or_cc $match_type_one "$value_one" move "$destination"\n); + } + else { + $new_filter = $predicate_one . qq(to_or_cc $match_type_one "$value_one" delete\n); + } + } + else { + if ($header_one =~ m/$normal_headers/) { + $new_filter .= $predicate_one . lc($header_one) . qq( $match_type_one "$value_one"); + } + else { + $new_filter .= $predicate_one . qq(header "$header_one" $match_type_one "$value_one"); + } + + if ($op ne " ") { + if ($header_two =~ m/$normal_headers/) { + $new_filter .= qq( $op ) . $predicate_two . lc($header_two) . qq( $match_type_two "$value_two"); + } + else { + $new_filter .= qq( $op ) . $predicate_two . qq(header "$header_two" $match_type_two "$value_two"); + } + } + + if (defined($new_filter)) { + if ($action eq "move") { + $new_filter .= qq( move "$destination"\n); } -} - -open (FILTERRC, "; -close FILTERRC; - -$WRITE_THIS = ""; -$COUNT = "0"; - -if (-e "matcherrc") { - open (MATCHER, "; - close MATCHER; - foreach $matcherrc (@matcherrc) { - $WRITE_THIS .= $matcherrc; - } -} - -$WRITE_THIS .= "[global]\n"; - -foreach $filterrc (@filterrc) { - $COUNT++; - @split_lines = split("\t", $filterrc); - if (($split_lines[3]) && ($split_lines[0] eq "To")) { - $WRITE_THIS .= "to_or_cc match \"$split_lines[1]\""; - } elsif ($split_lines[0] eq "To") { - $WRITE_THIS .= "to match \"$split_lines[1]\""; - } elsif ($split_lines[0] eq "Reply-To") { - $WRITE_THIS .= "inreplyto match \"$split_lines[1]\""; - } elsif ($split_lines[0] eq "Subject") { - $WRITE_THIS .= "subject match \"$split_lines[1]\""; - } elsif (($split_lines[0] eq "From") || ($split_lines[0] eq "Sender")){ - $WRITE_THIS .= "from match \"$split_lines[1]\""; - } - if (!$split_lines[5]) { - $WRITE_THIS .= " delete"; - } elsif ($split_lines[8] == "m"){ - $WRITE_THIS .= " move \"\#mh/$mailbox/$split_lines[5]\""; - } - $WRITE_THIS .= "\n"; - @split_lines = ""; -} - -open (MATCHERRC, ">matcherrc"); -print MATCHERRC $WRITE_THIS; -close MATCHERRC; - -print "\nYou have sucessfully converted $COUNT filtering rules\n\n"; -exit; + else { + $new_filter .= qq(delete\n); + } + } + } + + ########################################################################### + + push(@new_filters, $new_filter) if (defined($new_filter)); + } +close(FILTERRC); + +############################################################################### + +open(MATCHERRC, ">>matcherrc"); + print MATCHERRC @new_filters; +close(MATCHERRC); + +rename("filterrc", "filterrc.old"); + +############################################################################### +print "Converted $#new_filters filters\n"; +print "Renamed your old filter rules ('filterrc' to 'filterrc.old')\n";