Bug 39907

Summary: "no recipients" plus trace info; [WARN]  at C4/Letters.pm (while it had a to_address)
Product: Koha Reporter: Marcel de Rooy <m.de.rooy>
Component: NoticesAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: tomascohen
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Marcel de Rooy 2025-05-15 12:23:53 UTC
Above warnings with trace in plack-opac-error.log
In our 23.11 referred to Letters line 1558 (last line of the last catch block in sub _send_message_by_email)

The caller was opac-sendbasket.pl

Hard to see what happened here. opac-sendbasket will not send a mail without an email address. And Koha::Email::create checks the validity of the to address with Email::Address (no corresponding warn detected).
I also saw this preceding warning:
[2025/05/12 17:13:17] [WARN] Use of uninitialized value in string ne at /usr/share/koha/C4/Letters.pm line 1526.
Which is the line:
    _update_message_to_address( $message->{'message_id'}, $email->email->header('To') )
      if !$message->{to_address}
      || $message->{to_address} ne $email->email->header('To');

So at that point $message->{to_address} was not false! And therefore the To header must have been undefined and written back to the message! If you encounter this, should you already bail out ?

Later on, Letters called send_or_die on the email (with an emptied To header). And this produced the warning "no recipients" from the module Email::Sender::Simple. Interestingly, this modules does not use Email::Address to parse the addresses (again), but uses Email::Address::XS.
This triggers the above warns.

Any idea?