-
Notifications
You must be signed in to change notification settings - Fork 0
/
asf_cleanup
executable file
·70 lines (60 loc) · 1.72 KB
/
asf_cleanup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#! /bin/sh
# asf_cleanup (Bourne shell script) -- Advanced Spam Filtering's post-learning cleanup script
# Moves a given user's learned spam to their "spam" folder
#
# Usage: asf_cleanup [-d] <username>
#
# Note: this script must be run as the user given as <username>
# The cron job that calls this script should redirect stdout to a WRITABLE log file
#
# Version: 1.1
# Requires: GNU mv, GNU xargs
self=${0##*/}
syslog_facility=mail
syslog_tag="$self[$$]"
# *** MAINLINE ***
# check for -d (the debug switch)
if [ x"$1" = x-d ] ; then
shift
log()
{
log_level=$1
shift
echo "$self($log_level): $*"
}
else
log()
{
log_level=$1
shift
logger -t $syslog_tag -p $syslog_facility.$log_level "$*"
}
fi
if [ -n "$1" ] ; then
username=$1
else
echo "$self: no username supplied" >&2
exit 1
fi
user_homedir=$(getent passwd $username | cut -d: -f6)
if [ ! -d $user_homedir ] ; then
echo "$self: invalid user '$username'" >&2
exit 2
fi
if [ ! -d $user_homedir/Maildir/.learn-spam/cur ] ; then
echo "$self: ~$username/Maildir/.learn-spam doesn't exist" >&2
exit 3
fi
if [ ! -f $user_homedir/Maildir/.learn-spam/asf_learned ] ; then
echo "$self: ~$username/Maildir/.learn-spam/asf_learned doesn't exist" >&2
exit 4
fi
echo "$(date --rfc-3339=seconds) $username (cleanup)"
# find all files in "learn-spam" that are older than the tag file and move it
# to "spam"
# (Uses GNU mv's --target-directory option to allow xargs to work in multi-file
# mode.)
find $user_homedir/Maildir/.learn-spam/cur -type f ! -newer $user_homedir/Maildir/.learn-spam/asf_learned | \
xargs --no-run-if-empty mv -v --target-directory=$user_homedir/Maildir/.spam/cur
## xargs -I '{}' mv '{}' $user_homedir/Maildir/.spam/cur
echo