--- trunk/Nos.pm 2005/05/17 15:05:57 35 +++ trunk/Nos.pm 2005/05/17 17:49:14 36 @@ -24,6 +24,7 @@ use Carp; use Email::Auth::AddressHash; use Email::Simple; +use Email::Address; use Data::Dumper; =head1 NAME @@ -51,8 +52,12 @@ passwd => '', debug => 1, verbose => 1, + hash_len => 8, ); +Parametar C defined length of hash which will be added to each +outgoing e-mail message. + =cut sub new { @@ -73,6 +78,8 @@ relationships => 1, ) || croak "can't init Class::DBI::Loader"; + $self->{'hash_len'} ||= 8; + $self ? return $self : return undef; } @@ -170,8 +177,7 @@ $nos->add_message_to_list( list => 'My list', - message => 'From: My list - To: John A. Doe + message => 'Subject: welcome to list This is example message ', @@ -179,6 +185,10 @@ On success returns ID of newly created (or existing) message. +Only required header in e-mail is C. C and C headers +will be automatically generated, but if you want to use own headers, just +include them in messages. + =cut sub add_message_to_list { @@ -269,7 +279,7 @@ print "=> $to_email\n"; my $secret = $m->list_id->name . " " . $u->user_id->email . " " . $m->message_id; - my $auth = Email::Auth::AddressHash->new( $secret, 10 ); + my $auth = Email::Auth::AddressHash->new( $secret, $self->{'hash_len'} ); my $hash = $auth->generate_hash( $to_email ); @@ -287,6 +297,7 @@ $sent->create({ message_id => $m->message_id, user_id => $u->user_id, + hash => $hash, }); $sent->dbi_commit; } @@ -302,17 +313,50 @@ Receive single message for list's inbox. - my $ok = $nos->inbox_message($message); + my $ok = $nos->inbox_message( + list => 'My list', + message => $message, + ); =cut sub inbox_message { my $self = shift; - my $message = shift || return; + my $arg = {@_}; + + return unless ($arg->{'message'}); + croak "need list name" unless ($arg->{'list'}); + + 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"; + + my @addrs = Email::Address->parse( $to ); + + die "can't parse To: $to address\n" unless (@addrs); + + my $hl = $self->{'hash_len'} || confess "no hash_len?"; + + my $hash; + + foreach my $a (@addrs) { + if ($a->address =~ m/\+([a-f0-9]{$hl})@/) { + $hash = $1; + last; + } + } + + croak "can't find hash in e-mail $to\n" unless ($hash); + + 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 $m = new Email::Simple->new($message); +print "message_id: $message_id\n"; + warn "inbox is not yet implemented"; }