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