Bug 28581: Add 'from_email_address' method and use in Koha::Patron
This patch adds a new 'from_email_address' method to Koha::Library to return the appropriate email address to use as the 'from' field for email notices from the library. We then update Koha::Patron->queue_notice to use this new method instead of the incorrect inbound_email_address. I also update the POD for inbound_email_address to clarify it's use case. Test plan Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
5197b22d39
commit
eff0187295
|
|
@ -143,12 +143,35 @@ sub smtp_server {
|
|||
return $self;
|
||||
}
|
||||
|
||||
=head3 from_email_address
|
||||
|
||||
my $from_email = Koha::Library->from_email_address;
|
||||
|
||||
Returns the official 'from' email address for the branch.
|
||||
|
||||
It may well be a 'noreply' or other inaccessible local domain
|
||||
address that is being used to satisfy spam protection filters.
|
||||
|
||||
=cut
|
||||
|
||||
sub from_email_address {
|
||||
my ($self) = @_;
|
||||
|
||||
return
|
||||
$self->branchemail
|
||||
|| C4::Context->preference('KohaAdminEmailAddress')
|
||||
|| undef;
|
||||
}
|
||||
|
||||
=head3 inbound_email_address
|
||||
|
||||
my $to_email = Koha::Library->inbound_email_address;
|
||||
|
||||
Returns an effective email address which should be accessible to librarians at the branch.
|
||||
|
||||
NOTE: This is the address to use for 'reply_to' or 'to' fields; It should not usually be
|
||||
used as the 'from' address for emails as it may lead to mail being caught by spam filters.
|
||||
|
||||
=cut
|
||||
|
||||
sub inbound_email_address {
|
||||
|
|
|
|||
|
|
@ -1874,7 +1874,7 @@ sub queue_notice {
|
|||
return unless exists $params->{message_name} xor $params->{message_transports}; # We only want one of these
|
||||
|
||||
my $library = Koha::Libraries->find( $letter_params->{branchcode} );
|
||||
my $admin_email_address = $library->inbound_email_address;
|
||||
my $from_email_address = $library->from_email_address;
|
||||
|
||||
my @message_transports;
|
||||
my $letter_code;
|
||||
|
|
@ -1909,7 +1909,7 @@ sub queue_notice {
|
|||
C4::Letters::EnqueueLetter({
|
||||
letter => $letter,
|
||||
borrowernumber => $self->borrowernumber,
|
||||
from_address => $admin_email_address,
|
||||
from_address => $from_email_address,
|
||||
message_transport_type => $mtt
|
||||
}) unless $test_mode;
|
||||
push @{$return{sent}}, $mtt;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 11;
|
||||
use Test::More tests => 12;
|
||||
|
||||
use C4::Biblio;
|
||||
use C4::Context;
|
||||
|
|
@ -119,6 +119,36 @@ subtest '->get_effective_marcorgcode' => sub {
|
|||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest '->from_email_address' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
||||
$schema->storage->txn_begin;
|
||||
|
||||
my $library_1 = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Libraries',
|
||||
value => {
|
||||
branchemail => 'from@mybranc.com',
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', 'admin@mylibrary.com' );
|
||||
|
||||
is( $library_1->from_email_address, $library_1->branchemail,
|
||||
'If defined, use branches branchemail address');
|
||||
|
||||
$library_1->branchemail(undef)->store();
|
||||
is( $library_1->from_email_address, 'admin@mylibrary.com',
|
||||
'Fallback to KohaAdminEmailAddress email address when branchemail is undefined');
|
||||
|
||||
t::lib::Mocks::mock_preference( 'KohaAdminEmailAddress', '' );
|
||||
is( $library_1->from_email_address, undef,
|
||||
'Return undef when branchemail and KohaAdminEmailAddress are both undefined');
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest '->inbound_email_address' => sub {
|
||||
|
||||
plan tests => 5;
|
||||
|
|
|
|||
Loading…
Reference in New Issue