From 588ff195dd15b84ca9515b8a13817513a093c8ed Mon Sep 17 00:00:00 2001
From: Jonathan Druart <jonathan.druart@biblibre.com>
Date: Mon, 7 Oct 2013 14:04:16 +0200
Subject: [PATCH] Bug 9218: intranet cart email broken for non english
 templates

While bug 9189 is not resolved, we have to find workaround for
templates broken by missing carriage return.

This (dirty) patch adds a personal tag "PARAGRAPH" for adding new lines.

Test plan:
- add somes notices to the cart
- try to send the cart by email
- the email should be the same as before
- translate templates and retry with another language. Before this patch,
  the email was empty. With this patch, it contains the list of records
  and items.
---
 basket/sendbasket.pl                               |   37 +++++++-----
 .../prog/en/modules/basket/sendbasket.tt           |   62 +++++++++++---------
 2 files changed, 56 insertions(+), 43 deletions(-)

diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl
index 66f73fa..2c6aa7f 100755
--- a/basket/sendbasket.pl
+++ b/basket/sendbasket.pl
@@ -112,33 +112,42 @@ if ( $email_add ) {
     my $body;
 
     # Analysing information and getting mail properties
-    if ( $template_res =~ /<SUBJECT>\n(.*)\n<END_SUBJECT>/s ) {
-        $mail{'subject'} = $1;
+    if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) {
+        my $subject = $1;
+        $subject =~ s/\n?(.*)\n?/$1/;
+        $mail{'subject'} = $subject;
     }
     else { $mail{'subject'} = "no subject"; }
 
     my $email_header = "";
-    if ( $template_res =~ /<HEADER>\n(.*)\n<END_HEADER>/s ) {
-        $email_header = $1;
+    if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
+        my $tmp_header = $1;
+        $tmp_header =~ s|\n||g;
+        $email_header = $tmp_header;
+        while ($tmp_header =~ m|(<PARAGRAPH>)(.*?)(</PARAGRAPH>)|gs) {
+            my $text = $2;
+            $email_header =~ s|<PARAGRAPH>\Q$text\E</PARAGRAPH>|$text\n|;
+        }
     }
 
     my $email_file = "basket.txt";
-    if ( $template_res =~ /<FILENAME>\n(.*)\n<END_FILENAME>/s ) {
+    if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) {
         $email_file = $1;
+        $email_file =~ s/\n?(.*)\n?/$1/;
     }
 
-    if ( $template_res =~ /<MESSAGE>\n(.*)\n<END_MESSAGE>/s ) { $body = encode_qp($1); }
+    if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
+        my $tmp_body = $1;
+        $tmp_body =~ s|\n||g;
+        $body = $tmp_body;
+        while ($tmp_body =~ m|(<PARAGRAPH>)(.*?)(</PARAGRAPH>)|gs) {
+            my $text = $2;
+            $body =~ s|<PARAGRAPH>\Q$text\E</PARAGRAPH>|$text\n|;
+        }
+    }
 
     my $boundary = "====" . time() . "====";
 
-    #     $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
-    #
-    #     $email_header = encode_qp($email_header);
-    #
-    #     $boundary = "--".$boundary;
-    #
-    #     # Writing mail
-    #     $mail{body} =
     $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
     my $isofile = encode_base64(encode("UTF-8", $iso2709));
     $boundary = '--' . $boundary;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt
index ca8f06d..d9368b8 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/basket/sendbasket.tt
@@ -3,40 +3,44 @@ Your cart
 <END_SUBJECT>
 
 <HEADER>
-Hi,
-
-Here is your cart, sent from our online catalog.
-
-Please note that the attached file is a MARC bibliographic records file
+<PARAGRAPH>Hi,</PARAGRAPH>
+<PARAGRAPH>Here is your cart, sent from our online catalog.</PARAGRAPH>
+<PARAGRAPH></PARAGRAPH>
+<PARAGRAPH>Please note that the attached file is a MARC bibliographic records file
 which can be imported into a Personal Bibliographic Software like EndNote,
