follow up: Reading an array from a flat file
Mark Martinec
Mark.Martinec+amavis at ijs.si
Wed Aug 17 15:51:59 CEST 2011
Helga,
> I have some 50 users (out of 10000) for whom I want to bypass
> spamchecking. Instead of writing the addresses literally in amavisd.conf
> I would prefer to store them in a file. Could this be done in
> amavisd.conf or will I have to modify amavisd ?
>
> Will the following code work ?
>
> my $path_mailaddr = '/etc/postfix/bypass_spam_checks';
> my @all_mailaddr = ();
> open(MAILADDR, "<$path_mailaddr")
> || die "cannot open bypass_spam_checks\n";
> @all_mailaddr = <MAILADDR>;
Stll need to strip newlines from each.
> my %bypass_spam_checks = ();
> map { $bypass_spam_checks{lc($_)}=1 } (@all_mailaddr);
You are making a local copy of %bypass_spam_checks with a my(),
instead of using the %Amavis::Conf::bypass_spam_checks,
so it has no effect.
> close(MAILADDR);
>
> /etc/postfix/bypass_spam_checks contains:
>
> user1 at mydomain.de
> user2 at mydomain.de
> ....
> user50 at mydomain.de
Why not just use a read_hash to do the work:
@bypass_spam_checks_maps = ( read_hash('/etc/postfix/bypass_spam_checks') );
domains are lowercased, localpart is lowercased by default
(unless $localpart_is_case_sensitive is true).
> I forgot to mention I already tried the builtin function read_array.
>
> map { $bypass_spam_checks{lc($_)}=1 }
> (read_array('/etc/postfix/bypass_spam_checks'));
>
> amavisd was starting without errors, but the content of
> etc/postfix/bypass_spam_checks was ignored.
The read_array returns an array ref, not an array.
Mark
More information about the amavis-users
mailing list