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