/[notice-sender]/jifty-dbi/lib/Nos.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /jifty-dbi/lib/Nos.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 66 by dpavlin, Fri Jul 8 11:46:35 2005 UTC revision 68 by dpavlin, Mon Aug 1 08:59:36 2005 UTC
# Line 16  our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all' Line 16  our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'
16  our @EXPORT = qw(  our @EXPORT = qw(
17  );  );
18    
19  our $VERSION = '0.5';  our $VERSION = '0.6';
20    
21  use Class::DBI::Loader;  use Class::DBI::Loader;
22  use Email::Valid;  use Email::Valid;
# Line 122  sub new { Line 122  sub new {
122    
123  =head2 new_list  =head2 new_list
124    
125  Create new list. Required arguments are name of C<list> and  Create new list. Required arguments are name of C<list>, C<email> address
126  C<email> address.  and path to C<aliases> file.
127    
128   $nos->new_list(   $nos->new_list(
129          list => 'My list',          list => 'My list',
130          from => 'Outgoing from comment',          from => 'Outgoing from comment',
131          email => 'my-list@example.com',          email => 'my-list@example.com',
132            aliases => '/etc/mail/mylist',
133            archive => '/path/to/mbox/archive',
134   );   );
135    
136  Returns ID of newly created list.  Returns ID of newly created list.
# Line 692  Beware of dragons! You shouldn't need to Line 694  Beware of dragons! You shouldn't need to
694    
695  =head2 _add_aliases  =head2 _add_aliases
696    
697  Add new list to C</etc/aliases> (or equivavlent) file  Add or update alias in C</etc/aliases> (or equivavlent) file for selected list
698    
699   my $ok = $nos->add_aliases(   my $ok = $nos->add_aliases(
700          list => 'My list',          list => 'My list',
# Line 713  sub _add_aliases { Line 715  sub _add_aliases {
715    
716          my $arg = {@_};          my $arg = {@_};
717    
718          croak "need list and email options" unless ($arg->{'list'} && $arg->{'email'});          foreach my $o (qw/list email aliases/) {
719                    croak "need $o option" unless ($arg->{$o});
720            }
721    
722          my $aliases = $arg->{'aliases'} || croak "need aliases";          my $aliases = $arg->{'aliases'};
723            my $email = $arg->{'email'};
724            my $list = $arg->{'list'};
725    
726          unless (-e $aliases) {          unless (-e $aliases) {
727                  warn "aliases file $aliases doesn't exist, creating empty\n";                  warn "aliases file $aliases doesn't exist, creating empty\n";
728                  open(my $fh, '>', $aliases) || croak "can't create $aliases: $!";                  open(my $fh, '>', $aliases) || croak "can't create $aliases: $!";
729                  close($fh);                  close($fh);
730                    chmod 0777, $aliases || warn "can't change permission to 0777";
731          }          }
732    
733          my $a = new Mail::Alias($aliases) || croak "can't open aliases file $aliases: $!";          my $a = new Mail::Alias($aliases) || croak "can't open aliases file $aliases: $!";
# Line 744  sub _add_aliases { Line 751  sub _add_aliases {
751          $self_path =~ s#/[^/]+$##;          $self_path =~ s#/[^/]+$##;
752          $self_path =~ s#/t/*$#/#;          $self_path =~ s#/t/*$#/#;
753    
754          $target .= qq#| cd $self_path && ./sender.pl --inbox="$arg->{'list'}"#;          $target .= qq#| cd $self_path && ./sender.pl --inbox="$list"#;
755    
756          unless ($a->append($arg->{'email'}, $target)) {          if ($a->exists($email)) {
757                  croak "can't add alias ".$a->error_check;                  $a->update($email, $target) or croak "can't update alias ".$a->error_check;
758            } else {
759                    $a->append($email, $target) or croak "can't add alias ".$a->error_check;
760          }          }
761    
762          return 1;          return 1;
# Line 790  sub _add_list { Line 799  sub _add_list {
799                  list => $name,                  list => $name,
800                  email => $email,                  email => $email,
801                  aliases => $aliases,                  aliases => $aliases,
802          ) || croak "can't add alias $email for list $name";          ) || warn "can't add alias $email for list $name";
803    
804          my $l = $lists->find_or_create({          my $l = $lists->find_or_create({
805                  name => $name,                  name => $name,
# Line 900  sub new { Line 909  sub new {
909  sub NewList {  sub NewList {
910          my $self = shift;          my $self = shift;
911    
912          my $aliases = $self->{'aliases'} || croak "Nos::SOAP need 'aliases' argument to new constructor";          my $aliases = $nos->{'aliases'} || croak "need 'aliases' argument to new constructor";
913    
914          if ($_[0] !~ m/^HASH/) {          if ($_[0] !~ m/^HASH/) {
915                  return $nos->new_list(                  return $nos->new_list(

Legend:
Removed from v.66  
changed lines
  Added in v.68

  ViewVC Help
Powered by ViewVC 1.1.26