allow for collapsed folder trees
[claws.git] / tools / filter_conv.pl
index 6ad208bf04436d28f4330f9f2b393564bd173f4b..63dc5a5d62f13cc1a4befaac4d00ea244a8e47e9 100644 (file)
@@ -18,7 +18,7 @@
 #  *
 
 chdir;
-chdir '.sylpheed-claws.bakup-test' || die("You don't appear to have Sylpheed installed\n");
+chdir '.sylpheed' || die("You don't appear to have Sylpheed installed\n");
 
 open(FOLDERLIST, "<folderlist.xml") || die("Can't find folderlist.xml\n");
 @folderlist = <FOLDERLIST>;
@@ -27,7 +27,9 @@ close FOLDERLIST;
 foreach $folderlist (@folderlist) {
        if ($folderlist =~ m/<folder type="mh"/) {
                $folderlist =~ s/<folder type="mh" name="//;
-                $folderlist =~ s/" path="[A-Z0-9]+">\n//ig;
+                $folderlist =~ s/" path="[A-Z0-9]+"//ig;
+               $folderlist =~ s/ collapsed="1"//;
+               $folderlist =~ s/>\n//ig;
                 $folderlist =~ s/^ +//;
                 $mailbox = $folderlist;
         }
@@ -37,6 +39,11 @@ open (FILTERRC, "<filterrc") || die("Can't find your old filter rules\n");
 @filterrc = <FILTERRC>;
 close FILTERRC;
 
+if (!@filterrc) {
+       print "\nYou don't have any filter rules\n\n";
+       exit;
+}
+
 $WRITE_THIS = "";
 $COUNT      = "0";
 
@@ -47,6 +54,7 @@ if (-e "matcherrc") {
                foreach $matcherrc (@matcherrc) {
                        $WRITE_THIS .= $matcherrc;
                }
+       $WRITE_THIS .= "\n";
 }
 
 $WRITE_THIS .= "[global]\n";
@@ -54,20 +62,25 @@ $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]\"";
+       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";
@@ -78,6 +91,33 @@ open (MATCHERRC, ">matcherrc");
 print MATCHERRC $WRITE_THIS;
 close MATCHERRC;
 
+rename ("filterrc","filterrc.old");
+
 print "\nYou have sucessfully converted $COUNT filtering rules\n\n";
+print "'filterrc' has been renamed 'filterrc.old'\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]\"";
+       }
+}