]> Sergey Matveev's repositories - public-inbox.git/blob - scripts/report-spam
dsdeflate: shorten scope of initial buffer
[public-inbox.git] / scripts / report-spam
1 #!/bin/sh
2 # Copyright (C) 2008-2014, Eric Wong <e@80x24.org>
3 # License: GPLv3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>
4 # Usage: report-spam /path/to/message/in/maildir
5 # This is intended for use with incron or similar systems.
6 # my incrontab(5) looks like this:
7 #  /path/to/maildir/.INBOX.good/cur IN_MOVED_TO /path/to/report-spam $@/$#
8 #  /path/to/maildir/.INBOX.spam/cur IN_MOVED_TO /path/to/report-spam $@/$#
9
10 # gigantic emails tend not to be spam (but they suck anyways...)
11 bytes=$(stat -c %s $1)
12 if test $bytes -gt 512000
13 then
14         exit
15 fi
16
17 # Only tested with the /usr/sbin/sendmail which ships with postfix
18 # *** Why not call spamc directly in this script? ***
19 # I route this through my MTA so it gets queued properly.
20 # incrond has no concurrency limits and will fork a new process on
21 # every single event, which sucks with rename storms when a client
22 # commits folder changes.  The sendmail executable exits quickly and
23 # queues up the message for training.  This should also ensure fairness
24 # to newly arriving mail.  Instead of installing/configuring
25 # another queueing system, I reuse the queue in the MTA.
26 # See scripts/dc-dlvr for corresponding trainspam/trainham handlers,
27 # which are for my personal bayes training, and scripts/dc-dlvr.pre
28 # for the pispam/piham handlers for training emails going to public-inbox
29
30 DO_SENDMAIL='/usr/sbin/sendmail -oi'
31 PI_USER=pi
32
33 case $1 in
34 *[/.]spam/cur/*) # non-new messages in spam get trained
35         $DO_SENDMAIL $PI_USER+pispam <$1
36         exec $DO_SENDMAIL $USER+trainspam <$1
37         ;;
38 *:2,*S*) # otherwise, seen messages only
39         case $1 in
40         *:2,*T*) exit 0 ;; # ignore trashed messages
41         esac
42         $DO_SENDMAIL $PI_USER+piham <$1
43         exec $DO_SENDMAIL $USER+trainham <$1
44         ;;
45 esac