Re: [Exim] conversion from flatascii to cdb

Página Principal
Apagar esta mensagem
Responder a esta mensagem
Autor: Tony Finch
Data:  
Para: exim-users
Assunto: Re: [Exim] conversion from flatascii to cdb
Nico Erfurth <masta@???> wrote:
>Jim Pazarena wrote:
>
>> While conversion of most of my alias files worked as expected,
>>    joe:      sam
>> converts as:
>>    +3,3:joe->sam
>> a rejection file of the type:
>>    userID:    :fail: no longer a valid recipient
>> seems to have the message dropped by the cdb routine.
>> using the "cdbdump" shows for example that the above line converts to:
>>    +6,6:userID->:fail:
>> can cdb _not_ be used with this type of file ?

>
>How do you convert the files?
>I think the script does not handle this case correctly, cdb itself can
>handle such data.


Our script is attached.

Tony.
--
f.a.n.finch <dot@???> http://dotat.at/
ARDNAMURCHAN POINT TO CAPE WRATH INCLUDING THE OUTER HEBRIDES: WEST OR
SOUTHWEST 5 OR 6, INCREASING 7 OR GALE 8 THIS EVENING, THEN GALE 8 OR SEVERE
GALE 9 OVERNIGHT. RAIN OR SHOWERS. MODERATE OR GOOD, POSSIBLY POOR AT TIMES.
MODERATE OR ROUGH, BECOMING VERY ROUGH OR HIGH IN OPEN WATER.

#!/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
# 12tocdb 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
#
# XXX: input is not quite the same as Exim lsearch files
#      (whitespace line continuation isn't handled)
#
# $Cambridge: hermes/exim/sbin/mkcdb,v 1.3 2003/09/18 15:20:59 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");


while(<SOURCE>) {
    next if /^#/ or /^\s*$/;
    if (/^(\S+)\s*:\s*(\S.*)\n$/o) {   # key : values
        printf PIPE ("+%d,%d:%s->%s\n", length($1), length($2), $1, $2);
        next;
    }
    if (/^(\S+)\s+(\S.*)\n$/o) {       # key: values
        printf PIPE ("+%d,%d:%s->%s\n", length($1), length($2), $1, $2);
        next;
    }
    if (/^(\S+)\n$/o) {                # key (empty value)
        printf PIPE ("+%d,%d:%s->%s\n", length($1), length(''), $1, '');
        next;
    }
}
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;