]> git.ipfire.org Git - people/ms/dma.git/blame - dbounce-simple-safecat
Add the "opportunistic TLS" mode from trunk rev. 5085.
[people/ms/dma.git] / dbounce-simple-safecat
CommitLineData
3a343a9b
PP
1#!/bin/sh
2#
8fc96c1b 3# Copyright (c) 2009, 2010 Peter Pentchev
3a343a9b
PP
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
27set -e
28
29usage()
30{
31 cat <<EOUSAGE
32Usage: 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
38EOUSAGE
39}
40
41DEFBOUNCEDIR='/var/spool/mail/dma-bounces'
42BOUNCEDIR="$DEFBOUNCEDIR"
43
44while 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
65done
66
67if [ ! -r "$FILENAME" ]; then
68 echo "Nonexistent or unreadable bounce file $FILENAME" 1>&2
69 exit 1
70fi
71
8fc96c1b
PP
72bname=`basename "$FILENAME"`
73dname=`dirname "$FILENAME"`
3606980c
PP
74if expr "$bname" : 'Q' > /dev/null; then
75 qname="M${bname#Q}"
8fc96c1b
PP
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
81else
82 qfile=''
83fi
84
3606980c 85F=`cat "$FILENAME" ${qfile:+"$qfile"} | safecat "$BOUNCEDIR/tmp" "$BOUNCEDIR/new"`
3a343a9b
PP
86OUTFILE="$BOUNCEDIR/new/$F"
87if [ ! -f "$OUTFILE" ]; then
88 echo "safecat indicated success, but '$OUTFILE' does not exist" 1>&2
89 exit 1
90fi
91echo "Successfully written the message to $OUTFILE"