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

(-)lib/Mail/SpamAssassin.pm (-8 / +9 lines)
Lines 416-431 sub remove_spamassassin_markup { Link Here
416
  }
416
  }
417
417
418
  # remove the headers we added
418
  # remove the headers we added
419
  1 while $hdrs =~ s/\nX-Spam-[^\n]*?\n/\n/gs;
419
  $hdrs =~ s/^X-Spam-[[:alnum:]-]+: .*?\n//gm;
420
421
  my $tag = $self->{conf}->{subject_tag};
422
420
423
  while ( $tag =~ /(_HITS_|_REQD_)/g ) {
421
  my $tag = $self->{conf}->{tag_header_string};
424
       my $typeoftag = $1;
422
  $tag =  quotemeta($tag);
425
       $hdrs =~ s/^Subject: (\D*)\d\d\.\d\d/Subject: $1$typeoftag/m;
423
  $tag =~ s/_HITS_/\\d{2}\\.\\d{2}/g;
426
  } # Wow. Very Hackish.
424
  $tag =~ s/_REQD_/\\d{2}\\.\\d{2}/g;
427
425
428
  1 while $hdrs =~ s/^Subject: \Q${tag}\E /Subject: /gm;
426
  $hdrs =~ s/^Subject: ${tag} /Subject: /gm;
427
  $tag  =  '\(' . $tag . '\)';
428
  $hdrs =~ s/^(From: .*?)\t${tag}$/$1/gm;
429
  $hdrs =~ s/^(To: .*?)\t${tag}$/$1/gm;
429
430
430
  # ok, next, the report.
431
  # ok, next, the report.
431
  # This is a little tricky since we can have either 0, 1 or 2 reports;
432
  # This is a little tricky since we can have either 0, 1 or 2 reports;
(-)lib/Mail/SpamAssassin/Conf.pm (-20 / +79 lines)
Lines 6-12 Mail::SpamAssassin::Conf - SpamAssassin Link Here
6
6
7
  # a comment
7
  # a comment
8
8
9
  rewrite_subject                 1
9
  tag_header                      subject from
10
10
11
  full PARA_A_2_C_OF_1618         /Paragraph .a.{0,10}2.{0,10}C. of S. 1618/i
11
  full PARA_A_2_C_OF_1618         /Paragraph .a.{0,10}2.{0,10}C. of S. 1618/i
12
  describe PARA_A_2_C_OF_1618     Claims compliance with senate bill 1618
12
  describe PARA_A_2_C_OF_1618     Claims compliance with senate bill 1618
Lines 120-129 sub new { Link Here
120
  $self->{auto_whitelist_file_mode} = '0600';	# as string, with --x bits
120
  $self->{auto_whitelist_file_mode} = '0600';	# as string, with --x bits
121
  $self->{auto_whitelist_factor} = 0.5;
121
  $self->{auto_whitelist_factor} = 0.5;
122
122
123
  $self->{rewrite_subject} = 1;
123
  $self->{tag_header} = ['Subject'];
124
  $self->{tag_header_string} = '*****SPAM*****';
124
  $self->{spam_level_stars} = 1;
125
  $self->{spam_level_stars} = 1;
125
  $self->{spam_level_char} = '*';
126
  $self->{spam_level_char} = '*';
126
  $self->{subject_tag} = '*****SPAM*****';
127
  $self->{report_header} = 0;
127
  $self->{report_header} = 0;
128
  $self->{use_terse_report} = 0;
128
  $self->{use_terse_report} = 0;
129
  $self->{defang_mime} = 1;
129
  $self->{defang_mime} = 1;
Lines 327-342 SpamAssassin as a handle for that test; Link Here
327
      $self->{scores}->{$1} = $2+0.0; next;
327
      $self->{scores}->{$1} = $2+0.0; next;
328
    }
328
    }
