Bug 11944: Fix encoding on sending emails
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 14 Apr 2014 14:33:56 +0000 (16:33 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Tue, 13 Jan 2015 16:07:24 +0000 (13:07 -0300)
This patch fixes 2 places where mails were badly encoded:
1/ At the opac and the intranet, on sending baskets
2/ At the opac and the intranet, on sending shelf/list

Test plan:
Shelf/List:
- Create a list with non-latin characters in the name.
- Add some items containing non-latin characters in their content.
- Send the list by email

Basket/Cart:
- Add some items containing non-latin characters in their content to
  your cart..
- Send the cart by email

Signed-off-by: Paola Rossi <paola.rossi@cineca.it>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>

basket/sendbasket.pl
opac/opac-sendbasket.pl
opac/opac-sendshelf.pl
virtualshelves/sendshelf.pl

index 36f3c1a..df8d358 100755 (executable)
@@ -112,6 +112,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
         $mail{subject} = $1;
         $mail{subject} =~ s|\n?(.*)\n?|$1|;
+        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
     }
     else { $mail{'subject'} = "no subject"; }
 
@@ -119,7 +120,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
         $email_header = $1;
         $email_header =~ s|\n?(.*)\n?|$1|;
-        $email_header = encode_qp($email_header);
+        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
     }
 
     my $email_file = "basket.txt";
@@ -131,7 +132,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
         $body = $1;
         $body =~ s|\n?(.*)\n?|$1|;
-        $body = encode_qp($body);
+        $body = encode_qp(Encode::encode("UTF-8", $body));
     }
 
     my $boundary = "====" . time() . "====";
index 7b63ee2..1dac954 100755 (executable)
@@ -131,6 +131,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
         $mail{subject} = $1;
         $mail{subject} =~ s|\n?(.*)\n?|$1|;
+        $mail{subject} = Encode::encode("UTF-8", $mail{subject});
     }
     else { $mail{'subject'} = "no subject"; }
 
@@ -138,7 +139,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
         $email_header = $1;
         $email_header =~ s|\n?(.*)\n?|$1|;
-        $email_header = encode_qp($email_header);
+        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
     }
 
     my $email_file = "basket.txt";
@@ -150,7 +151,7 @@ if ( $email_add ) {
     if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
         $body = $1;
         $body =~ s|\n?(.*)\n?|$1|;
-        $body = encode_qp($body);
+        $body = encode_qp(Encode::encode("UTF-8", $body));
     }
 
     $mail{body} = $body;
index 61cc979..7856380 100755 (executable)
@@ -128,12 +128,13 @@ if ( $email ) {
         $mail{subject} =~ s|\n?(.*)\n?|$1|;
     }
     else { $mail{'subject'} = "no subject"; }
+    $mail{subject} = Encode::encode("UTF-8", $mail{subject});
 
     my $email_header = "";
     if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
         $email_header = $1;
         $email_header =~ s|\n?(.*)\n?|$1|;
-        $email_header = encode_qp($email_header);
+        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
     }
 
     my $email_file = "list.txt";
@@ -145,7 +146,7 @@ if ( $email ) {
     if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
         $body = $1;
         $body =~ s|\n?(.*)\n?|$1|;
-        $body = encode_qp($body);
+        $body = encode_qp(Encode::encode("UTF-8", $body));
     }
 
     my $boundary = "====" . time() . "====";
index c98e8ce..4649aa3 100755 (executable)
@@ -21,7 +21,7 @@ use strict;
 use warnings;
 
 use CGI qw ( -utf8 );
-use Encode qw(encode);
+use Encode qw( encode );
 use Carp;
 
 use Mail::Sendmail;
@@ -119,7 +119,7 @@ if ($email) {
 
     # Analysing information and getting mail properties
     if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
-        $mail{subject} = $1;
+        $mail{'subject'} = Encode::encode("UTF-8", $1);
         $mail{subject} =~ s|\n?(.*)\n?|$1|;
     }
     else { $mail{'subject'} = "no subject"; }
@@ -128,7 +128,7 @@ if ($email) {
     if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
         $email_header = $1;
         $email_header =~ s|\n?(.*)\n?|$1|;
-        $email_header = encode_qp($email_header);
+        $email_header = encode_qp(Encode::encode("UTF-8", $email_header));
     }
 
     my $email_file = "list.txt";
@@ -140,7 +140,7 @@ if ($email) {
     if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
         $body = $1;
         $body =~ s|\n?(.*)\n?|$1|;
-        $body = encode_qp($body);
+        $body = encode_qp(Encode::encode("UTF-8", $body));
     }
 
     my $boundary = "====" . time() . "====";