/[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 23 by dpavlin, Sun May 15 22:12:31 2005 UTC revision 27 by dpavlin, Mon May 16 16:25:14 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.1';  our $VERSION = '0.2';
20    
21  use Class::DBI::Loader;  use Class::DBI::Loader;
22  use Email::Valid;  use Email::Valid;
# Line 85  Add new member to list Line 85  Add new member to list
85    
86  C<name> parametar is optional.  C<name> parametar is optional.
87    
88  Return true if user is added.  Return member ID if user is added.
89    
90  =cut  =cut
91    
# Line 103  sub add_member_to_list { Line 103  sub add_member_to_list {
103                  return 0;                  return 0;
104          }          }
105    
106          print "# $name <$email>\n";          print STDERR "# $name <$email>\n";
107    
108          my $lists = $self->{'loader'}->find_class('lists');          my $lists = $self->{'loader'}->find_class('lists');
109          my $users = $self->{'loader'}->find_class('users');          my $users = $self->{'loader'}->find_class('users');
# Line 127  sub add_member_to_list { Line 127  sub add_member_to_list {
127          $this_user->dbi_commit;          $this_user->dbi_commit;
128          $user_on_list->dbi_commit;          $user_on_list->dbi_commit;
129    
130          return 1;          return $this_user->id;
131  }  }
132    
133    =head2 add_message_to_queue
134    
135    Adds message to one list's queue for later sending.
136    
137     $nos->add_message_to_queue(
138            list => 'My list',
139            message => 'From: My list <mylist@example.com>
140     To: John A. Doe <john.doe@example.com>
141    
142     This is example message
143     ',
144     );    
145    
146    On success returns ID of newly created (or existing) message.
147    
148    =cut
149    
150    sub add_message_to_queue {
151            my $self = shift;
152    
153            my $args = {@_};
154    
155            my $list_name = $args->{'list'} || confess "need list name";
156            my $message_text = $args->{'message'} || croak "need message";
157    
158            my $lists = $self->{'loader'}->find_class('lists');
159    
160            my $this_list = $lists->search(
161                    name => $list_name,
162            )->first || croak "can't find list $list_name";
163    
164            my $messages = $self->{'loader'}->find_class('messages');
165    
166            my $this_message = $messages->find_or_create({
167                    message => $message_text
168            }) || croak "can't insert message";
169    
170            $this_message->dbi_commit() || croak "can't add message";
171    
172            my $queue = $self->{'loader'}->find_class('queue');
173    
174            $queue->find_or_create({
175                    message_id => $this_message->id,
176                    list_id => $this_list->id,
177            }) || croak "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name;
178    
179            $queue->dbi_commit || croak "can't add message to list ",$this_list->name;
180    
181            return $this_message->id;
182    }
183    
184    
185  =head2 send_queued_messages  =head2 send_queued_messages
186    
187  Send queued messages or just ones for selected list  Send queued messages or just ones for selected list
188    
189   $noc->send_queued_messages("my list");   $nos->send_queued_messages("My list");
190    
191  =cut  =cut
192    
# Line 191  sub send_queued_messages { Line 243  sub send_queued_messages {
243    
244  }  }
245    
246  =head2 EXPORT  =head1 EXPORT
247    
248  None by default.  Nothing.
249    
250  =head1 SEE ALSO  =head1 SEE ALSO
251    
252  mailman, ezmlm, sympa, L<Mail::Salsa>  mailman, ezmlm, sympa, L<Mail::Salsa>
253    
254    
255  =head1 AUTHOR  =head1 AUTHOR
256    
257  Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt>  Dobrica Pavlinusic, E<lt>dpavlin@rot13.orgE<gt>
258    
259    
260  =head1 COPYRIGHT AND LICENSE  =head1 COPYRIGHT AND LICENSE
261    
262  Copyright (C) 2005 by Dobrica Pavlinusic  Copyright (C) 2005 by Dobrica Pavlinusic

Legend:
Removed from v.23  
changed lines
  Added in v.27

  ViewVC Help
Powered by ViewVC 1.1.26