>Вот имеется такой скриптик, но он , зараза, вместо одного письма отсылает
>мне 26, ни как не могу победить.
Херня все.
Вот нашел в сети (для автоответа, но кому - надо подправит)
соответствено в /etc/aliases
user: user, |/path_to_script/script.pl
____________________________________________________________
#!/usr/bin/perl
#
# echo.pl - "Echoput" auto response server
#
# version: 0.9 alpha pl3
#
# Usage:
# run the command echo.pl -h to get a "manpage" including installation
# and configuration steps
#
# Author:
# Paul A. Klarenberg (klarenberg@netconsult.ch)
#
# Purpose:
# Sends auto-reply to appropriate person: first to Reply-To field
# if it exists, else to "From:" field, or lastly to 1st arg. Will not
# reply to addresses which may cause loops (echo, etc).
#
# Copyright:
# ?!? You're welcome to use this echo-server instead of something worse.
#
# Acknowledgements:
# Allan Cargille - inspiration
# Felix Kugler - testing, patches, additions and PP configuration part
### User Configuration Section begin
# use UNIX sendmail or PP's sendmail substitute!
$MAILER = '/usr/lib/sendmail';
# RFC-1327 converter program - set this variable to "" if you don.t use PP !
#$RFC1327CONV = "/usr/local/nexor/xtpp/cmds/tools/ckadr";
$RFC1327CONV="";
# the Server's home directory
$ECHOHOME = '/var/tmp';
# the Server's logfile
$ECHOLOG = '/var/tmp/log';
# directory for temporary storage
$ECHOTMP = '/tmp';
# file of suspicious user names to which no response should be sent
$SUSPICIOUS = "$ECHOHOME/suspicious.echo";
# Your local mail domain
$ECHODOMAIN = 'mts.ru';
# the Server's mail address
$ECHOADDR = "hern@$ECHODOMAIN";
# the Server's administrator address
$ECHOADMINLOCAL = 'hren';
$ECHOADMIN = "$ECHOADMINLOCAL@$ECHODOMAIN";
# you might want to edit the leading text that is included in the response.
# Look for the comment "# include some explanatory text in the response",
# and edit the text between the lines "print RESP <<EoT;" and "EoT"
### User Configuration Section end
### Main Program begin
# read options from the commandline & configuration files
require('getopts.pl') || &HandleError("could not open 'getopts.pl': $!\n");
&Getopts('th') || &Usage;
# display usage when option "-h" given
$opt_h && &Usage;
# read suspicious user names from the file specified by $SUSPICIOUS, if any
# such file is defined
if ($SUSPICIOUS) {
if (-f $SUSPICIOUS) {
open(SUSP, "<$SUSPICIOUS") || &HandleError("could not open '$SUSPICIOUS': $!\n");
while (<SUSP>) {
tr/A-Z/a-z/;
$suspicious{$_} = 1;
}
} else {
# send a warning
&HandleError("configured file of suspicious user names, '$SUSPICIOUS' not found\n");
}
}
# save the request in a temporary file
$request = "$ECHOTMP/echo.request.$$";
open(REQ, ">$request") || &HandleError("could not open '$request': $!\n");
while (<>) {
# copy all lines to a temporary file
print REQ;
}
close(REQ);
# scan the header of the message
open(REQ, "$request") || &HandleError("could not open '$request': $!\n");
while(<REQ>) {
chop;
# at first empty line (end of header): exit loop
/^$/ && last;
# grab Reply-To, Sender, From, Authorizing-Users and Message-Id fields.
/^reply-to: *([^,]*)/i && ($ReplyTo = $1, next);
/^sender: *(.*)/i && ($Sender = $1, next);
/^from: *(.*)/i && ($From = $1, next);
/^message-id: *(.*)/i && ($MessageId = $1, next);
/^importance: *(.*)/i && ($Importance = $1, next);
/^sensitivity: *(.*)/i && ($Sensitivity = $1, next);
/^priority: *(.*)/i && ($Priority = $1, next);
/^subject: *(.*)/i && ($Subject = $1, next);
# if "In-Reply-To:", "References:" or "Autoforwarded: True" lines
# exist, do not reply but generate an error.
(/^in-reply-to/i || /^references/i || /^autoforwarded: true/i) &&
&HandleError("request's In-reply-To, References or Autoforwarded field set");
}
# canonicalize several possible address formats to "local@domain"
# handle "User Name <user@foo>"
$ReplyTo && ($ReplyTo = &Canonicalize($ReplyTo));
$Sender && ($Sender = &Canonicalize($Sender));
$From && ($From = &Canonicalize($From));
# determine the originator of the request
if ($Sender) {
$originator = $Sender;
} elsif ($From) {
$originator = $From;
} else {
# generate an error if the originator can't be determined
&HandleError("request has no originator");
}
# if there is a "Reply-To:" field in the request, make "To:" of the response
# equal to the Reply-To address
# if there is no "Reply-To:" field in the request, make "To:" of the response
# equal to the request's originator
if ($ReplyTo) {
$to = $ReplyTo;
} else {
$to = $originator;
}
# if the recipient of the response is not the originator of the request,
# the "From:" field of the response must contain the "From:" and "Sender:"
# fields of the request, and the "Sender:" field of the response the
# ECHO administrator's address
if ($to ne $originator) {
$from = $From;
if ($from && $Sender && !($from eq $Sender)) {
$from .= ", $Sender";
} elsif ($Sender) {
$from = $Sender;
}
$sender = $ECHOADMIN;
} else {
$from = $ECHOADMIN;
}
# check if the response's "To:" field is different form server's address
($to =~ /^$ECHOADDR$/i) && &HandleError("attempt to send response to '$to' itself");
# then check if it's user name is among the hard-wired dangerous ones
($userName) = split(/@/, $to);
if ($to =~ /^mirror$/i || $to =~ /^netserv$/i || $to =~ /^echo$/i ||
$to =~ /^autoanswer$/i || $to =~ /^listserv$/i || $to =~ /^mailer-daemon$/i ||
$to =~ /^server$/) {
&HandleError("attempt to send to (hard-wired) suspicious address '$to'");
}
# finally check if it is among the local parts listed in $SUSPICIOUS
$toTmp = $userName;
$toTmp =~ tr/A-Z/a-z/;
$suspicious{$toTmp} && &HandleError("attempt to send to (configured) suspicious address $toTmp");
# transform the response's To: address into an RFC-822 address with
# LHS-encapsulated X.400-address if RFC1327CONV parameter was specified
if ($RFC1327CONV) {
$_ = `$RFC1327CONV '$to'`;
unless (/failed/) {
/\(x400\) *(.*)/ && ($x400not = $1);
$xto = "\"$x400not\"@$ECHODOMAIN";
}
}
$xto && ($to = $xto);
# update the log file log
&WriteLog("OK ", $originator, $to);
# create a temporary file for the response
$response = "$ECHOTMP/echo.response$$";
open(RESP, ">$response") || &HandleError("could not open '$response': $!\n");
# create the obligatory header fields of the reponse
print RESP "From: $from\n";
print RESP "To: $to\n";
$sender && print RESP "Sender: $sender\n";
$MessageId && print RESP "In-Reply-To: $MessageId\n";
$Importance && print RESP "Importance: $Importance\n";
$Sensitivity && print RESP "Sensitivity: $Sensitivity\n";
$Priority && print RESP "Priority: $Priority\n";
print RESP "Mime-Version: 1.0\n";
#print RESP "Content-Type: Multipart/Mixed; Boundary=%#%NextPart#%#\n";
print RESP "Content-Type: text/plain; charset=\"windows-1251\"\n";
#print RESP "charset=\"windows-1251\"\n";
print RESP "Content-Transfer-Encoding: 8bit";
$Subject && ($Subject =~ s/^[Rr][Ee]: //, print RESP "Subject: Re: $Subject\n");
# insert header/body separator in the response
#print RESP "\n--%#%NextPart#%#\n\n";
# include some explanatory text in the response (backslashes must be escaped
# with a backslash)
print RESP <<EoT;
тут , типа текст мыла; сорри за правку ориджина - запостил рабочую версию.
EoT
# copy the complete request (header & body) in the response
#open(REQ, "$request") || &HandleError("could not open '$request': $!\n");
#print RESP "\n--%#%NextPart#%#\n\n";
#
#while(<REQ>) {
#print RESP;
#}
#print RESP "\n--%#%NextPart#%#--\n";
close(RESP);
# send the response off
&send;
# clean up temporary storage
system("/bin/rm -f $request");
system("/bin/rm -f $response");
### Main Program end
### Subroutines begin
sub Canonicalize {
local($addr) = @_;
$addr =~ s/^.*<(.*)>/$1/;
# handle "user@foo (User Name)"
$addr =~ s/\(.*\)//;
# handle more?
$addr;
}
sub send {
# if it's a test, copy response to screen; otherwise send response off
if ($opt_t) {
print "command: $MAILER -f $ECHOADMINLOCAL -t < $response\n";
print "message header+body:\n";
open(RESP, "<$response") || &HandleError("could not open '$response': $!\n");
while (<RESP>) { print; }
} else {
system("$MAILER -f $ECHOADMINLOCAL -t < $response");
}
}
sub HandleError {
local($msg) = @_;
# wtite error in log file
&WriteLog("ERR ", $originator, $to);
close(REQ);
# error message goes to the ECHO administrator
$to = $ECHOADMIN;
# create a temporary file
$response = "$ECHOTMP/echo.response$$";
open(RESP, ">$response") || die "could not open '$response': $!\n";
# create the obligatory header fields of the reponse
print RESP "From: $ECHOADMIN\n";
print RESP "To: $ECHOADMIN\n\n";
print RESP "ERROR DETECTED:\n$msg\n(ORIGINAL MESSAGE FOLLOWS)\n=========\n";
if (open(REQ, "$request")) {
while(<REQ>) { print RESP; }
} else {
print RESP "original message not available\n";
}
close(RESP);
&send;
exit;
}
sub WriteLog {
local($stat, $org, $rec) = @_;
# create a timestamp
open(DATE, "date|") || die("could not execute 'date': $!\n");
$time = <DATE>;
chop($time);
open(LOG, ">>$ECHOLOG") || die("could not open '$ECHOLOG': $!\n");
# lock the logfile
flock(LOG, 2);
seek(LOG, 0, 2);
# write log info
printf LOG "$stat $time $org $rec\n";
# ulock the logfile
flock(LOG, 8);
close(LOG);
}
sub Usage {
open(MAN, "|more");
print MAN <<EoT;
ECHO(8)
NAME
echo - send a mail echo
SYNOPSIS
echo [-th]
DESCRIPTION
"echo" is a Mail Based Server (MBS) that automatically sends back a copy
of a message received, back to the originator. It is supposed to be
compliant with the draft RFC ???. It works with sendmail and PP.
OPTIONS
-t Test mode. Prints the command line as as the mailer would be
invoked to send the echo response, as well as the header and body
of the echo response, to the standard output.
-h Prints this text piped through "more".
SYSTEM REQUIREMENTS
Successful operation of echo requires:
o a sendmail or PP mailer
o Perl 4.19 or higher
CONFIGURATION
General:
o you should have received the file: echo.pl
o edit the "User Configuration Section" in the script to
configure the correct e-mail addresses and paths. The
comments in the script are self explanatory.
o edit the "user defined message Section" in the script to
define the accompanion text in the echo response.
o Edit the "User Configuration Section" of this script to tailor
to your site.
o make sure all directories used in the "User Configuration
Section" in the script exist with correct privileges for
reading and writing.
o be sure that Perl is runnable as /usr/bin/perl, otherwise
change the interpreter path in the first line of the script.
Sendmail:
o create account for user "echo" and copy the files in echo's home
directory
o edit /etc/sendmail.cf and add "echo" to the list of trusted users
(in the line that begins with "T")
o put entry an entry in /etc/aliases to redirect incoming mail for
to the local echo administrator echo-reply. Create an entry (with
quotes):
"echo-reply: <echo-admin-address>"
o create a the world readble file ".forward" in /usr/echo, with
the contents:
"|/usr/echo/echo"
With IDA sendmail make an alias instead of a .forward file. Add
to /etc/aliases the line
echo:"|/usr/echo/echo"
Don't forget to run newaliases.
o The file .forward must be world readable.
o set the privileges of /usr/echo/echo to -xrwxr-xr-
o WARNING: replies will *not* be addressed from "echo-reply"
unless the /usr/lib/sendmail program is used (do *not* use
/usr/ucb/mail), and "echo" is a trusted user for sendmail.
PP:
o Create account for user "echo" and copy the files in echo's home
directory. Assure that echo.pl has the following permission
flags set: -rwxr--r--
o edit ~pp/tables/users and add a line:
echo:shell
o edit ~pp/tables/aliases and add a line:
echo-reply: alias <echo-admin-address> 822
o edit ~pp/tables/ch.shell and add:
echo:echo,,<echo-home-dir>/echo.pl
o run:
dbmbuild
PERFORMANCE
o you might want to make a slightly quicker version of the echo
server by stripping all comments. Proceed with
o mv echo.pl echo.pl.orig
grep -v '^#' > echo.pl
o you might want to save this built-in manual page in a separate
file and delete all these lines except for the synopsis.
SEE ALSO
"The PP manual", sendmail(8), man(1), "Programming Perl", RFC 822
BUGS
Please report bugs, patches any comments to:
"Paul Klarenberg" <klarenberg\@netconsult.ch>
EoT
close(MAN);
exit;
}
### Subroutines end