| Email-Store-Summary documentation | Contained in the Email-Store-Summary distribution. |
Email::Store::Summary - Provide subject and first-sentence for a mail
Remember to create the database table:
% make install
% perl -MEmail::Store="..." -e 'Email::Store->setup'
And now:
$mail->subject;
$mail->original;
This extension for Email::Store adds the summary table, and exports
the subject and original methods to the Email::Store::Mail class;
subject is the subject of the mail (duh) and original uses
Text::Original to extract the first unquoted sentence of the mail.
The original author is Simon Cozens, <simon@cpan.org> Currently maintained by Simon Wistow <simon@thegestalt.org>
This module is part of the Perl Email Project - http://pep.kwiki.org/
There is a mailing list at pep@perl.org (subscribe at pep-subscribe@perl.org) and an archive available at http://nntp.perl.org/group/pep.php
Copyright 2004, 2005 Simon Cozens
| Email-Store-Summary documentation | Contained in the Email-Store-Summary distribution. |
package Email::Store::Summary; use 5.006; use strict; use warnings; our $VERSION = '1.2'; use base 'Email::Store::DBI'; use Email::MIME; Email::Store::Summary->table("summary"); Email::Store::Summary->columns(All => qw/mail subject original/); Email::Store::Summary->columns(Primary => qw/mail/); use Text::Original qw(first_sentence); sub on_store_order { 80 } sub on_store { my ($self, $mail) = @_; my $mime = Email::MIME->new($mail->message); my $subject = $mime->header("Subject"); $subject =~ s/^(\s*(re|aw):\s*)+//i; # There's a bit of hackery here. my $body = $mail->simple->body; my $charset = $mime->{ct}->{attributes}{charset}; if ($charset and $charset !~ /utf-?8/) { eval { require Encode; $body = Encode::decode($charset, $body); }; } Email::Store::Summary->create({ mail => $mail->id, subject => $subject, original => first_sentence($body) }); } sub on_gather_plucene_fields_order { 80 } sub on_gather_plucene_fields { my ($self, $mail, $hash) = @_; $hash->{subject} = $mail->subject; } Email::Store::Summary->has_a(mail => "Email::Store::Mail"); Email::Store::Mail->might_have( summary => "Email::Store::Summary" => qw(subject original) );
1; __DATA__ CREATE TABLE IF NOT EXISTS summary ( mail varchar(255) NOT NULL PRIMARY KEY, subject varchar(255), original text );