Getmail: Spam subject is not rewritten with rspamd

IMHO if , as @AndreLinux just confirmed, mails with the header addition X-getmail-filter-classifier: Action: rewrite subject are spam,
it is enough to simply move them to the Junk folder with a adoption in the before.sieve without actually rewiring the subject.

@AndreLinux what do you think?

yes but nothing will be done if the checkbox move to junk is disabled :frowning:

1 Like

The subject is not actually rewritten, it remains unaltered. It is only the header that changes.

Is this different behavior as with ‘X-SPAM-FLAG’ ‘YES’ ?

But would it be good enough for you if the mails are moved to the Junk folder without rewriting the subject?

Rewriting the subject does not seem to be a simple task in our setup.

would be fine

Today I got an E-Mail from Univention which I tried before Nethserver. I am still on the mailing list. It was send to one of the domains I handle using Nethserver (my old myname.dyndns.org adress): The subject was replaces to anounce its spam status and it was moved to junk - at least this part seems to work 


this is the postfix milter job, this is the normal way to handle email :slight_smile:

this could be just another sieve script in before.sieve provided by nethserver-mail2-getmail

1 Like

Yes, that is my expectation, too. Just from this discussion, I was not sure if it works on my system at all :slight_smile:

Just a first workaround, replace the file with the content below

nano /etc/e-smith/templates/var/lib/nethserver/sieve-scripts/before.sieve/10junkmail

#
# 10junkmail 
#
{
return '# -- disabled (Spam is delivered to INBOX)' if ( ! $dovecot{SpamFolder});

$OUT .= qq(
# -- enabled (move marked SPAM messages into junkmail folder)
require ["fileinto", "mailbox","regex"];
if header :contains "X-Spam-Flag" "YES" {
    fileinto :create "$dovecot{SpamFolder}";
    stop;
}

# -- enabled (move spam subject to junkmail folder)
if header :regex ["X-getmail-filter-classifier"] ["add header"] {
    fileinto :create "Junk";
    stop;
}
);

$OUT .= qq(
# -- enabled (move spam subject to junkmail folder)
if header :contains "subject" "$rspamd{SpamSubjectPrefixString}" {
   fileinto :create "$dovecot{SpamFolder}";
   stop;
}

# -- enabled (move spam subject to junkmail folder)
if header :regex ["X-getmail-filter-classifier"] ["rewrite subject"] {
    fileinto :create "Junk";
    stop;
}
) if (($rspamd{SpamSubjectPrefixString}) && ($rspamd{SpamSubjectPrefixStatus} eq 'enabled'));
}

it is not supposed to rewrite the subject, only to move to junk when the header add header or rewrite subject is found

1 Like

Maybe we could have a solution to change the header subject with sieve

reading this it could be possible to delete a header and to make it again with a new value : https://tools.ietf.org/html/rfc5293

not tested yet, a bit tricky with the risk to delete an important header and break the email :frowning:

1 Like

ok we could rewrite the subject with dovecot/sieve

in /etc/dovecot/dovecot.conf

-       sieve_extensions = +imapflags
+       sieve_extensions = +imapflags, +editheader

restart dovecot

in /var/lib/nethserver/sieve-scripts/before.sieve

-   require ["fileinto", "mailbox"];
+    require ["fileinto", "mailbox","editheader","variables","regex"];

+    if header :matches "Subject" "*" {
+            set "subjwas" ": ${1}";
+    }

+    if header :regex ["X-getmail-filter-classifier"] ["rewrite subject"] {
+   deleteheader :index 1 "subject";
+    addheader :last "subject" "***SPAM*** ${subjwas}";
+    }

    if header :contains "X-Spam-Flag" "YES" {
        fileinto :create "Junk";
        stop;
    }

no need to install an extra rpm or service

@dev_team what do you think

  • create a sieve script to rename the subject if matches rewrite subject (our ***spam*** sieve rule should put it after to junk)
    or
  • create a sieve script to move to junk if matches rewrite subject or add header (if MoveToJunk is enabled’)
5 Likes

WOW - I am impressed :-:muscle::ok_hand::+1:
However I implemented “just move to junk” at the moment.

What is the correct module to apply changes for?
Is it

signal-event nethserver-mail-filter-save

WORKS! Spam mail collecte via Getmail ist placed in the corresponding spam folders!

1 Like

Issue opened

I confirm that it works!

Thanks @stephdl

what is working please ?

emails colleted by getmail and considered as spam by rspamd are correctly moved to the junk folder with the modified object.

1 Like