qpsmtpd/plugins/queue/smtp-forward
John Peacock b89a6d9e4c * plugins/queue/smtp-forward
s/register/init/ to match new plugin style (jpeacock)

* lib/Qpsmtpd/Address.pm
  t/qpsmtpd-address.t
    Ill-formed addresses should return null not partial garbage.
    Resolves https://rt.perl.org/rt3/Ticket/Display.html?id=38746
    Patch by Hanno Hecker.

* plugins/virus/clamav
    Clamav alternate config file.
    Resolves https://rt.perl.org/rt3/Ticket/Display.html?id=38736
    Patch by Robin Bowes.

* lib/Qpsmtpd/SMTP.pm
  lib/Qpsmtpd.pm
    Return multiline responses from plugins.
    Resolves https://rt.perl.org/rt3/Ticket/Display.html?id=38741
    Patch by Charlie Brady.

git-svn-id: https://svn.perl.org/qpsmtpd/branches/0.3x@630 958fd67b-6ff1-0310-b445-bb7760255be9
2006-03-20 16:47:05 +00:00

70 lines
2.0 KiB
Plaintext

=head1 NAME
smtp-forward
=head1 DESCRIPTION
This plugin forwards the mail via SMTP to a specified server, rather than
delivering the email locally.
=head1 CONFIG
It takes one required parameter, the IP address or hostname to forward to.
queue/smtp-forward 10.2.2.2
Optionally you can also add a port:
queue/smtp-forward 10.2.2.2 9025
=cut
use Net::SMTP;
sub init {
my ($self, $qp, @args) = @_;
if (@args > 0) {
if ($args[0] =~ /^([\.\w_-]+)$/) {
$self->{_smtp_server} = $1;
}
else {
die "Bad data in smtp server: $args[0]";
}
$self->{_smtp_port} = 25;
if (@args > 1 and $args[1] =~ /^(\d+)$/) {
$self->{_smtp_port} = $1;
}
$self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if (@args > 2);
} else {
die("No SMTP server specified in smtp-forward config");
}
}
sub hook_queue {
my ($self, $transaction) = @_;
$self->log(LOGINFO, "forwarding to $self->{_smtp_server}:$self->{_smtp_port}");
my $smtp = Net::SMTP->new(
$self->{_smtp_server},
Port => $self->{_smtp_port},
Timeout => 60,
Hello => $self->qp->config("me"),
) || die $!;
$smtp->mail( $transaction->sender->address || "" ) or return(DECLINED, "Unable to queue message ($!)");
for ($transaction->recipients) {
$smtp->to($_->address) or return(DECLINED, "Unable to queue message ($!)");
}
$smtp->data() or return(DECLINED, "Unable to queue message ($!)");
$smtp->datasend($transaction->header->as_string) or return(DECLINED, "Unable to queue message ($!)");
$transaction->body_resetpos;
while (my $line = $transaction->body_getline) {
$smtp->datasend($line) or return(DECLINED, "Unable to queue message ($!)");
}
$smtp->dataend() or return(DECLINED, "Unable to queue message ($!)");
$smtp->quit() or return(DECLINED, "Unable to queue message ($!)");
$self->log(LOGINFO, "finished queueing");
return (OK, "Queued!");
}