@@ -, +, @@ --- C4/Letters.pm | 24 +++++++++++++------ Koha/Email.pm | 9 ++++--- .../prog/en/modules/members/notices.tt | 2 +- 3 files changed, 22 insertions(+), 13 deletions(-) --- a/C4/Letters.pm +++ a/C4/Letters.pm @@ -1406,13 +1406,23 @@ sub _send_message_by_email { ); } catch { - _set_message_status( - { - message_id => $message->{'message_id'}, - status => 'failed', - failure_code => 'INVALID_EMAIL' - } - ); + if ( ref($_) eq 'Koha::Exceptions::BadParameter' ) { + _set_message_status( + { + message_id => $message->{'message_id'}, + status => 'failed', + failure_code => "INVALID_EMAIL:$_->parameter" + } + ); + } else { + _set_message_status( + { + message_id => $message->{'message_id'}, + status => 'failed', + failure_code => 'UNKNOWN_ERROR' + } + ); + } return 0; }; return unless $email; --- a/Koha/Email.pm +++ a/Koha/Email.pm @@ -77,8 +77,7 @@ sub create { my $args = {}; $args->{from} = $params->{from} || C4::Context->preference('KohaAdminEmailAddress'); - Koha::Exceptions::BadParameter->throw("Invalid 'from' parameter: ".$args->{from}) - unless Email::Valid->address( -address => $args->{from}, -fqdn => 0 ); # from is mandatory + Koha::Exceptions::BadParameter->throw( { parameter => 'from', error => "Invalid 'from' parameter: ".$args->{from} }) unless Email::Valid->address( -address => $args->{from}, -fqdn => 0 ); # from is mandatory $args->{subject} = $params->{subject} // ''; @@ -89,7 +88,7 @@ sub create { $args->{to} = $params->{to}; } - Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to}) + Koha::Exceptions::BadParameter->throw({ parameter => 'to', error => "Invalid 'to' parameter: ".$args->{to}}) unless Email::Valid->address( -address => $args->{to}, -fqdn => 0 ); # to is mandatory my $addresses = {}; @@ -109,8 +108,8 @@ sub create { } foreach my $address ( keys %{$addresses} ) { - Koha::Exceptions::BadParameter->throw( - "Invalid '$address' parameter: " . $addresses->{$address} ) + Koha::Exceptions::BadParameter->throw({ parameter => $address, error => + "Invalid '$address' parameter: " . $addresses->{$address} }) if $addresses->{$address} and !Email::Valid->address( -address => $addresses->{$address}, -fqdn => 0 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt @@ -95,7 +95,7 @@ [% IF ( QUEUED_MESSAGE.failure_code ) %] [% IF ( QUEUED_MESSAGE.failure_code == "INVALID_BORNUMBER" ) %]Invalid borrowernumber [% borrowernumber | html %] [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_EMAIL' ) %]Unable to find an email address for this borrower - [% ELSIF ( QUEUED_MESSAGE.failure_code == "INVALID_EMAIL" ) %]Invalid email address found [% borrowernumber | html %] + [% ELSIF (matches = QUEUED_MESSAGE.failure_code.match('INVALID_EMAIL:(\w+)') ) %]Invalid [% matches.0 | html %] email address found [% borrowernumber | html %] [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_FROM' ) %]Missing from email address [% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]Missing SMS number [% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]Message is duplicate --