Bug 28017: Allow non-FQDN (@localhost) addresses
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 22 Mar 2021 17:47:33 +0000 (14:47 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 1 Apr 2021 16:51:37 +0000 (18:51 +0200)
This patch makes Koha::Email support using @localhost addresses.

To test:
1. Apply the regression tests
2. Run:
   $ kshell
  k$ prove t/Koha/Email.t
=> FAIL: Koha::Email doesn't support non-fqdn addresses
3. Apply this patch
4. Repeat 2
=> SUCCESS: All tests pass!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Email.pm

index 64c811c..9c077a6 100644 (file)
@@ -78,7 +78,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($args->{from}); # from is mandatory
+        unless Email::Valid->address( -address => $args->{from}, -fqdn => 0 ); # from is mandatory
 
     $args->{subject} = $params->{subject} // '';
 
@@ -90,7 +90,7 @@ sub create {
     }
 
     Koha::Exceptions::BadParameter->throw("Invalid 'to' parameter: ".$args->{to})
-        unless Email::Valid->address($args->{to}); # to is mandatory
+        unless Email::Valid->address( -address => $args->{to}, -fqdn => 0 ); # to is mandatory
 
     my $addresses = {};
     $addresses->{reply_to} = $params->{reply_to};
@@ -108,9 +108,13 @@ sub create {
             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 !Email::Valid->address(
+            -address => $addresses->{$address},
+            -fqdn    => 0
+          );
     }
 
     $args->{cc} = $addresses->{cc}