-Reference Manager or ProCite.
+Reference Manager or ProCite.</PARAGRAPH>
 <END_HEADER>
 
 <MESSAGE>
----------------------------------------------
+<PARAGRAPH></PARAGRAPH>
+<PARAGRAPH>---------------------------------------------</PARAGRAPH>
+<PARAGRAPH></PARAGRAPH>
 [% IF ( comment ) %]
-[% comment %]
+<PARAGRAPH>[% comment %]</PARAGRAPH>
 [% END %]
-[% FOREACH BIBLIO_RESULT IN BIBLIO_RESULTS %][% BIBLIO_RESULT.title %][% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %][% IF ( BIBLIO_RESULT.HASAUTHORS ) %]
-Author(s): [% IF ( BIBLIO_RESULT.author ) %][% BIBLIO_RESULT.author %][% END %][% IF ( BIBLIO_RESULT.MARCAUTHORS ) %][% IF ( BIBLIO_RESULT.author ) %]; [% END %][% FOREACH MARCAUTHOR IN BIBLIO_RESULT.MARCAUTHORS %][% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %][% MARCAUTHOR_SUBFIELDS_LOO.separator %][% MARCAUTHOR_SUBFIELDS_LOO.value %][% END %][% UNLESS ( loop.last ) %]; [% ELSE %][% END %][% END %][% END %][% END %][% IF ( BIBLIO_RESULT.ISBN ) %]
-ISBN: [% BIBLIO_RESULT.ISBN %][% END %]
-[% IF ( BIBLIO_RESULT.publishercode ) %]Published by: [% BIBLIO_RESULT.publishercode %][% END %][% IF ( BIBLIO_RESULT.publicationyear ) %] in [% END %][% BIBLIO_RESULT.publicationyear %][% IF ( BIBLIO_RESULT.pages ) %], [% END %][% BIBLIO_RESULT.pages %][% IF ( BIBLIO_RESULT.size ) %], [% END %][% BIBLIO_RESULT.size %][% IF ( BIBLIO_RESULT.collection ) %]
-Collection: [% BIBLIO_RESULT.seriestitle %][% END %][% IF ( BIBLIO_RESULT.subject ) %]
-Subject: [% BIBLIO_RESULT.subject %][% END %][% IF ( BIBLIO_RESULT.copyrightdate ) %]
-Copyright year: [% BIBLIO_RESULT.copyrightdate %][% END %][% IF ( BIBLIO_RESULT.notes ) %]
-Notes : [% BIBLIO_RESULT.notes %][% END %][% IF ( BIBLIO_RESULT.unititle ) %]
-Unified title: [% BIBLIO_RESULT.unititle %][% END %][% IF ( BIBLIO_RESULT.serial ) %]
-Serial: [% BIBLIO_RESULT.serial %][% END %][% IF ( BIBLIO_RESULT.dewey ) %]
-Dewey: [% BIBLIO_RESULT.dewey %][% END %][% IF ( BIBLIO_RESULT.classification ) %]
-Classification: [% BIBLIO_RESULT.classification %][% END %][% IF ( BIBLIO_RESULT.lccn ) %]
-LCCN: [% BIBLIO_RESULT.lccn %][% END %][% IF ( BIBLIO_RESULT.url ) %]
-url : [% BIBLIO_RESULT.url %][% END %]
-In the online catalog:
-[% OPACBaseURL %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% BIBLIO_RESULT.biblionumber |url %]
-Items : [% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
-	[% ITEM_RESULT.branchname %] [% ITEM_RESULT.location %] [% IF ( ITEM_RESULT.itemcallnumber ) %]([% ITEM_RESULT.itemcallnumber %])[% END %] [% ITEM_RESULT.barcode %][% END %]
-
----------------------------------------------
-
+<PARAGRAPH></PARAGRAPH>
+[% FOREACH BIBLIO_RESULT IN BIBLIO_RESULTS %]
+<PARAGRAPH>[% BIBLIO_RESULT.title %][% IF ( BIBLIO_RESULT.subtitle ) %] [% BIBLIO_RESULT.subtitle %][% END %]</PARAGRAPH>
+[% IF ( BIBLIO_RESULT.HASAUTHORS ) %]<PARAGRAPH>Author(s): [% IF ( BIBLIO_RESULT.author ) %][% BIBLIO_RESULT.author %][% END %][% IF ( BIBLIO_RESULT.MARCAUTHORS ) %][% IF ( BIBLIO_RESULT.author ) %]; [% END %][% FOREACH MARCAUTHOR IN BIBLIO_RESULT.MARCAUTHORS %][% FOREACH MARCAUTHOR_SUBFIELDS_LOO IN MARCAUTHOR.MARCAUTHOR_SUBFIELDS_LOOP %][% MARCAUTHOR_SUBFIELDS_LOO.separator %][% MARCAUTHOR_SUBFIELDS_LOO.value %][% END %][% UNLESS ( loop.last ) %]; [% ELSE %][% END %][% END %][% END %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.ISBN ) %]<PARAGRAPH>ISBN: [% BIBLIO_RESULT.ISBN %]</PARAGRAPH>[% END %]
+<PARAGRAPH>[% IF ( BIBLIO_RESULT.publishercode ) %]Published by: [% BIBLIO_RESULT.publishercode %][% END %][% IF ( BIBLIO_RESULT.publicationyear ) %] in [% END %][% BIBLIO_RESULT.publicationyear %][% IF ( BIBLIO_RESULT.pages ) %], [% END %][% BIBLIO_RESULT.pages %][% IF ( BIBLIO_RESULT.size ) %], [% END %][% BIBLIO_RESULT.size %]</PARAGRAPH>
+[% IF ( BIBLIO_RESULT.collection ) %]<PARAGRAPH>Collection: [% BIBLIO_RESULT.seriestitle %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.subject ) %]<PARAGRAPH>Subject: [% BIBLIO_RESULT.subject %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.copyrightdate ) %]<PARAGRAPH>Copyright year: [% BIBLIO_RESULT.copyrightdate %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.notes ) %]<PARAGRAPH>Notes : [% BIBLIO_RESULT.notes %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.unititle ) %]<PARAGRAPH>Unified title: [% BIBLIO_RESULT.unititle %][% END %]
+[% IF ( BIBLIO_RESULT.serial ) %]<PARAGRAPH>Serial: [% BIBLIO_RESULT.serial %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.dewey ) %]<PARAGRAPH>Dewey: [% BIBLIO_RESULT.dewey %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.classification ) %]<PARAGRAPH>Classification: [% BIBLIO_RESULT.classification %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.lccn ) %]<PARAGRAPH>LCCN: [% BIBLIO_RESULT.lccn %]</PARAGRAPH>[% END %]
+[% IF ( BIBLIO_RESULT.url ) %]<PARAGRAPH>url : [% BIBLIO_RESULT.url %]</PARAGRAPH>[% END %]
+<PARAGRAPH>In the online catalog:</PARAGRAPH>
+<PARAGRAPH>[% OPACBaseURL %]/cgi-bin/koha/opac-detail.pl?biblionumber=[% BIBLIO_RESULT.biblionumber |url %]</PARAGRAPH>
+<PARAGRAPH>Items : </PARAGRAPH>
+[% FOREACH ITEM_RESULT IN BIBLIO_RESULT.ITEM_RESULTS %]
+<PARAGRAPH>	[% ITEM_RESULT.branchname %] [% ITEM_RESULT.location %] [% IF ( ITEM_RESULT.itemcallnumber ) %]([% ITEM_RESULT.itemcallnumber %])[% END %] [% ITEM_RESULT.barcode %]</PARAGRAPH>
+[% END %]
+<PARAGRAPH>---------------------------------------------</PARAGRAPH>
+<PARAGRAPH></PARAGRAPH>
 [% END %]
 <END_MESSAGE>
-- 
1.7.10.4