View | Details | Raw Unified | Return to bug 12532
Collapse All | Expand All

(-)a/C4/Letters.pm (-6 / +27 lines)
Lines 40-45 use Koha::Patrons; Link Here
40
use Koha::SMS::Providers;
40
use Koha::SMS::Providers;
41
use Koha::SMTP::Servers;
41
use Koha::SMTP::Servers;
42
use Koha::Subscriptions;
42
use Koha::Subscriptions;
43
use Data::Dumper;
43
44
44
use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822';
45
use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822';
45
46
Lines 1317-1328 sub _send_message_by_email { Link Here
1317
    my $message = shift or return;
1318
    my $message = shift or return;
1318
    my ( $username, $password, $method, $smtp_transports ) = @_;
1319
    my ( $username, $password, $method, $smtp_transports ) = @_;
1319
1320
1320
    my $patron;
1321
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1321
    my $to_address = $message->{'to_address'};
1322
    my $to_address = $message->{'to_address'};
1322
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1323
    my $cc_address;
1323
    if($use_garantor eq 'yes' || !$to_address) {
1324
    my @guarantor_address;
1324
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1325
    my $count_guarantor_address;
1325
        unless ($patron or $to_address) {
1326
    if (C4::Context->preference('RedirectGuaranteeEmail') eq 'yes' && $patron) {
1327
        #Get guanrantor adresses
1328
        my $guarantor_relationships = $patron->guarantor_relationships;
1329
        my @guarantors              = $guarantor_relationships->guarantors->as_list;
1330
        foreach my $guarantor (@guarantors) {
1331
            my $address = $guarantor->notice_email_address;
1332
            push( @guarantor_address, $address ) if $address;
1333
        }
1334
        $count_guarantor_address = scalar @guarantor_address;
1335
    }
1336
    unless ($to_address) {
1337
        if (!$patron && !$count_guarantor_address) {
1326
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1338
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1327
            _set_message_status(
1339
            _set_message_status(
1328
                {
1340
                {
Lines 1336-1342 sub _send_message_by_email { Link Here
1336
        if ($patron) {
1348
        if ($patron) {
1337
            $to_address = $patron->notice_email_address;
1349
            $to_address = $patron->notice_email_address;
1338
        }
1350
        }
1339
        unless ($to_address) {  
1351
        if (!$to_address && !$count_guarantor_address) {
1340
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1352
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1341
            # warning too verbose for this more common case?
1353
            # warning too verbose for this more common case?
1342
            _set_message_status(
1354
            _set_message_status(
Lines 1348-1355 sub _send_message_by_email { Link Here
1348
            );
1360
            );
1349
            return;
1361
            return;
1350
        }
1362
        }
1363
        if (!$to_address && $count_guarantor_address) {
1364
            $to_address = shift @guarantor_address;
1365
        }
1351
    }
1366
    }
1352
1367
1368
    $cc_address = join( ',', @guarantor_address );
1353
    # Skip this message if we exceed domain limits in this run
1369
    # Skip this message if we exceed domain limits in this run
1354
    if( Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }) ) {
1370
    if( Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }) ) {
1355
        # Save the to_address if you delay the message so that we dont need to look it up again
1371
        # Save the to_address if you delay the message so that we dont need to look it up again
Lines 1404-1409 sub _send_message_by_email { Link Here
1404
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1420
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1405
                : ()
1421
                : ()
1406
            ),
1422
            ),
1423
            (
1424
                $cc_address
1425
                ? ( cc => $cc_address )
1426
                : ()
1427
            ),
1407
            from     => $from_address,
1428
            from     => $from_address,
1408
            reply_to => $message->{'reply_address'} || $branch_replyto,
1429
            reply_to => $message->{'reply_address'} || $branch_replyto,
1409
            sender   => $branch_returnpath,
1430
            sender   => $branch_returnpath,
(-)a/Koha/Patron.pm (-25 / +4 lines)
Lines 1426-1461 Returns the empty string if no email address. Link Here
1426
1426
1427
=cut
1427
=cut
1428
1428
1429
sub notice_email_address {
1429
sub notice_email_address{
1430
    my ($self) = @_;
1430
    my ( $self ) = @_;
1431
    my $address;
1432
    my $guarantor_address;
1433
1431
1434
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1432
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1435
1436
    # if syspref is set to 'first valid' (value == OFF), look up email address
1433
    # if syspref is set to 'first valid' (value == OFF), look up email address
1437
    if ( $which_address eq 'OFF' ) {
1434
    if ( $which_address eq 'OFF' ) {
1438
        $address = $self->first_valid_email_address;
1435
        return $self->first_valid_email_address;
1439
    }
1440
    else {
1441
        $address = $self->$which_address || '';
1442
    }
1436
    }
1443
1437
1444
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1438
    return $self->$which_address || '';
1445
    if ($use_guarantor) {
1446
        my @guarantors =
1447
          map { $_->guarantors->as_list } $self->guarantor_relationships();
1448
        if (@guarantors) {
1449
            foreach my $guarantor (@guarantors) {
1450
                $guarantor_address = $guarantor->notice_email_address;
1451
                if ($address) {
1452
                    $address .= ', ';
1453
                }
1454
                $address .= $guarantor_address if $guarantor_address;
1455
            }
1456
        }
1457
    }
1458
    return $address;
1459
}
1439
}
1460
1440
1461
=head3 first_valid_email_address
1441
=head3 first_valid_email_address
1462
- 

Return to bug 12532