329
329
330
=item rewrite_subject { 0 | 1 }        (default: 1)
330
=item tag_header { subject | from | to | none }    (default: subject)
331
331
332
By default, the subject lines of suspected spam will be tagged.  This can be
332
By default,  the subject lines of suspected spam will be tagged.  With this
333
disabled here.
333
space-separated list the tagging can be extended to other headers (From and
334
To) or disabled completely. The use of the old option C<rewrite_subject> is
335
deprecated.
334
336
335
=cut
337
=cut
336
338
337
    if (/^rewrite[-_]subject\s+(\d+)$/) {
339
    if (/^tag[-_]headers?\s+(.+)$/) {
338
      $self->{rewrite_subject} = $1+0; next;
340
      my @h = sort(split(/\s+/, $1));
341
      unshift(@h, '');
342
      for (my $i = 1; $i < scalar(@h); $i++) {
343
        if ($h[$i] eq 'none') {
344
          @h = ('none');
345
          last;
346
        }
347
        $h[$i] = ucfirst(lc($h[$i]));
348
        if (($h[$i] !~ /^(?:Subject|From|To)$/) or
349
            ($h[$i] eq $h[$i - 1])) {
350
          splice(@h, $i, 1);
351
          redo;
352
        }
353
      }
354
      shift(@h);
355
356
      if(@h) {
357
        $self->{tag_header} = [ @h ];
358
      } else {
359
        $self->{tag_header} = undef;
360
      }
361
      next;
362
    }
363
    if (/^rewrite[-_]subject\s+(\d+)$/) { # for backward compatibility
364
      dbg("config option rewrite_subject is deprecated; please use tag_header");
365
      my @h = defined($self->{tag_header}) ? @{$self->{tag_header}} : ();
366
367
      my $missing = 1;
368
      for (my $i = 0; $i < scalar(@h); $i++) {
369
        if ($h[$i] eq 'Subject') {
370
          $missing = 0;
371
          unless ($1) {
372
            splice(@h, $i, 1);
373
          }
374
          last;
375
        }
376
      }
377
      if ($1 and $missing) {
378
        push(@h, 'Subject');
379
      }
380
381
      if(@h) {
382
        $self->{tag_header} = [ @h ];
383
      } else {
384
        $self->{tag_header} = undef;
385
      }
386
      next;
387
    }
388
389
=item tag_header_string STRING ...       (default: *****SPAM*****)
390
391
Text added to the headers of mails that are considered spam.  It will be
392
applied to the C<Subject:>, C<From:> and/or C<To:> header,  according to
393
the C<tag_header> option.
394
The string _HITS_ in the tag  will be replace  with the calculated score
395
for this message. _REQD_ will be replaced with the threshold.
396
397
=cut
398
399
    if (/^tag[-_]headers?[-_]string\s+(.+?)\s*$/) {
400
      $self->{tag_header_string} = $1; next;
401
    }
402
    if (/^subject[-_]tag\s+(.+?)\s*$/) { # for backward compatibility.
403
      dbg("config option subject_tag is deprecated; please use tag_header_string");
404
      $self->{tag_header_string} = $1; next;
405
    }
406
407
=item rewrite_subject { 0 | 1 }        (default: 1)
408
409
This option is deprecated. Please use C<tag_header>.
339
410
340
=item spam_level_stars { 0 | 1 }        (default: 1)
411
=item spam_level_stars { 0 | 1 }        (default: 1)
341
412
Lines 369-386 Some people don't like escaping *'s thou Link Here
369
   if(/^spam[-_]level[-_]char\s+(.)$/) {
439
   if(/^spam[-_]level[-_]char\s+(.)$/) {
370
      $self->{spam_level_char} = $1; next;
440
      $self->{spam_level_char} = $1; next;
371
   }
441
   }
372
373
=item subject_tag STRING ... 		(default: *****SPAM*****)
374
375
Text added to the C<Subject:> line of mails that are considered spam,
376
if C<rewrite_subject> is 1.  _HITS_ in the tag will be replace with the calculated
377
score for this message. _REQD_ will be replaced with the threshold.
378
379
=cut
380
381
    if (/^subject[-_]tag\s+(.+?)\s*$/) {
382
      $self->{subject_tag} = $1; next;
383
    }
384
442
385
=item report_header { 0 | 1 }	(default: 0)
443
=item report_header { 0 | 1 }	(default: 0)
386
444
(-)lib/Mail/SpamAssassin/PerMsgStatus.pm (-17 / +22 lines)
Lines 257-267 The modifications made are as follows: Link Here
257
257
258
=over 4
258
=over 4
259
259
260
=item Subject: header for spam mails
260
=item Subject:, From: and/or To: header for spam mails
261
261
262
The string C<*****SPAM*****> (changeable with C<subject_tag> config option) is
262
The string C<*****SPAM*****> (changeable with C<tag_header_string> config
263
prepended to the subject, unless the C<rewrite_subject 0> configuration option
263
option) is prepended to the subject and/or appended as a comment to the
264
is given.
264
from and/or to, depending on the config option C<tag_header>.
265
265
266
=item X-Spam-Status: header for spam mails
266
=item X-Spam-Status: header for spam mails
267
267
Lines 364-385 sub rewrite_as_spam { Link Here
364
    $self->{msg}->delete_header ("X-Spam-Level");
364
    $self->{msg}->delete_header ("X-Spam-Level");
365
  }
365
  }
366
366
367
  # First, rewrite the subject line.
367
  # First, rewrite the headers.
368
  if ($self->{conf}->{rewrite_subject}) {
368
  if ($self->{conf}->{tag_header}) {
369
    $_ = $srcmsg->get_header ("Subject");
369
    my $tag = $self->{conf}->{tag_header_string};
370
    $_ ||= '';
371
372
    my $tag = $self->{conf}->{subject_tag};
373
374
    my $hit = sprintf ("%05.2f", $self->{hits});
375
    $tag =~ s/_HITS_/$hit/;
376
370
371
    my $hits = sprintf ("%05.2f", $self->{hits});
372
    $tag =~ s/_HITS_/$hits/g;
377
    my $reqd = sprintf ("%05.2f", $self->{conf}->{required_hits});
373
    my $reqd = sprintf ("%05.2f", $self->{conf}->{required_hits});
378
    $tag =~ s/_REQD_/$reqd/;
374
    $tag =~ s/_REQD_/$reqd/g;
379
    
375
    
380
    s/^(?:\Q${tag}\E |)/${tag} /g;
376
    foreach my $header (@{$self->{conf}->{tag_header}}) {
377
      $_ = $srcmsg->get_header($header) || '';
381
378
382
    $self->{msg}->replace_header ("Subject", $_);
379
      if ($header eq 'Subject') {
380
        s/^(?:$\Q{tag}\E |)/${tag} /;
381
      }
382
      elsif ($header =~ /From|To/) {
383
        s/(?:\t\Q(${tag})\E|)$/\t(${tag})/;
384
      }
385
386
      $self->{msg}->replace_header($header, $_);
387
    }
383
  }
388
  }
384
389
385
  # add some headers...
390
  # add some headers...
Lines 862-868 sub get_decoded_stripped_body_text_array Link Here
862
867
863
  if ($html) {
868
  if ($html) {
864
    # Convert <Q> tags
869
    # Convert <Q> tags
865
    $text =~ s/<\/?Q\b[^>]*>/"/gis;
870
    $text =~ s/<\/?Q\b[^>]*>/"/gis; #dummy"# because KWrite's highlighting sucks
866
  }
871
  }
867
872
868
  if ($entities) {    
873
  if ($entities) {    

Return to bug 478