allow for Boolean Op and case-sensitivity
[claws.git] / tools / filter_conv.pl
index 380869a9225d5d2b08e0b6df753eec7bdf152858..4265a24a95f71c576638736a08208b601b5b87d1 100644 (file)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 
-#  * Copyright 2001 Paul Mangan <claws@thewildbeast.co.uk>
+#  * Copyright 2002 Paul Mangan <claws@thewildbeast.co.uk>
 #  *
 #  * 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
@@ -34,39 +34,80 @@ foreach $folderlist (@folderlist) {
 }
 
 open (FILTERRC, "<filterrc") || die("Can't find your old filter rules\n");
-@input_file = <FILTERRC>;
+@filterrc = <FILTERRC>;
 close FILTERRC;
 
 $WRITE_THIS = "";
 $COUNT      = "0";
 
-foreach $input_file (@input_file) {
+if (-e "matcherrc") {
+       open (MATCHER, "<matcherrc") || die("Can't open matcherrc\n");
+       @matcherrc = <MATCHER>;
+       close MATCHER;
+               foreach $matcherrc (@matcherrc) {
+                       $WRITE_THIS .= $matcherrc;
+               }
+       $WRITE_THIS .= "\n";
+}
+
+$WRITE_THIS .= "[global]\n";
+
+foreach $filterrc (@filterrc) {
        $COUNT++;
-       @split_lines = split("\t", $input_file);
-       if (($split_lines[3]) && ($split_lines[0] eq "To")) {
-               $WRITE_THIS .= "to_or_cc match \"$split_lines[1]\"";
+       @split_lines = split("\t", $filterrc);
+       if ($split_lines[2] eq "&") {
+               $operator = "&";
+               &sort_data;
+       }
+       elsif ($split_lines[2] eq "|") {
+               $operator = "|";
+               &sort_data;
        } elsif ($split_lines[0] eq "To") {
-               $WRITE_THIS .= "to match \"$split_lines[1]\"";
+               $WRITE_THIS .= "to matchcase \"$split_lines[1]\"";
        } elsif ($split_lines[0] eq "Reply-To") {
-               $WRITE_THIS .= "inreplyto match \"$split_lines[1]\"";
+               $WRITE_THIS .= "inreplyto matchcase \"$split_lines[1]\"";
        } elsif ($split_lines[0] eq "Subject") {
-               $WRITE_THIS .= "subject match \"$split_lines[1]\"";
+               $WRITE_THIS .= "subject matchcase \"$split_lines[1]\"";
        } elsif (($split_lines[0] eq "From") || ($split_lines[0] eq "Sender")){
-               $WRITE_THIS .= "from match \"$split_lines[1]\"";
+               $WRITE_THIS .= "from matchcase \"$split_lines[1]\"";
        }
        if (!$split_lines[5]) {
                $WRITE_THIS .= " delete";
-       } elsif ($split_lines[8] == "m"){
+       } elsif ($split_lines[8] eq "m\n"){
                $WRITE_THIS .= " move \"\#mh/$mailbox/$split_lines[5]\"";
        }
        $WRITE_THIS .= "\n";
        @split_lines = "";
 }
 
-open (FILTERINGRC, ">filteringrc");
-print FILTERINGRC $WRITE_THIS;
-close FILTERINGRC;
+open (MATCHERRC, ">matcherrc");
+print MATCHERRC $WRITE_THIS;
+close MATCHERRC;
 
 print "\nYou have sucessfully converted $COUNT filtering rules\n\n";
 exit;
 
+sub sort_data {
+       if ($split_lines[0] eq "To" && $split_lines[3] eq "Cc" && 
+       $split_lines[1] eq $split_lines[4]) {
+               $WRITE_THIS .= "to_or_cc matchcase \"$split_lines[1]\"";                
+       }
+       elsif ($split_lines[0] eq "To") {
+               $WRITE_THIS .= "to matchcase \"$split_lines[1]\" $operator ";
+       } elsif ($split_lines[0] eq "Reply-To") {
+               $WRITE_THIS .= "inreplyto matchcase \"$split_lines[1]\" $operator ";
+       } elsif ($split_lines[0] eq "Subject") {
+               $WRITE_THIS .= "subject matchcase \"$split_lines[1]\" $operator ";
+       } elsif (($split_lines[0] eq "From") || ($split_lines[0] eq "Sender")) {
+               $WRITE_THIS .= "from matchcase \"$split_lines[1]\" $operator ";
+       }
+       if ($split_lines[3] eq "To") {
+               $WRITE_THIS .= "to matchcase \"$split_lines[4]\"";
+       } elsif ($split_lines[3] eq "Reply-To") {
+               $WRITE_THIS .= "inreplyto matchcase \"$split_lines[4]\"";
+       } elsif ($split_lines[3] eq "Subject") {
+               $WRITE_THIS .= "subject matchcase \"$split_lines[4]\"";
+       } elsif (($split_lines[3] eq "From") || ($split_lines[3] eq "Sender")) {
+               $WRITE_THIS .= "from matchcase \"$split_lines[4]\"";
+       }
+}