rev 1811 - in branches/Email-Store-Readonly/Email-Store: lib/Email/Store t

[prev] [thread] [next] [lurker] [Date index for 2005/02/04]

From: richardc
Subject: rev 1811 - in branches/Email-Store-Readonly/Email-Store: lib/Email/Store t
Date: 04:26 on 04 Feb 2005
Author: richardc
Date: 2005-02-04 04:26:32 +0000 (Fri, 04 Feb 2005)
New Revision: 1811

Modified:
   branches/Email-Store-Readonly/Email-Store/lib/Email/Store/List.pm
   branches/Email-Store-Readonly/Email-Store/t/01basic.t
Log:
stop Email::Store::List munging the messages

Modified: branches/Email-Store-Readonly/Email-Store/lib/Email/Store/List.pm
===================================================================
--- branches/Email-Store-Readonly/Email-Store/lib/Email/Store/List.pm	2005-02-04 04:24:26 UTC (rev 1810)
+++ branches/Email-Store-Readonly/Email-Store/lib/Email/Store/List.pm	2005-02-04 04:26:32 UTC (rev 1811)
@@ -24,16 +24,12 @@
     my $list = $class->_detect($simple) or return;
     my $subject = $simple->header("Subject");
     my $name = $list->name;
-    if ($subject =~ s/\[\Q$name\E\]\s*//ig) {
-        $simple->header_set("Subject", $subject);
-        $mail->message($simple->as_string);
-        $mail->update;
-    }
-    $list->add_to_posts({mail => $mail->id});
+    $subject =~ s/\[\Q$name\E\]\s*//ig;
+    $list->add_to_posts({mail => $mail->id, subject => $subject});
 }
 
 sub on_seen_duplicate_order { 1 }
-sub on_seen_duplicate { 
+sub on_seen_duplicate {
     my ($class, $mail, $orig) = @_;
     my $new_list = $class->_detect($orig) or return;
     $new_list->add_to_posts({mail => $mail->id})
@@ -45,7 +41,7 @@
 package Email::Store::List::Post;
 use base 'Email::Store::DBI';
 Email::Store::List::Post->table("list_post");
-Email::Store::List::Post->columns(All => qw/id mail list/);
+Email::Store::List::Post->columns(All => qw/id mail list subject/);
 Email::Store::List::Post->columns(Primary => qw/id/);
 
 # Relationships
@@ -54,6 +50,15 @@
 Email::Store::List->has_many(posts => [ "Email::Store::List::Post" => "mail" ]);
 Email::Store::Mail->has_many(lists => [ "Email::Store::List::Post" => "list" ]);
 
+# XXX is there some Class::DBI magic for this?
+sub Email::Store::Mail::list_subject {
+    my $self = shift;
+    my ($post) = Email::Store::List::Post->search({mail => $self->id});
+    return $self->simple->header('subject') unless $post;
+    return $post->subject;
+}
+
+
 package Email::Store::List;
 1;
 
@@ -66,7 +71,7 @@
     # Look for cross-posts in perl6-internals
     my ($p6i) = Email::Store::List->search( name => "perl6-internals" );
     @mails = $p6i->posts;
-    
+
     for my $mail (@mails) {
         print "Mail ".$mail->message_id." cross-posted to ".$_->name."\n"
         for grep {$_ != $p6i} $mail->lists;
@@ -98,5 +103,6 @@
 CREATE TABLE IF NOT EXISTS list_post (
     id integer NOT NULL auto_increment primary key,
     list integer,
-    mail varchar(255)
+    mail varchar(255),
+    subject varchar(255)
 );

Modified: branches/Email-Store-Readonly/Email-Store/t/01basic.t
===================================================================
--- branches/Email-Store-Readonly/Email-Store/t/01basic.t	2005-02-04 04:24:26 UTC (rev 1810)
+++ branches/Email-Store-Readonly/Email-Store/t/01basic.t	2005-02-04 04:26:32 UTC (rev 1811)
@@ -1,4 +1,5 @@
-use Test::More tests => 20;
+# -*- cperl -*-
+use Test::More tests => 21;
 use File::Slurp;
 BEGIN { unlink("t/test.db"); }
 use Email::Store "dbi:SQLite:dbname=t/test.db";
@@ -19,8 +20,11 @@
 isa_ok($simple, "Email::Simple");
 is($simple, $mails[0]->simple, "Email::Simple objects should be singleton");
 
-# Subject munged correctly
-is($simple->header("Subject"), "ttree problems - the sequel", "Subject had relevant bits removed");
+# munged subject available as list_subject
+is($mails[0]->list_subject, "ttree problems - the sequel",
+   "list_subject has list bits removed");
+is($simple->header("Subject"), "[Templates] ttree problems - the sequel",
+   "actual subject line is unmunged");
 
 # And one list:
 my @lists = Email::Store::List->retrieve_all;
@@ -46,5 +50,5 @@
 # Dates:
 my $date;
 ok($date = $mails[0]->date );
-is (($date - $date->tzoffset)->ymd,"2000-11-28");                               
-is (($date - $date->tzoffset)->hms,"21:15:46");                                 
+is (($date - $date->tzoffset)->ymd,"2000-11-28");
+is (($date - $date->tzoffset)->hms,"21:15:46");

Generated at 05:00 on 04 Feb 2005 by mariachi 0.52