/[notice-sender]/trunk/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 /trunk/Nos.pm

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

revision 60 by dpavlin, Tue Jun 21 21:24:10 2005 UTC revision 65 by dpavlin, Wed Jun 29 17:05:30 2005 UTC
# Line 154  sub new_list { Line 154  sub new_list {
154  }  }
155    
156    
157    =head2 delete_list
158    
159    Delete list from database.
160    
161     my $ok = delete_list(
162            list => 'My list'
163     );
164    
165    Returns false if list doesn't exist.
166    
167    =cut
168    
169    sub delete_list {
170            my $self = shift;
171    
172            my $args = {@_};
173    
174            croak "need list to delete" unless ($args->{'list'});
175    
176            $args->{'list'} = lc($args->{'list'});
177    
178            my $lists = $self->{'loader'}->find_class('lists');
179    
180            my $this_list = $lists->search( name => $args->{'list'} )->first || return;
181    
182            $this_list->delete || croak "can't delete list\n";
183    
184            return $lists->dbi_commit || croak "can't commit";
185    }
186    
187    
188  =head2 add_member_to_list  =head2 add_member_to_list
189    
190  Add new member to list  Add new member to list
# Line 343  sub delete_member_from_list { Line 374  sub delete_member_from_list {
374          my $this_user = $user->search( email => $args->{'email'} )->first || croak "can't find user: ".$args->{'email'};          my $this_user = $user->search( email => $args->{'email'} )->first || croak "can't find user: ".$args->{'email'};
375          my $this_list = $list->search( name => $args->{'list'} )->first || croak "can't find list: ".$args->{'list'};          my $this_list = $list->search( name => $args->{'list'} )->first || croak "can't find list: ".$args->{'list'};
376    
377          my $this_user_list = $user_list->search_where( list_id => $this_list->id, user_id => $this_list->id )->first || return;          my $this_user_list = $user_list->search_where( list_id => $this_list->id, user_id => $this_user->id )->first || return;
378    
379          $this_user_list->delete || croak "can't delete user from list\n";          $this_user_list->delete || croak "can't delete user from list\n";
380    
# Line 489  sub send_queued_messages { Line 520  sub send_queued_messages {
520                          if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) {                          if ($sent->search( message_id => $m->message_id, user_id => $u->user_id )) {
521                                  print "SKIP $to_email message allready sent\n";                                  print "SKIP $to_email message allready sent\n";
522                          } else {                          } else {
523                                  print "=> $to_email\n";                                  print "=> $to_email ";
524    
525                                  my $secret = $m->list_id->name . " " . $u->user_id->email . " " . $m->message_id;                                  my $secret = $m->list_id->name . " " . $u->user_id->email . " " . $m->message_id;
526                                  my $auth = Email::Auth::AddressHash->new( $secret, $self->{'hash_len'} );                                  my $auth = Email::Auth::AddressHash->new( $secret, $self->{'hash_len'} );
# Line 515  sub send_queued_messages { Line 546  sub send_queued_messages {
546                                  $m_obj->header_set('X-Nos-Hash', $hash);                                  $m_obj->header_set('X-Nos-Hash', $hash);
547    
548                                  # really send e-mail                                  # really send e-mail
549                                    my $sent_status;
550    
551                                  if (@email_send_options) {                                  if (@email_send_options) {
552                                          send $email_send_driver => $m_obj->as_string, @email_send_options;                                          $sent_status = send $email_send_driver => $m_obj->as_string, @email_send_options;
553                                  } else {                                  } else {
554                                          send $email_send_driver => $m_obj->as_string;                                          $sent_status = send $email_send_driver => $m_obj->as_string;
555                                  }                                  }
556    
557                                  $sent->create({                                  croak "can't send e-mail: $sent_status\n\nOriginal e-mail follows:\n".$m_obj->as_string unless ($sent_status);
558                                          message_id => $m->message_id,                                  my @bad = @{ $sent_status->prop('bad') };
559                                          user_id => $u->user_id,                                  croak "failed sending to ",join(",",@bad) if (@bad);
560                                          hash => $hash,  
561                                  });                                  if ($sent_status) {
562                                  $sent->dbi_commit;  
563                                            $sent->create({
564                                                    message_id => $m->message_id,
565                                                    user_id => $u->user_id,
566                                                    hash => $hash,
567                                            });
568                                            $sent->dbi_commit;
569    
570                                            print " - $sent_status\n";
571    
572                                    } else {
573                                            warn "ERROR: $sent_status\n";
574                                    }
575    
576                                  if ($sleep) {                                  if ($sleep) {
577                                          warn "sleeping $sleep seconds\n";                                          warn "sleeping $sleep seconds\n";
# Line 769  sub NewList { Line 814  sub NewList {
814  }  }
815    
816    
817    =head2 DeleteList
818    
819     $ok = DeleteList(
820            list => 'My list',
821     );
822    
823    =cut
824    
825    sub DeleteList {
826            my $self = shift;
827    
828            if ($_[0] !~ m/^HASH/) {
829                    return $nos->delete_list(
830                            list => $_[0],
831                    );
832            } else {
833                    return $nos->delete_list( %{ shift @_ } );
834            }
835    }
836    
837  =head2 AddMemberToList  =head2 AddMemberToList
838    
839   $member_id = AddMemberToList(   $member_id = AddMemberToList(
# Line 801  sub AddMemberToList { Line 866  sub AddMemberToList {
866    
867  Returns array of hashes with user informations, see C<list_members>.  Returns array of hashes with user informations, see C<list_members>.
868    
869    Returning arrays from SOAP calls is somewhat fuzzy (at least to me). It
870    seems that SOAP::Lite client thinks that it has array with one element which
871    is array of hashes with data.
872    
873  =cut  =cut
874    
875  sub ListMembers {  sub ListMembers {
# Line 814  sub ListMembers { Line 883  sub ListMembers {
883                  $list_name = $_[0]->{'list'};                  $list_name = $_[0]->{'list'};
884          }          }
885    
886          return $nos->list_members( list => $list_name );          return [ $nos->list_members( list => $list_name ) ];
887  }  }
888    
889    
890    =head2 DeleteMemberFromList
891    
892     $member_id = DeleteMemberFromList(
893            list => 'My list',
894            email => 'e-mail@example.com',
895     );
896    
897    =cut
898    
899    sub DeleteMemberFromList {
900            my $self = shift;
901    
902            if ($_[0] !~ m/^HASH/) {
903                    return $nos->delete_member_from_list(
904                            list => $_[0], email => $_[1],
905                    );
906            } else {
907                    return $nos->delete_member_from_list( %{ shift @_ } );
908            }
909    }
910    
911    
912  =head2 AddMessageToList  =head2 AddMessageToList
913    
914   $message_id = AddMessageToList(   $message_id = AddMessageToList(

Legend:
Removed from v.60  
changed lines
  Added in v.65

  ViewVC Help
Powered by ViewVC 1.1.26