about summary refs log tree commit homepage
path: root/scripts
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-04-21 00:18:33 +0000
committerEric Wong <e@80x24.org>2014-04-21 00:23:33 +0000
commit62f57b7545eedf6a781efb2f5269b0a38ef2cd4c (patch)
treeb561952c8a3fa1ac8f033966e5971f3f89ec3751 /scripts
parent1c910ebd5d088b68fd1cec41285ad62641673845 (diff)
downloadpublic-inbox-62f57b7545eedf6a781efb2f5269b0a38ef2cd4c.tar.gz
The ~/.dc-dlvr.pre script for my public-inbox user does this.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/dc-dlvr12
-rw-r--r--scripts/dc-dlvr.pre12
-rwxr-xr-xscripts/report-spam25
3 files changed, 36 insertions, 13 deletions
diff --git a/scripts/dc-dlvr b/scripts/dc-dlvr
index 68123f84..ca64505c 100755
--- a/scripts/dc-dlvr
+++ b/scripts/dc-dlvr
@@ -1,6 +1,7 @@
 #!/bin/sh
 # Copyright (C) 2008-2013, Eric Wong <e@80x24.org>
 # License: GPLv3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>
+# This is installed as /etc/dc-dcvr on my system
 # to use with postfix main.cf: mailbox_command = /etc/dc-dlvr "$EXTENSION"
 DELIVER=/usr/lib/dovecot/deliver
 
@@ -11,7 +12,7 @@ catchall) exec $DELIVER ;;
 esac
 
 # change if your spamc/spamd listens elsewhere
-spamc='spamc -U /run/spamd.sock'
+spamc='spamc'
 
 # allow plus addressing to train spam filters, $1 is the $EXTENSION
 # which may be "trainspam" or "trainham".  Only allow spam training
@@ -30,11 +31,14 @@ then
         set -e
         cat > $TMPMSG
         DEFAULT_INBOX=$(. ~/.dc-dlvr.pre)
-        if test xINBOX != x"$DEFAULT_INBOX"
-        then
+        case $DEFAULT_INBOX in
+        '') exec rm -f $rm_list ;;
+        INBOX) ;; # do nothing
+        *)
                 $DELIVER -m $DEFAULT_INBOX < $TMPMSG
                 exec rm -f $rm_list
-        fi
+                ;;
+        esac
         PREMSG=$(mktemp -t dc-dlvr.orig.$USER.XXXXXX || exit 1)
         rm_list="$rm_list $PREMSG"
         set +e
diff --git a/scripts/dc-dlvr.pre b/scripts/dc-dlvr.pre
new file mode 100644
index 00000000..9183a96e
--- /dev/null
+++ b/scripts/dc-dlvr.pre
@@ -0,0 +1,12 @@
+# Copyright (C) 2014, Eric Wong <e@80x24.org>
+# License: AGPLv3 or later <http://www.gnu.org/licenses/agpl-3.0.txt>
+# sourced by /etc/dc-dlvr in ~$PI_USER/.dc-dlvr.rc, this just exits,
+# aborting /etc/dc-dlvr
+export PATH=/usr/local/bin:/usr/bin:/bin
+exec 2>> ~/log/dc-dlvr.pre.err
+trap 'err=$?; set +e; test $err -eq 0 || rm -f $TMPMSG; exit $err' EXIT
+case $1,$CLIENT_ADDRESS in
+pispam,) exec public-inbox-learn spam < $TMPMSG ;;
+piham,) exec public-inbox-learn ham < $TMPMSG ;;
+esac
+exec public-inbox-mda < $TMPMSG
diff --git a/scripts/report-spam b/scripts/report-spam
index 75200431..0015ef0b 100755
--- a/scripts/report-spam
+++ b/scripts/report-spam
@@ -1,12 +1,11 @@
 #!/bin/sh
-# Copyright (C) 2008-2013, Eric Wong <e@80x24.org>
+# Copyright (C) 2008-2014, Eric Wong <e@80x24.org>
 # License: GPLv3 or later <http://www.gnu.org/licenses/gpl-3.0.txt>
 # Usage: report-spam /path/to/message/in/maildir
-# This is intended to be used with incron or similar systems.
+# This is intended for use with incron or similar systems.
 # my incrontab(5) looks like this:
-#  /path/to/.maildir/cur IN_MOVED_TO /path/to/report-spam $@/$#
-#  /path/to/.maildir/.INBOX.good/cur IN_MOVED_TO /path/to/report-spam $@/$#
-#  /path/to/.maildir/.INBOX.spam/cur IN_MOVED_TO /path/to/report-spam $@/$#
+#  /path/to/maildir/.INBOX.good/cur IN_MOVED_TO /path/to/report-spam $@/$#
+#  /path/to/maildir/.INBOX.spam/cur IN_MOVED_TO /path/to/report-spam $@/$#
 
 # gigantic emails tend not to be spam (but they suck anyways...)
 bytes=$(stat -c %s $1)
@@ -21,18 +20,26 @@ fi
 # incrond has no concurrency limits and will fork a new process on
 # every single event, which sucks with rename storms when a client
 # commits folder changes.  The sendmail executable exits quickly and
-# queues up the message for training.  This shoudl also ensure fairness
+# queues up the message for training.  This should also ensure fairness
 # to newly arriving mail.  Instead of installing/configuring
 # another queueing system, I reuse the queue in the MTA.
-# See scripts/dc-dlvr for corresponding trainspam/trainham handlers.
+# See scripts/dc-dlvr for corresponding trainspam/trainham handlers,
+# which are for my personal bayes training, and scripts/dc-dlvr.pre
+# for the pispam/piham handlers for training emails going to public-inbox
+
+DO_SENDMAIL='/usr/sbin/sendmail -oi'
+PI_USER=pi
+
 case $1 in
 *[/.]spam/cur/*) # non-new messages in spam get trained
-        exec /usr/sbin/sendmail -oem -oi $USER+trainspam < $1
+        $DO_SENDMAIL $PI_USER+pispam < $1
+        exec $DO_SENDMAIL $USER+trainspam < $1
         ;;
 *:2,*S*) # otherwise, seen messages only
         case $1 in
         *:2,*T*) exit 0 ;; # ignore trashed messages
         esac
-        exec /usr/sbin/sendmail -oem -oi $USER+trainham < $1
+        $DO_SENDMAIL $PI_USER+piham < $1
+        exec $DO_SENDMAIL $USER+trainham < $1
         ;;
 esac