Skip to content

Commit

Permalink
Fix encoding email headers and fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pali committed Mar 29, 2016
1 parent fbe542f commit 95d0cda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 3 additions & 5 deletions lib/SVN/Notify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,9 @@ sub output_headers {
$self->_dbpnt( "Outputting headers") if $self->{verbose} > 2;

# Q-Encoding (RFC 2047)
my ($subj, $from, $to) = PERL58 ? map {
Encode::encode( 'MIME-Q', $_ );
} $self->{subject}, $self->{from}, join ', ', @{ $self->{to} } : (
$self->{subject}, $self->{from}, join ', ', @{ $self->{to} }
);
my $subj = ( PERL58 && $self->{subject} =~ /(?:\P{ASCII}|=)/s ) ? Encode::encode( 'MIME-Q', $self->{subject} ) : $self->{subject};
my $from = $self->{from};
my $to = join ', ', @{ $self->{to} };

my @headers = (
"MIME-Version: 1.0\n",
Expand Down
11 changes: 6 additions & 5 deletions t/base.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ my $subj = "Did this, that, and the «other».";
my $qsubj;
if (SVN::Notify::PERL58()) {
$subj = Encode::decode_utf8( $subj );
$qsubj = quotemeta Encode::encode( 'MIME-Q', $subj );
$qsubj = quotemeta Encode::encode( 'MIME-Q', '[111] ' . $subj );
} else {
$qsubj = quotemeta $subj;
}
Expand Down Expand Up @@ -94,7 +94,7 @@ ok( $notifier->execute, "Notify" );
my $email = get_output();

# Check the email headers.
like( $email, qr/Subject: \[111\] $qsubj\n/, "Check subject" );
like( $email, qr/Subject: $qsubj\n/, "Check subject" );
like( $email, qr/From: theory\n/, 'Check From');
like( $email, qr/Errors-To: theory\n/, 'Check Errors-To');
like( $email, qr/To: test\@example\.com\n/, 'Check To');
Expand Down Expand Up @@ -159,7 +159,7 @@ NO_BADLANG: {
# Get the output.
$email = get_output();

like( $email, qr/Subject: \[111\] $qsubj\n/, "Check diff subject" );
like( $email, qr/Subject: $qsubj\n/, "Check diff subject" );
like( $email, qr/From: theory\n/, 'Check diff From');
like( $email, qr/To: test\@example\.com\n/, 'Check diff To');
like( $email, qr/Content-Language: en_US\n/, 'Check diff Content-Language');
Expand Down Expand Up @@ -195,7 +195,7 @@ NO_BADLANG: {
# Get the output.
$email = get_output();

like( $email, qr/Subject: \[111\] $qsubj\n/, 'Check attach diff subject' );
like( $email, qr/Subject: $qsubj\n/, 'Check attach diff subject' );
like( $email, qr/From: theory\n/, 'Check attach diff From');
like( $email, qr/To: test\@example\.com\n/, 'Check attach diff To');

Expand Down Expand Up @@ -289,7 +289,8 @@ ok( $notifier->execute, "Notify subject_prefix" );

# Check the output.
$email = get_output();
like( $email, qr/Subject: \[C\] \[111\] $qsubj\n/, 'Check subject header for prefix' );
my $qsubj_prefix = SVN::Notify::PERL58() ? quotemeta Encode::encode( 'MIME-Q', '[C] [111] ' . $subj ) : '[C] [111] ' . $subj;
like( $email, qr/Subject: $qsubj_prefix\n/, 'Check subject header for prefix' );

##############################################################################
# Try subject_prefix with %n.
Expand Down

0 comments on commit 95d0cda

Please sign in to comment.