rev 1782 - in trunk/Email-Store: . lib/Email lib/Email/Store t

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

From: simon
Subject: rev 1782 - in trunk/Email-Store: . lib/Email lib/Email/Store t
Date: 08:57 on 02 Jan 2005
Author: simon
Date: 2005-01-02 08:57:23 +0000 (Sun, 02 Jan 2005)
New Revision: 1782

Added:
   trunk/Email-Store/t/date-test
   trunk/Email-Store/t/date-test2
   trunk/Email-Store/t/date.t
Modified:
   trunk/Email-Store/Changes
   trunk/Email-Store/MANIFEST
   trunk/Email-Store/Makefile.PL
   trunk/Email-Store/lib/Email/Store.pm
   trunk/Email-Store/lib/Email/Store/Date.pm
Log:
Update Date stuff


Modified: trunk/Email-Store/Changes
===================================================================
--- trunk/Email-Store/Changes	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/Changes	2005-01-02 08:57:23 UTC (rev 1782)
@@ -1,5 +1,11 @@
 Revision history for Perl extension Email::Store.
 
+0.16 Sun Dec 26 12:14:57 GMT 2004
+    - Some changes to Date
+    - Require certain versions of Email::Simple and Email::MIME
+    - Update contact information
+    - Happy Boxing day
+
 0.15 Thu Jul 15 15:04:54 BST 2004
     - After list order so that it gets does before summary gets to the
       mail
@@ -52,6 +58,6 @@
     - Connect addressings to mail
 
 0.01  Tue May 18 13:26:10 2004
-	- original version; created by h2xs 1.22 with options
-		-AX -b 5.6.0 -n Email::Store
+    - original version; created by h2xs 1.22 with options
+        -AX -b 5.6.0 -n Email::Store
 

Modified: trunk/Email-Store/MANIFEST
===================================================================
--- trunk/Email-Store/MANIFEST	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/MANIFEST	2005-01-02 08:57:23 UTC (rev 1782)
@@ -3,11 +3,15 @@
 mailman-test
 Makefile.PL
 MANIFEST
+MANIFEST.SKIP
 README
 t/1.t
 t/2.t
 t/attach-test
 t/attach.t
+t/date.t
+t/date-test
+t/date-test2
 t/limit.t
 t/troublesome
 lib/Email/Store/Attachment.pm

Modified: trunk/Email-Store/Makefile.PL
===================================================================
--- trunk/Email-Store/Makefile.PL	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/Makefile.PL	2005-01-02 08:57:23 UTC (rev 1782)
@@ -8,16 +8,16 @@
     PREREQ_PM         => {
         Module::Pluggable::Ordered => 1.0,
         Module::Pluggable => 1.4,
-        Email::Simple => 1.0,
-        Email::MIME => 0,
+        Email::Simple => 1.92,
+        Email::MIME => 1.8,
         DBD::SQLite => 0,
         Class::DBI => 0.9,
         Class::DBI::DATA::Schema => 0,
-        Mail::ListDetector => 0.30,
-        Email::MIME::Attachment::Stripper => 1.1,
+        Mail::ListDetector => 0.31,
+        Email::MIME::Attachment::Stripper => 1.3,
         Time::Piece => 0,
         File::Slurp => 0,
-        Email::Address => 0,
+        Email::Address => 1.80,
         SQL::Translator => 0,
     }, # e.g., Module::Name => 1.1
 );

Modified: trunk/Email-Store/lib/Email/Store/Date.pm
===================================================================
--- trunk/Email-Store/lib/Email/Store/Date.pm	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/lib/Email/Store/Date.pm	2005-01-02 08:57:23 UTC (rev 1782)
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 
-our $VERSION = '1.0';
+our $VERSION = '1.1';
 
 use Email::Store::DBI;
 use base 'Email::Store::DBI';
@@ -14,11 +14,11 @@
 use Date::Parse;
 
 Email::Store::Date->table("mail_date");
-Email::Store::Date->columns(All => qw/mail date/);
+Email::Store::Date->columns(All => qw/mail date year month day/);
 Email::Store::Date->columns(Primary => qw/mail/);
 Email::Store::Date->has_a( date => 'Time::Piece' );
 Email::Store::Date->has_a( mail => "Email::Store::Mail" );
-Email::Store::Mail->might_have( mail_date => "Email::Store::Date" => 'date');
+Email::Store::Mail->might_have( mail_date => "Email::Store::Date" => qw(date year month day));
 
 
 
@@ -27,12 +27,15 @@
 sub on_store {
     my ($self, $mail) = @_;
     my $simple = $mail->simple;
-	my $date   = $simple->header('date')
+
+    my $date   = $simple->header('date')
                  || _get_date_in_received_header($simple)
                  || $simple->header('resent-date');
-	my $time   = str2time($date);
-	Email::Store::Date->create( { mail => $mail->id, date => $time } );
 
+    my $time   = str2time($date);
+    my $tp     = Time::Piece->new($time);
+    Email::Store::Date->create( { mail => $mail->id, date => $time, year => $tp->year, month => $tp->mon, day => $tp->mday } );
+
 }
 
 sub _get_date_in_received_header {
@@ -42,6 +45,7 @@
     $date =~ s/.*;// and return $date;
 }
 
