Bugzilla – Attachment 111048 Details for
Bug 22343
Add configuration options for SMTP servers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22343: (QA follow-up) Wrap email creation inside the try/catch block
Bug-22343-QA-follow-up-Wrap-email-creation-inside-.patch (text/plain), 9.35 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-10-01 14:40:19 UTC
(
hide
)
Description:
Bug 22343: (QA follow-up) Wrap email creation inside the try/catch block
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-10-01 14:40:19 UTC
Size:
9.35 KB
patch
obsolete
>From b3f08cb181e561123b8d45f900e466fcfa5a81a5 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 1 Oct 2020 11:28:59 -0300 >Subject: [PATCH] Bug 22343: (QA follow-up) Wrap email creation inside the > try/catch block > >At a later development stage, exceptions where added for bad addresses. >This wasn't addressed in the controllers. > >This patch makes the basket and list sending controller scripts move >email creation inside the try/catch block to handle those situations. It >also UTF-8 encodes the attached marc. > >On broadly testing this I found that if the TT templates that are used >to build the email contains non-latin characters, those get >double-encoded. So this patch also removes an explicit encoding that is >done, which colides with Email::MIME implicit encoding. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > basket/sendbasket.pl | 35 +++++++++++++++++------------------ > opac/opac-sendbasket.pl | 35 +++++++++++++++-------------------- > opac/opac-sendshelf.pl | 30 +++++++++++++----------------- > virtualshelves/sendshelf.pl | 35 ++++++++++++++++------------------- > 4 files changed, 61 insertions(+), 74 deletions(-) > >diff --git a/basket/sendbasket.pl b/basket/sendbasket.pl >index d7e3fbc74b..9e273b1f45 100755 >--- a/basket/sendbasket.pl >+++ b/basket/sendbasket.pl >@@ -30,7 +30,7 @@ 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 +114,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 +130,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" ); >diff --git a/opac/opac-sendbasket.pl b/opac/opac-sendbasket.pl >index 76dd16019c..eee5e2c29b 100755 >--- a/opac/opac-sendbasket.pl >+++ b/opac/opac-sendbasket.pl >@@ -34,7 +34,7 @@ use Koha::Email; > use Koha::Patrons; > use Koha::Token; > >-my $query = new CGI; >+my $query = CGI->new; > > my ( $template, $borrowernumber, $cookie ) = get_template_and_user ( > { >@@ -127,26 +127,15 @@ if ( $email_add ) { > $subject = "no subject"; > } > >- # if you want to use the KohaAdmin address as from, that is the default no need to set it >- my $email = Koha::Email->create({ >- to => $email_add, >- reply_to => $email_replyto, >- subject => $subject, >- }); >- >- $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') ); >- > 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; >@@ -154,20 +143,26 @@ $email_header > $body > END_OF_BODY > >- $email->text_body( $THE_body ); >- $email->attach( >- $iso2709, >- content_type => 'application/octet-stream', >- name => 'basket.iso2709', >- disposition => 'attachment', >- ); >- > if ( !defined $iso2709 ) { > carp "Error sending mail: empty basket"; > $template->param( error => 1 ); > } > else { > try { >+ # if you want to use the KohaAdmin address as from, that is the default no need to set it >+ my $email = Koha::Email->create({ >+ to => $email_add, >+ reply_to => $email_replyto, >+ subject => $subject, >+ }); >+ $email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') ); >+ $email->text_body( $THE_body ); >+ $email->attach( >+ Encode::encode( "UTF-8", $iso2709 ), >+ content_type => 'application/octet-stream', >+ name => 'basket.iso2709', >+ disposition => 'attachment', >+ ); > my $library = $patron->library; > $email->transport( $library->smtp_server->transport ); > $email->send_or_die; >diff --git a/opac/opac-sendshelf.pl b/opac/opac-sendshelf.pl >index 44f2bd130d..a8ca0899d8 100755 >--- a/opac/opac-sendshelf.pl >+++ b/opac/opac-sendshelf.pl >@@ -128,24 +128,15 @@ if ( $email ) { > $subject = "no subject"; > } > >- my $email = Koha::Email->create( >- { >- to => $email, >- 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; >@@ -153,15 +144,20 @@ $email_header > $body > END_OF_BODY > >- $email->text_body( $THE_body ); >- $email->attach( >- $iso2709, >- content_type => 'application/octet-stream', >- name => 'list.iso2709', >- disposition => 'attachment', >- ); >- > try { >+ my $email = Koha::Email->create( >+ { >+ to => $email, >+ subject => $subject, >+ } >+ ); >+ $email->text_body( $THE_body ); >+ $email->attach( >+ Encode::encode( "UTF-8", $iso2709 ), >+ content_type => 'application/octet-stream', >+ name => 'list.iso2709', >+ disposition => 'attachment', >+ ); > my $library = Koha::Patrons->find( $borrowernumber )->library; > $email->transport( $library->smtp_server->transport ); > $email->send_or_die; >diff --git a/virtualshelves/sendshelf.pl b/virtualshelves/sendshelf.pl >index a0da25768f..f15e2c9f64 100755 >--- a/virtualshelves/sendshelf.pl >+++ b/virtualshelves/sendshelf.pl >@@ -31,7 +31,7 @@ use C4::Output; > use Koha::Email; > use Koha::Virtualshelves; > >-my $query = new CGI; >+my $query = CGI->new; > > my ( $template, $borrowernumber, $cookie ) = get_template_and_user( > { >@@ -108,24 +108,15 @@ if ($to_address) { > $subject = "no subject"; > } > >- my $email = Koha::Email->create( >- { >- to => $to_address, >- 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; >@@ -133,15 +124,21 @@ $email_header > $body > END_OF_BODY > >- $email->text_body( $THE_body ); >- $email->attach( >- $iso2709, >- content_type => 'application/octet-stream', >- name => 'shelf.iso2709', >- disposition => 'attachment', >- ); >- > try { >+ my $email = Koha::Email->create( >+ { >+ to => $to_address, >+ subject => $subject, >+ } >+ ); >+ $email->text_body( $THE_body ); >+ $email->attach( >+ Encode::encode("UTF-8", $iso2709), >+ content_type => 'application/octet-stream', >+ name => 'shelf.iso2709', >+ disposition => 'attachment', >+ ); >+ > my $library = Koha::Patrons->find( $borrowernumber )->library; > $email->send_or_die({ transport => $library->smtp_server->transport }); > $template->param( SENT => "1" ); >@@ -151,7 +148,7 @@ END_OF_BODY > $template->param( error => 1 ); > }; > >- $template->param( email => $email ); >+ $template->param( email => $to_address ); > output_html_with_http_headers $query, $cookie, $template->output; > > } >-- >2.28.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22343
:
107598
|
107599
|
107600
|
107601
|
107602
|
107603
|
107604
|
107605
|
107987
|
107988
|
107989
|
107990
|
107991
|
107992
|
107993
|
107994
|
107995
|
107996
|
107997
|
107998
|
107999
|
108009
|
108107
|
108108
|
108109
|
108110
|
108111
|
108112
|
108113
|
108114
|
108115
|
108116
|
108117
|
108118
|
108119
|
108131
|
108132
|
108133
|
108134
|
108135
|
108136
|
108137
|
108138
|
108139
|
108140
|
108141
|
108142
|
108143
|
108529
|
108537
|
108538
|
108539
|
108540
|
108541
|
108542
|
108543
|
108544
|
108545
|
108546
|
108547
|
108548
|
108549
|
108609
|
108638
|
108642
|
108643
|
108644
|
108645
|
108646
|
108647
|
108648
|
108649
|
108650
|
108651
|
108652
|
108653
|
108654
|
108655
|
108656
|
108715
|
108716
|
109003
|
109004
|
109005
|
109006
|
109007
|
109008
|
109009
|
109010
|
109011
|
109012
|
109013
|
109014
|
109015
|
109016
|
109017
|
109018
|
109155
|
109156
|
109157
|
109158
|
109159
|
109160
|
109161
|
109162
|
109163
|
109164
|
109165
|
109166
|
109167
|
109168
|
109169
|
109170
|
109601
|
109602
|
109603
|
109604
|
109605
|
109606
|
109607
|
109608
|
109609
|
109610
|
109611
|
109612
|
109613
|
109614
|
109615
|
109616
|
109723
|
109724
|
109725
|
109726
|
109727
|
109728
|
109729
|
109730
|
109731
|
109732
|
109733
|
109734
|
109735
|
109736
|
109737
|
109738
|
109739
|
109740
|
109787
|
109788
| 111048 |
111087
|
111088
|
111089
|
111090
|
111154
|
111165
|
111166
|
111175
|
111176
|
111213
|
111215
|
111216
|
111442
|
111482
|
113240
|
113827
|
113847