You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2023/03/18 09:00:57 UTC

svn commit: r1908472 - in /spamassassin/trunk: lib/Mail/SpamAssassin/PerMsgStatus.pm lib/Mail/SpamAssassin/Plugin/Check.pm t/header.t

Author: hege
Date: Sat Mar 18 09:00:56 2023
New Revision: 1908472

URL: http://svn.apache.org/viewvc?rev=1908472&view=rev
Log:
Bug 8121 - header rules with keyword all not working

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
    spamassassin/trunk/t/header.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1908472&r1=1908471&r2=1908472&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Sat Mar 18 09:00:56 2023
@@ -2091,12 +2091,16 @@ sub get_decoded_stripped_body_text_array
 
 =item $status->get (header_name [, default_value])
 
-Returns a message header, pseudo-header or a real name, email-address or
-some other parsed value set by modifiers.  C<header_name> is the name of a
-mail header, such as 'Subject', 'To', etc.
+Returns message headers, pseudo-headers, names, email-addresses or some
+other parsed values set by modifiers.  C<header_name> is the name of a mail
+header such as 'Subject', 'To' etc, or a pseudo/metadata-header like 'ALL',
+'X-Spam-Relays-Untrusted' etc.
 
-Should be called in list context since 4.0.  Will return list of headers
-content, or other values when modifiers used.
+Should be called in list context since SpamAssassin 4.0.  This supports
+returning multiple values for all header and modifier types.
+
+If called in scalar context (pre-4.0 style), only first value is returned
+for modifiers like C<:addr> or C<:name>.
 
 If C<default_value> is given, it will be used if the requested
 C<header_name> does not exist.  This is mainly useful when called in scalar

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=1908472&r1=1908471&r2=1908472&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Sat Mar 18 09:00:56 2023
@@ -666,11 +666,13 @@ sub do_head_tests {
     # setup the function to run the rules
     while(my($k,$v) = each %ordered) {
       my($hdrname, $def) = split(/\t/, $k, 2);
+      # get() might already include newlines, join accordingly (Bug 8121)
       $self->push_evalstr_prefix($pms, '
-        @harr = $self->get(q{'.$hdrname.'});
-        $hval = scalar(@harr) ? join("\n", @harr) : ' .
-                           (!defined($def) ? 'undef' :
-                              '$self->{conf}->{test_opt_unset}->{q{'.$def.'}}') . ';
+        if (scalar(@harr = $self->get(q{'.$hdrname.'}))) {
+          $hval = join($harr[0] =~ /\n\z/ ? "" : "\n", @harr);
+        } else {
+          $hval = '.(!defined($def) ? 'undef' :'$self->{conf}->{test_opt_unset}->{q{'.$def.'}}').'
+        }
       ');
       foreach my $rulename (@{$v}) {
           my $tc_ref = $testcode{$rulename};

Modified: spamassassin/trunk/t/header.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/header.t?rev=1908472&r1=1908471&r2=1908472&view=diff
==============================================================================
--- spamassassin/trunk/t/header.t (original)
+++ spamassassin/trunk/t/header.t Sat Mar 18 09:00:56 2023
@@ -2,7 +2,7 @@
 
 use lib '.'; use lib 't';
 use SATest; sa_t_init("header");
-use Test::More tests => 23;
+use Test::More tests => 26;
 
 # ---------------------------------------------------------------------------
 
@@ -35,6 +35,12 @@ tstprefs('
 
   # Meta should evaluate all
   meta TEST_META (TEST_EXISTS1 && TEST_UNSET2 && HEADER_FIRST1 && HEADER_LAST1 && HEADER_ALL1)
+
+  # ALL newlines (Bug 8121)
+  header TEST_ALL1 ALL =~ /\nTo: announce@ximian\.com\nContent-Type:/
+  # ALL selector
+  header TEST_ALL2 ALL-TRUSTED =~ /\nDelivered-To: jm@netnoteinc.com\nReceived:/
+  header TEST_ALL3 ALL-UNTRUSTED =~ /\nDelivered-To:/
 ');
 
 %patterns = (
@@ -44,6 +50,8 @@ tstprefs('
   q{ 1.0 HEADER_LAST1 }, '',
   q{ 1.0 HEADER_ALL1 }, '',
   q{ 1.0 TEST_META }, '',
+  q{ 1.0 TEST_ALL1 }, '',
+  q{ 1.0 TEST_ALL2 }, '',
 );
 %anti_patterns = (
   q{ TEST_EXISTS2 }, '',
@@ -52,6 +60,7 @@ tstprefs('
   q{ TEST_LEAK1 }, '',
   q{ TEST_LEAK2 }, '',
   q{ TEST_LEAK3 }, '',
+  q{ TEST_ALL3 }, '',
 );
 
 ok (sarun ("-L -t < data/nice/001", \&patterns_run_cb));