View | Details | Raw Unified | Return to bug 6392
Collapse All | Expand All

(-)lib/Mail/SpamAssassin/Plugin/BodyRuleBaseExtractor.pm (-24 / +23 lines)
Lines 160-187 Link Here
160
    }
160
    }
161
161
162
    # ignore ReplaceTags rules
162
    # ignore ReplaceTags rules
163
    # TODO: need cleaner way to do this
163
    my $is_a_replacetags_rule = $conf->{rules_to_replace}->{$name};
164
    goto NO if ($conf->{rules_to_replace}->{$name});
164
    my ($minlen, @bases);
165
165
166
    my ($qr, $mods) = $self->simplify_and_qr_regexp($rule);
166
    if (!$is_a_replacetags_rule) {
167
      my ($qr, $mods) = $self->simplify_and_qr_regexp($rule);
167
168
168
    my @bases;
169
      eval {  # catch die()s
169
    eval {  # catch die()s
170
        @bases = $self->extract_hints($rule, $qr, $mods);
170
      @bases = $self->extract_hints($rule, $qr, $mods);
171
      };
171
    };
172
      $@ and dbg("giving up on regexp: $@");
172
    $@ and dbg("giving up on regexp: $@");
173
173
174
    # if any of the extracted hints in a set are too short, the entire
174
      # if any of the extracted hints in a set are too short, the entire
175
    # set is invalid; this is because each set of N hints represents just
175
      # set is invalid; this is because each set of N hints represents just
176
    # 1 regexp.
176
      # 1 regexp.
177
    my $minlen;
177
      foreach my $str (@bases) {
178
    foreach my $str (@bases) {
178
        my $len = length $str;
179
      my $len = length $str;
179
        if ($len < $min_chars) { $minlen = undef; @bases = (); last; }
180
      if ($len < $min_chars) { $minlen = undef; @bases = (); last; }
180
        elsif (!defined($minlen) || $len < $minlen) { $minlen = $len; }
181
      elsif (!defined($minlen) || $len < $minlen) { $minlen = $len; }
181
      }
182
    }
182
    }
183
183
184
    if ($minlen && @bases) {
184
    if ($is_a_replacetags_rule || !$minlen || !@bases) {
185
      dbg("zoom: NO $rule");
186
      push @failed, { orig => $rule };
187
      $cached->{rule_bases}->{$cachekey} = { };
188
      $no++;
189
    }
190
    else {
185
      # dbg("zoom: YES <base>$base</base> <origrule>$rule</origrule>");
191
      # dbg("zoom: YES <base>$base</base> <origrule>$rule</origrule>");
186
192
187
      # figure out if we have e.g. ["foo", "foob", "foobar"]; in this
193
      # figure out if we have e.g. ["foo", "foob", "foobar"]; in this
Lines 206-218 Link Here
206
      $cached->{rule_bases}->{$cachekey} = { g => \@forcache };
212
      $cached->{rule_bases}->{$cachekey} = { g => \@forcache };
207
      $yes++;
213
      $yes++;
208
    }
214
    }
209
    else {
210
NO:
211
      dbg("zoom: NO $rule");
212
      push @failed, { orig => $rule };
213
      $cached->{rule_bases}->{$cachekey} = { };
214
      $no++;
215
    }
216
  }
215
  }
217
216
218
  $self->{show_progress} and $progress->final();
217
  $self->{show_progress} and $progress->final();

Return to bug 6392