~ubuntu-branches/ubuntu/maverick/lire/maverick

« back to all changes in this revision

Viewing changes to all/script/lr_rawmail2mail.in

  • Committer: Bazaar Package Importer
  • Author(s): Joost van Baal
  • Date: 2002-04-11 23:36:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020411233621-rj3dbr7z5wulfd7z
Tags: upstream-20020214
ImportĀ upstreamĀ versionĀ 20020214

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
 
 
3
# $Id: lr_rawmail2mail.in,v 1.15 2001/10/18 19:13:17 flacoste Exp $
 
4
 
 
5
#
 
6
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
 
7
 
8
#     This program is free software; you can redistribute it and/or modify
 
9
#     it under the terms of the GNU General Public License as published by
 
10
#     the Free Software Foundation; either version 2 of the License, or
 
11
#     (at your option) any later version.
 
12
 
13
#     This program is distributed in the hope that it will be useful,
 
14
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#     GNU General Public License for more details.
 
17
 
18
#     You should have received a copy of the GNU General Public License
 
19
#     along with this program (see COPYING); if not, check with
 
20
#     http://www.gnu.org/copyleft/gpl.html or write to the Free Software 
 
21
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 
22
#
 
23
 
 
24
PROGRAM=lr_rawmail2mail
 
25
identifier=${LR_ID:-UNSET}
 
26
tag="all all $identifier $PROGRAM"
 
27
 
 
28
if test $# -ne 2
 
29
then
 
30
    echo >&2 "$tag err please give 2 args, indicating dumpstem addressee"
 
31
    # when running directly from .qmail:
 
32
    # exit 100 : hard error
 
33
    # exit 111 : soft error
 
34
    # see qmail-command
 
35
    exit 1
 
36
fi  
 
37
 
 
38
# dereference sysconfdir's prefix dependency
 
39
prefix="@prefix@"
 
40
etcdir="@sysconfdir@/@PACKAGE@"
 
41
 
 
42
. $etcdir/defaults
 
43
# get sane path
 
44
. $etcdir/profile_lean
 
45
 
 
46
if test -z "$TMPDIR"
 
47
then
 
48
    echo >&2 "$tag err TMPDIR not set. did you source sysconfdir/defaults?"
 
49
    exit 1
 
50
fi
 
51
 
 
52
if test ! -d "$TMPDIR"
 
53
then
 
54
    echo >&2 "$tag notice dir $TMPDIR does not exist, creating it"
 
55
    if mkdir $TMPDIR
 
56
    then
 
57
        :
 
58
    else
 
59
        echo >&2 "$tag err cannot create $TMPDIR, exiting"
 
60
        exit 1
 
61
    fi
 
62
fi
 
63
 
 
64
DUMPSTEM="$1"
 
65
shift
 
66
TO="$1"
 
67
 
 
68
MAILFILE=$TMPDIR/$PROGRAM.$$.mail
 
69
cat > $MAILFILE
 
70
 
 
71
SHFILE=$TMPDIR/$PROGRAM.$$.sh
 
72
# this sets lr_getbody_BODYFILE, lr_getbody_SUBJECTFILE
 
73
# and lr_getbody_SUBMITTER
 
74
if lr_getbody -i $identifier -f $MAILFILE > $SHFILE
 
75
then
 
76
    . $SHFILE
 
77
    rm $SHFILE
 
78
else
 
79
    echo >&2 "$tag err lr_getbody -i $identifier -f $MAILFILE failed"
 
80
    echo >&2 "$tag notice keeping $MAILFILE and $SHFILE for debug"
 
81
    exit 1
 
82
fi 
 
83
 
 
84
REPORTFILE=$TMPDIR/$PROGRAM.$$.report
 
85
 
 
86
# SunOS's grep doesn't grok -q
 
87
if grep '^\[LogReport\]' < $lr_getbody_SUBJECTFILE > /dev/null
 
88
then
 
89
    echo >&2 "$tag info file $MAILFILE seems to be a message from LogReport"
 
90
    if grep ' notes on ' < $lr_getbody_SUBJECTFILE > /dev/null
 
91
    then
 
92
        # skip the explanation messages
 
93
        :
 
94
    else
 
95
        echo >&2 "$tag info file $lr_getbody_BODYFILE contains a raw xml report"
 
96
        # this does NOT exit when lr_xml2ascii exits unsuccessfully... XXX
 
97
        lr_deanonimize $DUMPSTEM < $lr_getbody_BODYFILE | lr_xml2ascii \
 
98
            > $REPORTFILE
 
99
 
 
100
        echo >&2 "$tag info gonna sent $REPORTFILE to $TO"
 
101
 
 
102
        # create new mailfile
 
103
 
 
104
        # get evil stuff out of lr_getbody_SUBJECTFILE
 
105
        sed 's/[^-_\.:a-zA-Z0-9 ]//g' $lr_getbody_SUBJECTFILE | head -1 \
 
106
            > $TMPDIR/$PROGRAM.$$.tmp
 
107
        mv $TMPDIR/$PROGRAM.$$.tmp $lr_getbody_SUBJECTFILE
 
108
        SUBJECT=`cat $lr_getbody_SUBJECTFILE`
 
109
 
 
110
        if { cat <<EOT
 
111
To: $TO
 
112
Subject: [LogReport] deanonimized report (was: $SUBJECT)
 
113
 
 
114
EOT
 
115
} | cat - $REPORTFILE > $MAILFILE
 
116
        then
 
117
            :
 
118
        else
 
119
            echo >&2 "$tag err writing $MAILFILE failed"
 
120
            exit 1
 
121
        fi
 
122
 
 
123
        if @PATHTOSENDMAIL@ -t < $MAILFILE
 
124
        then
 
125
            :
 
126
        else
 
127
            echo >&2 "$tag err sendmail failed"
 
128
            exit 1
 
129
        fi
 
130
 
 
131
        if test -n "$KEEP"
 
132
        then
 
133
            echo >&2 "$tag notice keeping $REPORTFILE on your request. remove manually."
 
134
        else
 
135
            rm $REPORTFILE
 
136
        fi
 
137
    fi
 
138
fi
 
139
 
 
140
if test -n "$KEEP"
 
141
then
 
142
    echo >&2 "$tag notice keeping $MAILFILE on your request. remove manually."
 
143
    echo >&2 "$tag notice keeping $lr_getbody_SUBJECTFILE on your request. remove manually."
 
144
    echo >&2 "$tag notice keeping $lr_getbody_BODYFILE on your request. remove manually."
 
145
else
 
146
    rm -f $MAILFILE
 
147
    rm -f $lr_getbody_SUBJECTFILE
 
148
    rm -f $lr_getbody_BODYFILE
 
149
fi
 
150