View | Details | Raw Unified | Return to bug 28803
Collapse All | Expand All

(-)a/C4/Letters.pm (-7 / +17 lines)
Lines 1406-1418 sub _send_message_by_email { Link Here
1406
        );
1406
        );
1407
    }
1407
    }
1408
    catch {
1408
    catch {
1409
        _set_message_status(
1409
        if ( ref($_) eq 'Koha::Exceptions::BadParameter' ) {
1410
            {
1410
            _set_message_status(
1411
                message_id   => $message->{'message_id'},
1411
                {
1412
                status       => 'failed',
1412
                    message_id   => $message->{'message_id'},
1413
                failure_code => 'INVALID_EMAIL'
1413
                    status       => 'failed',
1414
            }
1414
                    failure_code => "INVALID_EMAIL:".$_->parameter
1415
        );
1415
                }
1416
            );
1417
        } else {
1418
            _set_message_status(
1419
                {
1420
                    message_id   => $message->{'message_id'},
1421
                    status       => 'failed',
1422
                    failure_code => 'UNKNOWN_ERROR'
1423
                }
1424
            );
1425
        }
1416
        return 0;
1426
        return 0;
1417
    };
1427
    };
1418
    return unless $email;
1428
    return unless $email;
(-)a/Koha/Email.pm (-6 / +12 lines)
Lines 77-84 sub create { Link Here
77
77
78
    my $args = {};
78
    my $args = {};
79
    $args->{from} = $params->{from} || C4::Context->preference('KohaAdminEmailAddress');
79
    $args->{from} = $params->{from} || C4::Context->preference('KohaAdminEmailAddress');
80
    Koha::Exceptions::BadParameter->throw("Invalid 'from' parameter: ".$args->{from})
80
    Koha::Exceptions::BadParameter->throw(
81
        unless Koha::Email->is_valid($args->{from}); # from is mandatory
81
        error     => "Invalid 'from' parameter: " . $args->{from},
82
        parameter => 'from'
83
    ) unless Koha::Email->is_valid( $args->{from} );    # from is mandatory
82
84
83
    $args->{subject} = $params->{subject} // '';
85
    $args->{subject} = $params->{subject} // '';
84
86
Lines 89-96 sub create { Link Here
89
        $args->{to} = $params->{to};
91
        $args->{to} = $params->{to};
90
    }
92
    }
91
93
92
    Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to})
94
    Koha::Exceptions::BadParameter->throw(
93
        unless Koha::Email->is_valid($args->{to}); # to is mandatory
95
        error     => "Invalid 'to' parameter: " . $args->{to},
96
        parameter => 'to'
97
    ) unless Koha::Email->is_valid( $args->{to} );    # to is mandatory
94
98
95
    my $addresses = {};
99
    my $addresses = {};
96
    $addresses->{reply_to} = $params->{reply_to};
100
    $addresses->{reply_to} = $params->{reply_to};
Lines 110-118 sub create { Link Here
110
114
111
    foreach my $address ( keys %{$addresses} ) {
115
    foreach my $address ( keys %{$addresses} ) {
112
        Koha::Exceptions::BadParameter->throw(
116
        Koha::Exceptions::BadParameter->throw(
113
            "Invalid '$address' parameter: " . $addresses->{$address} )
117
            error => "Invalid '$address' parameter: " . $addresses->{$address},
118
            parameter => $address
119
          )
114
          if $addresses->{$address}
120
          if $addresses->{$address}
115
            and !Koha::Email->is_valid($addresses->{$address});
121
          and !Koha::Email->is_valid( $addresses->{$address} );
116
    }
122
    }
117
123
118
    $args->{cc} = $addresses->{cc}
124
    $args->{cc} = $addresses->{cc}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt (-1 / +1 lines)
Lines 95-101 Link Here
95
        [% IF ( QUEUED_MESSAGE.failure_code ) %]
95
        [% IF ( QUEUED_MESSAGE.failure_code ) %]
96
            [% IF ( QUEUED_MESSAGE.failure_code == "INVALID_BORNUMBER" ) %]Invalid borrowernumber [% borrowernumber | html %]
96
            [% IF ( QUEUED_MESSAGE.failure_code == "INVALID_BORNUMBER" ) %]Invalid borrowernumber [% borrowernumber | html %]
97
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_EMAIL' ) %]Unable to find an email address for this borrower
97
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_EMAIL' ) %]Unable to find an email address for this borrower
98
            [% ELSIF ( QUEUED_MESSAGE.failure_code == "INVALID_EMAIL" ) %]Invalid email address found [% borrowernumber | html %]
98
            [% ELSIF (matches = QUEUED_MESSAGE.failure_code.match('INVALID_EMAIL:(\w+)') ) %]Invalid [% matches.0 | html %] email address found [% borrowernumber | html %]
99
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_FROM' ) %]Missing from email address
99
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'NO_FROM' ) %]Missing from email address
100
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]Missing SMS number
100
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'MISSING_SMS' ) %]Missing SMS number
101
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]Message is duplicate
101
            [% ELSIF ( QUEUED_MESSAGE.failure_code == 'DUPLICATE_MESSAGE' ) %]Message is duplicate
