Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I spent the past few days looking for a good way to implement spamassassin server wide. Most solutions involve creating a .qmail files for all virtual users, but I don't like that. There's qmail-scanner that can use spamassassin to tag messages, but does not stop spam delivery. Local users benefit from /etc/procmailrc, but virtual users cannot.

To make things even worse, I don't want to stop spam, but deliver it to a mailbox that I can review to see if my spamassassin settings are correct.

After hours of searching and not finding anything that did what I want, I hacked up this little script that does exactly what I want. Perl's just the glue that holds things together, but I couldn't find strong glue like this elsewhere.

#!/usr/bin/perl # Server wide spam stopper for qmail, second version. # Meant to be used with qmail-qfilter and spamassassin. # Does not require or use procmail. # Use at your own risk. Sysadmin skills are required. # Made by Juerd Waalboer. # In tcpserver configuration or init.d/qmail # QMAILQUEUE=/path/to/somefilter # # #!/bin/sh # # This is /path/to/somefilter # exec /path/to/qmail-qfilter \ # /path/to/spamc -- \ # /path/to/thisscript -- \ # This Perl script # /path/to/qmail-inject -n use strict; use Sys::Hostname qw(hostname); use Time::HiRes qw(gettimeofday); use Fatal qw(open close link unlink); my $maildir = '/var/spam'; # Maildir to store spam in. my $spam = 0; my $headers = ''; while (<>) { /^$/ and do { $/ = \65536; if ($spam > 0) { my $tph = join '.', time(), "$$\_".(gettimeofday)[1], hostname(); open my $fh, ">$maildir/tmp/$tph"; print $fh $headers, $_; print $fh $_ while <>; close $fh; chmod 0660, "$maildir/tmp/$tph"; link "$maildir/tmp/$tph", "$maildir/new/$tph"; unlink "$maildir/tmp/$tph"; exit 99; # "Succesful", but don't deliver } else { print $headers, $_; print while <>; exit 0; # Deliver it } }; /^X-Spam-Flag: YES/ and $spam++; $headers .= $_; }

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to Server wide spam stop with qmail by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2020-04-05 14:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      The most amusing oxymoron is:
















      Results (34 votes). Check out past polls.

      Notices?