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

(-)a/C4/Letters.pm (-9 / +30 lines)
Lines 37-42 use Koha::SMS::Providers; Link Here
37
37
38
use Koha::Email;
38
use Koha::Email;
39
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
39
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
40
use Email::Valid;
40
41
41
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
42
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
42
43
Lines 413-419 sub SendAlerts { Link Here
413
        my $alerts = getalert( '', 'issue', $subscriptionid );
414
        my $alerts = getalert( '', 'issue', $subscriptionid );
414
        foreach (@$alerts) {
415
        foreach (@$alerts) {
415
            my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
416
            my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
416
            my $email = $borinfo->{email} or next;
417
            my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
418
            my $email = $sendAllEmailsTo;
419
            if (!($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo))){
420
                $email = $borinfo->{email} or next;
421
            }
417
422
418
#                    warn "sending issues...";
423
#                    warn "sending issues...";
419
            my $userenv = C4::Context->userenv;
424
            my $userenv = C4::Context->userenv;
Lines 571-580 sub SendAlerts { Link Here
571
        # Remove the order tag
576
        # Remove the order tag
572
        $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms;
577
        $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms;
573
578
579
        # SendAllEmailsTo system preference to override for testing
580
        my $emailsTo = join( ',', @email);
581
        my $emailsCC = join( ',', @cc);
582
        my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
583
        if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ) {
584
            $emailsTo = $sendAllEmailsTo;
585
            $emailsCC = '';
586
        }
587
574
        # ... then send mail
588
        # ... then send mail
575
        my %mail = (
589
        my %mail = (
576
            To => join( ',', @email),
590
            To             => $emailsTo,
577
            Cc             => join( ',', @cc),
591
            Cc             => $emailsCC,
578
            From           => $userenv->{emailaddress},
592
            From           => $userenv->{emailaddress},
579
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
593
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
580
            Message => $letter->{'is_html'}
594
            Message => $letter->{'is_html'}
Lines 628-636 sub SendAlerts { Link Here
628
        ) or return;
642
        ) or return;
629
        return { error => "no_email" } unless $externalid->{'emailaddr'};
643
        return { error => "no_email" } unless $externalid->{'emailaddr'};
630
        my $email = Koha::Email->new();
644
        my $email = Koha::Email->new();
645
        my $emailaddr = $externalid->{'emailaddr'};
646
        my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
647
        $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
631
        my %mail  = $email->create_message_headers(
648
        my %mail  = $email->create_message_headers(
632
            {
649
            {
633
                to      => $externalid->{'emailaddr'},
650
                to      => $emailaddr,
634
                from    => $library->{branchemail},
651
                from    => $library->{branchemail},
635
                replyto => $library->{branchreplyto},
652
                replyto => $library->{branchreplyto},
636
                sender  => $library->{branchreturnpath},
653
                sender  => $library->{branchreturnpath},
Lines 1289-1303 sub _send_message_by_email { Link Here
1289
1306
1290
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1307
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1291
    my $to_address = $message->{'to_address'};
1308
    my $to_address = $message->{'to_address'};
1309
    if (!$to_address && $member) {
1310
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1311
    }
1312
    my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
1313
    $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
1292
    unless ($to_address) {
1314
    unless ($to_address) {
1293
        unless ($member) {
1315
        if (!$member) {
1294
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1316
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1295
            _set_message_status( { message_id => $message->{'message_id'},
1317
            _set_message_status( { message_id => $message->{'message_id'},
1296
                                   status     => 'failed' } );
1318
                                   status     => 'failed' } );
1297
            return;
1319
            return;
1298
        }
1320
        }
1299
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1321
        else {
1300
        unless ($to_address) {  
1301
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1322
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1302
            # warning too verbose for this more common case?
1323
            # warning too verbose for this more common case?
1303
            _set_message_status( { message_id => $message->{'message_id'},
1324
            _set_message_status( { message_id => $message->{'message_id'},
Lines 1342-1349 sub _send_message_by_email { Link Here
1342
    _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
1363
    _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
1343
1364
1344
    if ( sendmail( %sendmail_params ) ) {
1365
    if ( sendmail( %sendmail_params ) ) {
1345
        _set_message_status( { message_id => $message->{'message_id'},
1366
        _set_message_status( { message_id     => $message->{'message_id'},
1346
                status     => 'sent' } );
1367
                               status         => 'sent' } );
1347
        return 1;
1368
        return 1;
1348
    } else {
1369
    } else {
1349
        _set_message_status( { message_id => $message->{'message_id'},
1370
        _set_message_status( { message_id => $message->{'message_id'},
(-)a/installer/data/mysql/atomicupdate/bz8000_TestModeForNotices.sql (+3 lines)
Line 0 Link Here
1
-- SYSPREF
2
INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
3
VALUES ('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system.  This is meant to help testing and validation   only.','Textarea');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 454-459 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
454
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
454
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
455
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
455
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
456
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
456
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
457
('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system.  This is meant to help testing only.','Textarea'),
457
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
458
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
458
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
459
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
459
('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'),
460
('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (+5 lines)
Lines 16-21 Administration: Link Here
16
              class: email
16
              class: email
17
            - "If you leave this empty, the From address will be used (often defaulting to the admin address)."
17
            - "If you leave this empty, the From address will be used (often defaulting to the admin address)."
18
        -
18
        -
19
            - "Redirect all emails from Koha to"
20
            - pref: SendAllEmailsTo
21
              class: email
22
            - "instead of their intended user."
23
        -
19
            - "How much debugging information to show in the browser when an internal error occurs: "
24
            - "How much debugging information to show in the browser when an internal error occurs: "
20
            - pref: DebugLevel
25
            - pref: DebugLevel
21
              default: 0
26
              default: 0
(-)a/t/db_dependent/Letters.t (-4 / +51 lines)
Lines 88-93 is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes Link Here
88
# EnqueueLetter
88
# EnqueueLetter
89
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
89
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
90
90
91
# used to trigger _send_message_by_sms in C4::Letter
91
my $my_message = {
92
my $my_message = {
92
    borrowernumber         => $borrowernumber,
93
    borrowernumber         => $borrowernumber,
93
    message_transport_type => 'sms',
94
    message_transport_type => 'sms',
Lines 112-124 $my_message->{message_transport_type} = 'sms'; Link Here
112
$message_id = C4::Letters::EnqueueLetter($my_message);
113
$message_id = C4::Letters::EnqueueLetter($my_message);
113
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
114
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
114
115
116
# This is will force C4::Context->preference() to read the DB.
117
C4::Context->disable_syspref_cache();
118
119
# used to trigger _send_message_by_email in C4::Letter
120
# first override.
121
$dbh->do("UPDATE systempreferences SET value='override\@example.com' WHERE variable='SendAllEmailsTo';");
122
my $message_id2 = C4::Letters::EnqueueLetter({
123
    borrowernumber         => $borrowernumber,
124
    message_transport_type => 'email',
125
    to_address             => 'to@example.com',
126
    from_address           => 'from@example.com',
127
    letter => {
128
        content      => 'a message',
129
        title        => 'message title',
130
        metadata     => 'metadata',
131
        code         => 'TEST_MESSAGE',
132
        content_type => 'text/plain',
133
    },
134
});
135
136
ok(defined $message_id2 && $message_id2 > 0, 'new message successfully queued');
137
115
138
116
# GetQueuedMessages
139
# GetQueuedMessages
117
my $messages = C4::Letters::GetQueuedMessages();
140
my $messages = C4::Letters::GetQueuedMessages();
118
is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' );
141
is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' );
119
142
120
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
143
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
121
is( @$messages, 1, 'one message stored for the borrower' );
144
is( @$messages, 2, 'two messages stored for the borrower' );
122
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
145
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
123
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
146
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
124
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
147
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
Lines 129-137 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
129
152
130
# SendQueuedMessages
153
# SendQueuedMessages
131
my $messages_processed = C4::Letters::SendQueuedMessages();
154
my $messages_processed = C4::Letters::SendQueuedMessages();
132
is($messages_processed, 1, 'all queued messages processed');
155
is($messages_processed, 2, 'all queued messages processed');
156
157
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
158
is(scalar(@$messages), 2, 'two messages stored for the borrower');
159
160
# used to trigger _send_message_by_email in C4::Letter
161
# second no override.
162
$dbh->do("UPDATE systempreferences SET value='' WHERE variable='SendAllEmailsTo';");
163
my $message_id3 = C4::Letters::EnqueueLetter({
164
    borrowernumber         => $borrowernumber,
165
    message_transport_type => 'email',
166
    to_address             => 'to@example.com',
167
    from_address           => 'from@example.com',
168
    letter => {
169
        content      => 'a message',
170
        title        => 'message title',
171
        metadata     => 'metadata',
172
        code         => 'TEST_MESSAGE',
173
        content_type => 'text/plain',
174
    },
175
});
176
177
$messages_processed = C4::Letters::SendQueuedMessages();
178
is($messages_processed, 1, 'third queued message processed');
133
179
134
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
180
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
181
is(scalar(@$messages), 3, 'three messages stored for the borrower');
182
135
is(
183
is(
136
    $messages->[0]->{status},
184
    $messages->[0]->{status},
137
    'failed',
185
    'failed',
138
- 

Return to bug 8000