--- trunk/Nos.pm 2005/05/17 17:49:14 36 +++ trunk/Nos.pm 2005/05/17 19:15:27 37 @@ -25,6 +25,7 @@ use Email::Auth::AddressHash; use Email::Simple; use Email::Address; +use Mail::DeliveryStatus::BounceParser; use Data::Dumper; =head1 NAME @@ -328,6 +329,8 @@ return unless ($arg->{'message'}); croak "need list name" unless ($arg->{'list'}); + my $this_list = $self->_get_list($arg->{'list'}) || croak "can't find list ".$arg->{'list'}."\n"; + my $m = Email::Simple->new($arg->{'message'}) || croak "can't parse message"; my $to = $m->header('To') || die "can't find To: address in incomming message\n"; @@ -352,9 +355,37 @@ my $sent = $self->{'loader'}->find_class('sent'); # will use null if no matching message_id is found - my $message_id = $sent->search( hash => $hash )->first->message_id; + my $sent_msg = $sent->search( hash => $hash )->first; + + my ($message_id, $user_id) = (undef, undef); # init with NULL + + if ($sent_msg) { + $message_id = $sent_msg->message_id || carp "no message_id"; + $user_id = $sent_msg->user_id || carp "no user_id"; + } + +print "message_id: ",($message_id || "not found"),"\n"; + + my $is_bounce = 0; + + my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( + $arg->{'message'}, { report_non_bounces=>1 }, + ) }; + carp "can't check if this message is bounce!" if ($@); + + $is_bounce++ if ($bounce && $bounce->is_bounce); + + my $received = $self->{'loader'}->find_class('received'); + + my $this_received = $received->find_or_create({ + user_id => $user_id, + list_id => $this_list->id, + message_id => $message_id, + message => $arg->{'message'}, + bounced => $is_bounce, + }) || croak "can't insert received message"; -print "message_id: $message_id\n"; + $this_received->dbi_commit; warn "inbox is not yet implemented"; }