/[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 29 by dpavlin, Mon May 16 20:58:44 2005 UTC revision 32 by dpavlin, Mon May 16 22:32:58 2005 UTC
# Line 76  sub new { Line 76  sub new {
76          $self ? return $self : return undef;          $self ? return $self : return undef;
77  }  }
78    
79    
80  =head2 add_member_to_list  =head2 add_member_to_list
81    
82  Add new member to list  Add new member to list
# Line 97  sub add_member_to_list { Line 98  sub add_member_to_list {
98    
99          my $arg = {@_};          my $arg = {@_};
100    
101          my $email = $arg->{'email'} || confess "can't add user without e-mail";          my $email = $arg->{'email'} || croak "can't add user without e-mail";
102          my $name = $arg->{'name'} || '';          my $name = $arg->{'name'} || '';
103          confess "need list name" unless ($arg->{'list'});          my $list_name = $arg->{'list'} || croak "need list name";
104    
105            my $list = $self->_get_list($list_name) || croak "list $list_name doesn't exist";
106    
107          if (! Email::Valid->address($email)) {          if (! Email::Valid->address($email)) {
108                  carp "SKIPPING $name <$email>\n" if ($self->{'verbose'});                  carp "SKIPPING $name <$email>\n" if ($self->{'verbose'});
# Line 108  sub add_member_to_list { Line 111  sub add_member_to_list {
111    
112          carp "# $name <$email>\n" if ($self->{'verbose'});          carp "# $name <$email>\n" if ($self->{'verbose'});
113    
         my $lists = $self->{'loader'}->find_class('lists');  
114          my $users = $self->{'loader'}->find_class('users');          my $users = $self->{'loader'}->find_class('users');
115          my $user_list = $self->{'loader'}->find_class('user_list');          my $user_list = $self->{'loader'}->find_class('user_list');
116    
         my $list = $lists->find_or_create({  
                 name => $arg->{'list'},  
         }) || croak "can't add list ",$arg->{'list'},"\n";  
           
117          my $this_user = $users->find_or_create({          my $this_user = $users->find_or_create({
118                  email => $email,                  email => $email,
119                  full_name => $name,                  full_name => $name,
# Line 158  sub add_message_to_list { Line 156  sub add_message_to_list {
156          my $list_name = $args->{'list'} || confess "need list name";          my $list_name = $args->{'list'} || confess "need list name";
157          my $message_text = $args->{'message'} || croak "need message";          my $message_text = $args->{'message'} || croak "need message";
158    
         warn Dumper($message_text);  
   
159          my $m = Email::Simple->new($message_text) || croak "can't parse message";          my $m = Email::Simple->new($message_text) || croak "can't parse message";
160    
161          croak "message doesn't have Subject header\n" unless( $m->header('Subject') );          unless( $m->header('Subject') ) {
162                    warn "message doesn't have Subject header\n";
163                    return;
164            }
165    
166          my $lists = $self->{'loader'}->find_class('lists');          my $lists = $self->{'loader'}->find_class('lists');
167    
# Line 225  sub send_queued_messages { Line 224  sub send_queued_messages {
224                  print "sending message ",$m->message_id," enqueued on ",$m->date," to list ",$m->list_id->name,"\n";                  print "sending message ",$m->message_id," enqueued on ",$m->date," to list ",$m->list_id->name,"\n";
225                  my $msg = $m->message_id->message;                  my $msg = $m->message_id->message;
226    
                 my $auth = Email::Auth::AddressHash->new(  
                         $m->list_id->name,      # secret  
                         10,                     # hashlen  
                 );  
   
227                  foreach my $u ($user_list->search(list_id => $m->list_id)) {                  foreach my $u ($user_list->search(list_id => $m->list_id)) {
228    
229                          my $to_email = $u->user_id->email;                          my $to_email = $u->user_id->email;
230    
231                            my ($from,$domain) = split(/@/, $u->list_id->email, 2);
232    
233                          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 )) {
234                                  print "SKIP $to_email message allready sent\n";                                  print "SKIP $to_email message allready sent\n";
235                          } else {                          } else {
236                                  print "\t$to_email\n";                                  print "=> $to_email\n";
237    
238                                    my $secret = $m->list_id->name . " " . $u->user_id->email . " " . $m->message_id;
239                                    my $auth = Email::Auth::AddressHash->new( $secret, 10 );
240    
241                                  my $hash = $auth->generate_hash( $to_email );                                  my $hash = $auth->generate_hash( $to_email );
242    
243                                  my $from = $u->list_id->name . " <" . $u->list_id->email . "+" . $hash . ">";                                  my $from = $u->list_id->name . " <" . $from . "+" . $hash . ( $domain ? "@" . $domain : '' ). ">";
244                                  my $to = $u->user_id->full_name . " <$to_email>";                                  my $to = $u->user_id->full_name . " <$to_email>";
245    
246                                  my $m = Email::Simple->new($msg) || croak "can't parse message";                                  my $m_obj = Email::Simple->new($msg) || croak "can't parse message";
247    
248                                  print Dumper($m);                                  $m_obj->header_set('From', $from) || croak "can't set From: header";
249                                    $m_obj->header_set('To', $to) || croak "can't set To: header";
                                 $m->header_set('From', $from) || croak "can't set From: header";  
                                 $m->header_set('To', $to) || croak "can't set To: header";  
250    
251                                  # FIXME do real sending :-)                                  # FIXME do real sending :-)
252                                  send IO => $m->as_string;                                  send IO => $m_obj->as_string;
253    
254                                  $sent->create({                                  $sent->create({
255                                          message_id => $m->message_id,                                          message_id => $m->message_id,
# Line 286  sub inbox_message { Line 283  sub inbox_message {
283  }  }
284    
285    
286    =head1 INTERNAL METHODS
287    
288    Beware of dragons! You shouldn't need to call those methods directly.
289    
290    =head2 _add_list
291    
292    Create new list
293    
294     my $list_obj = $nos->_add_list(
295            list => 'My list',
296            email => 'my-list@example.com',
297     );
298    
299    Returns C<Class::DBI> object for created list.
300    
301    =cut
302    
303    sub _add_list {
304            my $self = shift;
305    
306            my $arg = {@_};
307    
308            my $name = $arg->{'list'} || confess "can't add list without name";
309            my $email = $arg->{'email'} || confess "can't add list without e-mail";
310    
311            my $lists = $self->{'loader'}->find_class('lists');
312    
313            my $l = $lists->find_or_create({
314                    name => $name,
315                    email => $email,
316            });
317            
318            croak "can't add list $name\n" unless ($l);
319    
320            $l->dbi_commit;
321    
322            return $l;
323    
324    }
325    
326    
327    =head2 _get_list
328    
329    Get list C<Class::DBI> object.
330    
331     my $list_obj = $nos->check_list('My list');
332    
333    Returns false on failure.
334    
335    =cut
336    
337    sub _get_list {
338            my $self = shift;
339    
340            my $name = shift || return;
341    
342            my $lists = $self->{'loader'}->find_class('lists') || confess "can't find lists class";
343    
344            return $lists->search({ name => $name })->first;
345    }
346    
347    
348  =head1 EXPORT  =head1 EXPORT
349    
350  Nothing.  Nothing.

Legend:
Removed from v.29  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26