Fix for RT#32215 ticket for multipart not coming through
J. Shirley [Fri, 4 Jul 2008 02:37:30 +0000 (02:37 +0000)]
lib/Catalyst/View/Email.pm
lib/Catalyst/View/Email/Template.pm
t/05template.t
t/lib/TestApp/Controller/Root.pm

index 68aefe2..9cd6d5a 100644 (file)
@@ -11,7 +11,7 @@ use Email::MIME::Creator;
 
 use base qw/ Catalyst::View /;
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 __PACKAGE__->mk_accessors(qw/ mailer /);
 
@@ -211,8 +211,9 @@ sub process {
     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 @@ sub process {
             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 @@ sub process {
         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} )
     {
index e783585..8559775 100644 (file)
@@ -11,7 +11,7 @@ use Email::MIME::Creator;
 
 use base qw/ Catalyst::View::Email /;
 
-our $VERSION = '0.10';
+our $VERSION = '0.11';
 
 =head1 NAME
 
@@ -64,6 +64,7 @@ the template instead of the body and forwarding to your Email::Template view:
             from        => 'no-reply@foobar.com',
             subject     => 'I am a Catalyst generated email',
             template    => 'test.tt',
+            content_type => 'multipart/alternative'
         };
         
         $c->forward( $c->view('Email::Template') );
index ca488e4..10f48f4 100644 (file)
@@ -11,7 +11,7 @@ if ( $@ ) {
     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 @@ my @emails = Email::Send::Test->emails;
 
 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');
index 4e95693..bff9d20 100644 (file)
@@ -59,9 +59,10 @@ sub template_email : Global('template_email') {
     $c->stash->{time} = $c->req->params->{time} || time;
 
     $c->stash->{email} = {
-        to      => 'test-email@example.com',
-        from    => 'no-reply@example.com',
-        subject => 'Just a test',
+        to           => 'test-email@example.com',
+        from         => 'no-reply@example.com',
+        subject      => 'Just a test',
+        content_type => 'multipart/alternative',
         templates => [
             {
                 template        => 'text_plain/test.tt',