Lines 37-42
use Koha::SMS::Providers;
Link Here
|
37 |
|
37 |
|
38 |
use Koha::Email; |
38 |
use Koha::Email; |
39 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
39 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
|
|
40 |
use Email::Valid; |
40 |
|
41 |
|
41 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
42 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
42 |
|
43 |
|
Lines 413-419
sub SendAlerts {
Link Here
|
413 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
414 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
414 |
foreach (@$alerts) { |
415 |
foreach (@$alerts) { |
415 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
416 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
416 |
my $email = $borinfo->{email} or next; |
417 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
|
|
418 |
my $email = $sendAllEmailsTo; |
419 |
if (!($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo))){ |
420 |
$email = $borinfo->{email} or next; |
421 |
} |
417 |
|
422 |
|
418 |
# warn "sending issues..."; |
423 |
# warn "sending issues..."; |
419 |
my $userenv = C4::Context->userenv; |
424 |
my $userenv = C4::Context->userenv; |
Lines 571-580
sub SendAlerts {
Link Here
|
571 |
# Remove the order tag |
576 |
# Remove the order tag |
572 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
577 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
573 |
|
578 |
|
|
|
579 |
# SendAllEmailsTo system preference to override for testing |
580 |
my $emailsTo = join( ',', @email); |
581 |
my $emailsCC = join( ',', @cc); |
582 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
583 |
if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ) { |
584 |
$emailsTo = $sendAllEmailsTo; |
585 |
$emailsCC = ''; |
586 |
} |
587 |
|
574 |
# ... then send mail |
588 |
# ... then send mail |
575 |
my %mail = ( |
589 |
my %mail = ( |
576 |
To => join( ',', @email), |
590 |
To => $emailsTo, |
577 |
Cc => join( ',', @cc), |
591 |
Cc => $emailsCC, |
578 |
From => $userenv->{emailaddress}, |
592 |
From => $userenv->{emailaddress}, |
579 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
593 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
580 |
Message => $letter->{'is_html'} |
594 |
Message => $letter->{'is_html'} |
Lines 628-636
sub SendAlerts {
Link Here
|
628 |
) or return; |
642 |
) or return; |
629 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
643 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
630 |
my $email = Koha::Email->new(); |
644 |
my $email = Koha::Email->new(); |
|
|
645 |
my $emailaddr = $externalid->{'emailaddr'}; |
646 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
647 |
$emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
631 |
my %mail = $email->create_message_headers( |
648 |
my %mail = $email->create_message_headers( |
632 |
{ |
649 |
{ |
633 |
to => $externalid->{'emailaddr'}, |
650 |
to => $emailaddr, |
634 |
from => $library->{branchemail}, |
651 |
from => $library->{branchemail}, |
635 |
replyto => $library->{branchreplyto}, |
652 |
replyto => $library->{branchreplyto}, |
636 |
sender => $library->{branchreturnpath}, |
653 |
sender => $library->{branchreturnpath}, |
Lines 1289-1303
sub _send_message_by_email {
Link Here
|
1289 |
|
1306 |
|
1290 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1307 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1291 |
my $to_address = $message->{'to_address'}; |
1308 |
my $to_address = $message->{'to_address'}; |
|
|
1309 |
if (!$to_address && $member) { |
1310 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1311 |
} |
1312 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
1313 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
1292 |
unless ($to_address) { |
1314 |
unless ($to_address) { |
1293 |
unless ($member) { |
1315 |
if (!$member) { |
1294 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1316 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1295 |
_set_message_status( { message_id => $message->{'message_id'}, |
1317 |
_set_message_status( { message_id => $message->{'message_id'}, |
1296 |
status => 'failed' } ); |
1318 |
status => 'failed' } ); |
1297 |
return; |
1319 |
return; |
1298 |
} |
1320 |
} |
1299 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1321 |
else { |
1300 |
unless ($to_address) { |
|
|
1301 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1322 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1302 |
# warning too verbose for this more common case? |
1323 |
# warning too verbose for this more common case? |
1303 |
_set_message_status( { message_id => $message->{'message_id'}, |
1324 |
_set_message_status( { message_id => $message->{'message_id'}, |
Lines 1342-1349
sub _send_message_by_email {
Link Here
|
1342 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
1363 |
_update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated |
1343 |
|
1364 |
|
1344 |
if ( sendmail( %sendmail_params ) ) { |
1365 |
if ( sendmail( %sendmail_params ) ) { |
1345 |
_set_message_status( { message_id => $message->{'message_id'}, |
1366 |
_set_message_status( { message_id => $message->{'message_id'}, |
1346 |
status => 'sent' } ); |
1367 |
status => 'sent' } ); |
1347 |
return 1; |
1368 |
return 1; |
1348 |
} else { |
1369 |
} else { |
1349 |
_set_message_status( { message_id => $message->{'message_id'}, |
1370 |
_set_message_status( { message_id => $message->{'message_id'}, |