qpsmtpd does all sorts of logging but what i was missing was a complete log
entry showing the details of a mail after accepting it. Therefore i
programmed this new plugin. 

The loglevel can be configured via the configfile 'maillog_level' and defaults 
to 7 (LOGINFO). I suggest setting it to a higher level like 3 (although that
one is labelled LOGCRIT) to make sure, that this is logged.

The logfile entries look like the following example:

Sep  3 01:41:37 zeus qpsmtpd: 26253 maillog plugin: tcp client:   artemis.keleos.net 
[217.160.129.28]
Sep  3 01:41:37 zeus qpsmtpd: 26253 maillog plugin: mail from:    <[EMAIL PROTECTED]>
Sep  3 01:41:37 zeus qpsmtpd: 26253 maillog plugin: rcpt to:      <[EMAIL PROTECTED]>
Sep  3 01:41:37 zeus qpsmtpd: 26253 maillog plugin: mail size:    896 bytes
Sep  3 01:41:37 zeus qpsmtpd: 26253 maillog plugin: relay client: yes

Is there any way to get rid of the "maillog plugin: " part? I also would
like to be able to log if the client was authenticated by SMTP AUTH and
ideally also the username used for that. It seems that neither information
is available to plugins right now.

-kju

-- 
      It's an insane world, but i'm proud to be a part of it. -- Bill Hicks
#
# maillog 
# a qpsmtpd plugin for mail logging
#
# This plugin logs the relevant details like sending host, envelope sender,
# envelope recipient and size to the logfile after a mail got accepted
#
# written by Michael Holzt, <kju -at- debian.org>
# last modified on September 3th, 2004
#


sub register {
  my ($self, $qp) = @_;
  $self->register_hook("data_post", "maillog");
}

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

  $loglevel = $self->qp->config("maillog_level") || 7;

  # log remote hostname and ip
  $self->log($loglevel, "tcp client:   " . $self->qp->connection->remote_host . 
    " [" . $self->qp->connection->remote_ip . "]");

  # log envelope sender
  $self->log($loglevel, "mail from:    " . $transaction->sender->format);
  
  # log all envelope recipients
  foreach $recipient ( $transaction->recipients )
  {
    $self->log($loglevel, "rcpt to:      " . $recipient->format);
  }

  # log mail size
  $self->log($loglevel, "mail size:    " . $transaction->body_size . " bytes");

  # log whether this is an relay client
  $self->log($loglevel, "relay client: " . ( $transaction->{_relaying} ? "yes" : "no" 
) );

  return DECLINED;
}

Reply via email to