+
 sub on_gather_plucene_fields_order { 80 }
 sub on_gather_plucene_fields {
     my ($self, $mail, $hash) = @_;
@@ -63,10 +67,21 @@
 
 And now:
 
-	print $mail->date->ymd,"\n";
+    print $mail->date->ymd,"\n";
 
-=head1 DESCRIPTION
+or
 
+    $mail->year;
+    $mail->month;
+    $mail->day;
+
+You can also search for all mails between two unix epochs
+
+    # get all mails in the last day
+    my $time = time();
+    my $day  = 24*60*60;
+    Email::Store::Mail->search_between($time, $time-$day);
+
 =head1 SEE ALSO
 
 L<Email::Store::Mail>, L<Time::Piece>.
@@ -79,9 +94,23 @@
 
 =cut
 
+
+Email::Store::Mail->set_sql(between => qq{
+    SELECT mail.message_id
+    FROM mail_date, mail
+    WHERE mail.message_id = mail_date.mail AND
+    mail_date.date >= ? AND
+    mail_date.date <=  ?
+    ORDER BY mail_date.date DESC
+});
+
+
 1;
 __DATA__
 CREATE TABLE IF NOT EXISTS mail_date (
     mail varchar(255) NOT NULL PRIMARY KEY,                                                 
-	date int
+    date  int,
+    year  int,
+    month int,
+    day   int
 );

Modified: trunk/Email-Store/lib/Email/Store.pm
===================================================================
--- trunk/Email-Store/lib/Email/Store.pm	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/lib/Email/Store.pm	2005-01-02 08:57:23 UTC (rev 1782)
@@ -44,7 +44,7 @@
     }
 }
 
-our $VERSION = '0.15';
+our $VERSION = '0.16';
 # Preloaded methods go here.
 
 1;
@@ -146,7 +146,8 @@
 =item C<Email::Store::Date>
 
 This adds the C<date> method to a C<mail> object, returning a C<Time::Piece>
-representing the date of the email.
+representing the date of the email. It also provides various searches for
+mails between epoch times and for years, months and days.
 
 =item C<Email::Store::Entity>
 
@@ -313,8 +314,17 @@
 
 =head1 AUTHOR
 
-Simon Cozens, E<lt>simon@xxxx.xxxx<gt>
+The original author is Simon Cozens, E<lt>simon@xxxx.xxxx<gt>
+Currently maintained by Simon Wistow <simon@xxxxxxxxxx.xxx>
 
+=head1 SUPPORT
+
+This module is part of the Perl Email Project - http://pep.kwiki.org/
+
+There is a mailing list at pep@xxxx.xxx (subscribe at pep-subscribe@xxxx.xxx) 
+and an archive available at http://nntp.perl.org/group/pep.php
+
+
 =head1 CREDITS
 
 Many of the ideas (although none of the code) for this package were

Added: trunk/Email-Store/t/date-test
===================================================================
--- trunk/Email-Store/t/date-test	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/t/date-test	2005-01-02 08:57:23 UTC (rev 1782)
@@ -0,0 +1,9 @@
+From: Foo Bar <foo@xxx.xxx>
+To: Me <simon@xxxxxxxx.xxx>
+Subject: Test Mail
+Message-ID: 20001128211546.A29664@xxx.xxx
+Date: Fri, 18 Jun 2004 11:14:35 +0100 
+
+J0!
+
+Simon


Property changes on: trunk/Email-Store/t/date-test
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/Email-Store/t/date-test2
===================================================================
--- trunk/Email-Store/t/date-test2	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/t/date-test2	2005-01-02 08:57:23 UTC (rev 1782)
@@ -0,0 +1,11 @@
+From: Foo Bar <foo@xxx.xxx>
+To: Me <simon@xxxxxxxx.xxx>
+Subject: Test Mail
+Message-ID: 20001128211546.A29664@xxx.xxx
+Date: Fri, 19 Jun 2004 11:14:35 +0100 
+
+> J0!
+
+so true
+
+Simon


Property changes on: trunk/Email-Store/t/date-test2
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/Email-Store/t/date.t
===================================================================
--- trunk/Email-Store/t/date.t	2005-01-01 21:51:58 UTC (rev 1781)
+++ trunk/Email-Store/t/date.t	2005-01-02 08:57:23 UTC (rev 1782)
@@ -0,0 +1,38 @@
+use Test::More tests => 10;
+use File::Slurp;
+BEGIN { unlink("t/test.db"); }
+use Email::Store "dbi:SQLite:dbname=t/test.db";
+Email::Store->setup;
+ok(1, "Set up");
+
+my $data = read_file("t/date-test");
+Email::Store::Mail->store($data);
+
+
+
+# We need one mail:
+my @mails = Email::Store::Mail->retrieve_all;
+is(@mails, 1, "Only one mail");
+# is($mails[0]->message_id, '20001128211546.A29664@xxx.xxx', "Correct ID");
+
+my $date;
+
+ok($date = $mails[0]->date );
+
+
+is ($date->ymd,"2004-06-18");
+is ($date->hms,"11:14:35");
+is ($mails[0]->year,"2004");
+is ($mails[0]->month,"6");
+is ($mails[0]->day,"18");
+
+$data = read_file("t/date-test2");
+Email::Store::Mail->store($data);
+
+my @searched = Email::Store::Mail->search_between(1087516800,1087603199);
+
+is(@searched, 1, "Search only found one mail");
+
+@searched = Email::Store::Mail->search_between(1087516800,1087689600);
+is(@searched, 2, "Search only found two mail");
+


Property changes on: trunk/Email-Store/t/date.t
___________________________________________________________________
Name: svn:executable
   + *

Generated at 09:00 on 02 Jan 2005 by mariachi 0.52