Lines 22-30
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 Try::Tiny; |
26 |
use MIME::QuotedPrint; |
|
|
27 |
use MIME::Base64; |
28 |
|
26 |
|
29 |
use C4::Biblio; |
27 |
use C4::Biblio; |
30 |
use C4::Items; |
28 |
use C4::Items; |
Lines 56-62
if ( $email_add ) {
Link Here
|
56 |
session_id => scalar $query->cookie('CGISESSID'), |
54 |
session_id => scalar $query->cookie('CGISESSID'), |
57 |
token => scalar $query->param('csrf_token'), |
55 |
token => scalar $query->param('csrf_token'), |
58 |
}); |
56 |
}); |
59 |
my $email = Koha::Email->new(); |
|
|
60 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
57 |
my $patron = Koha::Patrons->find( $borrowernumber ); |
61 |
my $borcat = $patron ? $patron->categorycode : q{}; |
58 |
my $borcat = $patron ? $patron->categorycode : q{}; |
62 |
my $user_email = $patron->first_valid_email_address |
59 |
my $user_email = $patron->first_valid_email_address |
Lines 65-77
if ( $email_add ) {
Link Here
|
65 |
my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>"; |
62 |
my $email_replyto = $patron->firstname . " " . $patron->surname . " <$user_email>"; |
66 |
my $comment = $query->param('comment'); |
63 |
my $comment = $query->param('comment'); |
67 |
|
64 |
|
68 |
# if you want to use the KohaAdmin address as from, that is the default no need to set it |
|
|
69 |
my %mail = $email->create_message_headers({ |
70 |
to => $email_add, |
71 |
replyto => $email_replyto, |
72 |
}); |
73 |
$mail{'X-Abuse-Report'} = C4::Context->preference('KohaAdminEmailAddress'); |
74 |
|
75 |
# Since we are already logged in, no need to check credentials again |
65 |
# Since we are already logged in, no need to check credentials again |
76 |
# when loading a second template. |
66 |
# when loading a second template. |
77 |
my $template2 = C4::Templates::gettemplate( |
67 |
my $template2 = C4::Templates::gettemplate( |
Lines 128-195
if ( $email_add ) {
Link Here
|
128 |
my $body; |
118 |
my $body; |
129 |
|
119 |
|
130 |
# Analysing information and getting mail properties |
120 |
# Analysing information and getting mail properties |
131 |
|
121 |
my $subject; |
132 |
if ( $template_res =~ /<SUBJECT>(.*)<END_SUBJECT>/s ) { |
122 |
if ( $template_res =~ /\<SUBJECT\>(?<subject>.*)\<END_SUBJECT\>/s ) { |
133 |
$mail{subject} = $1; |
123 |
$subject = $+{subject}; |
134 |
$mail{subject} =~ s|\n?(.*)\n?|$1|; |
124 |
$subject =~ s|\n?(.*)\n?|$1|; |
135 |
$mail{subject} = encode('MIME-Header',$mail{subject}); |
125 |
} |
|
|
126 |
else { |
127 |
$subject = "no subject"; |
136 |
} |
128 |
} |
137 |
else { $mail{'subject'} = "no subject"; } |
129 |
|
|
|
130 |
# if you want to use the KohaAdmin address as from, that is the default no need to set it |
131 |
my $email = Koha::Email->create({ |
132 |
to => $email_add, |
133 |
reply_to => $email_replyto, |
134 |
subject => $subject, |
135 |
}); |
136 |
|
137 |
$email->header( 'X-Abuse-Report' => C4::Context->preference('KohaAdminEmailAddress') ); |
138 |
|
138 |
|
139 |
my $email_header = ""; |
139 |
my $email_header = ""; |
140 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
140 |
if ( $template_res =~ /<HEADER>(.*)<END_HEADER>/s ) { |
141 |
$email_header = $1; |
141 |
$email_header = $1; |
142 |
$email_header =~ s|\n?(.*)\n?|$1|; |
142 |
$email_header =~ s|\n?(.*)\n?|$1|; |
143 |
$email_header = encode_qp(Encode::encode("UTF-8", $email_header)); |
143 |
$email_header = Encode::encode("UTF-8", $email_header); |
144 |
} |
|
|
145 |
|
146 |
my $email_file = "basket.txt"; |
147 |
if ( $template_res =~ /<FILENAME>(.*)<END_FILENAME>/s ) { |
148 |
$email_file = $1; |
149 |
$email_file =~ s|\n?(.*)\n?|$1|; |
150 |
} |
144 |
} |
151 |
|
145 |
|
152 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
146 |
if ( $template_res =~ /<MESSAGE>(.*)<END_MESSAGE>/s ) { |
153 |
$body = $1; |
147 |
$body = $1; |
154 |
$body =~ s|\n?(.*)\n?|$1|; |
148 |
$body =~ s|\n?(.*)\n?|$1|; |
155 |
$body = encode_qp(Encode::encode("UTF-8", $body)); |
149 |
$body = Encode::encode("UTF-8", $body); |
156 |
} |
150 |
} |
157 |
|
151 |
|
158 |
$mail{body} = $body; |
152 |
my $THE_body = <<END_OF_BODY; |
159 |
|
|
|
160 |
my $boundary = "====" . time() . "===="; |
161 |
|
162 |
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; |
163 |
my $isofile = encode_base64(encode("UTF-8", $iso2709)); |
164 |
$boundary = '--' . $boundary; |
165 |
$mail{body} = <<END_OF_BODY; |
166 |
$boundary |
167 |
MIME-Version: 1.0 |
168 |
Content-Type: text/plain; charset="UTF-8" |
169 |
Content-Transfer-Encoding: quoted-printable |
170 |
|
171 |
$email_header |
153 |
$email_header |
172 |
$body |
154 |
$body |
173 |
$boundary |
|
|
174 |
Content-Type: application/octet-stream; name="basket.iso2709" |
175 |
Content-Transfer-Encoding: base64 |
176 |
Content-Disposition: attachment; filename="basket.iso2709" |
177 |
|
178 |
$isofile |
179 |
$boundary-- |
180 |
END_OF_BODY |
155 |
END_OF_BODY |
181 |
|
156 |
|
182 |
# Sending mail (if not empty basket) |
157 |
$email->text_body( $THE_body ); |
183 |
if ( defined($iso2709) && sendmail %mail ) { |
158 |
$email->attach( |
184 |
# do something if it works.... |
159 |
$iso2709, |
185 |
$template->param( SENT => "1" ); |
160 |
content_type => 'application/octet-stream', |
|
|
161 |
name => 'basket.iso2709', |
162 |
disposition => 'attachment', |
163 |
); |
164 |
|
165 |
if ( !defined $iso2709 ) { |
166 |
carp "Error sending mail: empty basket"; |
167 |
$template->param( error => 1 ); |
186 |
} |
168 |
} |
187 |
else { |
169 |
else { |
188 |
# do something if it doesn't work.... |
170 |
try { |
189 |
carp "Error sending mail: empty basket" if !defined($iso2709); |
171 |
my $library = $patron->library; |
190 |
carp "Error sending mail: $Mail::Sendmail::error" if $Mail::Sendmail::error; |
172 |
$email->transport( $library->smtp_server->transport ); |
191 |
$template->param( error => 1 ); |
173 |
$email->send_or_die; |
|
|
174 |
$template->param( SENT => "1" ); |
175 |
} |
176 |
catch { |
177 |
carp "Error sending mail: $_"; |
178 |
$template->param( error => 1 ); |
179 |
}; |
192 |
} |
180 |
} |
|
|
181 |
|
193 |
$template->param( email_add => $email_add ); |
182 |
$template->param( email_add => $email_add ); |
194 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
183 |
output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 }; |
195 |
} |
184 |
} |