Bug 17600: Standardize our EXPORT_OK
[srvgit] / basket / sendbasket.pl
index d7e3fbc..1ea56fc 100755 (executable)
 use Modern::Perl;
 
 use CGI qw ( -utf8 );
-use Encode qw(encode);
-use Carp;
-use Try::Tiny;
-
-use C4::Biblio;
-use C4::Items;
-use C4::Auth;
-use C4::Output;
-use C4::Templates ();
+use Encode;
+use Carp qw( carp );
+use Try::Tiny qw( catch try );
+
+use C4::Biblio qw(
+    GetBiblioData
+    GetMarcAuthors
+    GetMarcBiblio
+    GetMarcSubjects
+);
+use C4::Items qw( GetItemsInfo );
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_and_exit output_html_with_http_headers );
+use C4::Templates;
 use Koha::Email;
 use Koha::Token;
 
-my $query = new CGI;
+my $query = CGI->new;
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
     {
@@ -114,24 +119,15 @@ if ( $email_add ) {
         $subject = "no subject";
     }
 
-    my $email = Koha::Email->create(
-        {
-            to      => $email_add,
-            subject => $subject,
-        }
-    );
-
     my $email_header = "";
     if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) {
         $email_header = $1;
         $email_header =~ s|\n?(.*)\n?|$1|;
-        $email_header = Encode::encode("UTF-8", $email_header);
     }
 
     if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) {
         $body = $1;
         $body =~ s|\n?(.*)\n?|$1|;
-        $body = Encode::encode("UTF-8", $body);
     }
 
     my $THE_body = <<END_OF_BODY;
@@ -139,15 +135,23 @@ $email_header
 $body
 END_OF_BODY
 
-    $email->text_body( $THE_body );
-    $email->attach(
-        $iso2709,
-        content_type => 'application/octet-stream',
-        name         => 'basket.iso2709',
-        disposition  => 'attachment',
-    );
-
     try {
+
+        my $email = Koha::Email->create(
+            {
+                to      => $email_add,
+                subject => $subject,
+            }
+        );
+
+        $email->text_body( $THE_body );
+        $email->attach(
+            Encode::encode( "UTF-8", $iso2709 ),
+            content_type => 'application/octet-stream',
+            name         => 'basket.iso2709',
+            disposition  => 'attachment',
+        );
+
         my $library = Koha::Patrons->find( $borrowernumber )->library;
         $email->send_or_die({ transport => $library->smtp_server->transport });
         $template->param( SENT => "1" );