line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Email::Store::Pristine - keep a pristine copy of the mail |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Many Email::Store plugins will munge the underlying rfc2822 |
8
|
|
|
|
|
|
|
representation of the message, which in some cases is undesirable. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
When in use Email::Store::Pristine stores a copy of the original |
11
|
|
|
|
|
|
|
message in a pristine_copies relationship. This is a one-to-many |
12
|
|
|
|
|
|
|
relationship as in the case of a cross-posted mail you may recieve |
13
|
|
|
|
|
|
|
many subtly different versions of the same mail, for which there will |
14
|
|
|
|
|
|
|
be only one Email::Store::Mail message due to the unchanging |
15
|
|
|
|
|
|
|
Message-ID. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
A C accessor is added to the Email::Store::Mail |
18
|
|
|
|
|
|
|
object, which returns Email::Store::Pristine copies which encapsulate |
19
|
|
|
|
|
|
|
the original message. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 ->message |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The pristine rfc2822 message. A readonly accessor. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 ->simple |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
The message represented as an Email::Simple object. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 AUTHOR |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Richard Clamp |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 COPYRIGHT |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Copyright 2005 Richard Clamp. All Rights Reserved. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This program is free software; you can redistribute it |
40
|
|
|
|
|
|
|
and/or modify it under the same terms as Perl itself. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SEE ALSO |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
L |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
package Email::Store::Pristine; |
50
|
1
|
|
|
1
|
|
834
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
51
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
52
|
|
|
|
|
|
|
our $VERSION = '1.21'; |
53
|
1
|
|
|
1
|
|
17
|
use base 'Email::Store::DBI'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
842
|
|
54
|
|
|
|
|
|
|
__PACKAGE__->table("pristine"); |
55
|
|
|
|
|
|
|
__PACKAGE__->columns(All => qw/id mail message/); |
56
|
|
|
|
|
|
|
__PACKAGE__->columns(TEMP => qw/simple/); |
57
|
|
|
|
|
|
|
__PACKAGE__->has_a(mail => 'Email::Store::Mail'); |
58
|
|
|
|
|
|
|
Email::Store::Mail->has_many( pristine_copies => __PACKAGE__ ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# I damn well want to be first |
61
|
|
|
|
|
|
|
sub on_store_order { -20000 } |
62
|
|
|
|
|
|
|
sub on_seen_duplicate_order { -20000 } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub _store { |
65
|
|
|
|
|
|
|
my ($self, $mail, $message) = @_; |
66
|
|
|
|
|
|
|
$mail->add_to_pristine_copies({ |
67
|
|
|
|
|
|
|
mail => $mail, |
68
|
|
|
|
|
|
|
message => $message, |
69
|
|
|
|
|
|
|
}); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub on_store { |
73
|
|
|
|
|
|
|
my ($self, $mail) = @_; |
74
|
|
|
|
|
|
|
$self->_store( $mail, $mail->simple->as_string ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# don't store all duplicates, only the ones we've not got the exact |
78
|
|
|
|
|
|
|
# same rfc2822 body for |
79
|
|
|
|
|
|
|
sub on_seen_duplicate { |
80
|
|
|
|
|
|
|
my ($self, $mail, $simple) = @_; |
81
|
|
|
|
|
|
|
my $message = $simple->as_string; |
82
|
|
|
|
|
|
|
for my $check ($mail->pristine_copies) { |
83
|
|
|
|
|
|
|
return if $check->message eq $message; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
$self->_store( $mail, $message ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub message { |
89
|
|
|
|
|
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
if (@_) { |
91
|
|
|
|
|
|
|
die "which part of pristine didn't you get?" |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
$self->get('message'); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# hmm, is there a way to make this Email::Simple object readonly too? |
97
|
|
|
|
|
|
|
sub simple { |
98
|
|
|
|
|
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
return $self->{simple} ||= Email::Simple->new( $self->message ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
__DATA__ |