|
Lines 38-43
use Encode;
Link Here
|
| 38 |
use Carp; |
38 |
use Carp; |
| 39 |
use Koha::Email; |
39 |
use Koha::Email; |
| 40 |
use Koha::DateUtils qw( format_sqldatetime ); |
40 |
use Koha::DateUtils qw( format_sqldatetime ); |
|
|
41 |
use Data::Validate::Email qw(is_email); |
| 42 |
use Email::Valid; |
| 41 |
|
43 |
|
| 42 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
| 43 |
|
45 |
|
|
Lines 414-420
sub SendAlerts {
Link Here
|
| 414 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
416 |
my $alerts = getalert( '', 'issue', $subscriptionid ); |
| 415 |
foreach (@$alerts) { |
417 |
foreach (@$alerts) { |
| 416 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
418 |
my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'}); |
| 417 |
my $email = $borinfo->{email} or next; |
419 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
|
|
420 |
my $email = $sendAllEmailsTo; |
| 421 |
if (!($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo))){ |
| 422 |
$email = $borinfo->{email} or next; |
| 423 |
} |
| 418 |
|
424 |
|
| 419 |
# warn "sending issues..."; |
425 |
# warn "sending issues..."; |
| 420 |
my $userenv = C4::Context->userenv; |
426 |
my $userenv = C4::Context->userenv; |
|
Lines 528-537
sub SendAlerts {
Link Here
|
| 528 |
# Remove the order tag |
534 |
# Remove the order tag |
| 529 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
535 |
$letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms; |
| 530 |
|
536 |
|
|
|
537 |
# SendAllEmailsTo system preference to override for testing |
| 538 |
my $emailsTo = join( ',', @email); |
| 539 |
my $emailsCC = join( ',', @cc); |
| 540 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
| 541 |
if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ) { |
| 542 |
$emailsTo = $sendAllEmailsTo; |
| 543 |
$emailsCC = ''; |
| 544 |
} |
| 545 |
|
| 531 |
# ... then send mail |
546 |
# ... then send mail |
| 532 |
my %mail = ( |
547 |
my %mail = ( |
| 533 |
To => join( ',', @email), |
548 |
To => $emailsTo, |
| 534 |
Cc => join( ',', @cc), |
549 |
Cc => $emailsCC, |
| 535 |
From => $userenv->{emailaddress}, |
550 |
From => $userenv->{emailaddress}, |
| 536 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
551 |
Subject => Encode::encode( "UTF-8", "" . $letter->{title} ), |
| 537 |
Message => $letter->{'is_html'} |
552 |
Message => $letter->{'is_html'} |
|
Lines 583-591
sub SendAlerts {
Link Here
|
| 583 |
) or return; |
598 |
) or return; |
| 584 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
599 |
return { error => "no_email" } unless $externalid->{'emailaddr'}; |
| 585 |
my $email = Koha::Email->new(); |
600 |
my $email = Koha::Email->new(); |
|
|
601 |
my $emailaddr = $externalid->{'emailaddr'}; |
| 602 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
| 603 |
$emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
| 586 |
my %mail = $email->create_message_headers( |
604 |
my %mail = $email->create_message_headers( |
| 587 |
{ |
605 |
{ |
| 588 |
to => $externalid->{'emailaddr'}, |
606 |
to => $emailaddr, |
| 589 |
from => $library->{branchemail}, |
607 |
from => $library->{branchemail}, |
| 590 |
replyto => $library->{branchreplyto}, |
608 |
replyto => $library->{branchreplyto}, |
| 591 |
sender => $library->{branchreturnpath}, |
609 |
sender => $library->{branchreturnpath}, |
|
Lines 1049-1055
sub GetQueuedMessages {
Link Here
|
| 1049 |
|
1067 |
|
| 1050 |
my $dbh = C4::Context->dbh(); |
1068 |
my $dbh = C4::Context->dbh(); |
| 1051 |
my $statement = << 'ENDSQL'; |
1069 |
my $statement = << 'ENDSQL'; |
| 1052 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued |
1070 |
SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, sentto_address |
| 1053 |
FROM message_queue |
1071 |
FROM message_queue |
| 1054 |
ENDSQL |
1072 |
ENDSQL |
| 1055 |
|
1073 |
|
|
Lines 1228-1242
sub _send_message_by_email {
Link Here
|
| 1228 |
|
1246 |
|
| 1229 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
1247 |
my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); |
| 1230 |
my $to_address = $message->{'to_address'}; |
1248 |
my $to_address = $message->{'to_address'}; |
|
|
1249 |
if (!$to_address && $member) { |
| 1250 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
| 1251 |
} |
| 1252 |
my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo'); |
| 1253 |
$to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ); |
| 1231 |
unless ($to_address) { |
1254 |
unless ($to_address) { |
| 1232 |
unless ($member) { |
1255 |
if (!$member) { |
| 1233 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
1256 |
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; |
| 1234 |
_set_message_status( { message_id => $message->{'message_id'}, |
1257 |
_set_message_status( { message_id => $message->{'message_id'}, |
| 1235 |
status => 'failed' } ); |
1258 |
status => 'failed' } ); |
| 1236 |
return; |
1259 |
return; |
| 1237 |
} |
1260 |
} |
| 1238 |
$to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} ); |
1261 |
else { |
| 1239 |
unless ($to_address) { |
|
|
| 1240 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
1262 |
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; |
| 1241 |
# warning too verbose for this more common case? |
1263 |
# warning too verbose for this more common case? |
| 1242 |
_set_message_status( { message_id => $message->{'message_id'}, |
1264 |
_set_message_status( { message_id => $message->{'message_id'}, |
|
Lines 1281-1288
sub _send_message_by_email {
Link Here
|
| 1281 |
_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 |
1303 |
_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 |
| 1282 |
|
1304 |
|
| 1283 |
if ( sendmail( %sendmail_params ) ) { |
1305 |
if ( sendmail( %sendmail_params ) ) { |
| 1284 |
_set_message_status( { message_id => $message->{'message_id'}, |
1306 |
_set_message_status( { message_id => $message->{'message_id'}, |
| 1285 |
status => 'sent' } ); |
1307 |
status => 'sent', |
|
|
1308 |
sentto_address => $to_address } ); |
| 1286 |
return 1; |
1309 |
return 1; |
| 1287 |
} else { |
1310 |
} else { |
| 1288 |
_set_message_status( { message_id => $message->{'message_id'}, |
1311 |
_set_message_status( { message_id => $message->{'message_id'}, |
|
Lines 1366-1376
sub _set_message_status {
Link Here
|
| 1366 |
return unless exists $params->{ $required_parameter }; |
1389 |
return unless exists $params->{ $required_parameter }; |
| 1367 |
} |
1390 |
} |
| 1368 |
|
1391 |
|
| 1369 |
my $dbh = C4::Context->dbh(); |
|
|
| 1370 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
1392 |
my $statement = 'UPDATE message_queue SET status= ? WHERE message_id = ?'; |
|
|
1393 |
my @values; |
| 1394 |
push @values,$params->{'status'}; |
| 1395 |
if (exists($params->{'sentto_address'})) { |
| 1396 |
$statement = 'UPDATE message_queue SET status=?, sentto_address=? WHERE message_id = ?'; |
| 1397 |
push @values,$params->{'sentto_address'}; |
| 1398 |
} |
| 1399 |
push @values,$params->{'message_id'}; |
| 1400 |
my $dbh = C4::Context->dbh(); |
| 1371 |
my $sth = $dbh->prepare( $statement ); |
1401 |
my $sth = $dbh->prepare( $statement ); |
| 1372 |
my $result = $sth->execute( $params->{'status'}, |
1402 |
my $result = $sth->execute( @values ); |
| 1373 |
$params->{'message_id'} ); |
|
|
| 1374 |
return $result; |
1403 |
return $result; |
| 1375 |
} |
1404 |
} |
| 1376 |
|
1405 |
|