On Sat, Dec 26, 1998 at 04:58:02PM -0800, [EMAIL PROTECTED] wrote:
> Is it possible to use a cdb in place of a large number of .qmail-*
> files?
> 
> In general, it looks like any qmail-command style delivery is 
> re-injecting a message into the queue for delivery.
> 
> It seems that building a database who's purpose was looking up 
> delivery instructions based upon EXT2 would require the ability 
> to deliver to the returned maildir would require the ability
> to deliver to maildir without re-injecting the message.  Otherwise,
> the functionality of replacing .dot-qmail files would be lost. :)
> 
> Anyone done anything like this before?
 
In essense, I wrote the Qmail-Maildir perl module to take care of
this type of problem.
<ftp://triceratops.com/pub/software/john/Qmail-Maildir-0.31.tar.gz>

Now my ~/.qmail and ~/.qmail-default look like:

  |example-dot
  ./Maildir/

and

  |example-default
  ./Maildir/

respectively.

Which in turn look like:

---------------------------------------------------------------------------
#!/usr/bin/perl

########################################################################
# File:        example-dot
# Date:        Jan 3, 1999
# Purpose:     filter mail from ~/.qmail by sender
# Usage:       in ~/.qmail:
#                          |example-dot
#                          ./Maildir/ 
#
# Methodology: Construct a cdb key based on sender.  
#              Translate cdb key to maildir.
#              Deliver to maildir if it exists.
#              exit 0 if there is no maildir for the key.
#
# Notes: This script depends on having previously built hashes of sender
#        to maildir.  Dan Bernstein's constant database, cdb, is available
#        at: <http://pobox.com/~djb/software/cdb.html>  
#        Personally, I use the format:
#                                     key <tab> maildir
#        Then read that text file into a cdb using
#        12tocdbm <file.txt |cdbmake dot.cdb dot.tmp
#
#        Again, for more information on this, see the cdb package.
########################################################################

########################################################################
## Initialization 
########################################################################
#
# System executables
#
my $cdbget = "/tmpr/local/bin/cdbget";
my $cdbfile = "db/dot.cdb";

# Modules 
#
use strict;
use Qmail::Maildir qw (:DEFAULT hardfail);

# Capture the envelope sender, which qmail gives us in the
# form of the SENDER environment variable.
# For more information on this, see the qmail-command(8) man page.
#
my $sender = $ENV{SENDER};


########################################################################
## Construct cdb key 
########################################################################
#
# I use [everything before first dash or @]-[fully qualified domain]
# as my lookup key.  This is how I get that.

# grab portion of sender up to first dash OR @
# notice minimally matching quantifier bounded by dash or @
#
$sender =~ m/^(.*?)[-\@]/;
my $sendkey = $1 . "-";

# fully qualified domain portion of sender
# quantifier greedily matching everything after @, before end of line
#
$sender =~ m/\@(.*)$/;
$sendkey .= $1;

########################################################################
## Get maildir from key 
########################################################################

my $maildirpath = `$cdbget $sendkey <$cdbfile`;

########################################################################
## safely deliver to maildir if it exists 
########################################################################
#
# If we got a maildir back from cdbget, then try delivering to it.
# Signal permanent failure if we got back a maildir which doesn't exist.
#
# If the maildir exists, and we successfully deliver to it, exit 99 so
# .qmail-default processing halts.
#

if ($maildirpath) {

    ( -e "$maildirpath/" )
        or hardfail "Non-existant maildir. (#4.3.0)";
    my $maildir = new Qmail::Maildir($maildirpath);
    
    $maildir->deliver();
    exit 99;
}

########################################################################
## Condition: No maildir for key 
########################################################################
#
# Again, the example is meant to run in a dot-qmail file with
# a "fall-through" default delivery line.  This is reached by
# exiting 0.

exit 0;
---------------------------------------------------------------------------

---------------------------------------------------------------------------
#!/usr/bin/perl -w

########################################################################
# File:        example-defaut
# Date:        Jan 3, 1999
# Purpose:     filter mail from ~/.qmail-default by DEFAULT
# Usage:       in ~/.qmail-default:
#                          |example-default
#                          ./Maildir/
#
# Methodology: Capture DEFAULT to use as a hash key.
#              Translate cdb key to maildir.
#              Deliver to maildir if it exists.
#              exit 0 if there is no maildir for the key.
#
# Notes: This script depends on having previously built sender to maildir
#        hash.  Dan Bernstein's constant database, cdb, is available
#        at: <http://pobox.com/~djb/software/cdb.html>
#        Personally, I use the format:
#                                     key <tab> maildir
#        Then read that text file into a cdb using
#        12tocdbm <file.txt |cdbmake dot.cdb dot.tmp
#
#        Again, for more information on this, see the cdb package.
#        Most anything which works the same way can be used.
########################################################################

########################################################################
## Initialization
########################################################################
#
# System executables
#
my $cdbget = "/usr/local/bin/cdbget";
my $cdbfile = "db/default.cdb";

# Modules
#
use strict;
use Qmail::Maildir qw (:DEFAULT hardfail);

# Capture the DEFAULT environment variable.  qmail sets it to tell use
# who the message was addressed to.
#
$default = $ENV{DEFAULT};

########################################################################
## Get maildir from key
########################################################################
#
# We're using $default as the lookup key.
#
my $maildirpath = `$cdbget $default <$cdbfile`;


########################################################################
## safely deliver to maildir if it exists
########################################################################
#
# If we got a maildir back from cdbget, then try delivering to it.
# Signal permanent failure if we got back a maildir which doesn't exist.
# 
# If the maildir exists, and we successfully deliver to it, exit 99 so
# .qmail-default processing halts.
#
if ($maildirpath) {
    
    ( -e "$maildirpath/" )
        || hardfail "Non-existant maildir. (#4.3.0)";
    my $maildir = Qmail::Maildir->new ( $maildirpath );
    
    $maildir->deliver();
    exit 99;
}

########################################################################
## Condition: No maildir for key
########################################################################
#
# Again, the example is meant to run in a .qmail-default file with
# a "fall-through" default delivery line.  This is reached by
# exiting 0.

exit 0;
---------------------------------------------------------------------------




-- 
John White
[EMAIL PROTECTED]
PGP Public Key: http://www.triceratops.com/john/public-key.pgp

Reply via email to