Re: [exim] Sender Callout Checks

Góra strony
Delete this message
Reply to this message
Autor: Tony Finch
Data:  
Dla: Mike Zanker
CC: Exim Users
Temat: Re: [exim] Sender Callout Checks
On Wed, 29 Sep 2004, Mike Zanker wrote:
> On 28 September 2004 23:34 +0100 Tony Finch <dot@???> wrote:
>
> > http://www.exim.org/mail-archives/exim-users/Week-of-Mon-20040913/msg
> > 00181.html
>
> This looks useful - however, I'm a newbie when it comes to CDB. What's the
> format of the data that you need to feed to cdbmake to create the sender
> database?


You don't have to use cdb (it just happens to be what we use).
We use a script to populate CDB files from Exim lsearch files.

Tony.
--
f.a.n.finch <dot@???> http://dotat.at/
LYME REGIS TO LANDS END INCLUDING THE ISLES OF SCILLY: WEST 3 OR 4 BACKING
SOUTH. OUTBREAKS OF RAIN OR DRIZZLE. GOOD OR MODERATE. SLIGHT TO MODERATE.#!/usr/bin/perl -wT
#
# Create cdb file from flat alias file. DPC: 15/10/98.
# Args:      source  (may be relative or absolute)
#            target  (may be relative or absolute. Default = source)
# Generates: target.cdb
#            target.tmp
#
# Little Perl script to convert flat file into CDB file. Two advantages over
# cdbmake-12 awk script that is distributed with CDB:
#  1) Handles 'dpc22:dpc22@hermes' as well as 'dpc22 dpc22@hermes'
#  2) Perl works with arbitary length strings: awk chokes at 1,024 chars
#
# $Cambridge: hermes/src/admin/mkcdb,v 1.8 2004/05/06 17:50:02 fanf2 Exp $

use strict;

$ENV{'PATH'} = "";
umask(022);

my $CDB = '/opt/cdb/bin/cdbmake';

my $prog = $0;
$prog =~ s|(.*/)?([^/]+)|$2|;

my $source;
my $target;
if (@ARGV == 1) {
    $source = shift(@ARGV);
    $target = $source;
} elsif (@ARGV == 2) {
    $source = shift(@ARGV);
    $target = shift(@ARGV);
} else {
    die("$prog: usage: <source> [<target>]\n");
}
# trust the invoker ?!
$source =~ /(.*)/;
$source = $1;
$target =~ /(.*)/;
$target = $1;

open(SOURCE, "< ${source}")
    or die("$prog: open < $source: $!\n");

open(PIPE, "| $CDB $target.cdb $target.tmp")
    or die("$prog: open | $CDB $target: $!\n");

sub add_item ($$) {
    my $key = shift;
    my $val = shift;
    printf PIPE ("+%d,%d:%s->%s\n", length($key), length($val), $key, $val);
}

sub add_line ($) {
    my $line = shift;
    if ($line =~ /^(\S+)\s*:\s*(.*)$/s) {   # key : values
    add_item($1,$2);
    return;
    }
    if ($line =~ /^(\S+)\s+(.*)$/s) {       # key: values
    add_item($1,$2);
    return;
    }
    if ($line =~ /^(\S+)$/s) {              # key (empty value)
    add_item($1,'');
    return;
    }
    warn "$prog: unrecognized item: $line";
}

my $data;
while(<SOURCE>) {
    next if /^#/ or /^\s*$/;
    m/^(\s*)(\S.*)\s+$/s;
    if (length($1) == 0) {
        add_line($data) if defined $data;
        $data = $2;
    } else {
        $data .= " $2";
    }
}
add_line($data) if defined $data;
print PIPE "\n";

close(SOURCE)
    or die("$prog: close < $source: $!\n");
close(PIPE)
    or die($! ? "$prog: close | $CDB $target: $!\n"
       : "$prog: close | $CDB $target: exited $?\n");

exit 0;