Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/Email/Stuffer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ use Email::MIME 1.920 ();
use Email::MIME::Creator ();
use Email::Sender::Simple ();
use Module::Runtime qw(require_module);
use Net::IDN::Encode qw(email_to_ascii);

#####################################################################
# Constructor and Accessors
Expand Down Expand Up @@ -277,7 +278,7 @@ Sets the To: header in the email
sub to {
my $self = shift()->_self;
Carp::croak("to is a required field") unless defined $_[0];
$self->{email}->header_str_set(To => join(q{, }, @_));
$self->{email}->header_str_set(To => join(q{, }, map { email_to_ascii $_ } @_));
return $self;
}

Expand All @@ -290,7 +291,7 @@ Sets the From: header in the email
sub from {
my $self = shift()->_self;
Carp::croak("from is a required field") unless defined $_[0];
$self->{email}->header_str_set(From => shift);
$self->{email}->header_str_set(From => email_to_ascii shift);
return $self;
}

Expand All @@ -302,7 +303,7 @@ Sets the Cc: header in the email

sub cc {
my $self = shift()->_self;
$self->{email}->header_str_set(Cc => join(q{, }, @_));
$self->{email}->header_str_set(Cc => join(q{, }, map { email_to_ascii $_ } @_));
return $self;
}

Expand All @@ -314,7 +315,7 @@ Sets the Bcc: header in the email

sub bcc {
my $self = shift()->_self;
$self->{email}->header_str_set(Bcc => join(q{, }, @_));
$self->{email}->header_str_set(Bcc => join(q{, }, map { email_to_ascii $_ } @_));
return $self;
}

Expand Down
15 changes: 14 additions & 1 deletion t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;
use File::Spec::Functions ':ALL';

use Test::More tests => 62;
use Test::More tests => 66;
use Test::Fatal;
use Email::Stuffer;

Expand Down Expand Up @@ -127,4 +127,17 @@ like $error,
qr/\Aerror opening no such file: \Q$enoent/,
'_slurp croaks when passed a bad filename';

# Set a To, From, Cc and BCc name and check if ascii
$rv = $Stuffer->to('adam@äli.as');
is( $Stuffer->email->header('To'), 'adam@xn--li-dda5w.as', '->To sets To header' );

$rv->from('adam@äli.as');
is( $Stuffer->email->header('From'), 'adam@xn--li-dda5w.as', '->From sets From header' );

$rv->cc ('adam@äli.as');
is( $Stuffer->email->header('Cc'), 'adam@xn--li-dda5w.as', '->Cc sets From header' );

$rv->bcc ('adam@äli.as');
is( $Stuffer->email->header('BCc'), 'adam@xn--li-dda5w.as', '->BCc sets From header' );

1;