cvs commit: qpsmtpd/plugins check_basicheaders

[email protected] (John Peacock)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/09/25 04:40:43

  Added:       plugins  check_basicheaders
  Log:
  *    plugins/check_basicheaders
       Refuse messages that lack basic headers per RFC-2822
       (Jim Winstead)
       modified by John Peacock to block null messages, too
  
  Revision  Changes    Path
  1.1                  qpsmtpd/plugins/check_basicheaders
  
  Index: check_basicheaders
  ===================================================================
  #!/usr/bin/perl
  
  =head1 NAME
  
  check_basicheaders - Make sure both From and Date headers are present, and
  do optional range checking on the Date header
  
  =head1 DESCRIPTION
  
  Rejects messages that do not have a From or Date header or are completely 
  empty.
  
  Can also reject messages where the date in the Date header is more than
  some number of the days in the past or future.
  
  =head1 CONFIGURATION
  
  Takes one optional parameter, the number of days in the future or past
  beyond which to reject messages. (The default is to not reject messages
  based on the date.)
  
  =head1 AUTHOR
  
  Written by Jim Winstead Jr.
  
  =head1 LICENSE
  
  Released to the public domain, 26 March 2004.
  
  =cut
  
  use Date::Parse qw(str2time);
  
  sub register {
    my ($self, $qp, @args) = @_;
    $self->register_hook("data_post", "check_basic_headers");
  
    if (@args > 0) {
      $self->{_days} = $args[0];
      $self->log(1, "WARNING: Ignoring additional arguments.") if (@args > 1);
    }
  }
  
  sub check_basic_headers {
    my ($self, $transaction) = @_;
  
    return (DENY, "You have to send some data first")
      if $transaction->body_size == 0;
  
    return (DENY, "Mail with no From header not accepted here")
      unless $transaction->header->get('From');
  
    my $date = $transaction->header->get('Date');
  
    return (DENY, "Mail with no Date header not accepted here")
      unless $date;
  
    return (DECLINED) unless defined $self->{_days};
  
    my $ts = str2time($date);
  
    return (DECLINED) unless $ts;
  
    return (DENY, "The Date in the header was too far in the past")
      if $ts < time - ($self->{_days}*24*3600);
  
    return (DENY, "The Date in the header was too far in the future")
      if $ts > time + ($self->{_days}*24*3600);
  
    return (DECLINED);
  }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.