added basic documentation
[p5sagit/Email-Archive.git] / lib / Email / Archive.pm
CommitLineData
8581da38 1package Email::Archive;
8a5453ad 2use Moo;
c5f5125c 3use Email::Archive::Storage::DBI;
8581da38 4
5e15a8a0 5our $VERSION = '0.02';
6
8581da38 7has storage => (
8 is => 'rw',
9 does => 'Email::Archive::Storage',
58854002 10 handles => {
11 store => 'store',
12 retrieve => 'retrieve',
13 connect => 'storage_connect',
14 },
c5f5125c 15 lazy => 1,
16 default => sub { Email::Archive::Storage::DBI->new }
8581da38 17);
18
8581da38 191;
5e15a8a0 20
21
d5161b4d 22__END__
5e15a8a0 23
24=head1 NAME
25
26Email::Archive - write emails to a database, fetch them
27
28=head1 WARNING!
29
30I only uploaded this to get it out there and kick myself into making it more
31useful. As you can see it's not documented or tested yet. I put this together
32mostly in one evening in a coffeeshop. It shows in some ways. caveat programmer.
33
20b4be81 34=head1 SYNOPSIS
35
8e812f39 36Email::Archive provides an interface to store emails.
37
38The default storage is Email::Archive::Storage::DBI that uses DBI.
39All dokumented examples assume you use this default. For information
40on how to use different engines see those modules documentation.
41
42 my $email_archive = Email::Archive->new;
43 $email_archive->connect($dsn);
44 $email_archive->store($msg);
45
46 $email_archive->retrieve($msg_id);
47 $email_archive->search({ from_addr => $from });
48
49=head1 ATTRIBUTES
50
51=head2 storage
52
53Defaults to Email::Archive::Storage::DBI->new.
54
55 my $e = Email::Archive->new;
56
57is equvalent to
58
59 my $storage = Email::Archive::Storage::DBI->new;
60 my $e = Email::Archive->new(
61 storage => $storage,
62 );
63
64This usage will be necessary if a storage different form
65Email::Archive::Storage::DBI is used.
66
67=head1 METHODS
68
69=head2 connect
70
71Takes a DBI connection string as parameter.
72
73 $email_archive->connect('dbi:SQLite:dbname=emails');
74
75For more information see DBI documentation.
76
77If the database schema does not exist it will be deployed automatically by
78the connect method.
79
80=head2 store
81
82 $email_archive->store($msg);
83
84Where $msg could be anything feedable to Email::Abstract. That is a raw
85email, an Email::MIME object or even an Email::Abstract object.
86
87The message will be stored in the messages table of the connected database.
88
89=head2 search
90
91 $email_archive->search($attributes);
92
93Search the database for emails where $attributes is a hashref containing
94the fields to search and the values filter.
95
96 $attributes = { from_addr => $addr };
97
98Will return the first found result as Email::MIME object.
99
100 $email_archive->search({ message_id => $some_id });
101
102Is exactly the same as retrieval by Message-ID.
103
104=head2 retrieve
105
106 $email_archive->retrieve($msg_id);
107
108Retrieve emails by Message-ID. Is a shortcut for
109
110 $email_archive->search({ message_id => $some_id });
20b4be81 111
5e15a8a0 112=head1 LICENSE
113
114This library may be used under the same terms as Perl itself.
115
116=head1 AUTHOR AND COPYRIGHT
117
118Copyright (c) 2010, 2011 Chris Nehren C<apeiron@cpan.org>.