diff options
| author | fukachan <fukachan> | 2002-04-25 04:40:03 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2002-04-25 04:40:03 +0000 |
| commit | 490037641f3ec804d1ed84dfe9d49cd566425aba (patch) | |
| tree | 7dd474791f508cc6b12129952997c7cdc504dba4 /fml/lib | |
| parent | 69694866041e4b1563b2c1aba87b369cc4501b53 (diff) | |
| download | fml8-490037641f3ec804d1ed84dfe9d49cd566425aba.tar.gz fml8-490037641f3ec804d1ed84dfe9d49cd566425aba.tar.bz2 fml8-490037641f3ec804d1ed84dfe9d49cd566425aba.zip | |
implement get_aliases_as_hash_ref()
new() accepts { mta_type => ... } argument
Diffstat (limited to 'fml/lib')
| -rw-r--r-- | fml/lib/FML/MTAControl.pm | 98 |
1 files changed, 92 insertions, 6 deletions
diff --git a/fml/lib/FML/MTAControl.pm b/fml/lib/FML/MTAControl.pm index 8fcb48e6..945db757 100644 --- a/fml/lib/FML/MTAControl.pm +++ b/fml/lib/FML/MTAControl.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: MTAControl.pm,v 1.1 2002/04/24 03:59:14 fukachan Exp $ +# $FML: MTAControl.pm,v 1.2 2002/04/24 04:35:38 fukachan Exp $ # package FML::MTAControl; @@ -27,18 +27,31 @@ FML::MTAControl - postfix utilities =head1 METHODS +=head2 new($args) + + $args = { + mta_type => 'postfix', + }; + +C<postfix> as C<mta_type> is available now. + =cut -# Descriptions: standard constructor -# Arguments: OBJ($self) +# Descriptions: ordinary constructor +# Arguments: OBJ($self) HASH_REF($args) # Side Effects: none # Return Value: OBJ sub new { - my ($self) = @_; + my ($self, $args) = @_; my ($type) = ref($self) || $self; my $me = {}; + + # default values + $me->{ mta_type } = + defined $args->{ mta_type } ? $args->{ mta_type } : 'postfix'; + return bless $me, $type; } @@ -50,7 +63,9 @@ sub new sub update_alias { my ($self, $curproc, $optargs) = @_; - my $mta_type = $optargs->{ mta_type }; + my $mta_type = + defined $optargs->{ mta_type } ? $optargs->{ mta_type } : + $self->{ mta_type }; if ($mta_type eq 'postfix') { $self->postfix_update_alias($curproc, $optargs); @@ -85,7 +100,9 @@ sub postfix_update_alias sub find_key_in_alias { my ($self, $curproc, $optargs) = @_; - my $mta_type = $optargs->{ mta_type }; + my $mta_type = + defined $optargs->{ mta_type } ? $optargs->{ mta_type } : + $self->{ mta_type }; my $key = $optargs->{ key }; if ($mta_type eq 'postfix') { @@ -97,6 +114,26 @@ sub find_key_in_alias } +# Descriptions: find key +# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs) +# Side Effects: none +# Return Value: none +sub get_aliases_as_hash_ref +{ + my ($self, $curproc, $optargs) = @_; + my $mta_type = + defined $optargs->{ mta_type } ? $optargs->{ mta_type } : + $self->{ mta_type }; + + if ($mta_type eq 'postfix') { + $self->postfix_get_aliases_as_hash_ref($curproc, $optargs); + } + else { + croak("unknown MTA"); + } +} + + # Descriptions: find key in aliases # Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs) # Side Effects: none @@ -127,6 +164,55 @@ sub postfix_find_key_in_alias } +# Descriptions: get { key => value } in aliases +# Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs) +# Side Effects: none +# Return Value: HASH_REF +sub postfix_get_aliases_as_hash_ref +{ + my ($self, $curproc, $optargs) = @_; + my $config = $curproc->{ config }; + my $alias_file = $config->{ mail_aliases_file }; + my $key = $optargs->{ key }; + my $mode = $optargs->{ mode }; + my $maps = $self->postfix_alias_maps($curproc, $optargs); + my $aliases = {}; + + # $0 -n shows fml only aliases + if ($mode eq 'fmlonly') { + $maps = [ $alias_file ]; + } + + for my $map (@$maps) { + print STDERR "scan key = $key, map = $map\n" if $debug; + + use FileHandle; + my $fh = new FileHandle $map; + if (defined $fh) { + my ($key, $value); + + LINE: + while (<$fh>) { + next LINE if /^#/; + next LINE if /^\s*$/; + + chomp; + ($key, $value) = split(/:/, $_, 2); + $value =~ s/^\s*//; + $value =~ s/s*$//; + $aliases->{ $key } = $value; + } + } + else { + warn("cannot open $map"); + } + $fh->close; + } + + return $aliases; +} + + # Descriptions: return alias_maps as ARRAY_REF # Arguments: OBJ($self) HASH_REF($curproc) HASH_REF($optargs) # Side Effects: none |
