On Sun, Jun 18, 2006 at 11:33:22AM -0700, Robert Spier wrote:
> > >
> > > I like the idea, but nothing else in qpsmtpd knows about local
> > > delivery.
> > >
> > > Can you rewrite this to be a plugin?
> >
> > Yes. But are you sure it's necessary to split it? Given that nothing
> > happens
> > unless users create ~/.preforward files, I'd say it's quite harmless.
>
> Yes. It is definitely necessary. As a qpsmtpd policy, we don't put
> things in the core unless we need to. Especially things that make
> assumptions about where users actually live and how delivery works.
Ok, here you are.
--
Robert Millan
diff -Nur qpsmtpd-0.32.old/config.sample/plugins
qpsmtpd-0.32/config.sample/plugins
--- qpsmtpd-0.32.old/config.sample/plugins 2006-02-26 13:22:16.000000000
+0100
+++ qpsmtpd-0.32/config.sample/plugins 2006-06-18 22:03:46.523425232 +0200
@@ -25,6 +25,7 @@
check_badmailfrom
check_badrcptto
check_spamhelo
+preforward
# sender_permitted_from
diff -Nur qpsmtpd-0.32.old/debian/etc/plugins qpsmtpd-0.32/debian/etc/plugins
--- qpsmtpd-0.32.old/debian/etc/plugins 2006-06-18 21:59:41.000000000 +0200
+++ qpsmtpd-0.32/debian/etc/plugins 2006-06-18 22:03:11.125806488 +0200
@@ -167,6 +167,10 @@
#
# quit_fortune
+# preforward -- checks for ~/.preforward file, and uses DSN 551 to indicate
+# that this user is somewhere else.
+preforward
+
# rcpt_ok -- checks /etc/qpsmtpd/me and /etc/qpsmtpd/rcpthosts to see if the
# recipient hostname is intended to be accepted here. This should be the last
# plugin before the queue plugin(s), and should not be disabled unless you
diff -Nur qpsmtpd-0.32.old/lib/Qpsmtpd/Constants.pm
qpsmtpd-0.32/lib/Qpsmtpd/Constants.pm
--- qpsmtpd-0.32.old/lib/Qpsmtpd/Constants.pm 2006-02-26 13:22:16.000000000
+0100
+++ qpsmtpd-0.32/lib/Qpsmtpd/Constants.pm 2006-06-18 22:00:12.034032576
+0200
@@ -23,6 +23,7 @@
DENYHARD => 903, # 550 + disconnect (deprecated in 0.29)
DENY_DISCONNECT => 903, # 550 + disconnect
DENYSOFT_DISCONNECT => 904, # 450 + disconnect
+ PREFORWARD => 905, # 551
DECLINED => 909,
DONE => 910,
);
diff -Nur qpsmtpd-0.32.old/lib/Qpsmtpd/DSN.pm qpsmtpd-0.32/lib/Qpsmtpd/DSN.pm
--- qpsmtpd-0.32.old/lib/Qpsmtpd/DSN.pm 2006-02-26 13:22:16.000000000 +0100
+++ qpsmtpd-0.32/lib/Qpsmtpd/DSN.pm 2006-06-18 22:00:12.035032424 +0200
@@ -172,7 +172,7 @@
sub addr_unspecified { shift->_dsn(shift,shift,DENYSOFT,1,0); }
-=item no_such_user, addr_bad_dest_mbox
+=item no_such_user, addr_bad_dest_mbox, user_not_local
X.1.1
default: DENY
@@ -181,6 +181,7 @@
sub no_such_user { shift->_dsn(shift,(shift||"No such
user"),DENY,1,1); }
sub addr_bad_dest_mbox { shift->_dsn(shift,shift,DENY,1,1); }
+sub user_not_local { shift->_dsn(shift,shift,PREFORWARD,1,1); }
=item addr_bad_dest_system
diff -Nur qpsmtpd-0.32.old/lib/Qpsmtpd/SMTP.pm qpsmtpd-0.32/lib/Qpsmtpd/SMTP.pm
--- qpsmtpd-0.32.old/lib/Qpsmtpd/SMTP.pm 2006-02-26 13:22:16.000000000
+0100
+++ qpsmtpd-0.32/lib/Qpsmtpd/SMTP.pm 2006-06-18 22:00:12.035032424 +0200
@@ -355,6 +355,9 @@
$self->respond(421, $msg);
$self->disconnect;
}
+ elsif ($rc == PREFORWARD) {
+ $self->respond(551, $msg);
+ }
elsif ($rc == OK) {
$self->respond(250, $rcpt->format . ", recipient ok");
return $self->transaction->add_recipient($rcpt);
diff -Nur qpsmtpd-0.32.old/plugins/preforward qpsmtpd-0.32/plugins/preforward
--- qpsmtpd-0.32.old/plugins/preforward 1970-01-01 01:00:00.000000000 +0100
+++ qpsmtpd-0.32/plugins/preforward 2006-06-18 22:01:58.640825880 +0200
@@ -0,0 +1,18 @@
+# this plugin checks for ~/.preforward
+#
+use Qpsmtpd::DSN;
+use File::HomeDir;
+
+sub hook_rcpt {
+ my ($self, $transaction, $recipient) = @_;
+
+ # Check for ~/.preforward
+ if (open (PREFWD, home(lc($recipient->user)) . "/.preforward")) {
+ my ($prefwd) = <PREFWD>;
+ close(PREFWD);
+ chomp ($prefwd);
+ return Qpsmtpd::DSN->user_not_local("User not local; please try
<$prefwd>");
+ }
+
+ return (OK);
+}