/[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 45 by dpavlin, Wed May 18 13:12:54 2005 UTC revision 47 by dpavlin, Tue May 24 14:02:05 2005 UTC
# Line 28  use Email::Address; Line 28  use Email::Address;
28  use Mail::DeliveryStatus::BounceParser;  use Mail::DeliveryStatus::BounceParser;
29  use Data::Dumper;  use Data::Dumper;
30    
31    my $email_send_driver = 'Email::Send::IO';
32    my @email_send_options;
33    
34    #$email_send_driver = 'Sendmail';
35    
36    
37  =head1 NAME  =head1 NAME
38    
39  Nos - Notice Sender core module  Nos - Notice Sender core module
# Line 92  C<email> address. Line 98  C<email> address.
98    
99   $nos->new_list(   $nos->new_list(
100          list => 'My list',          list => 'My list',
101            from => 'Outgoing from comment',
102          email => 'my-list@example.com',          email => 'my-list@example.com',
103   );   );
104    
# Line 325  sub add_message_to_list { Line 332  sub add_message_to_list {
332    
333  Send queued messages or just ones for selected list  Send queued messages or just ones for selected list
334    
335   $nos->send_queued_messages("My list");   $nos->send_queued_messages("My list",'smtp');
336    
337    Second option is driver which will be used for e-mail delivery. If not
338    specified, C<IO> driver will be used which will dump e-mail to C<STDERR>.
339    
340    Other valid drivers are:
341    
342    =over 10
343    
344    =item smtp
345    
346    Send e-mail using SMTP server at 127.0.0.1
347    
348    =back
349    
350  =cut  =cut
351    
# Line 334  sub send_queued_messages { Line 354  sub send_queued_messages {
354    
355          my $list_name = shift;          my $list_name = shift;
356    
357            my $driver = shift || '';
358    
359            if (lc($driver) eq 'smtp') {
360                    $email_send_driver = 'Email::Send::SMTP';
361                    @email_send_options = ['127.0.0.1'];
362            }
363            warn "using $driver [$email_send_driver]\n";
364    
365          my $lists = $self->{'loader'}->find_class('lists');          my $lists = $self->{'loader'}->find_class('lists');
366          my $queue = $self->{'loader'}->find_class('queue');          my $queue = $self->{'loader'}->find_class('queue');
367          my $user_list = $self->{'loader'}->find_class('user_list');          my $user_list = $self->{'loader'}->find_class('user_list');
# Line 371  sub send_queued_messages { Line 399  sub send_queued_messages {
399    
400                                  my $hash = $auth->generate_hash( $to_email );                                  my $hash = $auth->generate_hash( $to_email );
401    
402                                  my $from = $u->list_id->name . " <" . $from . "+" . $hash . ( $domain ? "@" . $domain : '' ). ">";                                  my $from_addr;
403                                  my $to = $u->user_id->name . " <$to_email>";                                  my $from_email_only = $from . "+" . $hash . ( $domain ? '@' . $domain : '');
404                                    $from_addr .= '"' . $u->list_id->from_addr . '" ' if ($u->list_id->from_addr);
405                                    $from_addr .= '<' . $from_email_only . '>';
406                                    my $to = '"' . $u->user_id->name . '" <' . $to_email . '>';
407    
408                                  my $m_obj = Email::Simple->new($msg) || croak "can't parse message";                                  my $m_obj = Email::Simple->new($msg) || croak "can't parse message";
409    
410                                  $m_obj->header_set('From', $from) || croak "can't set From: header";                                  $m_obj->header_set('Return-Path', $from_email_only) || croak "can't set Return-Path: header";
411                                    $m_obj->header_set('Sender', $from_email_only) || croak "can't set Return-Path: header";
412                                    $m_obj->header_set('Errors-To', $from_email_only) || croak "can't set Return-Path: header";
413                                    $m_obj->header_set('From', $from_addr) || croak "can't set From: header";
414                                  $m_obj->header_set('To', $to) || croak "can't set To: header";                                  $m_obj->header_set('To', $to) || croak "can't set To: header";
415    
416                                  $m_obj->header_set('X-Nos-Version', $VERSION);                                  $m_obj->header_set('X-Nos-Version', $VERSION);
417                                  $m_obj->header_set('X-Nos-Hash', $hash);                                  $m_obj->header_set('X-Nos-Hash', $hash);
418    
419                                  # FIXME do real sending :-)                                  # really send e-mail
420                                  send IO => $m_obj->as_string;                                  if (@email_send_options) {
421                                            send $email_send_driver => $m_obj->as_string, @email_send_options;
422                                    } else {
423                                            send $email_send_driver => $m_obj->as_string;
424                                    }
425    
426                                  $sent->create({                                  $sent->create({
427                                          message_id => $m->message_id,                                          message_id => $m->message_id,
# Line 452  sub inbox_message { Line 490  sub inbox_message {
490          if ($sent_msg) {          if ($sent_msg) {
491                  $message_id = $sent_msg->message_id || carp "no message_id";                  $message_id = $sent_msg->message_id || carp "no message_id";
492                  $user_id = $sent_msg->user_id || carp "no user_id";                  $user_id = $sent_msg->user_id || carp "no user_id";
493            } else {
494                    warn "can't find sender with hash $hash\n";
495          }          }
496    
497    
498          my $is_bounce = 0;          my $is_bounce = 0;
499    
500          my $bounce = eval { Mail::DeliveryStatus::BounceParser->new(          {
501                  $arg->{'message'}, { report_non_bounces=>1 },                  no warnings;
502          ) };                  my $bounce = eval { Mail::DeliveryStatus::BounceParser->new(
503          carp "can't check if this message is bounce!" if ($@);                          $arg->{'message'}, { report_non_bounces=>1 },
504                    ) };
505          $is_bounce++ if ($bounce && $bounce->is_bounce);                  carp "can't check if this message is bounce!" if ($@);
506            
507                    $is_bounce++ if ($bounce && $bounce->is_bounce);
508            }
509    
510          my $received = $self->{'loader'}->find_class('received');          my $received = $self->{'loader'}->find_class('received');
511    
# Line 493  Create new list Line 536  Create new list
536    
537   my $list_obj = $nos->_add_list(   my $list_obj = $nos->_add_list(
538          list => 'My list',          list => 'My list',
539            from => 'Outgoing from comment',
540          email => 'my-list@example.com',          email => 'my-list@example.com',
541   );   );
542    
# Line 512  sub _add_list { Line 556  sub _add_list {
556    
557          my $name = $arg->{'list'} || confess "can't add list without name";          my $name = $arg->{'list'} || confess "can't add list without name";
558          my $email = $arg->{'email'} || confess "can't add list without e-mail";          my $email = $arg->{'email'} || confess "can't add list without e-mail";
559            my $from_addr = $arg->{'from'};
560    
561          my $lists = $self->{'loader'}->find_class('lists');          my $lists = $self->{'loader'}->find_class('lists');
562    
# Line 519  sub _add_list { Line 564  sub _add_list {
564                  name => $name,                  name => $name,
565                  email => $email,                  email => $email,
566          });          });
567            
568          croak "can't add list $name\n" unless ($l);          croak "can't add list $name\n" unless ($l);
569    
570            if ($from_addr && $l->from_addr ne $from_addr) {
571                    $l->from_addr($from_addr);
572                    $l->update;
573            }
574    
575          $l->dbi_commit;          $l->dbi_commit;
576    
577          return $l;          return $l;

Legend:
Removed from v.45  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.26