(-)a/t/db_dependent/Letters.t (-6 / +5 lines)
Lines 949-964 subtest 'Test message_id parameter for SendQueuedMessages' => sub { Link Here
949
        'borrowernumber'         => $borrowernumber,
949
        'borrowernumber'         => $borrowernumber,
950
        'to_address'             => 'to@example.org',
950
        'to_address'             => 'to@example.org',
951
        'message_transport_type' => 'email',
951
        'message_transport_type' => 'email',
952
        'from_address'           => 'root@localhost.' # invalid KohaAdminEmailAddress
952
        'from_address'           => '@example.com' # invalid from_address
953
    };
953
    };
954
    my $message_id = C4::Letters::EnqueueLetter($my_message);
954
    my $message_id = C4::Letters::EnqueueLetter($my_message);
955
    my $processed = C4::Letters::SendQueuedMessages( { message_id => $message_id } );
955
    my $processed = C4::Letters::SendQueuedMessages( { message_id => $message_id } );
956
    is( $processed, 1, 'Processed 1 message when one message_id passed' );
956
    is( $processed, 1, 'Processed 1 message when one message_id passed' );
957
    my $message_1 = C4::Letters::GetMessage($message_id);
957
    my $message_1 = C4::Letters::GetMessage($message_id);
958
    is( $message_1->{status}, 'failed', 'Invalid KohaAdminEmailAddress => status failed' );
958
    is( $message_1->{status}, 'failed', 'Invalid from_address => status failed' );
959
    is( $message_1->{failure_code}, 'INVALID_EMAIL', 'Failure code set correctly for invalid email parameter');
959
    is( $message_1->{failure_code}, 'INVALID_EMAIL:from', 'Failure code set correctly for invalid email parameter');
960
960
961
    $my_message->{from_address} = 'root@example.org'; # valid KohaAdminEmailAddress
961
    $my_message->{from_address} = 'root@example.org'; # valid from_address
962
    $message_id = C4::Letters::EnqueueLetter($my_message);
962
    $message_id = C4::Letters::EnqueueLetter($my_message);
963
    warning_like { C4::Letters::SendQueuedMessages( { message_id => $message_id } ); }
963
    warning_like { C4::Letters::SendQueuedMessages( { message_id => $message_id } ); }
964
        qr|Fake send_or_die|,
964
        qr|Fake send_or_die|,
Lines 966-970 subtest 'Test message_id parameter for SendQueuedMessages' => sub { Link Here
966
    $message_1 = C4::Letters::GetMessage($message_1->{message_id});
966
    $message_1 = C4::Letters::GetMessage($message_1->{message_id});
967
    my $message_2 = C4::Letters::GetMessage($message_id);
967
    my $message_2 = C4::Letters::GetMessage($message_id);
968
    is( $message_1->{status}, 'failed', 'Message 1 status is unchanged' );
968
    is( $message_1->{status}, 'failed', 'Message 1 status is unchanged' );
969
    is( $message_2->{status}, 'sent', 'Valid KohaAdminEmailAddress => status sent' );
969
    is( $message_2->{status}, 'sent', 'Valid from_address => status sent' );
970
};
970
};
971
- 

Return to bug 28803