[Catalyst-commits] r8081 - in Catalyst-View-Email/0.10: lib/Catalyst/View lib/Catalyst/View/Email t t/lib/TestApp/Controller

jshirley at dev.catalyst.perl.org jshirley at dev.catalyst.perl.org
Fri Jul 4 03:37:30 BST 2008


Author: jshirley
Date: 2008-07-04 03:37:30 +0100 (Fri, 04 Jul 2008)
New Revision: 8081

Modified:
   Catalyst-View-Email/0.10/lib/Catalyst/View/Email.pm
   Catalyst-View-Email/0.10/lib/Catalyst/View/Email/Template.pm
   Catalyst-View-Email/0.10/t/05template.t
   Catalyst-View-Email/0.10/t/lib/TestApp/Controller/Root.pm
Log:
Fix for RT#32215 ticket for multipart not coming through

Modified: Catalyst-View-Email/0.10/lib/Catalyst/View/Email/Template.pm
===================================================================
--- Catalyst-View-Email/0.10/lib/Catalyst/View/Email/Template.pm	2008-07-04 00:56:01 UTC (rev 8080)
+++ Catalyst-View-Email/0.10/lib/Catalyst/View/Email/Template.pm	2008-07-04 02:37:30 UTC (rev 8081)
@@ -11,7 +11,7 @@
 
 use base qw/ Catalyst::View::Email /;
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 =head1 NAME
 
@@ -64,6 +64,7 @@
             from        => 'no-reply at foobar.com',
             subject     => 'I am a Catalyst generated email',
             template    => 'test.tt',
+            content_type => 'multipart/alternative'
         };
         
         $c->forward( $c->view('Email::Template') );

Modified: Catalyst-View-Email/0.10/lib/Catalyst/View/Email.pm
===================================================================
--- Catalyst-View-Email/0.10/lib/Catalyst/View/Email.pm	2008-07-04 00:56:01 UTC (rev 8080)
+++ Catalyst-View-Email/0.10/lib/Catalyst/View/Email.pm	2008-07-04 02:37:30 UTC (rev 8081)
@@ -11,7 +11,7 @@
 
 use base qw/ Catalyst::View /;
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 __PACKAGE__->mk_accessors(qw/ mailer /);
 
@@ -211,8 +211,9 @@
     croak "Can't send email without a valid email structure"
         unless $email;
 
-    if ( exists $self->{content_type} ) {
-        $email->{content_type} ||= $self->{content_type};
+    # Default content type
+    if ( exists $self->{content_type} and not $email->{content_type} ) {
+        $email->{content_type} = $self->{content_type};
     }
 
     my $header  = $email->{header} || [];
@@ -226,7 +227,7 @@
             if $email->{from};
         push @$header, ('Subject' => delete $email->{subject})
             if $email->{subject};
-        push @$header, ('Content-type' => delete $email->{content_type})
+        push @$header, ('Content-type' => $email->{content_type})
             if $email->{content_type};
 
     my $parts = $email->{parts};
@@ -236,14 +237,16 @@
         croak "Can't send email without parts or body, check stash";
     }
 
-    my %mime = ( header => $header );
+    my %mime = ( header => $header, attributes => {} );
 
     if ( $parts and ref $parts eq 'ARRAY' ) {
         $mime{parts} = $parts;
     } else {
         $mime{body} = $body;
     }
-    
+
+    $mime{attributes}->{content_type} = $email->{content_type} 
+        if $email->{content_type};
     if ( $mime{attributes} and not $mime{attributes}->{charset} and
          $self->{default}->{charset} )
     {

Modified: Catalyst-View-Email/0.10/t/05template.t
===================================================================
--- Catalyst-View-Email/0.10/t/05template.t	2008-07-04 00:56:01 UTC (rev 8080)
+++ Catalyst-View-Email/0.10/t/05template.t	2008-07-04 02:37:30 UTC (rev 8081)
@@ -11,7 +11,7 @@
     plan skip_all => 'Catalyst::View::TT required for Template tests';
     exit;
 }
-plan tests => 10;
+plan tests => 11;
 
 use_ok('Catalyst::Test', 'TestApp');
 
@@ -24,10 +24,13 @@
 
 cmp_ok(@emails, '==', 1, 'got emails');
 isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+
+like($emails[0]->content_type, qr#^multipart/alternative#, 'Multipart email');
+
 my @parts = $emails[0]->parts;
 cmp_ok(@parts, '==', 2, 'got parts');
 
-is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain ok');
+is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain part ok');
 like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
 
 is($parts[1]->content_type, 'text/html; charset="us-ascii"', 'text/html ok');

Modified: Catalyst-View-Email/0.10/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-View-Email/0.10/t/lib/TestApp/Controller/Root.pm	2008-07-04 00:56:01 UTC (rev 8080)
+++ Catalyst-View-Email/0.10/t/lib/TestApp/Controller/Root.pm	2008-07-04 02:37:30 UTC (rev 8081)
@@ -59,9 +59,10 @@
     $c->stash->{time} = $c->req->params->{time} || time;
 
     $c->stash->{email} = {
-        to      => 'test-email at example.com',
-        from    => 'no-reply at example.com',
-        subject => 'Just a test',
+        to           => 'test-email at example.com',
+        from         => 'no-reply at example.com',
+        subject      => 'Just a test',
+        content_type => 'multipart/alternative',
         templates => [
             {
                 template        => 'text_plain/test.tt',




More information about the Catalyst-commits mailing list