File: mailscanner.cron.daily

package info (click to toggle)
mailscanner 4.79.11-2.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,820 kB
  • ctags: 1,309
  • sloc: perl: 25,655; sh: 2,666; xml: 624; makefile: 242
file content (75 lines) | stat: -rw-r--r-- 2,295 bytes parent folder | download
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
71
72
73
74
75
#! /bin/bash
#
# cron script to clean up mailscanner files
#
# $Id: local-clock,v 1.5 2002/03/13 02:18:38 bcwhite Exp $
#
# Written by Brian White <bcwhite@precidia.com>
#

# how many days to keep quarantined messages
q_days=3

# test existens of directories #435998
if [[ ! -d /var/spool/MailScanner ]]; then
		exit 0
fi

# load user-defaults
if [[ -f /etc/default/mailscanner ]]; then
    . /etc/default/mailscanner
fi

# go to mailscanner spool directory
cd /var/spool/MailScanner

# remove old files and directories
find quarantine -type f -ctime +$q_days    -exec rm -f {} \; >/dev/null 2>&1
find quarantine -type d -depth -mindepth 1 -exec rmdir {} \; >/dev/null 2>&1

# exit if exim4 isn't installed #406643
if [ ! -x /usr/sbin/exim ]; then
		exit 0
fi

# bug #401329 on pre 4.55.10-4 installations with exim
# cron.daily/exim4-base cleans up /var/spool/exim4_incoming
# so we have to clean up /var/spool/exim
# on post 4.55.10-4 the following should do nothing

# what cron.daily/exim4-base should do
SPOOLDIRDEFAULT="/var/spool/exim4"
# what cron.daily/exim4-base does
SPOOLDIR="$(/usr/sbin/exim4 -bP spool_directory | sed 's/.*=[[:space:]]\(.*\)/\1/')"

# if exim-base doesn't do what it should
if [ "$SPOOLDIR" != "$SPOOLDIRDEFAULT" ]; then

		# and there is the default spool directory
		if [ -d "$SPOOLDIRDEFAULT" ]; then

        # do what exim-base should have done
        # run tidydb as Debian-exim:Debian-exim.
				if [ -x /usr/sbin/exim_tidydb ]; then
						cd $SPOOLDIRDEFAULT/db || exit 1
						if ! find $SPOOLDIRDEFAULT/db -maxdepth 1 -name '*.lockfile' -or -type f \
								-printf '%f\0' | \
								xargs -0r -n 1 \
								start-stop-daemon --start --exec /usr/sbin/exim_tidydb \
								--chuid Debian-exim:Debian-exim -- $SPOOLDIRDEFAULT > /dev/null; then
                # if we reach this, invoking exim_tidydb from start-stop-daemon has
                # failed, most probably because of libpam-tmpdir being in use
                # (see #373786 and #376165)
								find $SPOOLDIRDEFAULT/db -maxdepth 1 -name '*.lockfile' -or -type f \
										-printf '%f\0' | \
										su - --shell /bin/bash \
										--command "xargs -0r -n 1 /usr/sbin/exim_tidydb $SPOOLDIRDEFAULT > /dev/null" \
										Debian-exim
						fi
				fi

		fi
fi

# exit cleanly
exit 0