Lines 22-28
use Modern::Perl;
Link Here
|
22 |
use CGI qw ( -utf8 ); |
22 |
use CGI qw ( -utf8 ); |
23 |
use Encode qw(encode); |
23 |
use Encode qw(encode); |
24 |
use Carp; |
24 |
use Carp; |
25 |
use Mail::Sendmail; |
25 |
use Email::Sender::Simple qw(sendmail); |
26 |
use MIME::QuotedPrint; |
26 |
use MIME::QuotedPrint; |
27 |
use MIME::Base64; |
27 |
use MIME::Base64; |
28 |
|
28 |
|
Lines 34-39
use C4::Members;
Link Here
|
34 |
use C4::Templates (); |
34 |
use C4::Templates (); |
35 |
use Koha::Email; |
35 |
use Koha::Email; |
36 |
use Koha::Patrons; |
36 |
use Koha::Patrons; |
|
|
37 |
use Koha::SMTP::Servers; |
37 |
use Koha::Token; |
38 |
use Koha::Token; |
38 |
|
39 |
|
39 |
my $query = new CGI; |
40 |
my $query = new CGI; |
Lines 57-63
if ( $email_add ) {
Link Here
|
57 |
session_id => scalar $query->cookie('CGISESSID'), |
58 |
session_id => scalar $query->cookie('CGISESSID'), |
58 |
token => scalar $query->param('csrf_token'), |
59 |
token => scalar $query->param('csrf_token'), |
59 |
}); |
60 |
}); |
60 |
my $email = Koha::Email->new(); |
|
|
61 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
61 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
62 |
my $borcat = $patron ? $patron->categorycode : q{}; |
62 |
my $borcat = $patron ? $patron->categorycode : q{}; |
63 |
my $user_email = $patron->first_valid_email_address |
63 |
my $user_email = $patron->first_valid_email_address |
Lines 67-77
if ( $email_add ) {
Link Here
|
67 |
my $comment = $query->param('comment'); |
67 |
my $comment = $query->param('comment'); |
68 |
|
68 |
|
69 |
# if you want to use the KohaAdmin address as from, that is the default no need to set it |
69 |
# if you want to use the KohaAdmin address as from, that is the default no need to set it |
70 |
my %mail = $email->create_message_headers({ |
70 |
my $email = Koha::Email->create({ |
71 |
to => $email_add, |
71 |
to => $email_add, |
72 |
replyto => $email_replyto, |
72 |
replyto => $email_replyto, |
73 |
}); |
73 |
}); |
74 |
$mail{'X-Abuse-Report'} = C4::Context->preference('KohaAdminEmailAddress'); |
74 |
|
|
|
75 |
$email->header_set( 'X-Abuse-Report', C4::Context->preference('KohaAdminEmailAddress') ); |
75 |
|
76 |
|
76 |
# Since we are already logged in, no need to check credentials again |
77 |
# Since we are already logged in, no need to check credentials again |
77 |
# when loading a second template. |
78 |
# when loading a second template. |
Lines 129-141
if ( $email_add ) {
Link Here
|
129 |
my $body; |
130 |
my $body; |
130 |
|
131 |
|
131 |
# Analysing information and getting mail properties |
132 |
# Analysing information and getting mail properties |
132 |
|
133 |
my $subject; |
133 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
134 |
if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) { |
134 |
$mail{subject} = $1; |
135 |
$subject = $+{subject}; |
135 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
136 |
$subject =~ s|\n?(.*)\n?|$1|; |
136 |
$mail{subject} = encode('MIME-Header',$mail{subject}); |
137 |
} |
|
|
138 |
else { |
139 |
$subject = "no subject"; |
137 |
} |
140 |
} |
138 |
else { $mail{'subject'} = "no subject"; } |
141 |
|
|
|
142 |
$email->header_set( 'Subject', encode('MIME-Header', $subject) ); |
139 |
|
143 |
|
140 |
my $email_header = ""; |
144 |
my $email_header = ""; |
141 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
145 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
Lines 156-169
if ( $email_add ) {
Link Here
|
156 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
160 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
157 |
} |
161 |
} |
158 |
|
162 |
|
159 |
$mail{body} = $body; |
|
|
160 |
|
161 |
my $boundary = "====" . time() . "===="; |
163 |
my $boundary = "====" . time() . "===="; |
162 |
|
164 |
|
163 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
165 |
$email->header_set( 'content-type', "multipart/mixed; boundary=\"$boundary\"" ); |
|
|
166 |
|
164 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
167 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
165 |
$boundary = '--' . $boundary; |
168 |
$boundary = '--' . $boundary; |
166 |
$mail{body} = <<END_OF_BODY; |
169 |
my $THE_body = <<END_OF_BODY; |
167 |
$boundary |
170 |
$boundary |
168 |
MIME-Version: 1.0 |
171 |
MIME-Version: 1.0 |
169 |
Content-Type: text/plain; charset="UTF-8" |
172 |
Content-Type: text/plain; charset="UTF-8" |
Lines 180-196
$isofile
Link Here
|
180 |
$boundary-- |
183 |
$boundary-- |
181 |
END_OF_BODY |
184 |
END_OF_BODY |
182 |
|
185 |
|
183 |
# Sending mail (if not empty basket) |
186 |
$email->body_set( $THE_body ); |
184 |
if ( defined($iso2709) && sendmail %mail ) { |
187 |
|
185 |
# do something if it works.... |
188 |
if ( !defined $iso2709 ) { |
186 |
$template->param( SENT => "1" ); |
189 |
carp "Error sending mail: empty basket"; |
|
|
190 |
$template->param( error => 1 ); |
187 |
} |
191 |
} |
188 |
else { |
192 |
else { |
189 |
# do something if it doesn't work.... |
193 |
try { |
190 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
194 |
my $library = $patron->library; |
191 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
195 |
my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library }); |
192 |
$template->param( error => 1 ); |
196 |
Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } ); |
|
|
197 |
$template->param( SENT => "1" ); |
198 |
} |
199 |
catch { |
200 |
carp "Error sending mail: $_"; |
201 |
$template->param( error => 1 ); |
202 |
}; |
193 |
} |
203 |
} |
|
|
204 |
|
194 |
$template->param( email_add => $email_add ); |
205 |
$template->param( email_add => $email_add ); |
195 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
206 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
196 |
} |
207 |
} |