spamassassin-users June 2010 archive
Main Archive Page > Month Archives  > spamassassin-users archives
spamassassin-users: Re: Writing Spamassassin plugin.

Re: Writing Spamassassin plugin.

From: Karsten Bräckelmann <guenther_at_nospam>
Date: Fri Jun 18 2010 - 13:52:24 GMT
To: users@spamassassin.apache.org

On Fri, 2010-06-18 at 09:38 +0200, Massimiliano Giovine wrote:
> Hi all. I'm writing a simple spamassassin plugin that eval just
> subject but it does not.

> $self->register_eval_rule ("check_header_token");

It's an eval() rule. So you also need to define a SA rule, that calls
the function. Please read the docs carefully. Also, looking at existing
code and basing off of it likely is a good idea...

  http://spamassassin.apache.org/full/3.2.x/doc/Mail_SpamAssassin_Plugin.html

> sub check_header_token
> {
> my ($self, $pms) = @_;
> $subject = $pms->get('Subject');
>
> if($subject == 'HELLO')
> {
> #bad message
> return 0;
> }
> return 1;

Your eval() rule claims a hit, if the Subject does *not* match. You
reversed the logic.

> What i miss? I put log message on new and on rule and i saw that it
> did the new function but if i telnet a mail message with "HELLO" as a
> subject it write it into mailbox.

Anyway, I hope this is just meant as a first attempt, not a real plugin.
It duplicates the existing WhiteListSubject plugin (which also handles
blacklisting subjects).

Moreover, for arbitrary scores, a simple header rule does the same, much
more flexible than a plugin.

  header FOO Subject =~ /^bad subject$/

-- char *t="\10pse\0r\0dtu\0.@ghno\x4e\xc8\x79\xf4\xab\x51\x8a\x10\xf4\xf4\xc4"; main(){ char h,m=h=*t++,*x=t+2*h,c,i,l=*x,s=0; for (i=0;i<l;i++){ i%8? c<<=1: (c=*++x); c&128 && (s+=h); if (!(h>>=1)||!t[s+h]){ putchar(t[s]);h=m;s=0; }}}