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

(-)a/C4/Letters.pm (-9 / +12 lines)
Lines 479-496 sub SendAlerts { Link Here
479
479
480
        # ... then send mail
480
        # ... then send mail
481
        my $library = Koha::Libraries->find( $userenv->{branch} );
481
        my $library = Koha::Libraries->find( $userenv->{branch} );
482
        my %mail = (
482
        my $email = Koha::Email->new();
483
            To => join( ',', @email),
483
        my %mail = $email->create_message_headers(
484
            Cc             => join( ',', @cc),
484
            {
485
            From           => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'),
485
                to      => join( ',', @email),
486
            Subject        => Encode::encode( "UTF-8", "" . $letter->{title} ),
486
                cc      => join( ',', @cc),
487
            Message => $letter->{'is_html'}
487
                from    => $library->branchemail || C4::Context->preference('KohaAdminEmailAddress'),
488
                subject => Encode::encode( "UTF-8", "" . $letter->{title} ),
489
                message => $letter->{'is_html'}
488
                            ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
490
                            ? _wrap_html( Encode::encode( "UTF-8", $letter->{'content'} ),
489
                                          Encode::encode( "UTF-8", "" . $letter->{'title'} ))
491
                                          Encode::encode( "UTF-8", "" . $letter->{'title'} ))
490
                            : Encode::encode( "UTF-8", "" . $letter->{'content'} ),
492
                            : Encode::encode( "UTF-8", "" . $letter->{'content'} ),
491
            'Content-Type' => $letter->{'is_html'}
493
                contenttype => $letter->{'is_html'}
492
                                ? 'text/html; charset="utf-8"'
494
                                ? 'text/html; charset="utf-8"'
493
                                : 'text/plain; charset="utf-8"',
495
                                : 'text/plain; charset="utf-8"',
496
            }
494
        );
497
        );
