use Modern::Perl;
-use Email::Valid;
+use Email::Address;
use Email::MessageID;
+use List::Util qw( pairs );
+
use Koha::Exceptions;
use C4::Context;
my $args = {};
$args->{from} = $params->{from} || C4::Context->preference('KohaAdminEmailAddress');
Koha::Exceptions::BadParameter->throw("Invalid 'from' parameter: ".$args->{from})
- unless Email::Valid->address($args->{from}); # from is mandatory
+ unless $args->{from} =~ m/$Email::Address::mailbox/; # from is mandatory
$args->{subject} = $params->{subject} // '';
}
Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to})
- unless Email::Valid->address($args->{to}); # to is mandatory
+ unless $args->{to} =~ m/$Email::Address::mailbox/; # to is mandatory
my $addresses = {};
$addresses->{reply_to} = $params->{reply_to};
if exists $params->{bcc};
}
- foreach my $address ( keys %{ $addresses } ) {
- Koha::Exceptions::BadParameter->throw("Invalid '$address' parameter: ".$addresses->{$address})
- if $addresses->{$address} and !Email::Valid->address($addresses->{$address});
+ foreach my $address ( keys %{$addresses} ) {
+ Koha::Exceptions::BadParameter->throw(
+ "Invalid '$address' parameter: " . $addresses->{$address} )
+ if $addresses->{$address}
+ and $addresses->{$address} !~ m/$Email::Address::mailbox/;
}
$args->{cc} = $addresses->{cc}
my $email = $self->SUPER::new( $args );
- $email->header( 'ReplyTo', $addresses->{reply_to} )
+ $email->header( 'Reply-To', $addresses->{reply_to} )
if $addresses->{reply_to};
$email->header( 'Sender' => $addresses->{sender} ) if $addresses->{sender};
my @recipients;
- # extract all recipient addresses from header
- foreach my $header ( 'To', 'Cc', 'Bcc' ) {
- push @recipients,
- map { $_->as_string }
- $self->email->header_obj->header_as_obj($header)->addresses;
+ my @headers = $self->email->header_str_pairs;
+ foreach my $pair ( pairs @headers ) {
+ my ( $header, $value ) = @$pair;
+ push @recipients, split (', ', $value)
+ if grep { $_ eq $header } ('To', 'Cc', 'Bcc');
}
# Remove the Bcc header