remove reference to freshmeat_search.pl
[claws.git] / tools / filter_conv_new.pl
old mode 100644 (file)
new mode 100755 (executable)
index b63ef35..4bae1bc
@@ -1,10 +1,11 @@
 #!/usr/bin/perl -w
 
 use strict;
+use XML::SimpleObject;
 
 #  * 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
+#  * the Free Software Foundation; either version 3 of the License, or
 #  * (at your option) any later version.
 #  *
 #  * This program is distributed in the hope that it will be useful, but
@@ -16,18 +17,18 @@ use strict;
 #  * along with this program; if not, write to the Free Software
 #  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #  *
-#  * Copyright 2006 Paul Mangan <claws@thewildbeast.co.uk>
+#  * Copyright 2006 Paul Mangan <paul@claws-mail.org>
 #  *
 
 #
 # Convert new style Sylpheed filter rules (Sylpheed >= 0.9.99) to
-# Sylpheed-Claws filtering rules
+# Claws Mail filtering rules
 #
 
 #
 # TABLE OF EQUIVALENTS
 #
-# SYLPHEED                     :       SYLPHEED-CLAWS
+# SYLPHEED                     :       Claws Mail
 #------------------------------------------------------
 #
 # NAME
@@ -75,19 +76,17 @@ use strict;
 # stop-eval                    :       stop
 #
 
-use XML::SimpleObject;
-
 my $old_config = "$ENV{HOME}/.sylpheed-2.0/filter.xml";
 my $older_config = "$ENV{HOME}/.sylpheed/filter.xml";
 my $old_filters;
 
-my $config_dir = `sylpheed-claws --config-dir` or die("ERROR:
-       You don't appear to have Sylpheed-Claws installed\n");
+my $config_dir = `claws-mail --config-dir` or die("ERROR:
+       You don't appear to have Claws Mail installed\n");
 chomp $config_dir;
 
 chdir($ENV{HOME} . "/$config_dir") or die("ERROR:
-       Sylpheed-Claws config directory not found [~/$config_dir]
-       You need to run Sylpheed-Claws once, quit it, and then rerun this script\n");
+       Claws Mail config directory not found [~/$config_dir]
+       You need to run Claws Mail once, quit it, and then rerun this script\n");
 
 if (-e $old_config) {
        $old_filters = $old_config;
@@ -98,14 +97,24 @@ if (-e $old_config) {
        exit;
 }
 
+my $claws_version = `claws-mail --version`;
+$claws_version =~ s/^Claws Mail version //;
+
+my ($major, $minor) = split(/\./, $claws_version);
+
+my $version_test = 0;
+if ($major > 2 || ($major == 2 && $minor >= 3)) {
+       $version_test = 1;
+}
+
 my $parser = XML::Parser->new(ErrorContext => 2, Style => "Tree");
 my $xmlobj = XML::SimpleObject->new($parser->parsefile($old_filters));
 
 my @conditions = ('match-header','match-to-or-cc','match-any-header',
                  'match-body-text','command-test','size','age');
 
-my @actions = ('move','copy','not-receive','delete','mark','color-label',
-              'mark-as-read','exec','stop-eval');
+my @actions = ('copy','not-receive','mark','color-label','mark-as-read',
+              'exec','stop-eval','move','delete');
 
 my $standard_headers = qr/^(?:Subject|From|To|Cc)$/;
 my $negative_matches = qr/^(?:not-contain|is-not|not-regex)$/;
@@ -119,17 +128,23 @@ my $bool;
 
 ## rules list
 foreach my $element ($xmlobj->child("filter")->children("rule")) {
-       my $new_filter;
+       my $new_filter = "\n";
+       if ($element->attribute("enabled")) {
+               if ($element->attribute("enabled") eq "false") {
+                       if ($version_test) {
+                               $new_filter .= "disabled ";
+                       } else {
+                               $disabled++;
+                               next;   # skip disabled rules
+                       }
+               } elsif ($version_test) {
+                               $new_filter .= "enabled ";
+               }
+       }
        if ($element->attribute("name")) {
                my $name = $element->attribute("name");
                $name = clean_me($name);
-               $new_filter = "\nrulename \"$name\" ";
-       }
-       if ($element->attribute("enabled")) {
-               if ($element->attribute("enabled") eq "false") {
-                       $disabled++;
-                       next;   # skip disabled rules
-               }
+               $new_filter .= "rulename \"$name\" ";
        }
 ## condition list
        foreach my $parent ($element->children("condition-list")) {
@@ -164,6 +179,8 @@ foreach my $element ($xmlobj->child("filter")->children("rule")) {
                                        }
                                        if ($condition eq "match-any-header") {
                                                $new_filter .= "headers_part ";
+                                       } elsif ($condition eq "match-header-content") {
+                                               $new_filter .= "headers_cont ";
                                        } elsif ($condition eq "match-to-or-cc") {
                                                $new_filter .= "to_or_cc ";
                                        } elsif ($condition eq "match-body-text") {