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>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
use Koha::Email;
use Koha::Token;
-my $query = new CGI;
+my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
{
$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;
$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" );
use Koha::Patrons;
use Koha::Token;
-my $query = new CGI;
+my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user (
{
$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;
$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;
$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;
$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;
use Koha::Email;
use Koha::Virtualshelves;
-my $query = new CGI;
+my $query = CGI->new;
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
{
$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;
$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" );
$template->param( error => 1 );
};
- $template->param( email => $email );
+ $template->param( email => $to_address );
output_html_with_http_headers $query, $cookie, $template->output;
}