Guillaume Filion a écrit :
It would be nice if they all could be configured like the
SMTP greeting is going to be.
I spent some time this evening doing this. I was a bit rusty (all SQL
and no perl make gfk a dull boy) but it's pretty simple, the result is
somewhat bulky though.
I thought of allowing perl code in each configuration file, but it would
fail the taint check. So I decided to do variable substitution:
#me# is replaced by the server FQDN.
#version# is replaced by the qpsmtpd version.
#remote_info# is replaced by the client hostname.
#remote_ip# is replaced by the client IP.
In file mail_sender_ok, #from# is replaced by the sender address.
In file rcpt_recipient_ok, #rcpt# is replaced by the recipient address.
Here are the strings that I made customizable. Note that to prevent the
patch from getting real big -- and some laziness -- I only did the ones
that I found useful.
- smtpgreeting
The SMTP greeting that it displayed at the beginning of each connection,
it should start with your FQDN.
Default: #me# ESMTP qpsmtpd #version# ready; send us your mail, but not
your spam.
- helo_response
The response to a valid HELO command.
Default: Hi #remote_info# [#remote_ip#]; I am so happy to meet you.
- ehlo_response
The response to a valid EHLO command.
Default: Hi #remote_info# [#remote_ip#]
- mail_sender_ok
The response to a valid MAIL command.
Default: #from#, sender OK - how exciting to get mail from you!
- rcpt_recipient_ok
The response to a valid RCPT command.
Default: #rcpt#, recipient ok
- help_response
The response to the help command.
Default:
This is qpsmtpd #version#
See http://smtpd.develooper.com/
To report bugs or send comments, see http://smtpd.develooper.com/bugs.html.
- data_response
The response to a successful DATA command.
Default: go ahead
- quit_response
The response to a successful QUIT command.
Default: #me# closing connection. Have a wonderful day.
The patch to the latest dev version is attached.
Cheers,
GFK's
--
Guillaume Filion, ing. jr
Logidac Tech., Beaumont, Québec, Canada - http://logidac.com/
PGP Key and more: http://guillaume.filion.org/
Index: SMTP.pm
===================================================================
--- SMTP.pm (revision 489)
+++ SMTP.pm (working copy)
@@ -86,7 +86,46 @@
return $self->respond(451, "Internal error - try again later - " . $msg);
}
+sub response {
+ my $self = shift;
+ my $cmd = shift;
+ my $obj = shift if
+ ($cmd eq 'mail_sender_ok' || $cmd eq 'rcpt_recipient_ok');
+ my @resp = $self->config($cmd);
+
+ # default values
+ unless (@resp) {
+ @resp = "#me# ESMTP qpsmtpd #version# ready; send us your mail, but not
your spam."
+ if ($cmd eq 'smtpgreeting');
+ @resp = "Hi #remote_info# [#remote_ip#]; I am so happy to meet you."
+ if ($cmd eq 'helo_response');
+ @resp = "Hi #remote_info# [#remote_ip#]"
+ if ($cmd eq 'ehlo_response');
+ @resp = "#from#, sender OK - how exciting to get mail from you!"
+ if ($cmd eq 'mail_sender_ok');
+ @resp = "#rcpt#, recipient ok"
+ if ($cmd eq 'rcpt_recipient_ok');
+ @resp = ("This is qpsmtpd #version#",
+ "See http://smtpd.develooper.com/",
+ 'To report bugs or send comments, see
http://smtpd.develooper.com/bugs.html.')
+ if ($cmd eq 'help_response');
+ @resp = "go ahead"
+ if ($cmd eq 'data_response');
+ @resp="#me# closing connection. Have a wonderful day."
+ if ($cmd eq 'quit_response');
+ }
+
+ for (@resp) { s/#me#/$self->config('me')/ge; }
+ for (@resp) { s/#version#/$self->version/ge; }
+ for (@resp) { s/#remote_info#/$self->connection->remote_info/ge; }
+ for (@resp) { s/#remote_ip#/$self->connection->remote_ip/ge; }
+ if ($cmd eq 'mail_sender_ok') {for (@resp) {s/#from#/$obj->format/ge;}}
+ if ($cmd eq 'rcpt_recipient_ok') {for (@resp) {s/#rcpt/$obj->format/ge;}}
+
+ return @resp;
+}
+
sub start_conversation {
my $self = shift;
# this should maybe be called something else than "connect", see
@@ -104,8 +143,7 @@
return $rc;
}
elsif ($rc != DONE) {
- $self->respond(220, $self->config('me') ." ESMTP qpsmtpd "
- . $self->version ." ready; send us your mail, but not your spam.");
+ $self->respond(220, $self->response('smtpgreeting'));
return DONE;
}
}
@@ -152,7 +190,7 @@
$conn->hello("helo");
$conn->hello_host($hello_host);
$self->transaction;
- $self->respond(250, $self->config('me') ." Hi " . $conn->remote_info . "
[" . $conn->remote_ip ."]; I am so happy to meet you.");
+ $self->respond(250, $self->response('helo_response'));
}
}
@@ -204,8 +242,8 @@
$self->{_commands}->{'auth'} = "";
}
- $self->respond(250,
- $self->config("me") . " Hi " . $conn->remote_info . " [" .
$conn->remote_ip ."]",
+ $self->respond(250,
+ $self->response('ehlo_response'),
"PIPELINING",
"8BITMIME",
($self->config('databytes') ? "SIZE ".
($self->config('databytes'))[0] : ()),
@@ -289,7 +327,7 @@
}
else { # includes OK
$self->log(LOGINFO, "getting mail from ".$from->format);
- $self->respond(250, $from->format . ", sender OK - how exciting to get
mail from you!");
+ $self->respond(250, $self->response('mail_sender_ok', $from));
$self->transaction->sender($from);
}
}
@@ -332,7 +370,7 @@
$self->disconnect;
}
elsif ($rc == OK) {
- $self->respond(250, $rcpt->format . ", recipient ok");
+ $self->respond(250, $self->response('rcpt_recipient_ok', $rcpt));
return $self->transaction->add_recipient($rcpt);
}
else {
@@ -345,10 +383,7 @@
sub help {
my $self = shift;
- $self->respond(214,
- "This is qpsmtpd " . $self->version,
- "See http://smtpd.develooper.com/",
- 'To report bugs or send comments, mail to <[EMAIL PROTECTED]>.');
+ $self->respond(214, $self->response('help_response'));
}
sub noop {
@@ -392,7 +427,7 @@
my $self = shift;
my ($rc, $msg) = $self->run_hooks("quit");
if ($rc != DONE) {
- $self->respond(221, $self->config('me') . " closing connection. Have a
wonderful day.");
+ $self->respond(221, $self->response('quit_response'));
}
$self->disconnect();
}
@@ -431,7 +466,7 @@
}
$self->respond(503, "MAIL first"), return 1 unless
$self->transaction->sender;
$self->respond(503, "RCPT first"), return 1 unless
$self->transaction->recipients;
- $self->respond(354, "go ahead");
+ $self->respond(354, $self->response('data_response'));
my $buffer = '';
my $size = 0;