line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
4073
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
2
|
|
|
|
|
|
|
package Email::LocalDelivery::Store; |
3
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
4
|
1
|
|
|
1
|
|
5
|
use File::Path qw(mkpath); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
5
|
1
|
|
|
1
|
|
15
|
use File::Basename qw( dirname ); |
|
1
|
|
|
|
|
66
|
|
|
1
|
|
|
|
|
173
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Email::LocalDelivery::Store - deliver mail via L |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use Email::LocalDelivery; |
14
|
|
|
|
|
|
|
use Email::FolderType::Register qw[register_type]; |
15
|
|
|
|
|
|
|
register_type Store => sub { $_[0] =~ m/^DBI/i }; |
16
|
|
|
|
|
|
|
... |
17
|
|
|
|
|
|
|
Email::LocalDelivery->deliver($mail, $dsn) or die "couldn't deliver to $dsn"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
...where $dsn is a full DBI DSN, including user= and password=, e.g. |
20
|
|
|
|
|
|
|
'DBI:mysql:database=DATABASE;host=HOSTNAME;port=PORT;user=USER;password=PASSWORD' |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module is an Email::LocalDelivery wrapper for L, |
25
|
|
|
|
|
|
|
which is a "framework for database-backed email storage." |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
It allows you to easily swap in database email storage instead of Mbox or Maildir. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Just register the "Store" FolderType, like this: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over |
32
|
|
|
|
|
|
|
use Email::FolderType::Register qw[register_type]; |
33
|
|
|
|
|
|
|
register_type Store => sub { $_[0] =~ m/^DBI/i }; |
34
|
|
|
|
|
|
|
=back |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
and then call Email::LocalDelivery->deliver( $mail, $dsn ) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
This module was created to allow L to archive mail in MySQL. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 deliver( $rfc822, @dsns ) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
C<$rfc822> is an RFC822 formatted email message, and C<@dsns> is a list of DBI DSN strings. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Since Email::Store is instantiated with the DSN, and I really don't know what I'm doing, |
47
|
|
|
|
|
|
|
I had to eval 'use Email::Store $dsn' inside the deliver() method. |
48
|
|
|
|
|
|
|
I suspect that this will blow up if you try to pass more than one DSN, so I made it exit after the first one. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 ATTENTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
L (obviously) requires some form of database backend. |
53
|
|
|
|
|
|
|
Since you will have already figured all that out, this module doesn't test your database connection itself. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub deliver { |
58
|
0
|
|
|
0
|
1
|
|
my ($class, $mail, @dsns) = @_; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my @delivered; |
61
|
0
|
|
|
|
|
|
for my $dsn (@dsns) { |
62
|
0
|
|
|
|
|
|
eval "use Email::Store '$dsn'"; |
63
|
0
|
|
|
|
|
|
my $stored = Email::Store::Mail->store($mail); |
64
|
0
|
|
|
|
|
|
push @delivered, $stored; |
65
|
0
|
|
|
|
|
|
last; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
return @delivered; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |