On Thu, Jun 22, 2006 at 02:55:29PM -0700, Ask Bjørn Hansen wrote:
> >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).
> 
> Hi Robert,
> 
> Nice job on making the plugin self-contained.

Thank you.  It took me a while as I'm quite new to perl ;).

I just noticed a small bug (the DSN message for 251 shouldn't be
the same as the one for 551).  I'm attaching the revised plugin.

> Until it's supported with some of the sending smtp servers then I'm  
> not sure it won't just be confusing for the users if we put it into  
> the distribution.

Note that sendmail already supports it, but only in the recieving part.  For
exim, I have a working patch for the reciever already, and I have plans to do
the sending part as well.

> It would be good to put on the wiki though (or  
> maybe in our contrib/ directory[1]).
> [1] https://svn.perl.org/qpsmtpd/contrib/

Sure!  Would you please do that?

-- 
Robert Millan
# 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.
#
# See RFC 2821, section 3.4, for details.

use Qpsmtpd::DSN;
use File::HomeDir;

sub hook_rcpt {
  my ($self, $transaction, $recipient) = @_;

  if (open (REDIR, home(lc($recipient->user)) . "/.redirect")) {
    my ($redir) = <REDIR>;
    close(REDIR);
    chomp ($redir);

    if (-f home(lc($recipient->user)) . "/.forward") {
      $self->qp->respond(251, "User not local; will forward to <$redir>");
    } else {
      $self->qp->respond(551, "User not local; please try <$redir>");
    }

    return DONE;
  }

  return OK;
}

Reply via email to