rev 1419 - trunk/mariachi/lib/Mariachi

[prev] [thread] [next] [lurker] [Date index for 2003/10/16]

From: richardc
Subject: rev 1419 - trunk/mariachi/lib/Mariachi
Date: 09:46 on 16 Oct 2003
Author: richardc
Date: 2003-10-16 09:46:02 +0100 (Thu, 16 Oct 2003)
New Revision: 1419

Modified:
   trunk/mariachi/lib/Mariachi/Message.pm
Log:
well now it runs through

Modified: trunk/mariachi/lib/Mariachi/Message.pm
===================================================================
--- trunk/mariachi/lib/Mariachi/Message.pm	2003-10-16 01:05:52 UTC (rev 1418)
+++ trunk/mariachi/lib/Mariachi/Message.pm	2003-10-16 08:46:02 UTC (rev 1419)
@@ -9,41 +9,37 @@
 
 use base 'Mariachi::DBI';
 __PACKAGE__->set_up_later(
-    rawmail    => 'Email::Simple',
-    body       => '',
-    epoch_date => '',
+    rawmail         => 'Email::Simple',
+    hdr_message_id  => '',
+    hdr_from        => '',
+    hdr_subject     => '',
+    hdr_date        => '',
+    hdr_references  => '',
+    hdr_in_reply_to => '',
+    body            => '',
+    epoch_date      => '',
    );
 __PACKAGE__->add_trigger( before_create => \&pre_create );
 
+#these are just sops
+__PACKAGE__->columns( TEMP => qw( prev next root day month year ) );
+
 # copy things out of the email::simple message and into the columns
+sub _blat {
+    my $thing = shift;
+    $thing =~ tr/-/_/;
+    return lc $thing;
+}
+
 sub pre_create {
     my $data = shift;
-    warn "pre_create";
-}
 
-=for later
-
-    $self->linked({});
-    $self->_header({});
-    $self->header_set( $_, $mail->header($_) ) for
+    my $mail = $data->{rawmail};
+    $data->{ 'hdr_' . _blat( $_ ) } = $mail->header($_) for
       qw( message-id from subject date references in-reply-to );
-    $self->body( $mail->body );
 
-    $self->header_set('message-id', $self->_make_fake_id)
-      unless $self->header('message-id');
-
-    # this is a bit ugly to be here but much quicker than making it a
-    # memoized lookup
-    my @date = localtime $self->epoch_date(str2time( $self->header('date') )
-                                             || 0);
-    my @ymd = ( $date[5] + 1900, $date[4] + 1, $date[3] );
-    $self->ymd(\@ymd);
-    $self->day(   sprintf "%04d/%02d/%02d", @ymd );
-    $self->month( sprintf "%04d/%02d", @ymd );
-    $self->year(  sprintf "%04d", @ymd );
-
-    return $self;
-
+    $data->{body}       = $mail->body;
+    $data->{epoch_date} = str2time( $data->{hdr_date} ) || 0;
 }
 
 =head1 NAME
@@ -61,16 +57,16 @@
 =cut
 
 sub new {
-    die "don't look at me";
-}
+    my $class = shift;
+    my $mail  = Email::Simple->new(shift) or return;
 
-
-sub _make_fake_id {
-    my $self = shift;
-    my $hash = substr( md5_hex( $self->header('from').$self->date ), 0, 8 );
-    return "$hash\@made_up";
+    my $msgid = $mail->header('message-id') or die "gotta have a message-id";
+    my ($old) = $class->search({ hdr_message_id => $msgid });
+    return $old if $old;
+    return $class->create({ rawmail => $mail });
 }
 
+
 =head2 ->body
 
 =head2 ->header
@@ -84,13 +80,14 @@
 
 sub header {
     my $self = shift;
-    $self->_header->{ lc shift() };
+    my $meth = "hdr_" . _blat( shift );
+    $self->$meth();
 }
 
 sub header_set {
     my $self = shift;
-    my $hdr = shift;
-    $self->_header->{ lc $hdr } = shift;
+    my $meth = "hdr_" . _blat( shift );
+    $self->$meth( shift );
 }
 
 =head2 ->first_lines

Generated at 13:57 on 01 Jul 2004 by mariachi 0.52