How to forward spam to SpamCop.net with procmail

79 Views Asked by At

From https://de.wikipedia.org/wiki/Procmail


:0fw
| /usr/bin/spamassassin

:0H
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*
/dev/null

:0H:
* ^X-Spam-Status: Yes
./Spam

I would like to complement the move to /dev/null with a forward to submit.[id]@spam.spamcop.net.

I have only found simple forwarding as an action (!). But Spamcop also needs the headers, so I would have to create an empty email with the email as attachment.

{
    :0 c
    ! submit.[id]@spam.spamcop.net

    :0
    /dev/null
}
2

There are 2 best solutions below

0
AnFi On

Have you considered using spamassasin/spamc for sending spam reports via SMTP to spamcop.net? See Mail::SpamAssassin::Plugin::SpamCop and --reporttype command line option of spamc. It would require confirmation via WWW unless you use "quick" spamcop reporting.

0
xebeche On

Procmail has no built-in mechanism to forward as attachment. However, a simple shell script does the trick. In fact, spamcop.net offers a simple Perl script for exactly this purpose.

Download this script, edit in your eMail addresses and make it executable, let's say as $HOME/bin/reporter.pl.

Then, in your .procmailrc use the action | ("pipe" or "filter") instead of ! ("forward"). For instance:

:0fw
| /usr/bin/spamassassin

:0w
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*
| $HOME/bin/reporter.pl

:0H:
* ^X-Spam-Status: Yes
./Spam

Note that the 2nd recipe does not use the flag "f" (filter). With "f" procmail would expect the script to return a message at stdout. That's the case e.g. with "|spamassassin", but our "|reporter.pl" is a so-called delivering recipe. It should not create any output. Hence, /dev/null is not needed.

Edit

As tripleee pointed out messages can also be forwarded "inline", and SpamCop.net is accepting and processing this format apparently just fine. So, adapting tripleee's code the recipe could be

:0fw
| /usr/bin/spamassassin

:0w
* ^X-Spam-Level: \*\*\*\*\*\*\*\*\*\*
| (echo "From: [email protected]"; echo "To: submit.[id]@spam.spamcop.net"; \
   echo "Subject: report spam"; echo "MIME-Version: 1.0"; \
   echo "Content-type: message/rfc822"; echo; cat -) | $SENDMAIL -t

:0H:
* ^X-Spam-Status: Yes
./Spam