cvs commit: qpsmtpd/plugins/queue maildir

[email protected] (Ask "Bj?rn" Hansen)
Newsgroups perl.cvs.qpsmtpd
Message-ID <[email protected]>
cvsuser     04/05/24 04:36:04

  Modified:    .        Changes
  Added:       plugins/queue maildir
  Log:
  maildir queue plugin
  
  Revision  Changes    Path
  1.67      +2 -1      qpsmtpd/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /cvs/public/qpsmtpd/Changes,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -w -r1.66 -r1.67
  --- Changes	21 Apr 2004 12:42:44 -0000	1.66
  +++ Changes	24 May 2004 11:36:04 -0000	1.67
  @@ -1,5 +1,6 @@
   0.28
   
  +  Added a "queue/maildir" plugin for writing incoming mails to a maildir.
   
     Create temp files with permissions 0600 (thanks to Robert James Kaes again)
   
  @@ -10,7 +11,7 @@
     $Include feature in config/plugins
   
   
  -0.27 - 2004/03/11
  +0.27.1 - 2004/03/11
   
     SpamAssassin plugin Outlook compatibility fix (Thanks to Gergely Risko)
   
  
  
  
  1.1                  qpsmtpd/plugins/queue/maildir
  
  Index: maildir
  ===================================================================
  =head1 NAME
  
  queue/maildir
  
  =head1 DESCRIPTION
  
  This plugin delivers mails to a maildir spool. 
  
  =head1 CONFIG
  
  It takes one required parameter, the location of the maildir.
  
  =cut
  
  use File::Path qw(mkpath);
  use Sys::Hostname qw(hostname);
  use Time::HiRes qw(gettimeofday);
  
  sub register {
    my ($self, $qp, @args) = @_;
  
    if (@args > 0) {
      ($self->{_maildir}) = ($args[0] =~ m!([/\w\.]+)!);
    }
  
    unless ($self->{_maildir}) {
      $self->log(1, "WARNING: maildir directory not specified");
      return 0;
    }
  
    map { my $d = $self->{_maildir} . "/$_"; -e $d or mkpath $d, 0, 0700 } qw(cur tmp new); 
  
    my $hostname = (hostname =~ m/([\w\._\-]+)/)[0];
    $self->{_hostname} = $hostname;
  
    $self->register_hook("queue", "queue_handler");
  
  }
  
  my $maildir_counter = 0;
  
  sub queue_handler {
    my ($self, $transaction) = @_;
  
    my ($time, $microseconds) = gettimeofday;
  
    $time = ($time =~ m/(\d+)/)[0];
    $microseconds =~ s/\D//g;
  
    my $unique  = "P$$" . "M$microseconds" . "Q" . $maildir_counter++;
    my $file    = join ".", $time, $unique, $self->{_hostname};
    my $maildir = $self->{_maildir};
  
    open (MF, ">$maildir/tmp/$file") or 
      $self->log(LOGWARN, "could not open $maildir/tmp/$file: $!"),
      return(DECLINED, "queue error (open)");
  
    $transaction->header->print(\*MF);
    $transaction->body_resetpos;
    while (my $line = $transaction->body_getline) {
      print MF $line;
    }
  
    close MF or
      $self->log(LOGWARN, "could not close $maildir/tmp/$file: $!")
      and return(DECLINED, "queue error (close)");
  
    link "$maildir/tmp/$file", "$maildir/new/$file" or
      $self->log(LOGWARN, "could not link $maildir/tmp/$file to $maildir/new/$file: $!")
      and return(DECLINED, "queue error (link)");
  
    unlink "$maildir/tmp/$file";
  
    my $msg_id = $transaction->header->get('Message-Id') || '';
    $msg_id =~ s/[\r\n].*//s;
  
    return (OK, "Queued! $msg_id"); 
  }
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.