495
498
496
        if ($type eq 'claimacquisition' || $type eq 'claimissues' ) {
499
        if ($type eq 'claimacquisition' || $type eq 'claimissues' ) {
Lines 499-505 sub SendAlerts { Link Here
499
            $mail{'Sender'} = C4::Context->preference('ReturnpathDefault')
502
            $mail{'Sender'} = C4::Context->preference('ReturnpathDefault')
500
              if C4::Context->preference('ReturnpathDefault');
503
              if C4::Context->preference('ReturnpathDefault');
501
            $mail{'Bcc'} = $userenv->{emailaddress}
504
            $mail{'Bcc'} = $userenv->{emailaddress}
502
              if C4::Context->preference("ClaimsBccCopy");
505
              if C4::Context->preference("ClaimsBccCopy") and not C4::Context->preference("SendAllEmailsTo");
503
        }
506
        }
504
507
505
        unless ( Mail::Sendmail::sendmail(%mail) ) {
508
        unless ( Mail::Sendmail::sendmail(%mail) ) {
Lines 1304-1310 sub _send_message_by_email { Link Here
1304
1307
1305
    $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
1308
    $sendmail_params{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
1306
    if ( my $bcc = C4::Context->preference('NoticeBcc') ) {
1309
    if ( my $bcc = C4::Context->preference('NoticeBcc') ) {
1307
       $sendmail_params{ Bcc } = $bcc;
1310
       $sendmail_params{ Bcc } = C4::Context->preference("SendAllEmailsTo") || $bcc;
1308
    }
1311
    }
1309
1312
1310
    _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
1313
    _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
(-)a/Koha/Email.pm (+9 lines)
Lines 18-23 Link Here
18
package Koha::Email;
18
package Koha::Email;
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Email::Valid;
21
22
22
use base qw(Class::Accessor);
23
use base qw(Class::Accessor);
23
use C4::Context;
24
use C4::Context;
Lines 49-54 sub create_message_headers { Link Here
49
        From    => $params->{from},
50
        From    => $params->{from},
50
        charset => $params->{charset}
51
        charset => $params->{charset}
51
    );
52
    );
53
54
    if (C4::Context->preference('SendAllEmailsTo') && Email::Valid->address(C4::Context->preference('SendAllEmailsTo'))) {
55
        $mail{'To'} = C4::Context->preference('SendAllEmailsTo');
56
    }
57
    else {
58
        $mail{'Cc'} = $params->{cc};
59
    }
60
52
    if ( C4::Context->preference('ReplytoDefault') ) {
61
    if ( C4::Context->preference('ReplytoDefault') ) {
53
        $params->{replyto} ||= C4::Context->preference('ReplytoDefault');
62
        $params->{replyto} ||= C4::Context->preference('ReplytoDefault');
54
    }
63
    }
(-)a/installer/data/mysql/atomicupdate/Bug8000-SendAllEmailsTo.syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
2
VALUES ('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free');
(-)a/installer/data/mysql/sysprefs.sql (-1 / +2 lines)
Lines 1-4 Link Here
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
1
INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'),` ) VALUES
2
('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'),
2
('AcqCreateItem','ordering','ordering|receiving|cataloguing','Define when the item is created : when ordering, when receiving, or in cataloguing module','Choice'),
3
('AcqEnableFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to invoice records.','YesNo'),
3
('AcqEnableFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to invoice records.','YesNo'),
4
('AcqItemSetSubfieldsWhenReceiptIsCancelled','', '','Upon cancelling a receipt, update the items subfields if they were created when placing an order (e.g. o=5|a="bar foo")', 'Free'),
4
('AcqItemSetSubfieldsWhenReceiptIsCancelled','', '','Upon cancelling a receipt, update the items subfields if they were created when placing an order (e.g. o=5|a="bar foo")', 'Free'),
Lines 495-500 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
495
('SelfCheckoutByLogin','1',NULL,'Have patrons login into the web-based self checkout system with their username/password or their cardnumber','YesNo'),
495
('SelfCheckoutByLogin','1',NULL,'Have patrons login into the web-based self checkout system with their username/password or their cardnumber','YesNo'),
496
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
496
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
497
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
497
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
498
('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'),
498
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
499
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
499
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
500
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
500
('SessionRestrictionByIP','1','Check for change in remote IP address for session security. Disable only when remote IP address changes frequently.','','YesNo'),
501
('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
            - "Email to redirect all messages to: "
20
            - pref: SendAllEmailsTo
21
              class: email
22
            - "(Leave this field empty to send messages to their normal recipient)"
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 (-2 / +12 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 => 64;
21
use Test::More tests => 66;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 479-484 my $borrowernumber = AddMember( Link Here
479
my $subscription = Koha::Subscriptions->find( $subscriptionid );
479
my $subscription = Koha::Subscriptions->find( $subscriptionid );
480
$subscription->add_subscriber( scalar Koha::Patrons->find( $borrowernumber ) );
480
$subscription->add_subscriber( scalar Koha::Patrons->find( $borrowernumber ) );
481
481
482
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', '' );
483
482
my $err2;
484
my $err2;
483
warning_is {
485
warning_is {
484
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
486
$err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
Lines 487-492 $err2 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) } Link Here
487
is($err2, 1, "Successfully sent serial notification");
489
is($err2, 1, "Successfully sent serial notification");
488
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
490
is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notification");
489
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
491
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
492
493
t::lib::Mocks::mock_preference( 'SendAllEmailsTo', 'robert.tables@mail.com' );
494
495
my $err3;
496
warning_is {
497
$err3 = SendAlerts( 'issue', $serial->{serialid}, 'RLIST' ) }
498
    "Fake sendmail",
499
    "SendAlerts is using the mocked sendmail routine";
500
is($mail{'To'}, 'robert.tables@mail.com', "mailto address overwritten by SendAllMailsTo preference");
490
}
501
}
491
502
492
subtest 'GetPreparedLetter' => sub {
503
subtest 'GetPreparedLetter' => sub {
493
- 

Return to bug 8000