On Tue, 15 Jul 2003, Mark Powell wrote:
>   We currently have a custom qmail-inject+rw which can rewrite the
> addresses from user's dumb email clients, into their proper email address.
>   Anyone done this? Or as I'm new to writing these plugins, give me any
> pointers on the best way to do this?

Thanks to everyone for not helping as it made me get off my arse and learn
more about the internals of qpsmtpd :)
  Can people please comment on whether I'm doing things right/wrong here
as I've not really done much object orientated perl before?
  Cheers.

-- 
Mark Powell - UNIX System Administrator - The University of Salford
Information Services Division, Clifford Whitworth Building,
Salford University, Manchester, M5 4WT, UK.
Tel: +44 161 295 4837  Fax: +44 161 295 5888  www.pgp.com for PGP key
#
# Rewrite the From and envelope sender lines a la ofmipd, see 
http://cr.yp.to/mess822.html
#
# takes one argument in the config/plugins file which is the 
# pathname to the ofmipname style cdb database otherwise this defaults to
# /var/qmail/control/ofmipname.cdb
#
# Basically the format is:
#
# [EMAIL PROTECTED]:Joe Schmoe:[EMAIL PROTECTED]:
#
# When this plugin finds [EMAIL PROTECTED] as the envelope sender, it will rewrite
# the envelope sender to '[EMAIL PROTECTED]' (without the single quotes) and
# it will also rewrite the From: line to '"Joe Schmoe" <[EMAIL PROTECTED]>'.
# If the comment field in the ofmipname cdb is empty then the From: line will
# be rewritten to simply '[EMAIL PROTECTED]'.
#
# Copyright 2003 [EMAIL PROTECTED]
# Permission granted to use freely as long as this copyright message is kept intact.
# This software comes with NO warranty at all.
# 1/10/03
#

sub register {
  my ($self, $qp, @args) = @_;

  if (@args > 0) {
    $self->{_ofmipname} = $args[0];
    $self->log(1, "WARNING: Ignoring additional arguments.") if (@args > 1);
  } else {
    $self->{_ofmipname} = '/var/qmail/control/ofmipname.cdb';
  }

  $self->register_hook("queue", "rewrite_from");
}

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

  return (DECLINED) unless exists $ENV{RELAYCLIENT};

  my $sender = $transaction->sender->address;
  my $lcsender = lc $sender;
  my $headers = $transaction->header();
  #my $msgid = $headers->get('Message-Id');
  #my $subject = $headers->get('Subject');

  my $c = tie (my %h, 'CDB_File', $self->{_ofmipname}) or return (DECLINED);
  my $found = $h{$lcsender};
  if (defined $found) {
    my ( $comment, $email ) = split /\0/, $found;
    #$self->log(0, "comment = $comment");
    #$self->log(0, "email = $email");
    $transaction->sender->address($email);
    my $from = $comment ne "" ? "\"$comment\" <$email>" : $email;
    $headers->replace('From', $from);
    $self->log(0, "Rewriting: $sender as $from");
  }
  undef $c;
  untie %h;

  #$self->log(0, "Env-Sender: $sender");

  return (DECLINED);
}

Reply via email to