~ubuntu-branches/ubuntu/dapper/dbacl/dapper

« back to all changes in this revision

Viewing changes to ts/spamassassin

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams
  • Date: 2005-05-07 12:59:53 UTC
  • Revision ID: james.westby@ubuntu.com-20050507125953-xzy2bwkb2qamglwm
Tags: upstream-1.9
ImportĀ upstreamĀ versionĀ 1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
3
# Copyright (C) 2002 Laird Breyer
 
4
#  
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 
19
# Author:   Laird Breyer <laird@lbreyer.com>
 
20
#
 
21
# IMPLEMENTATION NOTES
 
22
#
 
23
# This script follows the mailcross testsuite interface
 
24
# requirements. Type man mailcross for details.
 
25
#
 
26
# The script accepts one of more commands on the command line,
 
27
# and may read STDIN and write STDOUT as follows:
 
28
#
 
29
# If $1 == "filter":
 
30
# In this case, a single email is expected on STDIN,
 
31
# and a list of category filenames is expected in $2, $3, etc.
 
32
# The script writes the category name corresponding to the 
 
33
# input email on STDOUT.
 
34
#
 
35
# If $1 == "learn":
 
36
# In this case, a standard mbox stream is expected on STDIN,
 
37
# while a suitable category file name is expected in $2. No output
 
38
# is written to STDOUT.
 
39
#
 
40
# If $1 == "clean":
 
41
# In this case, a directory is expected in $2, which is examined
 
42
# for old database information. If any old databases are found, they
 
43
# are purged or reset. No output is written to STDOUT.
 
44
#
 
45
# If $1 == "describe":
 
46
# In this case, STDIN and the command line are ignored. A single
 
47
# line is written on STDOUT, describing the filter functionality.
 
48
#
 
49
# If $1 == "bootstrap":
 
50
# In this case, the current script is copied to the directory $2,
 
51
# provided the classifier we're wrapping exists on the system.
 
52
#
 
53
 
 
54
LEARN="sa-learn"
 
55
SA="spamassassin"
 
56
[ -z "$TEMPDIR" ] && TEMPDIR=/tmp
 
57
 
 
58
case "$1" in
 
59
    filter)
 
60
        shift
 
61
        CATEGORY=`basename $1`
 
62
        DBPATH=`dirname $1`
 
63
        $SA -L -e --prefspath="${DBPATH}/sa-bayes.config" > /dev/null
 
64
        if [ "$?" = "0" ]; then
 
65
            echo "notspam"
 
66
        else
 
67
            echo "spam"
 
68
        fi
 
69
        ;;
 
70
    learn)
 
71
        shift
 
72
        CATEGORY=`basename $1`
 
73
        DBPATH=`dirname $1`
 
74
        if [ ! -e "${DBPATH}/sa-bayes.config" ]; then
 
75
            # this config should probably be tweaked, any takers?
 
76
            cat > "${DBPATH}/sa-bayes.config" <<EOF
 
77
bayes_path ${DBPATH}/sa-bayes
 
78
EOF
 
79
        fi
 
80
        cat > "${TEMPDIR}/mbox.tmp"
 
81
        if [ "$CATEGORY" = "spam" ]; then
 
82
            $LEARN --spam --mbox --prefspath="${DBPATH}/sa-bayes.config" "${TEMPDIR}/mbox.tmp"
 
83
        else
 
84
            $LEARN --ham --mbox --prefspath="${DBPATH}/sa-bayes.config" "${TEMPDIR}/mbox.tmp"
 
85
        fi
 
86
        rm -f "${TEMPDIR}/mbox.tmp"
 
87
        ;;
 
88
    clean)
 
89
        shift
 
90
        find "$1" -name "sa-bayes*" -exec rm {} \;
 
91
        find "$1" -name "*.tmp" -exec rm {} \;
 
92
        ;;
 
93
    describe)
 
94
        VER="(unavailable?)"
 
95
        if [ -n "`which $SA`" ] ; then
 
96
            VER=`$SA -V | sed 's/^.*version //'`
 
97
        fi
 
98
        echo "SpamAssassin $VER (Bayes module) with default settings"
 
99
        ;;
 
100
    bootstrap)
 
101
        if [ -d "$2" ] ; then
 
102
            if [ -n "`which $SA`" -a -n "`which $LEARN`" ] ; then
 
103
                echo "selecting $0"
 
104
                cp "$0" "$2"
 
105
                echo -e "\tspamassassin is hard-coded for use only with exactly"
 
106
                echo -e "\ttwo categories named 'spam' and 'notspam'."
 
107
            else
 
108
                echo "spamassassin appears to be missing"
 
109
            fi
 
110
        else
 
111
            echo "bad target directory $2"
 
112
        fi
 
113
        ;;
 
114
    toe)
 
115
        ME="$0"
 
116
        shift
 
117
        TRUECAT="$1"
 
118
        DBPATH=`dirname $1`
 
119
        shift
 
120
        cat > "$TEMPDIR/mailtoe.tmp"
 
121
        VERDICT=`cat $TEMPDIR/mailtoe.tmp | $ME filter "$@"`
 
122
        if [ "x$VERDICT" != "x`basename $TRUECAT`" ] ; then
 
123
            if [ "`basename $TRUECAT`" = "spam" ]; then
 
124
                cat "$TEMPDIR/mailtoe.tmp" | $LEARN --spam --prefspath="${DBPATH}/sa-bayes.config" > /dev/null
 
125
            else
 
126
                cat "$TEMPDIR/mailtoe.tmp" | $LEARN --ham --prefspath="${DBPATH}/sa-bayes.config" > /dev/null
 
127
            fi
 
128
        fi
 
129
        echo -ne "$VERDICT"
 
130
        ;;
 
131
 
 
132
    foot)
 
133
        ME="$0"
 
134
        shift
 
135
        TRUECAT="$1"
 
136
        DBPATH=`dirname $1`
 
137
        shift
 
138
        cat > "$TEMPDIR/mailfoot.tmp"
 
139
        VERDICT=`cat "$TEMPDIR/mailfoot.tmp" | $ME filter "$@"`
 
140
        if [ "`basename $TRUECAT`" = "spam" ]; then
 
141
            cat "$TEMPDIR/mailtoe.tmp" | $LEARN --spam --prefspath="${DBPATH}/sa-bayes.config" > /dev/null
 
142
        else
 
143
            cat "$TEMPDIR/mailtoe.tmp" | $LEARN --ham --prefspath="${DBPATH}/sa-bayes.config" > /dev/null
 
144
        fi
 
145
        echo -ne "$VERDICT"
 
146
        ;;
 
147
 
 
148
esac