]> git.ipfire.org Git - people/ms/dma.git/blob - dbounce-simple-safecat
Add a Debian news file mentioning dma-migrate and the MX lookups.
[people/ms/dma.git] / dbounce-simple-safecat
1 #!/bin/sh
2 #
3 # Copyright (c) 2009, 2010 Peter Pentchev
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 # SUCH DAMAGE.
26
27 set -e
28
29 usage()
30 {
31 cat <<EOUSAGE
32 Usage: dbounce-simple-safecat [-a addr] [-d dir] [-i queueid] [-t type] -f msg
33 -a the recipient of the bounced message
34 -d the bounce directory, default $DEFBOUNCEDIR
35 -f the full path to the bounced message to process
36 -i the ID of the bounce message in the local MTA's queue
37 -t the MTA type, currently ignored
38 EOUSAGE
39 }
40
41 DEFBOUNCEDIR='/var/spool/mail/dma-bounces'
42 BOUNCEDIR="$DEFBOUNCEDIR"
43
44 while getopts 'a:d:f:i:t:' o; do
45 case "$o" in
46 a)
47 ADDR="$OPTARG"
48 ;;
49 d)
50 BOUNCEDIR="$OPTARG"
51 ;;
52 f)
53 FILENAME="$OPTARG"
54 ;;
55 i)
56 QUEUEID="$OPTARG"
57 ;;
58 t)
59 MTA="$OPTARG"
60 ;;
61 *)
62 usage 1>&2
63 exit 1
64 esac
65 done
66
67 if [ ! -r "$FILENAME" ]; then
68 echo "Nonexistent or unreadable bounce file $FILENAME" 1>&2
69 exit 1
70 fi
71
72 bname=`basename "$FILENAME"`
73 dname=`dirname "$FILENAME"`
74 if expr "$bname" : 'Q' > /dev/null; then
75 qname="M${bname#Q}"
76 qfile="$dname/$qname"
77 if [ ! -r "$qfile" ]; then
78 echo "Nonexistent or unreadable bounce queue file $qfile" 1>&2
79 exit 1
80 fi
81 else
82 qfile=''
83 fi
84
85 F=`cat "$FILENAME" ${qfile:+"$qfile"} | safecat "$BOUNCEDIR/tmp" "$BOUNCEDIR/new"`
86 OUTFILE="$BOUNCEDIR/new/$F"
87 if [ ! -f "$OUTFILE" ]; then
88 echo "safecat indicated success, but '$OUTFILE' does not exist" 1>&2
89 exit 1
90 fi
91 echo "Successfully written the message to $OUTFILE"