From 9b5cb15309ad35e30b83ba26cd50399d743f69d5 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 6 Oct 2015 08:39:43 -0400 Subject: [PATCH] Bug 14964 - Email notices will be queued for patrons with no email address If a patron has email messaging preferences set but no email address, a message will be added to the message queue anyway, but will always end up 'failed'. This could be resolved by modifying C4::Letters::enqueue to not enqueue call EnqueueLetter if the transport is email or sms and no to address is returned. Test Plan: 1) Set up patron with checkout messaging preference and no email address 2) Check out an item to the patron 3) Note the message in the message queue with no email address 4) Apply this patch 5) Check out an item to the patron 6) Note no message was queued this time --- C4/Message.pm | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diff --git a/C4/Message.pm b/C4/Message.pm index 30b71c8..0f039fb 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -160,6 +160,8 @@ sub enqueue { my $metadata = _metadata($letter); my $to_address = _to_address($borrower, $transport); + return if $to_address = -1; + # Same as render_metadata my $format ||= sub { $_[0] || "" }; my $body = join('', map { $format->($_) } @{$metadata->{body}}); @@ -181,16 +183,18 @@ sub _to_address { if ($transport eq 'email') { $address = $borrower->{email} || $borrower->{emailpro} - || $borrower->{B_email}; + || $borrower->{B_email} + || -1; } elsif ($transport eq 'sms') { $address = $borrower->{smsalertnumber} || $borrower->{phone} || $borrower->{phonepro} - || $borrower->{B_phone}; + || $borrower->{B_phone} + || -1; } else { warn "'$transport' is an unknown message transport."; } - if (not defined $address) { + if ($address == -1) { warn "An appropriate $transport address " . "for borrower $borrower->{userid} " . "could not be found."; -- 1.7.2.5