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

(-)a/C4/Letters.pm (-3 / +10 lines)
Lines 1305-1312 sub _send_message_by_email { Link Here
1305
1305
1306
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1306
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1307
    my $to_address = $message->{'to_address'};
1307
    my $to_address = $message->{'to_address'};
1308
    unless ($to_address) {
1308
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1309
        unless ($patron) {
1309
    if($use_garantor eq 'yes' || !$to_address) {
1310
        unless ($patron or $to_address) {
1310
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1311
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1311
            _set_message_status(
1312
            _set_message_status(
1312
                {
1313
                {
Lines 1317-1323 sub _send_message_by_email { Link Here
1317
            );
1318
            );
1318
            return;
1319
            return;
1319
        }
1320
        }
1320
        $to_address = $patron->notice_email_address;
1321
        if ($patron) {
1322
            $to_address = $patron->notice_email_address;
1323
        }
1321
        unless ($to_address) {  
1324
        unless ($to_address) {  
1322
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1325
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1323
            # warning too verbose for this more common case?
1326
            # warning too verbose for this more common case?
Lines 1443-1448 sub _send_message_by_email { Link Here
1443
      if !$message->{to_address}
1446
      if !$message->{to_address}
1444
      || $message->{to_address} ne $email->email->header('To');
1447
      || $message->{to_address} ne $email->email->header('To');
1445
1448
1449
    _update_message_from_address($message->{'message_id'},$email->email->header('From') )
1450
      if !$message->{from_address}
1451
      || $message->{from_address} ne $email->email->header('From');
1452
1446
    try {
1453
    try {
1447
        $email->send_or_die({ transport => $smtp_server->transport });
1454
        $email->send_or_die({ transport => $smtp_server->transport });
1448
1455
(-)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 1399-1412 Returns the empty string if no email address. Link Here
1399
1399
1400
sub notice_email_address{
1400
sub notice_email_address{
1401
    my ( $self ) = @_;
1401
    my ( $self ) = @_;
1402
    my $address;
1403
    my $guarantor_address;
1402
1404
1403
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1405
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1404
    # if syspref is set to 'first valid' (value == OFF), look up email address
1406
    # if syspref is set to 'first valid' (value == OFF), look up email address
1405
    if ( $which_address eq 'OFF' ) {
1407
    if ( $which_address eq 'OFF' ) {
1406
        return $self->first_valid_email_address;
1408
        $address = $self->first_valid_email_address;
1409
    } else {
1410
        $address = $self->$which_address || '';
1407
    }
1411
    }
1408
1412
1409
    return $self->$which_address || '';
1413
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
1414
    if ($use_guarantor) {
1415
        my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships();
1416
        if (@guarantors) {
1417
            foreach my $guarantor (@guarantors) {
1418
                if ( $which_address eq 'OFF' ) {
1419
                    $guarantor_address = $guarantor->first_valid_email_address;
1420
                } else {
1421
                    $guarantor_address = $guarantor->$which_address || '';
1422
                }
1423
                if ($address){
1424
                    $address .= ', ';
1425
                }
1426
                $address .=  $guarantor_address if $guarantor_address;
1427
            }
1428
        }
1429
    }
1430
    return $address;
1410
}
1431
}
1411
1432
1412
=head3 first_valid_email_address
1433
=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 596-601 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
596
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
596
('RecallsMaxPickUpDelay','7',NULL,'Define the maximum time a recall can be awaiting pickup','Integer'),
597
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
597
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
598
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
598
('Reference_NFL_Statuses','1|2',NULL,'Contains not for loan statuses considered as available for reference','Free'),
599
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
599
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
600
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
600
('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'),
601
('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'),
601
('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'),
602
('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 343-348 Patrons: Link Here
343
               1: Allow
343
               1: Allow
344
               0: "Don't allow"
344
               0: "Don't allow"
345
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
345
         - staff to set the ability for a patron's checkouts to be viewed by linked patrons in the OPAC.
346
     -
347
         - pref: RedirectGuaranteeEmail
348
           choices:
349
               yes: Enable
350
               no: Disable
351
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
346
     -
352
     -
347
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
353
         - pref: AllowStaffToSetFinesVisibilityForGuarantor
348
           choices:
354
           choices:
(-)a/t/db_dependent/Letters.t (+1 lines)
Lines 837-842 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
837
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
837
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
838
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
838
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
839
839
840
    t::lib::Mocks::mock_preference('RedirectGuaranteeEmail', '0');
840
    my $patron = Koha::Patrons->find($borrowernumber);
841
    my $patron = Koha::Patrons->find($borrowernumber);
841
    $dbh->do(q|
842
    $dbh->do(q|
842
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
843
        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( 'AutoEmailPrimaryAddress', '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 AutoEmailPrimaryAddress is off");
158
159
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', '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 AutoEmailPrimaryAddress is emailpro");
164
165
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', '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