|
Lines 22-28
use Modern::Perl;
Link Here
|
| 22 |
|
22 |
|
| 23 |
use Email::Address; |
23 |
use Email::Address; |
| 24 |
use Email::MessageID; |
24 |
use Email::MessageID; |
|
|
25 |
use Email::MIME; |
| 25 |
use List::Util qw( pairs ); |
26 |
use List::Util qw( pairs ); |
|
|
27 |
use Scalar::Util qw( blessed ); |
| 26 |
|
28 |
|
| 27 |
use Koha::Exceptions; |
29 |
use Koha::Exceptions; |
| 28 |
|
30 |
|
|
Lines 38-43
Koha::Email - A wrapper around Email::Stuffer
Link Here
|
| 38 |
|
40 |
|
| 39 |
=head2 Class methods |
41 |
=head2 Class methods |
| 40 |
|
42 |
|
|
|
43 |
=head3 new_from_string |
| 44 |
|
| 45 |
my $email = Koha::Email->new_from_string( $email_string ); |
| 46 |
|
| 47 |
Constructor for the Koha::Email class. The I<$email_string> (mandatory) |
| 48 |
parameter will be parsed with I<Email::MIME>. |
| 49 |
|
| 50 |
Note: I<$email_string> can be the produced by the I<as_string> method from |
| 51 |
B<Koha::Email> or B<Email::MIME>. |
| 52 |
|
| 53 |
=cut |
| 54 |
|
| 55 |
sub new_from_string { |
| 56 |
my ( $class, $email_string ) = @_; |
| 57 |
|
| 58 |
Koha::Exceptions::MissingParameter->throw("Mandatory string parameter missing.") |
| 59 |
unless $email_string; |
| 60 |
|
| 61 |
my $self = $class->SUPER::new(); |
| 62 |
my $mime = Email::MIME->new( $email_string ); |
| 63 |
$self->{email} = $mime; |
| 64 |
|
| 65 |
return $self; |
| 66 |
} |
| 67 |
|
| 41 |
=head3 create |
68 |
=head3 create |
| 42 |
|
69 |
|
| 43 |
my $email = Koha::Email->create( |
70 |
my $email = Koha::Email->create( |
|
Lines 126-132
sub create {
Link Here
|
| 126 |
$args->{bcc} = $addresses->{bcc} |
153 |
$args->{bcc} = $addresses->{bcc} |
| 127 |
if $addresses->{bcc}; |
154 |
if $addresses->{bcc}; |
| 128 |
|
155 |
|
| 129 |
my $email = $self->SUPER::new( $args ); |
156 |
my $email; |
|
|
157 |
# FIXME: This is ugly, but aids backportability |
| 158 |
# TODO: Remove this and move address and default headers handling |
| 159 |
# to separate subs to be (re)used |
| 160 |
if ( blessed($self) ) { |
| 161 |
$email = $self; |
| 162 |
$email->to( $args->{to} ) if $args->{to}; |
| 163 |
$email->from( $args->{from} ) if $args->{from}; |
| 164 |
$email->cc( $args->{cc} ) if $args->{cc}; |
| 165 |
$email->bcc( $args->{bcc} ) if $args->{bcc}; |
| 166 |
$email->reply_to( $args->{reply_to} ) if $args->{reply_to}; |
| 167 |
$email->subject( $args->{subject} ) if $args->{subject}; |
| 168 |
} |
| 169 |
else { |
| 170 |
$email = $self->SUPER::new( $args ); |
| 171 |
} |
| 130 |
|
172 |
|
| 131 |
$email->header( 'Reply-To', $addresses->{reply_to} ) |
173 |
$email->header( 'Reply-To', $addresses->{reply_to} ) |
| 132 |
if $addresses->{reply_to}; |
174 |
if $addresses->{reply_to}; |