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-582 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 $library = Koha::Libraries->find( $userenv->{branch} );
589
        my $library = Koha::Libraries->find( $userenv->{branch} );
576
        my %mail = (
590
        my %mail = (
577
            To => join( ',', @email),
578
            Cc             => join( ',', @cc),
579
            From           => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'),
591
            From           => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'),
592
            To             => $emailsTo,
593
            Cc             => $emailsCC,
580
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
594
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
581
            Message => $letter->{'is_html'}
595
            Message => $letter->{'is_html'}
582
                            ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
596
                            ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
Lines 629-637 sub SendAlerts { Link Here
629
        ) or return;
643
        ) or return;
630
        return { error => "no_email" } unless $externalid->{'emailaddr'};
644
        return { error => "no_email" } unless $externalid->{'emailaddr'};
631
        my $email = Koha::Email->new();
645
        my $email = Koha::Email->new();
646
        my $emailaddr = $externalid->{'emailaddr'};
647
        my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
648
        $emailaddr = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
632
        my %mail  = $email->create_message_headers(
649
        my %mail  = $email->create_message_headers(
633
            {
650
            {
634
                to      => $externalid->{'emailaddr'},
651
                to      => $emailaddr,
635
                from    => $library->{branchemail},
652
                from    => $library->{branchemail},
636
                replyto => $library->{branchreplyto},
653
                replyto => $library->{branchreplyto},
637
                sender  => $library->{branchreturnpath},
654
                sender  => $library->{branchreturnpath},
Lines 1296-1310 sub _send_message_by_email { Link Here
1296
1313
1297
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1314
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1298
    my $to_address = $message->{'to_address'};
1315
    my $to_address = $message->{'to_address'};
1316
    if (!$to_address && $member) {
1317
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1318
    }
1319
    my $sendAllEmailsTo = C4::Context->preference('SendAllEmailsTo');
1320
    $to_address = $sendAllEmailsTo if ($sendAllEmailsTo && Email::Valid->address($sendAllEmailsTo) );
1299
    unless ($to_address) {
1321
    unless ($to_address) {
1300
        unless ($member) {
1322
        if (!$member) {
1301
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1323
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1302
            _set_message_status( { message_id => $message->{'message_id'},
1324
            _set_message_status( { message_id => $message->{'message_id'},
1303
                                   status     => 'failed' } );
1325
                                   status     => 'failed' } );
1304
            return;
1326
            return;
1305
        }
1327
        }
1306
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1328
        else {
1307
        unless ($to_address) {  
1308
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1329
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1309
            # warning too verbose for this more common case?
1330
            # warning too verbose for this more common case?
1310
            _set_message_status( { message_id => $message->{'message_id'},
1331
            _set_message_status( { message_id => $message->{'message_id'},
Lines 1349-1356 sub _send_message_by_email { Link Here
1349
    _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
1370
    _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
1350
1371
1351
    if ( sendmail( %sendmail_params ) ) {
1372
    if ( sendmail( %sendmail_params ) ) {
1352
        _set_message_status( { message_id => $message->{'message_id'},
1373
        _set_message_status( { message_id     => $message->{'message_id'},
1353
                status     => 'sent' } );
1374
                               status         => 'sent' } );
1354
        return 1;
1375
        return 1;
1355
    } else {
1376
    } else {
1356
        _set_message_status( { message_id => $message->{'message_id'},
1377
        _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 466-471 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
466
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
466
('SelfCheckHelpMessage','','70|10','Enter HTML to include under the basic Web-based Self Checkout instructions on the Help page','Textarea'),
467
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
467
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
468
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
468
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
469
('SendAllEmailsTo','',NULL,'This email will replace the To address in every message sent by the system.  This is meant to help testing only.','Textarea'),
469
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
470
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
470
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
471
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
471
('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'),
472
('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 89-94 is_deeply( $mtts, ['email', 'phone', 'print', 'sms'], 'GetMessageTransportTypes Link Here
89
# EnqueueLetter
89
# EnqueueLetter
90
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
90
is( C4::Letters::EnqueueLetter(), undef, 'EnqueueLetter without argument returns undef' );
91
91
92
# used to trigger _send_message_by_sms in C4::Letter
92
my $my_message = {
93
my $my_message = {
93
    borrowernumber         => $borrowernumber,
94
    borrowernumber         => $borrowernumber,
94
    message_transport_type => 'sms',
95
    message_transport_type => 'sms',
Lines 113-125 $my_message->{message_transport_type} = 'sms'; Link Here
113
$message_id = C4::Letters::EnqueueLetter($my_message);
114
$message_id = C4::Letters::EnqueueLetter($my_message);
114
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
115
ok(defined $message_id && $message_id > 0, 'new message successfully queued');
115
116
117
# This is will force C4::Context->preference() to read the DB.
118
C4::Context->disable_syspref_cache();
119
120
# used to trigger _send_message_by_email in C4::Letter
121
# first override.
122
$dbh->do("UPDATE systempreferences SET value='override\@example.com' WHERE variable='SendAllEmailsTo';");
123
my $message_id2 = C4::Letters::EnqueueLetter({
124
    borrowernumber         => $borrowernumber,
125
    message_transport_type => 'email',
126
    to_address             => 'to@example.com',
127
    from_address           => 'from@example.com',
128
    letter => {
129
        content      => 'a message',
130
        title        => 'message title',
131
        metadata     => 'metadata',
132
        code         => 'TEST_MESSAGE',
133
        content_type => 'text/plain',
134
    },
135
});
136
137
ok(defined $message_id2 && $message_id2 > 0, 'new message successfully queued');
138
116
139
117
# GetQueuedMessages
140
# GetQueuedMessages
118
my $messages = C4::Letters::GetQueuedMessages();
141
my $messages = C4::Letters::GetQueuedMessages();
119
is( @$messages, 1, 'GetQueuedMessages without argument returns all the entries' );
142
is( @$messages, 2, 'GetQueuedMessages without argument returns all the entries' );
120
143
121
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
144
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
122
is( @$messages, 1, 'one message stored for the borrower' );
145
is( @$messages, 2, 'two messages stored for the borrower' );
123
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
146
is( $messages->[0]->{message_id}, $message_id, 'EnqueueLetter returns the message id correctly' );
124
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
147
is( $messages->[0]->{borrowernumber}, $borrowernumber, 'EnqueueLetter stores the borrower number correctly' );
125
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
148
is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter stores the subject correctly' );
Lines 130-138 is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pendin Link Here
130
153
131
# SendQueuedMessages
154
# SendQueuedMessages
132
my $messages_processed = C4::Letters::SendQueuedMessages();
155
my $messages_processed = C4::Letters::SendQueuedMessages();
133
is($messages_processed, 1, 'all queued messages processed');
156
is($messages_processed, 2, 'all queued messages processed');
157
158
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
159
is(scalar(@$messages), 2, 'two messages stored for the borrower');
160
161
# used to trigger _send_message_by_email in C4::Letter
162
# second no override.
163
$dbh->do("UPDATE systempreferences SET value='' WHERE variable='SendAllEmailsTo';");
164
my $message_id3 = C4::Letters::EnqueueLetter({
165
    borrowernumber         => $borrowernumber,
166
    message_transport_type => 'email',
167
    to_address             => 'to@example.com',
168
    from_address           => 'from@example.com',
169
    letter => {
170
        content      => 'a message',
171
        title        => 'message title',
172
        metadata     => 'metadata',
173
        code         => 'TEST_MESSAGE',
174
        content_type => 'text/plain',
175
    },
176
});
177
178
$messages_processed = C4::Letters::SendQueuedMessages();
179
is($messages_processed, 1, 'third queued message processed');
134
180
135
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
181
$messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber });
182
is(scalar(@$messages), 3, 'three messages stored for the borrower');
183
136
is(
184
is(
137
    $messages->[0]->{status},
185
    $messages->[0]->{status},
138
    'failed',
186
    'failed',
139
- 

Return to bug 8000