aboutsummaryrefslogtreecommitdiff
path: root/mail/squirrelmail/files/111.clean-squirrelmail
blob: 9e76568179f39b5cb1fe3a465b1c86db48a5ef6a (plain) (blame)
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
#!/bin/sh
#
# This script copied from /etc/periodic/daily/110.clean-tmps,v 1.6.2.4 2002/10/13 19:59:01
#
# Perform attachment directory cleaning so that long-lived systems
# don't end up with excessively old files there.
#

# Define these variables in either /etc/periodic.conf or
# /etc/periodic.conf.local to override the default values.
#
# 111.clean-squirrelmail
clean_squirrelmail_enable="NO"					# Delete squirrelmail attachments
clean_squirrelmail_dirs="/var/spool/squirrelmail/attach"	# Delete under here
clean_squirrelmail_days="10"					# If not accessed for
clean_squirrelmail_ignore="quota.user quota.group"		# Don't delete these
clean_squirrelmail_verbose="YES"				# Mention files deleted

# If there is a global system configuration file, suck it in.
#
if [ -r /etc/defaults/periodic.conf ]
then
    . /etc/defaults/periodic.conf
    source_periodic_confs
fi

case "$clean_squirrelmail_enable" in
    [Yy][Ee][Ss])
	if [ -z "$clean_squirrelmail_days" ]
	then
	    echo '$clean_squirrelmail_enable is set but' \
		'$clean_squirrelmail_days is not'
	    rc=2
	else
	    echo ""
	    echo "Removing old SquirrelMail Attachment files:"

	    set -f noglob
	    args="-atime +$clean_squirrelmail_days -mtime +$clean_squirrelmail_days"
	    args="${args} -ctime +$clean_squirrelmail_days"
	    [ -n "$clean_squirrelmail_ignore" ] &&
		args="$args "`echo " ${clean_squirrelmail_ignore% }" |
		    sed 's/[ 	][ 	]*/ ! -name /g'`
	    case "$clean_squirrelmail_verbose" in
		[Yy][Ee][Ss])
		    print=-print;;
		*)
		    print=;;
	    esac

	    rc=$(for dir in $clean_squirrelmail_dirs
		do
		    [ ."${dir#/}" != ."$dir" -a -d $dir ] && cd $dir && {
			find -d . -type f $args -delete $print
			find -d . ! -name . -type d -empty -mtime \
			    +$clean_squirrelmail_days -delete $print
		    } | sed "s,^\\.,  $dir,"
		done | tee /dev/stderr | wc -l)
	    [ -z "$print" ] && rc=0
	    [ $rc -gt 1 ] && rc=1
	    set -f glob
	fi;;

    *)  rc=0;;
esac

exit $rc