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

(-)a/C4/Letters.pm (-6 / +27 lines)
Lines 40-45 use Koha::Auth::TwoFactorAuth; Link Here
40
use Koha::Patrons;
40
use Koha::Patrons;
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 1319-1330 sub _send_message_by_email { Link Here
1319
    my $message = shift or return;
1320
    my $message = shift or return;
1320
    my ( $username, $password, $method, $smtp_transports ) = @_;
1321
    my ( $username, $password, $method, $smtp_transports ) = @_;
1321
1322
1322
    my $patron;
1323
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1323
    my $to_address = $message->{'to_address'};
1324
    my $to_address = $message->{'to_address'};
1324
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1325
    my $cc_address;
1325
    if($use_garantor eq 'yes' || !$to_address) {
1326
    my @guarantor_address;
1326
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1327
    my $count_guarantor_address;
1327
        unless ($patron or $to_address) {
1328
    if (C4::Context->preference('RedirectGuaranteeEmail') eq 'yes' && $patron) {
1329
        #Get guanrantor adresses
1330
        my $guarantor_relationships = $patron->guarantor_relationships;
1331
        my @guarantors              = $guarantor_relationships->guarantors->as_list;
1332
        foreach my $guarantor (@guarantors) {
1333
            my $address = $guarantor->notice_email_address;
1334
            push( @guarantor_address, $address ) if $address;
1335
        }
1336
        $count_guarantor_address = scalar @guarantor_address;
1337
    }
1338
    unless ($to_address) {
1339
        if (!$patron && !$count_guarantor_address) {
1328
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1340
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1329
            _set_message_status(
1341
            _set_message_status(
1330
                {
1342
                {
Lines 1338-1344 sub _send_message_by_email { Link Here
1338
        if ($patron) {
1350
        if ($patron) {
1339
            $to_address = $patron->notice_email_address;
1351
            $to_address = $patron->notice_email_address;
1340
        }
1352
        }
1341
        unless ($to_address) {  
1353
        if (!$to_address && !$count_guarantor_address) {
1342
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1354
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1343
            # warning too verbose for this more common case?
1355
            # warning too verbose for this more common case?
1344
            _set_message_status(
1356
            _set_message_status(
Lines 1350-1357 sub _send_message_by_email { Link Here
1350
            );
1362
            );
1351
            return;
1363
            return;
1352
        }
1364
        }
1365
        if (!$to_address && $count_guarantor_address) {
1366
            $to_address = shift @guarantor_address;
1367
        }
1353
    }
1368
    }
1354
1369
1370
    $cc_address = join( ',', @guarantor_address );
1355
    # Skip this message if we exceed domain limits in this run
1371
    # Skip this message if we exceed domain limits in this run
1356
    if( Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }) ) {
1372
    if( Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }) ) {
1357
        # Save the to_address if you delay the message so that we dont need to look it up again
1373
        # Save the to_address if you delay the message so that we dont need to look it up again
Lines 1406-1411 sub _send_message_by_email { Link Here
1406
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1422
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1407
                : ()
1423
                : ()
1408
            ),
1424
            ),
1425
            (
1426
                $cc_address
1427
                ? ( cc => $cc_address )
1428
                : ()
1429
            ),
1409
            from     => $from_address,
1430
            from     => $from_address,
1410
            reply_to => $message->{'reply_address'} || $branch_replyto,
1431
            reply_to => $message->{'reply_address'} || $branch_replyto,
1411
            sender   => $branch_returnpath,
1432
            sender   => $branch_returnpath,
(-)a/Koha/Patron.pm (-25 / +4 lines)
Lines 1411-1446 Returns the empty string if no email address. Link Here
1411
1411
1412
=cut
1412
=cut
1413
1413
1414
sub notice_email_address {
1414
sub notice_email_address{
1415
    my ($self) = @_;
1415
    my ( $self ) = @_;
1416
    my $address;
1417
    my $guarantor_address;
1418
1416
1419
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1417
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1420
1421
    # if syspref is set to 'first valid' (value == OFF), look up email address
1418
    # if syspref is set to 'first valid' (value == OFF), look up email address
1422
    if ( $which_address eq 'OFF' ) {
1419
    if ( $which_address eq 'OFF' ) {
1423
        $address = $self->first_valid_email_address;
1420
        return $self->first_valid_email_address;
1424
    }
1425
    else {
1426
        $address = $self->$which_address || '';
1427
    }
1421
    }
1428
1422
1429
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1423
    return $self->$which_address || '';
1430
    if ($use_guarantor) {
1431
        my @guarantors =
1432
          map { $_->guarantors->as_list } $self->guarantor_relationships();
1433
        if (@guarantors) {
1434
            foreach my $guarantor (@guarantors) {
1435
                $guarantor_address = $guarantor->notice_email_address;
1436
                if ($address) {
1437
                    $address .= ', ';
1438
                }
1439
                $address .= $guarantor_address if $guarantor_address;
1440
            }
1441
        }
1442
    }
1443
    return $address;
1444
}
1424
}
1445
1425
1446
=head3 first_valid_email_address
1426
=head3 first_valid_email_address
1447
- 

Return to bug 12532