--- trunk/Nos.pm 2005/05/15 22:12:31 23 +++ trunk/Nos.pm 2005/05/16 16:25:14 27 @@ -16,7 +16,7 @@ our @EXPORT = qw( ); -our $VERSION = '0.1'; +our $VERSION = '0.2'; use Class::DBI::Loader; use Email::Valid; @@ -85,7 +85,7 @@ C parametar is optional. -Return true if user is added. +Return member ID if user is added. =cut @@ -103,7 +103,7 @@ return 0; } - print "# $name <$email>\n"; + print STDERR "# $name <$email>\n"; my $lists = $self->{'loader'}->find_class('lists'); my $users = $self->{'loader'}->find_class('users'); @@ -127,14 +127,66 @@ $this_user->dbi_commit; $user_on_list->dbi_commit; - return 1; + return $this_user->id; } +=head2 add_message_to_queue + +Adds message to one list's queue for later sending. + + $nos->add_message_to_queue( + list => 'My list', + message => 'From: My list + To: John A. Doe + + This is example message + ', + ); + +On success returns ID of newly created (or existing) message. + +=cut + +sub add_message_to_queue { + my $self = shift; + + my $args = {@_}; + + my $list_name = $args->{'list'} || confess "need list name"; + my $message_text = $args->{'message'} || croak "need message"; + + my $lists = $self->{'loader'}->find_class('lists'); + + my $this_list = $lists->search( + name => $list_name, + )->first || croak "can't find list $list_name"; + + my $messages = $self->{'loader'}->find_class('messages'); + + my $this_message = $messages->find_or_create({ + message => $message_text + }) || croak "can't insert message"; + + $this_message->dbi_commit() || croak "can't add message"; + + my $queue = $self->{'loader'}->find_class('queue'); + + $queue->find_or_create({ + message_id => $this_message->id, + list_id => $this_list->id, + }) || croak "can't add message ",$this_message->id," to list ",$this_list->id, ": ",$this_list->name; + + $queue->dbi_commit || croak "can't add message to list ",$this_list->name; + + return $this_message->id; +} + + =head2 send_queued_messages Send queued messages or just ones for selected list - $noc->send_queued_messages("my list"); + $nos->send_queued_messages("My list"); =cut @@ -191,18 +243,20 @@ } -=head2 EXPORT +=head1 EXPORT -None by default. +Nothing. =head1 SEE ALSO mailman, ezmlm, sympa, L + =head1 AUTHOR Dobrica Pavlinusic, Edpavlin@rot13.orgE + =head1 COPYRIGHT AND LICENSE Copyright (C) 2005 by Dobrica Pavlinusic