Bug 26705: Make Koha::Email->send_or_die handle Bcc
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 23 Mar 2021 13:57:13 +0000 (10:57 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 7 Apr 2021 09:44:12 +0000 (11:44 +0200)
commit1f8bbb408a52543d8e2b45790fdcd67e125d45ac
treedc8cbec8ddf0cc33d8d0c9020512fba1f189afb1
parentbd12b6050f0b1c83d7af4df71959d4c0950069e4
Bug 26705: Make Koha::Email->send_or_die handle Bcc

Koha used to rely on Mail::Sendmail for sending emails. As an SMTP
client, the library took the job of extracting Bcc headers (and removing
them) to pass them along with the recipients listed on To: and Cc: to
the SMTP protocol in the form of RCPT TO: lines. [1]

This was overlooked when we moved to Email::Stuffer/Email::Simple and
there's a different behavior, that is a design decision [2].

This patchset re-introduces the behavior from Mail::Sendmail by
overriding the send_or_die method locally (in Koha::Email) and doing the
right thing.

Unless an explicit {to} parameter is passed, it extracts the recipients
from the headers, as Mail::Sendmail does, and calls
$self->SUPER::send_or_die with the right parameters.

To test:
1. Apply the regression tests
2. Run:
   $ kshell
  k$ prove t/Koha/Email.t
=> FAIL: Bcc is not handled correctly!
3. Apply this patch
4. Repeat 2
=> SUCCESS: Tests pass! The recipients list is correct! No Bcc header
sent!
5. Sign off :-D

[1] https://metacpan.org/release/Mail-Sendmail/source/lib/Mail/Sendmail.pm#L331
[2] https://metacpan.org/pod/Email::Sender::Manual::QuickStart#Hey,-where's-my-Bcc-support

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
(cherry picked from commit ebf9c134d160ab9dfd905a0b26fe7db6ad04d093)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Koha/Email.pm