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

(-)a/C4/Letters.pm (-9 / +30 lines)
Lines 39-44 use Koha::SMS::Providers; Link Here
39
39
40
use Koha::Email;
40
use Koha::Email;
41
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
41
use Koha::DateUtils qw( format_sqldatetime dt_from_string );
42
use Email::Valid;
42
43
43
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
44
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
44
45
Lines 403-409 sub SendAlerts { Link Here
403
        my $alerts = getalert( '', 'issue', $subscriptionid );
404
        my $alerts = getalert( '', 'issue', $subscriptionid );
404
        foreach (@$alerts) {
405
        foreach (@$alerts) {
405
            my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
406
            my $borinfo = C4::Members::GetMember('borrowernumber' => $_->{'borrowernumber'});
406
            my $email = $borinfo->{email} or next;
407
            my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
408
            my $email = $sendAllEmailsTo;
409
            if (!($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo))){
410
                $email = $borinfo->{email} or next;
411
            }
407
412
408
#                    warn "sending issues...";
413
#                    warn "sending issues...";
409
            my $userenv = C4::Context->userenv;
414
            my $userenv = C4::Context->userenv;
Lines 517-526 sub SendAlerts { Link Here
517
        # Remove the order tag
522
        # Remove the order tag
518
        $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms;
523
        $letter->{content} =~ s/<order>(.*?)<\/order>/$1/gxms;
519
524
525
        # SendAllEmailsTo system preference to override for testing
526
        my $emailsTo = join( ',', @email);
527
        my $emailsCC = join( ',', @cc);
528
        my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
529
        if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) ) {
530
            $emailsTo = $sendAllEmailsTo;
531
            $emailsCC = '';
532
        }
533
520
        # ... then send mail
534
        # ... then send mail
521
        my %mail = (
535
        my %mail = (
522
            To => join( ',', @email),
536
            To             => $emailsTo,
523
            Cc             => join( ',', @cc),
537
            Cc             => $emailsCC,
524
            From           => $userenv->{emailaddress},
538
            From           => $userenv->{emailaddress},
525
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
539
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
526
            Message => $letter->{'is_html'}
540
            Message => $letter->{'is_html'}
Lines 572-580 sub SendAlerts { Link Here
572
        ) or return;
586
        ) or return;
573
        return { error => "no_email" } unless $externalid->{'emailaddr'};
587
        return { error => "no_email" } unless $externalid->{'emailaddr'};
574
        my $email = Koha::Email->new();
588
        my $email = Koha::Email->new();
589
        my $emailaddr = $externalid->{'emailaddr'};
590
        my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
591
        $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
575
        my %mail  = $email->create_message_headers(
592
        my %mail  = $email->create_message_headers(
576
            {
593
            {
577
                to      => $externalid->{'emailaddr'},
594
                to      => $emailaddr,
578
                from    => $library->{branchemail},
595
                from    => $library->{branchemail},
579
                replyto => $library->{branchreplyto},
596
                replyto => $library->{branchreplyto},
580
                sender  => $library->{branchreturnpath},
597
                sender  => $library->{branchreturnpath},
Lines 1223-1237 sub _send_message_by_email { Link Here
1223
1240
1224
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1241
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1225
    my $to_address = $message->{'to_address'};
1242
    my $to_address = $message->{'to_address'};
1243
    if (!$to_address && $member) {
1244
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1245
    }
1246
    my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
1247
    $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
1226
    unless ($to_address) {
1248
    unless ($to_address) {
1227
        unless ($member) {
1249
        if (!$member) {
1228
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1250
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1229
            _set_message_status( { message_id => $message->{'message_id'},
1251
            _set_message_status( { message_id => $message->{'message_id'},
1230
                                   status     => 'failed' } );
1252
                                   status     => 'failed' } );
1231
            return;
1253
            return;
1232
        }
1254
        }
1233
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1255
        else {
1234
        unless ($to_address) {  
1235
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1256
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1236
            # warning too verbose for this more common case?
1257
            # warning too verbose for this more common case?
1237
            _set_message_status( { message_id => $message->{'message_id'},
1258
            _set_message_status( { message_id => $message->{'message_id'},
Lines 1276-1283 sub _send_message_by_email { Link Here
1276
    _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
1297
    _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
1277
1298
1278
    if ( sendmail( %sendmail_params ) ) {
1299
    if ( sendmail( %sendmail_params ) ) {
1279
        _set_message_status( { message_id => $message->{'message_id'},
1300
        _set_message_status( { message_id     => $message->{'message_id'},
1280
                status     => 'sent' } );
1301
                               status         => 'sent' } );
1281
        return 1;
1302
        return 1;
1282
    } else {
1303
    } else {
1283
        _set_message_status( { message_id => $message->{'message_id'},
1304
        _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 444-449 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
444
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
444
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
445
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
445
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
446
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
446
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
447
('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system.  This is meant to help testing only.','Textarea'),
447
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
448
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
448
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
449
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
449
('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'),
450
('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 71-76 Administration: Link Here
71
                  yes: "logged in library's"
71
                  yes: "logged in library's"
72
                  no: "all libraries"
72
                  no: "all libraries"
73
            - rules by default.
73
            - rules by default.
74
        -
75
            - Redirect all emails from Koha to
76
            - pref: SendAllEmailsTo
77
              class: email
78
            - instead of their intended user.
74
    Login options:
79
    Login options:
75
        -
80
        -
76
            - Automatically log out users after
81
            - Automatically log out users after
(-)a/t/db_dependent/Letters.t (-5 / +52 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 74;
21
use Test::More tests => 78;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 87-92 is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes Link Here
87
# EnqueueLetter
87
# EnqueueLetter
88
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
88
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
89
89
90
# used to trigger _send_message_by_sms in C4::Letter
90
my $my_message = {
91
my $my_message = {
91
    borrowernumber         => $borrowernumber,
92
    borrowernumber         => $borrowernumber,
92
    message_transport_type => 'sms',
93
    message_transport_type => 'sms',
Lines 111-123 $my_message->{message_transport_type} = 'sms'; Link Here
111
$message_id = C4::Letters::EnqueueLetter($my_message);
112
$message_id = C4::Letters::EnqueueLetter($my_message);
112
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
113
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
113
114
115
# This is will force C4::Context->preference() to read the DB.
116
C4::Context->disable_syspref_cache();
117
118
# used to trigger _send_message_by_email in C4::Letter
119
# first override.
120
$dbh->do("UPDATE systempreferences SET value='override\@example.com' WHERE variable='SendAllEmailsTo';");
121
my $message_id2 = C4::Letters::EnqueueLetter({
122
    borrowernumber         => $borrowernumber,
123
    message_transport_type => 'email',
124
    to_address             => 'to@example.com',
125
    from_address           => 'from@example.com',
126
    letter => {
127
        content      => 'a message',
128
        title        => 'message title',
129
        metadata     => 'metadata',
130
        code         => 'TEST_MESSAGE',
131
        content_type => 'text/plain',
132
    },
133
});
134
135
ok(defined $message_id2 && $message_id2 > 0, 'new message successfully queued');
136
114
137
115
# GetQueuedMessages
138
# GetQueuedMessages
116
my $messages = C4::Letters::GetQueuedMessages();
139
my $messages = C4::Letters::GetQueuedMessages();
117
is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' );
140
is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' );
118
141
119
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
142
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
120
is( @$messages, 1, 'one message stored for the borrower' );
143
is( @$messages, 2, 'two messages stored for the borrower' );
121
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
144
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
122
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
145
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
123
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
146
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
Lines 128-136 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
128
151
129
# SendQueuedMessages
152
# SendQueuedMessages
130
my $messages_processed = C4::Letters::SendQueuedMessages();
153
my $messages_processed = C4::Letters::SendQueuedMessages();
131
is($messages_processed, 1, 'all queued messages processed');
154
is($messages_processed, 2, 'all queued messages processed');
155
156
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
157
is(scalar(@$messages), 2, 'two messages stored for the borrower');
158
159
# used to trigger _send_message_by_email in C4::Letter
160
# second no override.
161
$dbh->do("UPDATE systempreferences SET value='' WHERE variable='SendAllEmailsTo';");
162
my $message_id3 = C4::Letters::EnqueueLetter({
163
    borrowernumber         => $borrowernumber,
164
    message_transport_type => 'email',
165
    to_address             => 'to@example.com',
166
    from_address           => 'from@example.com',
167
    letter => {
168
        content      => 'a message',
169
        title        => 'message title',
170
        metadata     => 'metadata',
171
        code         => 'TEST_MESSAGE',
172
        content_type => 'text/plain',
173
    },
174
});
175
176
$messages_processed = C4::Letters::SendQueuedMessages();
177
is($messages_processed, 1, 'third queued message processed');
132
178
133
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
179
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
180
is(scalar(@$messages), 3, 'three messages stored for the borrower');
181
134
is(
182
is(
135
    $messages->[0]->{status},
183
    $messages->[0]->{status},
136
    'failed',
184
    'failed',
137
- 

Return to bug 8000