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

(-)a/Koha/Email.pm (-1 / +8 lines)
Lines 245-252 Return true is the email address passed in parameter is valid following RFC 2822 Link Here
245
245
246
sub is_valid {
246
sub is_valid {
247
    my ( $class, $email ) = @_;
247
    my ( $class, $email ) = @_;
248
    my @addrs = Email::Address->parse($email);
248
    my @addrs = _temporary_host_test( Email::Address->parse($email) );
249
    return @addrs ? 1 : 0;
249
    return @addrs ? 1 : 0;
250
}
250
}
251
251
252
sub _temporary_host_test {
253
254
    # regex looks for a dot in the domain, other case should be caught by E::A
255
    # exception for localhost (see bug 28017 and Email.t)
256
    return grep { $_->host =~ /\.|^localhost$/ } @_;
257
}
258
252
1;
259
1;
(-)a/t/Koha/Email.t (-6 / +8 lines)
Lines 269-286 subtest 'send_or_die() tests' => sub { Link Here
269
};
269
};
270
270
271
subtest 'is_valid' => sub {
271
subtest 'is_valid' => sub {
272
    plan tests => 8;
272
    plan tests => 11;
273
273
274
    is( Koha::Email->is_valid('Fróm <from@example.com>'), 1 );
274
    is( Koha::Email->is_valid('Fróm <from@example.com>'), 1 );
275
    is( Koha::Email->is_valid('from@example.com'),        1 );
275
    is( Koha::Email->is_valid('from@example.com'),        1 );
276
    is( Koha::Email->is_valid('<from@example.com>'),      1 );
276
    is( Koha::Email->is_valid('<from@example.com>'),      1 );
277
    is( Koha::Email->is_valid('root@localhost'),          1 );    # See bug 28017
277
    is( Koha::Email->is_valid('root@localhost'),    1, 'localhost allowed as exception' );               # See bug 28017
278
    is( Koha::Email->is_valid('root@example.com.'), 1, 'trailing period got accepted, dont ask me why' );
278
279
279
    is( Koha::Email->is_valid('<from@fróm.com>'), 0 )
280
    is( Koha::Email->is_valid('<from@fróm.com>'), 0 )
280
        ;    # "In accordance with RFC 822 and its descendants, this module demands that email addresses be ASCII only"
281
        ;    # "In accordance with RFC 822 and its descendants, this module demands that email addresses be ASCII only"
281
    isnt( Koha::Email->is_valid('@example.com'), 1 );
282
    isnt( Koha::Email->is_valid('@example.com'),      1 );
282
    isnt( Koha::Email->is_valid('example.com'),  1 );
283
    isnt( Koha::Email->is_valid('example.com'),       1 );
283
    isnt( Koha::Email->is_valid('from'),         1 );
284
    isnt( Koha::Email->is_valid('from'),              1 );
285
    isnt( Koha::Email->is_valid('root@example'),      1, 'example is not a TLD' );
286
    isnt( Koha::Email->is_valid('root@.example.com'), 1, 'period in front of domain' );
284
};
287
};
285
288
286
subtest 'new_from_string() tests' => sub {
289
subtest 'new_from_string() tests' => sub {
287
- 

Return to bug 41025