Description: Fix avoid broken Email::Address
Author: Jonas Smedegaard <dr@jones.dk>
Bug: https://github.com/CiderWebmail/CiderWebmail/issues/39
Bug-Debian: https://bugs.debian.org/887535
Last-Update: 2020-02-24
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -53,8 +53,7 @@
 requires 'Email::Simple';
 requires 'Email::Sender';
 requires 'Email::Valid';
-requires 'Email::Address';
-requires 'Regexp::Common::Email::Address';
+requires 'Email::Address::XS';
 requires 'Regexp::Common::URI';
 
 requires 'Text::Iconv';
@@ -64,7 +63,7 @@
 
 requires 'Net::ManageSieve';
 
-requires 'Email::Address';
+requires 'Email::Address::XS';
 
 requires 'Parse::RecDescent' => '1.967009'; #https://rt.cpan.org/Public/Bug/Display.html?id=76118
 requires 'Mail::IMAPClient' => '3.41';
--- a/lib/CiderWebmail/Controller/Message.pm
+++ b/lib/CiderWebmail/Controller/Message.pm
@@ -15,7 +15,7 @@
 use DateTime::Format::Mail;
 use Email::Valid;
 
-use Email::Address;
+use Email::Address::XS;
 
 use Clone qw(clone);
 use List::Util qw(first);
@@ -236,10 +236,10 @@
     }
 
     if ($settings and $settings->from_address) {
-        $c->stash->{message}{from} = [ Email::Address->parse($settings->from_address) ];
+        $c->stash->{message}{from} = [ Email::Address::XS->parse($settings->from_address) ];
     }
     elsif ($c->config->{username_default_address}) {
-        $c->stash->{message}{from} = [ Email::Address->parse($c->session->{username}) ]
+        $c->stash->{message}{from} = [ Email::Address::XS->parse($c->session->{username}) ]
     }
 
     my $folders = clone($c->stash->{folders_hash});
--- a/lib/CiderWebmail/Header.pm
+++ b/lib/CiderWebmail/Header.pm
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Email::Address;
+use Email::Address::XS;
 use Time::Piece;
 use Date::Parse;
 
@@ -20,11 +20,11 @@
 
 =over 4
 
-=item * from -> Email::Address object
+=item * from -> Email::Address::XS object
 
-=item * to -> Email::Address object
+=item * to -> Email::Address::XS object
 
-=item * cc -> Email::Address object
+=item * cc -> Email::Address::XS object
 
 =item * date -> CiderWebmail::Date object
 
@@ -59,14 +59,14 @@
     my ($o) = @_;
 
     #here data might be defined but empty (no address given for example no Cc address)
-    #we still need a empty Email::Address object so we don't break templates that rely on it
-    return [Email::Address->parse('')] unless length($o->{data} // '');
+    #we still need a empty Email::Address::XS object so we don't break templates that rely on it
+    return [Email::Address::XS->parse('')] unless length($o->{data} // '');
 
     $o->{data} = decode_mime_words($o);
 
     $o->{data} =~ s/mailto://gi;
 
-    my @address = Email::Address->parse($o->{data});
+    my @address = Email::Address::XS->parse($o->{data});
 
     return \@address;
 }
--- a/lib/CiderWebmail/Mailbox.pm
+++ b/lib/CiderWebmail/Mailbox.pm
@@ -18,7 +18,6 @@
 use Moose;
 
 use CiderWebmail::Message;
-use Email::Address;
 
 =head1 ATTRIBUTES
 
--- a/lib/CiderWebmail/Util.pm
+++ b/lib/CiderWebmail/Util.pm
@@ -184,7 +184,7 @@
 
 =head2 filter_unusable_addresses(@addresses)
 
-Filters a list of addresses (string or Email::Address) to get rid of stuff like 'undisclosed-recipients:'
+Filters a list of addresses (string or Email::Address::XS) to get rid of stuff like 'undisclosed-recipients:'
 
 =cut
 
--- a/t/04controller_Root.t
+++ b/t/04controller_Root.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 
 $mech->follow_link_ok({ url_regex => qr{/mailboxes\z} });
 
--- a/t/06-send-message.t
+++ b/t/06-send-message.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use English qw(-no_match_vars);
 
 
--- a/t/addressbook.t
+++ b/t/addressbook.t
@@ -2,8 +2,7 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
+use Email::Address::XS;
 use English qw(-no_match_vars);
 
 my $unix_time = time();
@@ -69,8 +68,11 @@
     my ($mech, $field, $empty) = @_;
 
     my $value = $mech->value(lc $field);
-    $empty = $empty ? '^$|' :  '';
-    like($value, qr($empty$RE{Email}{Address}), $mech->uri . ": '$field' field contains an email address");
+    if ($empty and !$value) {
+        pass($mech->uri . ": '$field' field is empty");
+    } else {
+        ok(Email::Address::XS->parse($value)->is_valid(), $mech->uri . ": '$field' field contains an email address");
+    }
 }
 
 sub field_contains {
--- a/t/append_signature.t
+++ b/t/append_signature.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use English qw(-no_match_vars);
 
 
--- a/t/compose_message_errorhandling.t
+++ b/t/compose_message_errorhandling.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use English qw(-no_match_vars);
 
 use JSON::XS;
--- a/t/hebrew.t
+++ b/t/hebrew.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use English qw(-no_match_vars);
 
 use charnames ':full';
--- a/t/html5_validation.t
+++ b/t/html5_validation.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use WWW::Mechanize;
 
 use English qw(-no_match_vars);
--- a/t/message_handling.t
+++ b/t/message_handling.t
@@ -2,8 +2,7 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
+use Email::Address::XS;
 use English qw(-no_match_vars);
 
 
@@ -116,8 +115,11 @@
     my ($mech, $field, $empty) = @_;
 
     my $value = $mech->value(lc $field);
-    $empty = $empty ? '^$|' :  '';
-    like($value, qr($empty$RE{Email}{Address}), $mech->uri . ": '$field' field contains an email address");
+    if ($empty and !$value) {
+        pass($mech->uri . ": '$field' field is empty");
+    } else {
+        ok(Email::Address::XS->parse($value)->is_valid(), $mech->uri . ": '$field' field contains an email address");
+    }
 }
 
 done_testing;
--- a/t/utf8.t
+++ b/t/utf8.t
@@ -2,8 +2,6 @@
 use warnings;
 use Test::More;
 use CiderWebmail::Test {login => 1};
-use Regexp::Common qw(Email::Address);
-use Email::Address;
 use English qw(-no_match_vars);
 
 use charnames ':full';
