--- trunk/Nos.pm 2005/06/29 17:05:30 65 +++ trunk/Nos.pm 2005/07/08 11:46:35 66 @@ -27,6 +27,8 @@ use Email::Address; use Mail::DeliveryStatus::BounceParser; use Class::DBI::AbstractSearch; +use Mail::Alias; +use Cwd qw(abs_path); =head1 NAME @@ -687,6 +689,70 @@ Beware of dragons! You shouldn't need to call those methods directly. + +=head2 _add_aliases + +Add new list to C (or equivavlent) file + + my $ok = $nos->add_aliases( + list => 'My list', + email => 'my-list@example.com', + aliases => '/etc/mail/mylist', + archive => '/path/to/mbox/archive', + + ); + +C parametar is optional. + +Return false on failure. + +=cut + +sub _add_aliases { + my $self = shift; + + my $arg = {@_}; + + croak "need list and email options" unless ($arg->{'list'} && $arg->{'email'}); + + my $aliases = $arg->{'aliases'} || croak "need aliases"; + + unless (-e $aliases) { + warn "aliases file $aliases doesn't exist, creating empty\n"; + open(my $fh, '>', $aliases) || croak "can't create $aliases: $!"; + close($fh); + } + + my $a = new Mail::Alias($aliases) || croak "can't open aliases file $aliases: $!"; + + my $target = ''; + + if (my $archive = $arg->{'archive'}) { + $target .= "$archive, "; + + if (! -e $archive) { + warn "please make sure that file $archive is writable for your e-mail user (defaulting to bad 777 permission for now)"; + + open(my $fh, '>', $archive) || croak "can't create archive file $archive: $!"; + close($fh); + chmod 0777, $archive || croak "can't chmod archive file $archive to 0777: $!"; + } + } + + # resolve my path to absolute one + my $self_path = abs_path($0); + $self_path =~ s#/[^/]+$##; + $self_path =~ s#/t/*$#/#; + + $target .= qq#| cd $self_path && ./sender.pl --inbox="$arg->{'list'}"#; + + unless ($a->append($arg->{'email'}, $target)) { + croak "can't add alias ".$a->error_check; + } + + return 1; +} + =head2 _add_list Create new list @@ -695,6 +761,7 @@ list => 'My list', from => 'Outgoing from comment', email => 'my-list@example.com', + aliases => '/etc/mail/mylist', ); Returns C object for created list. @@ -713,10 +780,18 @@ my $name = lc($arg->{'list'}) || confess "can't add list without name"; my $email = lc($arg->{'email'}) || confess "can't add list without e-mail"; + my $aliases = lc($arg->{'aliases'}) || confess "can't add list without path to aliases file"; + my $from_addr = $arg->{'from'}; my $lists = $self->{'loader'}->find_class('lists'); + $self->_add_aliases( + list => $name, + email => $email, + aliases => $aliases, + ) || croak "can't add alias $email for list $name"; + my $l = $lists->find_or_create({ name => $name, email => $email, @@ -736,6 +811,7 @@ } + =head2 _get_list Get list C object. @@ -780,9 +856,29 @@ my $nos; + +=head2 new + +Create new SOAP object + + my $soap = new Nos::SOAP( + dsn => 'dbi:Pg:dbname=notices', + user => 'dpavlin', + passwd => '', + debug => 1, + verbose => 1, + hash_len => 8, + aliases => '/etc/aliases', + ); + +=cut + sub new { my $class = shift; my $self = {@_}; + + croak "need aliases parametar" unless ($self->{'aliases'}); + bless($self, $class); $nos = new Nos( @_ ) || die "can't create Nos object"; @@ -804,12 +900,15 @@ sub NewList { my $self = shift; + my $aliases = $self->{'aliases'} || croak "Nos::SOAP need 'aliases' argument to new constructor"; + if ($_[0] !~ m/^HASH/) { return $nos->new_list( list => $_[0], from => $_[1], email => $_[2], + aliases => $aliases, ); } else { - return $nos->new_list( %{ shift @_ } ); + return $nos->new_list( %{ shift @_ }, aliases => $aliases ); } }