/[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 52 by dpavlin, Wed May 25 15:03:10 2005 UTC revision 60 by dpavlin, Tue Jun 21 21:24:10 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.4';  our $VERSION = '0.5';
20    
21  use Class::DBI::Loader;  use Class::DBI::Loader;
22  use Email::Valid;  use Email::Valid;
# Line 26  use Email::Auth::AddressHash; Line 26  use Email::Auth::AddressHash;
26  use Email::Simple;  use Email::Simple;
27  use Email::Address;  use Email::Address;
28  use Mail::DeliveryStatus::BounceParser;  use Mail::DeliveryStatus::BounceParser;
29    use Class::DBI::AbstractSearch;
30    
31    
32  =head1 NAME  =head1 NAME
# Line 39  Nos - Notice Sender core module Line 40  Nos - Notice Sender core module
40    
41  =head1 DESCRIPTION  =head1 DESCRIPTION
42    
43  Core module for notice sender's functionality.  Notice sender is mail handler. It is not MTA, since it doesn't know how to
44    receive e-mails or send them directly to other hosts. It is not mail list
45    manager because it requires programming to add list members and send
46    messages. You can think of it as mechanisam for off-loading your e-mail
47    sending to remote server using SOAP service.
48    
49    It's concept is based around B<lists>. Each list can have zero or more
50    B<members>. Each list can have zero or more B<messages>.
51    
52    Here comes a twist: each outgoing message will have unique e-mail generated,
53    so Notice Sender will be able to link received replies (or bounces) with
54    outgoing messages.
55    
56    It doesn't do much more than that. It B<can't> create MIME encoded e-mail,
57    send attachments, handle 8-bit characters in headers (which have to be
58    encoded) or anything else.
59    
60    It will just queue your e-mail message to particular list (sending it to
61    possibly remote Notice Sender SOAP server just once), send it out at
62    reasonable rate (so that it doesn't flood your e-mail infrastructure) and
63    track replies.
64    
65    It is best used to send smaller number of messages to more-or-less fixed
66    list of recipients while allowing individual responses to be examined.
67    Tipical use include replacing php e-mail sending code with SOAP call to
68    Notice Sender. It does support additional C<ext_id> field for each member
69    which can be used to track some unique identifier from remote system for
70    particular user.
71    
72    It comes with command-line utility C<sender.pl> which can be used to perform
73    all available operation from scripts (see C<perldoc sender.pl>).
74    This command is also useful for debugging while writing client SOAP
75    application.
76    
77  =head1 METHODS  =head1 METHODS
78    
# Line 74  sub new { Line 107  sub new {
107                  user            => $self->{'user'},                  user            => $self->{'user'},
108                  password        => $self->{'passwd'},                  password        => $self->{'passwd'},
109                  namespace       => "Nos",                  namespace       => "Nos",
110  #               additional_classes      => qw/Class::DBI::AbstractSearch/,                  additional_classes      => qw/Class::DBI::AbstractSearch/,
111  #               additional_base_classes => qw/My::Stuff/,  #               additional_base_classes => qw/My::Stuff/,
112                  relationships   => 1,                  relationships   => 1,
113          ) || croak "can't init Class::DBI::Loader";          ) || croak "can't init Class::DBI::Loader";
# Line 98  C<email> address. Line 131  C<email> address.
131    
132  Returns ID of newly created list.  Returns ID of newly created list.
133    
134  Calls internally L<_add_list>, see details there.  Calls internally C<_add_list>, see details there.
135    
136  =cut  =cut
137    
# Line 129  Add new member to list Line 162  Add new member to list
162          list => "My list",          list => "My list",
163          email => "john.doe@example.com",          email => "john.doe@example.com",
164          name => "John A. Doe",          name => "John A. Doe",
165            ext_id => 42,
166   );   );
167    
168  C<name> parametar is optional.  C<name> and C<ext_id> parametars are optional.
169    
170  Return member ID if user is added.  Return member ID if user is added.
171    
# Line 145  sub add_member_to_list { Line 179  sub add_member_to_list {
179          my $email = lc($arg->{'email'}) || croak "can't add user without e-mail";          my $email = lc($arg->{'email'}) || croak "can't add user without e-mail";
180          my $name = $arg->{'name'} || '';          my $name = $arg->{'name'} || '';
181          my $list_name = lc($arg->{'list'}) || croak "need list name";          my $list_name = lc($arg->{'list'}) || croak "need list name";
182            my $ext_id = $arg->{'ext_id'};
183    
184          my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";          my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";
185    
# Line 167  sub add_member_to_list { Line 202  sub add_member_to_list {
202                  $this_user->update;                  $this_user->update;
203          }          }
204    
205            if (defined($ext_id) && ($this_user->ext_id || '') ne $ext_id) {
206                    $this_user->ext_id($ext_id);
207                    $this_user->update;
208            }
209    
210          my $user_on_list = $user_list->find_or_create({          my $user_on_list = $user_list->find_or_create({
211                  user_id => $this_user->id,                  user_id => $this_user->id,
212                  list_id => $list->id,                  list_id => $list->id,
# Line 194  Returns array of hashes with user inform Line 234  Returns array of hashes with user inform
234          email => 'dpavlin@rot13.org          email => 'dpavlin@rot13.org
235   }   }
236    
237  If list is not found, returns false.  If list is not found, returns false. If there is C<ext_id> in user data,
238    it will also be returned.
239    
240  =cut  =cut
241    
# Line 218  sub list_members { Line 259  sub list_members {
259                          email => $user_on_list->user_id->email,                          email => $user_on_list->user_id->email,
260                  };                  };
261    
262                    my $ext_id = $user_on_list->user_id->ext_id;
263                    $row->{'ext_id'} = $ext_id if (defined($ext_id));
264    
265                  push @results, $row;                  push @results, $row;
266          }          }
267    
# Line 240  Delete member from database. Line 284  Delete member from database.
284    
285  Returns false if user doesn't exist.  Returns false if user doesn't exist.
286    
287    This function will delete member from all lists (by cascading delete), so it
288    shouldn't be used lightly.
289    
290  =cut  =cut
291    
292  sub delete_member {  sub delete_member {
# Line 263  sub delete_member { Line 310  sub delete_member {
310          return $users->dbi_commit || croak "can't commit";          return $users->dbi_commit || croak "can't commit";
311  }  }
312    
313    =head2 delete_member_from_list
314    
315    Delete member from particular list.
316    
317     my $ok = delete_member_from_list(
318            list => 'My list',
319            email => 'dpavlin@rot13.org',
320     );
321    
322    Returns false if user doesn't exist on that particular list.
323    
324    It will die if list or user doesn't exist. You have been warned (you might
325    want to eval this functon to prevent it from croaking).
326    
327    =cut
328    
329    sub delete_member_from_list {
330            my $self = shift;
331    
332            my $args = {@_};
333    
334            croak "need list name and email of user to delete" unless ($args->{'list'} && $args->{'email'});
335    
336            $args->{'list'} = lc($args->{'list'});
337            $args->{'email'} = lc($args->{'email'});
338    
339            my $user = $self->{'loader'}->find_class('users');
340            my $list = $self->{'loader'}->find_class('lists');
341            my $user_list = $self->{'loader'}->find_class('user_list');
342    
343            my $this_user = $user->search( email => $args->{'email'} )->first || croak "can't find user: ".$args->{'email'};
344            my $this_list = $list->search( name => $args->{'list'} )->first || croak "can't find list: ".$args->{'list'};
345    
346            my $this_user_list = $user_list->search_where( list_id => $this_list->id, user_id => $this_list->id )->first || return;
347    
348            $this_user_list->delete || croak "can't delete user from list\n";
349    
350            return $user_list->dbi_commit || croak "can't commit";
351    }
352    
353  =head2 add_message_to_list  =head2 add_message_to_list
354    
355  Adds message to one list's queue for later sending.  Adds message to one list's queue for later sending.
# Line 463  Receive single message for list's inbox. Line 550  Receive single message for list's inbox.
550          message => $message,          message => $message,
551   );   );
552    
553    This method is used by C<sender.pl> when receiving e-mail messages.
554    
555  =cut  =cut
556    
557  sub inbox_message {  sub inbox_message {
# Line 661  sub new { Line 750  sub new {
750    
751   $message_id = NewList(   $message_id = NewList(
752          list => 'My list',          list => 'My list',
753            from => 'Name of my list',
754          email => 'my-list@example.com'          email => 'my-list@example.com'
755   );   );
756    
# Line 671  sub NewList { Line 761  sub NewList {
761    
762          if ($_[0] !~ m/^HASH/) {          if ($_[0] !~ m/^HASH/) {
763                  return $nos->new_list(                  return $nos->new_list(
764                          list => $_[0], email => $_[1],                          list => $_[0], from => $_[1], email => $_[2],
765                  );                  );
766          } else {          } else {
767                  return $nos->new_list( %{ shift @_ } );                  return $nos->new_list( %{ shift @_ } );
# Line 684  sub NewList { Line 774  sub NewList {
774   $member_id = AddMemberToList(   $member_id = AddMemberToList(
775          list => 'My list',          list => 'My list',
776          email => 'e-mail@example.com',          email => 'e-mail@example.com',
777          name => 'Full Name'          name => 'Full Name',
778            ext_id => 42,
779   );   );
780    
781  =cut  =cut
# Line 694  sub AddMemberToList { Line 785  sub AddMemberToList {
785    
786          if ($_[0] !~ m/^HASH/) {          if ($_[0] !~ m/^HASH/) {
787                  return $nos->add_member_to_list(                  return $nos->add_member_to_list(
788                          list => $_[0], email => $_[1], name => $_[2],                          list => $_[0], email => $_[1], name => $_[2], ext_id => $_[4],
789                  );                  );
790          } else {          } else {
791                  return $nos->add_member_to_list( %{ shift @_ } );                  return $nos->add_member_to_list( %{ shift @_ } );

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

  ViewVC Help
Powered by ViewVC 1.1.26