Commit 5961c08a authored by Joe Atzberger's avatar Joe Atzberger Committed by Galen Charlton

Bug 3350 - fail on queued emails w/ no address

If a patron has no email address, we need to avoid stockpiling all
their messages indefinitely.  Otherwise they get mailbombed when
their email IS added.

Note that overdues should not be affected, since the overdues job
checks whether the patron email exists before sending the message
(falling back to the admin).  The other messaging features are the
targets affected by this patch.
Signed-off-by: default avatarGalen Charlton <galen.charlton@liblime.com>
parent d914fb60
......@@ -607,7 +607,7 @@ sub SendQueuedMessages (;$) {
if ( lc( $message->{'message_transport_type'} ) eq 'email' ) {
_send_message_by_email( $message );
}
if ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
elsif ( lc( $message->{'message_transport_type'} ) eq 'sms' ) {
_send_message_by_sms( $message );
}
}
......@@ -761,24 +761,35 @@ ENDSQL
}
sub _send_message_by_email ($) {
my $message = shift or return undef;
my $member = C4::Members::GetMember( $message->{'borrowernumber'} );
return unless $message->{'to_address'} or $member->{'email'};
my $message = shift or return;
my $to_address = $message->{to_address};
unless ($to_address) {
my $member = C4::Members::GetMember( $message->{'borrowernumber'} );
unless ($member) {
warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
return;
}
unless ($to_address = $member->{email}) { # assigment, not comparison
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
# warning too verbose for this more common case?
_set_message_status( { message_id => $message->{'message_id'},
status => 'failed' } );
return;
}
}
my $content = encode('utf8', $message->{'content'});
my %sendmail_params = (
To => $message->{'to_address'} || $member->{'email'},
To => $to_address,
From => $message->{'from_address'} || C4::Context->preference('KohaAdminEmailAddress'),
Subject => $message->{'subject'},
charset => 'utf8',
charset => 'utf8',
Message => $content,
'content-type' => $message->{'content_type'} || 'text/plain; charset="UTF-8"',
);
if ($message->{'content_type'}) {
$sendmail_params{'content-type'} = $message->{'content_type'};
}else{
$sendmail_params{'content-type'} = 'text/plain; charset="UTF-8"';
}
my $success = sendmail( %sendmail_params );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment