#! /bin/sh -e PROGRAM=lr_rawmail2mail tag="all all ${LR_ID:-UNSET} $PROGRAM" # when running directly from .qmail: # exit 100 : hard error # exit 111 : soft error # see qmail-command # dereference sysconfdir's prefix dependency prefix="@prefix@" etcdir="@sysconfdir@/@PACKAGE@" . $etcdir/profile_lean echo >&2 "$tag info started with $*" USAGE="Usage $PROGRAM [-i] [-o ] anondb sendto+" # get options (x) output_flag="" image_flag="" subject="" while getopts :o:ivh\? o; do case $o in o) output_flag="-o $OPTARG" ;; i) image_flag="-i" ;; h | "?") echo >&2 "$tag notice $USAGE" exit 0 ;; v) echo >&2 "$tag notice $PROGRAM" '$Id: lr_rawmail2mail.in,v 1.25 2006/07/23 13:16:33 vanbaal Exp $,' "shipped with Lire @VERSION@" exit 0 ;; *) echo >&2 "$tag err $USAGE" exit 1 ;; esac done # yes, the '|| true' is needed. solaris' /bin/sh feels it should bawl out when # encountering an 'expr 1 - 1', while running -e shift `expr $OPTIND - 1 || true` if test $# -lt 2 then echo >&2 "$tag err $USAGE" exit 1 fi if test -z "$TMPDIR" then echo >&2 "$tag err TMPDIR not set. did you source sysconfdir/defaults?" exit 1 fi if test ! -d "$TMPDIR" then echo >&2 "$tag notice dir $TMPDIR does not exist, creating it" if mkdir $TMPDIR then : else echo >&2 "$tag err cannot create $TMPDIR, exiting" exit 1 fi fi if @PERL@ -MMIME::Tools -e 'exit 0' 2>/dev/null then : else cat >&2 < $MAILFILE # this sets lr_getbody_FILE, lr_getbody_SUBJECT # and lr_getbody_SUBMITTER eval `lr_getbody -c text/xml $MAILFILE || true` if test -z "lr_getbody_OK" then echo >&2 "$tag err lr_getbody failed. Keeping $MAILFILE for debugging" exit 1 else echo >&2 "$tag info lr_getbody gave FILE '$lr_getbody_FILE'" echo >&2 "$tag info lr_getbody gave SUBJECT '$lr_getbody_SUBJECT'" echo >&2 "$tag info lr_getbody gave SUBMITTER '$lr_getbody_SUBMITTER'" fi if test -n "$lr_getbody_FILE" then # We found an text/xml attachment echo >&2 "$tag info file $MAILFILE is a message containing a XML report" REPORTFILE=$TMPDIR/$PROGRAM.$$.xml # Deanonymize the report if lr_deanonymize $DUMPSTEM < $lr_getbody_FILE > $REPORTFILE then : else echo >&2 "$tag err lr_deanonymize failed. Keeping $lr_getbody_FILE for debugging" exit 1 fi echo >&2 "$tag info Formatting and sending report to $@" subject="[LogReport] deanonymized report (was: $lr_getbody_SUBJECT)" if lr_xml2mail -q -s "$subject" $image_flag $output_flag $REPORTFILE "$@" then : else echo >&2 "$tag err lr_xml2mail failed. Keeping $lr_getbody_FILE for debugging" exit 1 fi if test -n "$LR_KEEP" then echo >&2 "$tag notice keeping $lr_getbody_FILE on your request. remove manually." echo >&2 "$tag notice keeping $REPORTFILE on your request. remove manually." else rm $lr_getbody_FILE $REPORTFILE fi fi if test -n "$LR_KEEP" then echo >&2 "$tag notice keeping $MAILFILE on your request. remove manually." else rm $MAILFILE fi exit 0 POD=<<'EOPOD' =pod =head1 NAME B - deanonymizes and formats a report from an email message =head1 SYNOPSIS B B<[I]> I I... B B<-h> B B<-v> =head1 OPTIONS =over 4 =item B<-h> Prints usage information and exits. =item B<-i> Generate charts for all reports that support it. Normally, charts will be generated only if the variable I is set to 1. =item B<-o> I One of B, B, B, B, B, B, B, B and B. Per default, simple txt output is generated. =item B<-v> Prints Lire's version and exits. =back =head1 DESCRIPTION B can be used to automatically process reply from an Online Responder which contains a XML report. It will extract the report (which should have a content type of text/xml) and deanonymized it. It will then use the lr_xml2mail(1) command to formats and send the report to the recipients specified on the command line. The I argument is used by lr_deanonymize(1) to find the database that was used in the anonymization process. Environment variable TMPDIR, as set in sysconfdir/defaults, is used to store tmpfiles; if LR_KEEP is set to a nonempty string, temporary files are kept. =head1 VERSION $Id: lr_rawmail2mail.in,v 1.25 2006/07/23 13:16:33 vanbaal Exp $ =head1 COPYRIGHT Copyright (C) 2000, 2001, 2002 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. =head1 AUTHOR Joost van Baal =cut EOPOD