On Mon, Jun 19, 2006 at 10:53:08AM -0400, Matt Sergeant wrote:
> On 19-Jun-06, at 7:31 AM, Peter J. Holzer wrote:
> 
> >Which reminds me: I think we should move to a more flexible system of
> >return codes
> 
> We do. $self->qp->respond(CODE, @MESSAGE); return DONE;
> 
> (that's why we have the DONE return code).

New patch.  This time using $self->qp->respond to avoid modifying the core.

Taking advantage of this, I also implemented code 251, just for completeness
(when ~/.forward exists, it'll return 251.  Otherwise 551).

-- 
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-22 20:53:47.413601000 +0200
@@ -26,6 +26,8 @@
 check_badrcptto
 check_spamhelo
 
+# redirect_local
+
 # sender_permitted_from
 
 # this plugin needs to run after all other "rcpt" plugins
diff -Nur qpsmtpd-0.32.old/plugins/redirect_local 
qpsmtpd-0.32/plugins/redirect_local
--- qpsmtpd-0.32.old/plugins/redirect_local     1970-01-01 01:00:00.000000000 
+0100
+++ qpsmtpd-0.32/plugins/redirect_local 2006-06-22 21:12:26.725439736 +0200
@@ -0,0 +1,47 @@
+# This plugin checks for ~/.redirect.  If it exists, it uses the recipient
+# address contained there to inform the sender that this user is actualy
+# somewhere else.  This is specialy useful as an alternative for traditional
+# forwarding because:
+#
+# - It doesn't break when the sender has published SPF records.
+# - It gives the final recipient's MTA a chance to perform its own 
delivery-time
+#   anti-spam checks (greylisting, spf, etc), in addition to whatever checks we
+#   have (or have not) performed on our side.
+#
+# Note that ATTOW most senders will not automaticaly redirect their mail to the
+# final recipient.  In that case, a sane MTA would generate an MDN, informing
+# the user of the new recipient address.  RFC 2821 says that you must not 
assume
+# this will actualy happen, though, so you do it on your own responsability.
+#
+# From RFC 2821, section 3.4:
+#
+#   *  Servers MAY reject or bounce messages when they are not
+#      deliverable when addressed.  When they do so, they MAY either
+#      provide address-updating information with a 551 code, or may
+#      reject the message as undeliverable with a 550 code and no
+#      address-specific information.  But, if a 551 code is used, they
+#      MUST NOT assume that the client will actually update address
+#      information or even return that information to the user.
+
+use Qpsmtpd::DSN;
+use File::HomeDir;
+
+sub hook_rcpt {
+  my ($self, $transaction, $recipient) = @_;
+
+  if (open (REDIR, home(lc($recipient->user)) . "/.redirect")) {
+    my ($redir) = <REDIR>;
+    my ($code) = 551;
+    close(REDIR);
+    chomp ($redir);
+
+    if (-f home(lc($recipient->user)) . "/.forward") {
+      $code = 251;
+    }
+
+    $self->qp->respond($code, "User not local; please try <$redir>");
+    return DONE;
+  }
+
+  return OK;
+}

Reply via email to