properly encode email body content
authorTony Cook <tony@develop-help.com>
Fri, 4 Apr 2014 05:20:49 +0000 (16:20 +1100)
committerTony Cook <tony@develop-help.com>
Fri, 11 Apr 2014 06:00:18 +0000 (16:00 +1000)
site/cgi-bin/modules/BSE/ComposeMail.pm

index cee174ed1c5d5c6af95a99027c6644a83574b1bc..5a6b4b7c0ee5ef72a82436ce9055ef9812ef9351 100644 (file)
@@ -6,7 +6,7 @@ use Carp 'confess';
 use Digest::MD5 qw(md5_hex);
 use BSE::Variables;
 
-our $VERSION = "1.009";
+our $VERSION = "1.010";
 
 =head1 NAME
 
@@ -333,6 +333,8 @@ sub _build_mime_lite {
   $text_content .= "\n" unless $text_content =~ /\n$/;
   $html_content .= "\n" unless $html_content =~ /\n$/;
 
+  my $charset = $self->{cfg}->charset;
+
   my $msg = MIME::Lite->new
     (
      From => $self->{from},
@@ -342,7 +344,7 @@ sub _build_mime_lite {
     );
   my $text_part = $msg->attach
     (
-     Type => 'text/plain',
+     Type => "text/plain; charset=$charset",
      Data => [ $text_content ],
      $text_content =~ /.{79}/ || $text_content =~ /[^ -~\x0d\x0a]/
      ? ( Encoding => 'quoted-printable' ) : (),
@@ -350,7 +352,7 @@ sub _build_mime_lite {
   my $html_part = $msg->attach(Type => 'multipart/related');
   $html_part->attach
     (
-     Type => 'text/html',
+     Type => BSE::Template->html_type($self->{cfg}),
      Data => $html_content,
      Encoding => 'quoted-printable',
     );
@@ -444,6 +446,9 @@ sub done {
   my @headers;
   my $content = BSE::Template->
     get_page($self->{template}, $self->{cfg}, \%acts, undef, undef, $self->{vars});
+
+  $content = BSE::Template->encode_content($content, $self->{cfg});
+
   if (!$self->{allow_html} || $self->{encrypt} || 
       !BSE::Template->find_source($self->{html_template}, $self->{cfg})) {
     my $text_type = 'text/plain';
@@ -497,6 +502,8 @@ DUMP
       }
     }
 
+    $html_content = BSE::Template->encode_content($html_content, $self->{cfg});
+
     $message = $self->_build_mime_lite($content, $html_content, \@headers);
   }
   push @headers, $self->extra_headers;