Lines 19-25
package C4::Letters;
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use MIME::Lite; |
|
|
23 |
use Carp qw( carp croak ); |
22 |
use Carp qw( carp croak ); |
24 |
use Template; |
23 |
use Template; |
25 |
use Module::Load::Conditional qw( can_load ); |
24 |
use Module::Load::Conditional qw( can_load ); |
Lines 955-961
sub EnqueueLetter {
Link Here
|
955 |
$params->{'letter'} = _add_attachments( |
954 |
$params->{'letter'} = _add_attachments( |
956 |
{ letter => $params->{'letter'}, |
955 |
{ letter => $params->{'letter'}, |
957 |
attachments => $params->{'attachments'}, |
956 |
attachments => $params->{'attachments'}, |
958 |
message => MIME::Lite->new( Type => 'multipart/mixed' ), |
|
|
959 |
} |
957 |
} |
960 |
); |
958 |
); |
961 |
} |
959 |
} |
Lines 1219-1263
sub ResendMessage {
Link Here
|
1219 |
|
1217 |
|
1220 |
=head2 _add_attachements |
1218 |
=head2 _add_attachements |
1221 |
|
1219 |
|
|
|
1220 |
_add_attachments({ letter => $letter, attachments => $attachments }); |
1221 |
|
1222 |
named parameters: |
1222 |
named parameters: |
1223 |
letter - the standard letter hashref |
1223 |
letter - the standard letter hashref |
1224 |
attachments - listref of attachments. each attachment is a hashref of: |
1224 |
attachments - listref of attachments. each attachment is a hashref of: |
1225 |
type - the mime type, like 'text/plain' |
1225 |
type - the mime type, like 'text/plain' |
1226 |
content - the actual attachment |
1226 |
content - the actual attachment |
1227 |
filename - the name of the attachment. |
1227 |
filename - the name of the attachment. |
1228 |
message - a MIME::Lite object to attach these to. |
|
|
1229 |
|
1228 |
|
1230 |
returns your letter object, with the content updated. |
1229 |
returns your letter object, with the content updated. |
|
|
1230 |
This routine picks the I<content> of I<letter> and generates a MIME |
1231 |
email, attaching the passed I<attachments> using Koha::Email. The |
1232 |
content is replaced by the string representation of the MIME object, |
1233 |
and the content-type is updated to B<MIME> for later handling. |
1231 |
|
1234 |
|
1232 |
=cut |
1235 |
=cut |
1233 |
|
1236 |
|
1234 |
sub _add_attachments { |
1237 |
sub _add_attachments { |
1235 |
my $params = shift; |
1238 |
my $params = shift; |
1236 |
|
1239 |
|
1237 |
my $letter = $params->{'letter'}; |
1240 |
my $letter = $params->{letter}; |
1238 |
my $attachments = $params->{'attachments'}; |
1241 |
my $attachments = $params->{attachments}; |
1239 |
return $letter unless @$attachments; |
1242 |
return $letter unless @$attachments; |
1240 |
my $message = $params->{'message'}; |
1243 |
|
1241 |
|
1244 |
my $message = Koha::Email->new; |
1242 |
# First, we have to put the body in as the first attachment |
1245 |
|
1243 |
$message->attach( |
1246 |
if ( $letter->{is_html} ) { |
1244 |
Type => $letter->{'content-type'} || 'TEXT', |
1247 |
$message->html_body( _wrap_html( $letter->{content}, $letter->{title} ) ); |
1245 |
Data => $letter->{'is_html'} |
1248 |
} |
1246 |
? _wrap_html($letter->{'content'}, $letter->{'title'}) |
1249 |
else { |
1247 |
: $letter->{'content'}, |
1250 |
$message->text_body( $letter->{content} ); |
1248 |
); |
1251 |
} |
1249 |
|
1252 |
|
1250 |
foreach my $attachment ( @$attachments ) { |
1253 |
foreach my $attachment ( @$attachments ) { |
1251 |
$message->attach( |
1254 |
$message->attach( |
1252 |
Type => $attachment->{'type'}, |
1255 |
Encode::encode( "UTF-8", $attachment->{content} ), |
1253 |
Data => $attachment->{'content'}, |
1256 |
content_type => 'application/octet-stream', |
1254 |
Filename => $attachment->{'filename'}, |
1257 |
name => $attachment->{filename}, |
|
|
1258 |
disposition => 'attachment', |
1255 |
); |
1259 |
); |
1256 |
} |
1260 |
} |
1257 |
# we're forcing list context here to get the header, not the count back from grep. |
1261 |
|
1258 |
( $letter->{'content-type'} ) = grep( /^Content-Type:/, split( /\n/, $params->{'message'}->header_as_string ) ); |
1262 |
$letter->{'content-type'} = 'MIME'; |
1259 |
$letter->{'content-type'} =~ s/^Content-Type:\s+//; |
1263 |
$letter->{content} = $message->as_string; |
1260 |
$letter->{'content'} = $message->body_as_string; |
|
|
1261 |
|
1264 |
|
1262 |
return $letter; |
1265 |
return $letter; |
1263 |
|
1266 |
|
Lines 1389-1409
sub _send_message_by_email {
Link Here
|
1389 |
); |
1392 |
); |
1390 |
return; |
1393 |
return; |
1391 |
}; |
1394 |
}; |
1392 |
my $email = try { |
1395 |
my $email; |
1393 |
Koha::Email->create( |
1396 |
|
1394 |
{ |
1397 |
try { |
1395 |
to => $to_address, |
1398 |
|
1396 |
( |
1399 |
my $params = { |
1397 |
C4::Context->preference('NoticeBcc') |
1400 |
to => $to_address, |
1398 |
? ( bcc => C4::Context->preference('NoticeBcc') ) |
1401 |
( |
1399 |
: () |
1402 |
C4::Context->preference('NoticeBcc') |
1400 |
), |
1403 |
? ( bcc => C4::Context->preference('NoticeBcc') ) |
1401 |
from => $from_address, |
1404 |
: () |
1402 |
reply_to => $message->{'reply_address'} || $branch_replyto, |
1405 |
), |
1403 |
sender => $branch_returnpath, |
1406 |
from => $from_address, |
1404 |
subject => "" . $message->{subject} |
1407 |
reply_to => $message->{'reply_address'} || $branch_replyto, |
|
|
1408 |
sender => $branch_returnpath, |
1409 |
subject => "" . $message->{subject} |
1410 |
}; |
1411 |
|
1412 |
if ( $message->{'content_type'} && $message->{'content_type'} eq 'MIME' ) { |
1413 |
|
1414 |
# The message has been previously composed as a valid MIME object |
1415 |
# and serialized as a string on the DB |
1416 |
$email = Koha::Email->new_from_string($content); |
1417 |
$email->create($params); |
1418 |
} else { |
1419 |
$email = Koha::Email->create($params); |
1420 |
if ($is_html) { |
1421 |
$email->html_body( _wrap_html( $content, $subject ) ); |
1422 |
} else { |
1423 |
$email->text_body($content); |
1405 |
} |
1424 |
} |
1406 |
); |
1425 |
} |
1407 |
} |
1426 |
} |
1408 |
catch { |
1427 |
catch { |
1409 |
if ( ref($_) eq 'Koha::Exceptions::BadParameter' ) { |
1428 |
if ( ref($_) eq 'Koha::Exceptions::BadParameter' ) { |
Lines 1427-1441
sub _send_message_by_email {
Link Here
|
1427 |
}; |
1446 |
}; |
1428 |
return unless $email; |
1447 |
return unless $email; |
1429 |
|
1448 |
|
1430 |
if ( $is_html ) { |
|
|
1431 |
$email->html_body( |
1432 |
_wrap_html( $content, $subject ) |
1433 |
); |
1434 |
} |
1435 |
else { |
1436 |
$email->text_body( $content ); |
1437 |
} |
1438 |
|
1439 |
my $smtp_server; |
1449 |
my $smtp_server; |
1440 |
if ( $library ) { |
1450 |
if ( $library ) { |
1441 |
$smtp_server = $library->smtp_server; |
1451 |
$smtp_server = $library->smtp_server; |
1442 |
- |
|
|