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

(-)a/C4/Letters.pm (-3 / +10 lines)
Lines 1321-1329 sub _send_message_by_email { Link Here
1321
1321
1322
    my $patron;
1322
    my $patron;
1323
    my $to_address = $message->{'to_address'};
1323
    my $to_address = $message->{'to_address'};
1324
    unless ($to_address) {
1324
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1325
    if($use_garantor eq 'yes' || !$to_address) {
1325
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1326
        $patron = Koha::Patrons->find( $message->{borrowernumber} );
1326
        unless ($patron) {
1327
        unless ($patron or $to_address) {
1327
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1328
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1328
            _set_message_status(
1329
            _set_message_status(
1329
                {
1330
                {
Lines 1334-1340 sub _send_message_by_email { Link Here
1334
            );
1335
            );
1335
            return;
1336
            return;
1336
        }
1337
        }
1337
        $to_address = $patron->notice_email_address;
1338
        if ($patron) {
1339
            $to_address = $patron->notice_email_address;
1340
        }
1338
        unless ($to_address) {  
1341
        unless ($to_address) {  
1339
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1342
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1340
            # warning too verbose for this more common case?
1343
            # warning too verbose for this more common case?
Lines 1472-1477 sub _send_message_by_email { Link Here
1472
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1475
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1473
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1476
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1474
1477
1478
    _update_message_from_address($message->{'message_id'},$email->email->header('From') )
1479
      if !$message->{from_address}
1480
      || $message->{from_address} ne $email->email->header('From');
1481
1475
    try {
1482
    try {
1476
        $email->send_or_die({ transport => $smtp_transport });
1483
        $email->send_or_die({ transport => $smtp_transport });
1477
1484
(-)a/Koha/Email.pm (-4 / +8 lines)
Lines 118-127 sub create { Link Here
118
        $args->{to} = $params->{to};
118
        $args->{to} = $params->{to};
119
    }
119
    }
120
120
121
    Koha::Exceptions::BadParameter->throw(
121
    my @emails = split(',', $args->{to});
122
        error     => "Invalid 'to' parameter: " . $args->{to},
122
    foreach my $email (@emails) {
123
        parameter => 'to'
123
       $email =~ s/ //g;
124
    ) unless Koha::Email->is_valid( $args->{to} );    # to is mandatory
124
       Koha::Exceptions::BadParameter->throw(
125
           error     => "Invalid 'to' parameter: ".$email,
126
           parameter => 'to'
127
       ) unless Koha::Email->is_valid($email);
128
    }
125
129
126
    my $addresses = {};
130
    my $addresses = {};
127
    $addresses->{reply_to} = $params->{reply_to};
131
    $addresses->{reply_to} = $params->{reply_to};
(-)a/Koha/Patron.pm (-2 / +23 lines)
Lines 1413-1426 Returns the empty string if no email address. Link Here
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;
1416
1418
1417
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1419
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1418
    # if syspref is set to 'first valid' (value == OFF), look up email address
1420
    # if syspref is set to 'first valid' (value == OFF), look up email address
1419
    if ( $which_address eq 'OFF' ) {
1421
    if ( $which_address eq 'OFF' ) {
1420
        return $self->first_valid_email_address;
1422
        $address = $self->first_valid_email_address;
1423
    } else {
1424
        $address = $self->$which_address || '';
1421
    }
1425
    }
1422
1426
1423
    return $self->$which_address || '';
1427
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1428
    if ($use_guarantor) {
1429
        my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships();
1430
        if (@guarantors) {
1431
            foreach my $guarantor (@guarantors) {
1432
                if ( $which_address eq 'OFF' ) {
1433
                    $guarantor_address = $guarantor->first_valid_email_address;
1434
                } else {
1435
                    $guarantor_address = $guarantor->$which_address || '';
1436
                }
1437
                if ($address){
1438
                    $address .= ', ';
1439
                }
1440
                $address .=  $guarantor_address if $guarantor_address;
1441
            }
1442
        }
1443
    }
1444
    return $address;
1424
}
1445
}
1425
1446
1426
=head3 first_valid_email_address
1447
=head3 first_valid_email_address
(-)a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.pl (+14 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "12532",
5
    description => "Add new system preference RedirectGuaranteeEmail",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('RedirectGuaranteeEmail', '0', 'Enable the ability to redirect guarantee email messages to guarantor.', NULL, 'YesNo') });
11
12
        say $out "Added system preference 'RedirectGuaranteeEmail'";
13
    },
14
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+1 lines)
Lines 599-604 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
599
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
599
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
600
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
600
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
601
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
601
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
602
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
602
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
603
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
603
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
604
('RenewAccruingItemWhenPaid','0','','If enabled, when the fines on an item accruing is paid off, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
604
('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
605
('RenewAccruingItemInOpac','0','','If enabled, when the fines on an item accruing is paid off in the OPAC via a payment plugin, attempt to renew that item. If the syspref "RenewalPeriodBase" is set to "due date", renewed items may still be overdue','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 357-362 Patrons: Link Here
357
               1: Allow
357
               1: Allow
358
               0: "Don't allow"
358
               0: "Don't allow"
359
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
359
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
360
     -
361
         - pref: RedirectGuaranteeEmail
362
           choices:
363
               yes: Enable
364
               no: Disable
365
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
360
     -
366
     -
361
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
367
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
362
           choices:
368
           choices:
(-)a/perltidy.ERR (+16 lines)
Line 0 Link Here
1
Perltidy version is 20210717
2
3
<stdin>: Begin Error Output Stream
4
1: final indentation level: 3
5
6
Final nesting depth of '{'s is 1
7
The most recent un-matched '{' is on line 1
8
1: if (!$to_address && !$count_guarantor_address) {
9
                                                  ^
10
1: final indentation level: 3
11
12
Final nesting depth of '{'s is 1
13
The most recent un-matched '{' is on line 1
14
1: if (!$to_address && !$count_guarantor_address) {
15
                                                  ^
16
1: To save a full .LOG file rerun with -g
(-)a/t/db_dependent/Letters.t (+1 lines)
Lines 853-858 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
853
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
853
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
854
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
854
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
855
855
856
    t::lib::Mocks::mock_preference('RedirectGuaranteeEmail', '0');
856
    my $patron = Koha::Patrons->find($borrowernumber);
857
    my $patron = Koha::Patrons->find($borrowernumber);
857
    $dbh->do(q|
858
    $dbh->do(q|
858
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
859
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
(-)a/t/db_dependent/Members.t (-2 / +49 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 53;
20
use Test::More tests => 57;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 119-124 C4::Context->clear_syspref_cache(); Link Here
119
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
119
$checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, "");
120
is ($checkcardnum, "2", "Card number is too long");
120
is ($checkcardnum, "2", "Card number is too long");
121
121
122
# Test notice_email_address
123
# Add Guarantor for testing
124
my $GUARANTOR_EMAIL = "Robert\@email.com";
125
%data = (
126
    cardnumber => "2997924548",
127
    firstname =>  "Robert",
128
    surname => "Tables",
129
    categorycode => $patron_category->{categorycode},
130
    branchcode => $BRANCHCODE,
131
    dateofbirth => '',
132
    dateexpiry => '9999-12-31',
133
    userid => 'bobbytables',
134
    email => $GUARANTOR_EMAIL
135
);
136
137
$addmem=Koha::Patron->new(\%data)->store->borrowernumber;
138
ok($addmem, "Koha::Patron->store()");
139
140
my $patron_guarantor = Koha::Patrons->find( { cardnumber => (\%data)->{'cardnumber'} } )
141
  or BAIL_OUT("Cannot read member with card (\%data)->{'cardnumber'}");
142
my $member_guarantor = $patron_guarantor->unblessed;
143
144
my %data2 = (
145
    guarantor_id => $member_guarantor->{borrowernumber},
146
    guarantee_id => $member->{borrowernumber},
147
    relationship => "father"
148
);
149
Koha::Patron::Relationship->new(\%data2)->store;
150
151
$member = Koha::Patrons->find( { cardnumber => $CARDNUMBER } );
152
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
153
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
154
C4::Context->clear_syspref_cache();
155
156
my $notice_email = $member->notice_email_address;
157
is ($notice_email, $EMAIL, "notice_email_address returns correct value when EmailFieldPrimary is off");
158
159
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
160
C4::Context->clear_syspref_cache();
161
162
$notice_email = $member->notice_email_address;
163
is ($notice_email, $EMAILPRO, "notice_email_address returns correct value when EmailFieldPrimary is emailpro");
164
165
t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
166
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
167
C4::Context->clear_syspref_cache();
168
$notice_email = $member->notice_email_address;
169
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "notice_email_address returns correct value when RedirectGuaranteeEmail is enabled");
122
170
123
# Add a new borrower
171
# Add a new borrower
124
%data = (
172
%data = (
125
- 

Return to bug 12532