And to follow-up on my previous follow-up (sorry, it's late here and I'm tired) :-) ...

The "1+" I mentioned was actually "0+" originally... I had changed it to 1+ while debugging this. Oops. So my final changed is actually a bit simpler:

  {  $1 eq 'SCORE'     ? (sprintf("%07.3f",$spam_level))

I'm not really sure why the "0+" was there originally. I'm sure there's some subtle need for it that I'm missing. Possibly the idea was to truncate the score to a precision of 3, rather than right-pad to a precision of 3? In any event, for my purposes it works as above, simply eliminating the "0+" and adding my preferred formatting to the sprintf, since I want my score both left-padded and right-padded with zeros for easy sorting.

Hopefully if anyone else is trying to accomplish the same this will help them out!


On 3/29/2017 2:32 AM, Jeff Morris wrote:

After a few more hours of hacking away at this, I finally solved it!

I was actually on the right track when I mentioned the $subject_tag parsing code on line 16373 in my previous email. That is in fact the code that gets executed for $sa_spam_subject_tag as well. The reason it wasn't working for me was that the sprintf statement was preceded by "1+". I can't believe I missed this. Since the sprintf was being interpreted first and then having 1 added to it, this was causing perl to convert the string back to a number, thus wiping out the formatting I had applied in sprintf. Ultimately I changed this line:

  {  $1 eq 'SCORE'     ? (1+sprintf("%.3f",$spam_level))

To this, so the addition would be done before the sprintf formatting:

  {  $1 eq 'SCORE'     ? (sprintf("%07.3f",$spam_level+1))

...and now my subject line is being formatted as I wanted, with the score zero padded.


On 3/28/2017 11:24 PM, Jeff Morris wrote:
I posted about this last year but wasn't able to find a solution, so I'm revisiting it.

I have amavis configured to add the spam score to the subject line of spammy messages via the following variable in amavisd.conf:

  $sa_spam_subject_tag = '[SPAM: _SCORE_] ';

This gives me subject lines like the following examples:

  Subject: [SPAM: 21.21] Spammy Subject
  Subject: [SPAM: 7.13] Another Spammy Subject

I would like the scores to be zero-padded, so I can easily sort the spam in my email client (Thunderbird) by subject, so I can look for false-positives with lowish scores. For example, I would like the above examples to be changed to this:

  Subject: [SPAM: 007.13] Another Spammy Subject
Subject: [SPAM: 021.21] Spammy Subject

When I posted here last year someone suggested changing "_SCORE_" in my amavisd.conf to "_SCORE(000)_", however this does not work. It does not get parsed, instead it gives me the literal "_SCORE(000)_" in my subject lines, like this:

  Subject: [_SCORE(000)_] Spammy Subject
  Subject: [_SCORE(000)_] Another Spammy Subject

I've spent quite a bit of time trying to figure this out and have made no progress.

Could someone explain to me, in layman's terms, what amavisd does with the contents of the $sa_spam_subject_tag variable? Does it pass this to Spamassassin (in which case the problem I'm having would be with Spamassasin, rather than Amavis), or does Amavis parse this and replace it? I really don't understand the flow here through Amavis. I've done a fair amount of Perl scripting in my time, but I don't recognize the underscores as a Perl construct, and strings in single-quotes aren't parsed by Perl, so I really don't understand where the contents of this variable are getting parsed? I've been looking at /usr/sbin/amavisd, and it looks like _SCORE_ is some sort of amavisd macro. For example, on line 12304 I see this:

  SCORE  => sub {macro_score($MSGINFO,undef,@_)}

And on line 11849 I see the definition for the above macro_score function, which looks like is should parse "_SCORE(000)_", but as I said above, it doesn't when it's used in $sa_spam_subject_tag. I also see on line 16373 code to parse the contents of $subject_tag (not $sa_spam_subject_tag). This code does NOT appear to be capable of parsing the "_SCORE(000)_" syntax, so I tried changing the sprintf format on line 16377 from "%.3f" to "%07.3f", but this had no effect, so apparently $subject_tag and $sa_spam_subject_tag are not equivalent.

This is getting really frustrating, as it seems like such a simple change, but I've spent many hours trying different configuration options and digging through amavis' source code off and on over the past year trying to understand it, but still don't feel like I've made any progress. I'd really appreciate any help anyone could give.

I'm running CentOS 7.3.1611, amavisd-new-2.10.1-5, and spamassassin-3.4.0-2.

Thanks!



Reply via email to