#!/usr/local/bin/perl -T
#
# This software has been created by Genome Research Limited (GRL).
# GRL hereby grants permission to use, copy, modify and distribute
# this software and its documentation for non-commercial purposes
# without fee at the user's own risk on the basis set out below.
# GRL neither undertakes nor accepts any duty whether contractual or
# otherwise in connection with the software, its use or the use of
# any derivative, and makes no representations or warranties, express
# or implied, concerning the software, its suitability, fitness for
# a particular purpose or non-infringement.
# In no event shall the authors of the software or GRL be responsible
# or liable for any loss or damage whatsoever arising in any way
# directly or indirectly out of the use of this software or its
# derivatives, even if advised of the possibility of such damage.
# Our software can be freely distributed under the conditions set out
# above, and must contain this copyright notice.
#
# Author: Richard Bemrose and Jonathan Nicholson
# Email : ssg@sanger.ac.uk
# Date : July, 2000
#
# Installation:
# Simple place the following line in /etc/aliases on the email server
# faq-archive: "|/mail/autofaqomatic"
# changing the email address and/or the location of autofaqomatic
#
use Safe;
use strict;
use FAQ::OMatic::API;
use Mail::Header;
use Mail::Internet;
use Mail::Mailer;
# email address of Faq-O-Matic administrator
my $faqadmin = 'Faq-O-Matic Admin < faqadmin@some.domain.com >';
# email address of root administrator
my $rootadmin = 'root@some.domain.com';
eval {
# Configure for local specifications
my $url = 'http://some.domain.com/cgi-bin/fom';
# A valid Faq-O-Matic user/password
my $id = 'email@some.domain.com';
my $pass = 'password';
# set up 'mail' object from stdin
my $mail = new Mail::Internet( \*STDIN) or die "Failed to create Mail object $!";
# place the header in object 'head'
my $head = $mail->head() or die "Failed to retreive mail header $!\n";
my $user;
# optional: allow email submission from only user who are part
# of a certain UNIX group on the email server
# get fields of interest
my $group = 'system';
my $root_users = (getgrnam("$group"))[-1];
my $from = $head->get('from') or die "Failed to get from line $!\n";
# NOTE:
# include no white space before or after less than or greater than
# Faq-O-Matic thinks it is a hyperlink
if($from =~ /([^< \s]+)@([^ >\s]+)/) {
$from = "$1\@$2";
$user = $1;
die "User ($user) not in $group\n" unless grep $user, split(/,/, $root_users);
}
else {
die "Couldn't parse from line $from\n";
}
my $subject = $head->get('subject') or die "Failed to get subject line $!\n";
my $body = $mail->body() or die "Failed to get body text $!\n";
push my @bodytext, sprintf("Author: %s mailto:%s\n", (getpwnam($user))[6], $from);
foreach ( @{$body}) {
last if /^!--/;
push @bodytext, $_;
}
if($subject =~ /Re:(.*)/i) {
my $msg = new Mail::Mailer qw(sendmail) or die "Failed to create Mail::Mailer object for reply handling $!\n";
$msg->open({ Subject => $1,
To => $from,
From => $faqadmin,
}) or die "Failed to open mail handler for reply handling $!\n";
print $msg <<End_of_help;
Hi, you appear to have replied to an auto-faq-o-matic submission
If you want to append a response to an item in the Faq-O-Matic please use
the web interface at $url
End_of_help
$msg->close;
exit;
}
# create new API object
my $fom_api = new FAQ::OMatic::API() or die "Failed to create FaqOMatic object $!\n";
$fom_api->setURL($url) or die "Set URL call failed $!\n";
$fom_api->setAuth($id, $pass) or die "Set Auth call failed $!\n";
$fom_api->newAnswer(1, $subject, join ("\n", @bodytext)) or die "new Answer call failed $!\n";
};
if($@) {
my $error = $@;
my $msg = new Mail::Mailer qw(sendmail) or die "Failed to create Mail::Mailer object for reply handling $!\n";
$msg->open({ Subject => 'ERROR FROM MAIL PARSER!',
To => $faqadmin,
From => $rootadmin,
}) or die "Failed to open Mail::Mailer $!\n";
print $msg <<End_Of_Sendmail;
An error has been generated while trying to parse an auto-faq-o-matic update
message. The error was:-
$error
End_Of_Sendmail
close SENDMAIL
} |