[Jifty-commit] jifty branch, utf8-notification, created. 3f5b436ba4997a1dcca18aac6097af0feff9cee0

Jifty commits jifty-commit at lists.jifty.org
Wed Dec 30 02:48:28 EST 2009


The branch, utf8-notification has been created
        at  3f5b436ba4997a1dcca18aac6097af0feff9cee0 (commit)

- Log -----------------------------------------------------------------
commit 83de269cb5969ed0a54151b6c4a75565533b9ba1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:12:56 2009 -0500

    Revert 4db2709; Email::MIME takes bytes, and full_body is characters
    
    Email::MIME takes _bytes_, not characters, for the "body" argument, so
    we need to encode the full_body (which has characters) into UTF8.
    Modern Email::MIME->create takes a "body_str" argument which does the
    encoding for us, but Email::MIME::CreateHTML doesn't grok it (yet).

diff --git a/lib/Jifty/Notification.pm b/lib/Jifty/Notification.pm
index f597dc6..af4e1e1 100644
--- a/lib/Jifty/Notification.pm
+++ b/lib/Jifty/Notification.pm
@@ -113,9 +113,12 @@ sub send_one_message {
 
     if ( defined $self->html_body ) {
 
-        # NOTICE: we should keep string in perl string (with utf8
-        # flag) rather then encode it into octets. Email::MIME would
-        # call Encode::encode in its create function.
+        # Email::MIME takes _bytes_, not characters, for the "body"
+        # argument, so we need to encode the full_body into UTF8.
+        # Modern Email::MIME->create takes a "body_str" argument which
+        # does the encoding for us, but Email::MIME::CreateHTML
+        # doesn't grok it.  See also L</parts> for the other location
+        # which does the encode.
         $message = Email::MIME->create_html(
             header => [
                 From    => $from,
@@ -125,8 +128,8 @@ sub send_one_message {
             attributes           => \%attrs,
             text_body_attributes => \%attrs,
             body_attributes      => \%attrs,
-            text_body            => $self->full_body,
-            body                 => $self->full_html,
+            text_body            => Encode::encode_utf8( $self->full_body ),
+            body                 => Encode::encode_utf8( $self->full_html ),
             embed                => 0,
             inline_css           => 0,
         );
@@ -333,7 +336,7 @@ sub parts {
 # its create function.
   return [ Email::MIME->create(
       attributes => { charset => 'UTF-8' },
-      body       => $self->full_body,
+      body       => Encode::encode_utf8( $self->full_body ),
     ) ];
 }
 

commit 1b51087b3fc7b50118fbcf948f7a7636d8ba3b39
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:23:36 2009 -0500

    Use Email::MIME's ->body_str method, which does charset decoding
    
    This also causes "use encoding" to be no longer necessary.  The "use
    encoding" line papered over the fact that emails loaded from the file
    weren't being decoded -- "use encoding" happened to be silently
    decoding them as UTF8, however.

diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index 66f3c56..7ad4b6a 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -4,7 +4,6 @@ use strict;
 
 use Jifty::Test::Dist tests => 4;
 use TestApp::Notifications::Notification;
-use encoding 'utf8';
 
 sub send_and_receive {
     local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -21,7 +20,7 @@ sub send_and_receive {
     Jifty::Test->teardown_mailbox;
 
     is(scalar @emails, 1, "Sent one notification email");
-    return $emails[0]->body;
+    return Email::MIME->new($emails[0]->as_string)->body_str;
 }
 
 {

commit f9cd3b75ae43d0d34cd987b25f1ca90e44b4a2ee
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:24:47 2009 -0500

    Bodies should be characters, not bytes

diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index 7ad4b6a..c7f5aea 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -25,7 +25,6 @@ sub send_and_receive {
 
 {
     my $str = "Simple Latin-1\n\n";  # latin bytes string
-    utf8::encode( $str );  # upgrade $str to utf8 bytes string
     my $body = send_and_receive( $str );
     is($body, $str );
 }
@@ -33,7 +32,6 @@ sub send_and_receive {
 # XXX: should this be "All L\N{LATIN SMALL LETTER E WITH ACUTE}on's fault"
 {
     my $str = "All L\x{c3}\x{a9}on's fault\n\n";   # latin1 bytes string
-    utf8::encode( $str );  # upgrade to utf8 bytes string
     my $body = send_and_receive( $str );
     is($body, $str );
 }

commit 6b2598ba7779f80bddee0492cd2188bd7b54da17
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:27:27 2009 -0500

    Use the explicit character name from "use charnames"

diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index c7f5aea..0abe273 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -4,6 +4,7 @@ use strict;
 
 use Jifty::Test::Dist tests => 4;
 use TestApp::Notifications::Notification;
+use charnames ':full';
 
 sub send_and_receive {
     local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -29,9 +30,8 @@ sub send_and_receive {
     is($body, $str );
 }
 
-# XXX: should this be "All L\N{LATIN SMALL LETTER E WITH ACUTE}on's fault"
 {
-    my $str = "All L\x{c3}\x{a9}on's fault\n\n";   # latin1 bytes string
+    my $str = "All L\N{LATIN SMALL LETTER E WITH ACUTE}on's fault\n\n";
     my $body = send_and_receive( $str );
     is($body, $str );
 }

commit 9ad4f58ea7d40619314fa1744e7c5272e2d48197
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:31:06 2009 -0500

    Fold t/encoding-2.t into t/encoding.t
    
    The t/encoding-2.t test was only failing because Jifty::Test::Email is
    based on Test::Email, which is based on MIME::Entity -- which makes no
    attempt to parse or understand character sets.  Thus, the message
    failed to match the regular expression, which was in characters.
    
    Using the same infrastructure as t/encoding.t causes the test to
    succeed.

diff --git a/t/TestApp-Notifications/t/encoding-2.t b/t/TestApp-Notifications/t/encoding-2.t
deleted file mode 100644
index 903dfe2..0000000
--- a/t/TestApp-Notifications/t/encoding-2.t
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/env perl
-use warnings;
-use strict;
-use Jifty::Test::Dist tests => 4;
-use Jifty::Test::Email;
-use Test::Exception;
-
-mail_ok  {
-    my $n = Jifty->app_class( 'Notification' => 'Foo' )->new;
-    $n->body( "Simple Latin-1\n\n" );
-    $n->send_one_message;
-    } { body => qr'Simple Latin-1's };
-
-mail_ok  {
-    my $n = Jifty->app_class( 'Notification' => 'Foo' )->new;
-    $n->body( "中文\n\n\n" );
-    $n->send_one_message;
-    } { body => qr'中文's };
-
-1;
diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index 0abe273..3e40e50 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -2,9 +2,10 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 4;
+use Jifty::Test::Dist tests => 6;
 use TestApp::Notifications::Notification;
 use charnames ':full';
+use utf8;
 
 sub send_and_receive {
     local $Test::Builder::Level = $Test::Builder::Level + 1;
@@ -27,11 +28,17 @@ sub send_and_receive {
 {
     my $str = "Simple Latin-1\n\n";  # latin bytes string
     my $body = send_and_receive( $str );
-    is($body, $str );
+    is($body, $str, "Latin looks fine" );
 }
 
 {
     my $str = "All L\N{LATIN SMALL LETTER E WITH ACUTE}on's fault\n\n";
     my $body = send_and_receive( $str );
-    is($body, $str );
+    is($body, $str, "Implicit UTF8 char" );
+}
+
+{
+    my $str = "中文\n\n\n";
+    my $body = send_and_receive( $str );
+    is($body, $str, "Explicit UTF8 char" );
 }

commit 77c2dbaadd854f7a9504f3732e6ff47183602ffd
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:47:07 2009 -0500

    Messages seem to loose a newline somewhere between sending and loading

diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index 3e40e50..c1398db 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -22,7 +22,7 @@ sub send_and_receive {
     Jifty::Test->teardown_mailbox;
 
     is(scalar @emails, 1, "Sent one notification email");
-    return Email::MIME->new($emails[0]->as_string)->body_str;
+    return Email::MIME->new($emails[0]->as_string)->body_str . "\n";
 }
 
 {

commit 3f5b436ba4997a1dcca18aac6097af0feff9cee0
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Dec 30 02:34:15 2009 -0500

    Test L10N round-trips through notifications, using _

diff --git a/t/TestApp-Notifications/t/encoding.t b/t/TestApp-Notifications/t/encoding.t
index c1398db..39f60fe 100644
--- a/t/TestApp-Notifications/t/encoding.t
+++ b/t/TestApp-Notifications/t/encoding.t
@@ -2,7 +2,7 @@
 use warnings;
 use strict;
 
-use Jifty::Test::Dist tests => 6;
+use Jifty::Test::Dist tests => 8;
 use TestApp::Notifications::Notification;
 use charnames ':full';
 use utf8;
@@ -42,3 +42,12 @@ sub send_and_receive {
     my $body = send_and_receive( $str );
     is($body, $str, "Explicit UTF8 char" );
 }
+
+{
+    my $lh = Jifty::I18N->get_handle("ja");
+    Jifty::I18N->install_global_loc(\$lh);
+
+    my $str = _("Alert") . "\n\n";
+    my $body = send_and_receive( $str );
+    is($body, $str, "L10N UTF8 char" );
+}

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list