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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#! /bin/sh -e
#
# $Id: lr_processmail,v 1.26 2002/01/11 13:31:40 vanbaal Exp $
#
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see COPYING); if not, check with
# http://www.gnu.org/copyleft/gpl.html or write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#
#
# This extracts the body from email
#
PROGRAM=lr_processmail
id=${LR_ID:-UNSET}
tag="all all $id $PROGRAM"
if test $# -lt 2
then
echo >&2 "$tag err please give at least 2 args, indicating superservice, service"
exit 1
fi
echo >&2 "$tag info started with $@"
SUPERSERVICE=$1; shift
SERVICE=$1; shift
flags="$@"
tag="$SUPERSERVICE $SERVICE $id $PROGRAM"
if test -n "$TMPDIR"
then
newfile=$TMPDIR/$PROGRAM.$SERVICE.$id.$$.mail
else
echo >&2 "$tag err aborted, TMPDIR not set. did you source etc/defaults?"
exit 1
fi
if touch $newfile 2>/dev/null
then
:
else
echo >&2 "$tag err aborted, cannot create $newfile"
exit 1
fi
cat > $newfile
echo >&2 "$tag info processing $newfile"
echo >&2 "$tag info running lr_getbody"
# this sets lr_getbody_BODYFILE, lr_getbody_SUBJECTFILE
# and lr_getbody_SUBMITTER
eval `lr_getbody -i $id -f $newfile`
echo >&2 "$tag info lr_getbody gave BODYFILE '$lr_getbody_BODYFILE'"
echo >&2 "$tag info lr_getbody gave SUBJECTFILE '$lr_getbody_SUBJECTFILE'"
echo >&2 "$tag info lr_getbody gave SUBMITTER '$lr_getbody_SUBMITTER'"
bodyfile="$lr_getbody_BODYFILE"
subjectfile="$lr_getbody_SUBJECTFILE"
submitter="$lr_getbody_SUBMITTER"
if test -z "$bodyfile"
then
echo >&2 "$tag err extracting body failed"
exit 1
fi
echo >&2 "$tag info inflating body"
inflatedbody=`lr_inflate $bodyfile`
if test -z "$inflatedbody"
then
echo >&2 "$tag err inflating body failed"
exit 1
fi
# get evil stuff out of subjectfile
sed 's/[^-_.:a-zA-Z0-9 ]/_/g' $subjectfile > $TMPDIR/$PROGRAM.$$.tmp
head -1 $TMPDIR/$PROGRAM.$$.tmp > $subjectfile
rm $TMPDIR/$PROGRAM.$$.tmp
if grep ^anon $subjectfile >/dev/null
then
anon='-a'
subject=`cut -d ' ' -f2- $subjectfile`
else
anon=''
subject=`cat $subjectfile`
fi
if test -n "$subject"
then
# submitter - email address of sender of logfile
# extid - a string the submitter has given us to track his
# submission, e.g. hostname
# flags - e.g. common
LR_EXTID=`echo $subject | sed 's/ /_/g; s/\.\./__/g'`
else
LR_EXTID=UNSET
fi
export LR_EXTID
if test -n "$ARCHIVE"
then
if lr_db_store $id extid "$LR_EXTID"
then
:
else
echo >&2 "$tag crit cannot lr_db_store $id extid $LR_EXTID, exiting"
exit 1
fi
fi
if test -n "$subject"
then
lr_log2mail $anon -s "$subject" $SUPERSERVICE $SERVICE "$submitter" \
$flags < $inflatedbody
else
lr_log2mail $anon $SUPERSERVICE $SERVICE "$submitter" \
$flags < $inflatedbody
fi
if test -n "$ARCHIVE"
then
# go store $newfile in the archive
# first find out how the archived file should get named
TMPFILE=$TMPDIR/$PROGRAM.$SERVICE.$id.$$.time_span
if lr_db_fetch $id time_span > $TMPFILE
then
echo >&2 "$tag info lr_db_fetch $LR_ID timespan succeeded"
LR_TIME=`cat $TMPFILE`
rm $TMPFILE
else
echo >&2 "$tag crit lr_db_fetch $LR_ID timespan failed, exiting" echo >&2 "$tag notice keeping $TMPFILE for debugging"
exit 1
fi
ARCHIVEDIR=$LR_ARCHIVEDIR/email/raw/$SUPERSERVICE/$SERVICE/$LR_EXTID
# might better be some other filename? TODO
ARCHIVEFILE=$ARCHIVEDIR/$LR_TIME
echo >&2 "$tag notice storing $newfile in $ARCHIVEFILE"
test -d $ARCHIVEDIR || mkdir -p $ARCHIVEDIR
mv $newfile $ARCHIVEFILE
elif test -n "$KEEP"
then
echo >&2 "$tag notice keeping $newfile on your request. remove manually."
else
rm $newfile
fi
echo >&2 "$tag info stopped"
|