#800434: drupal_mail, allow hook_mail_alter implementation to cancel mail β
adds a bit more complexity to drupal_mail() and hook_mail_alter(), but it's supporting a good feature.
However, it would be great to clean that up, hook_mail() is near the top of the list of weird hooks in core.
Pasting from irc chat with permission from Gabor.
<catch> GaborHojtsy: do you have any ideas sitting around somewhere for ways to change drupal_mail?
<catch> GaborHojtsy: not related to anything, just there is a patch in the queue for it that reminds me how much I dislike it.
<GaborHojtsy> catch: LOL
<xjm> haha
<GaborHojtsy> catch: I think we can eliminate the whole pseudo-hook-mail thing if we wanted to
<catch> GaborHojtsy: yeah it is that bit I'm thinking of. I know it was added for translation but it was a long time ago.
<GaborHojtsy> catch: that was an attempt resulting in horrifying DX to enforce localizability of emails
<catch> And plenty of stuff moved along since then.
<GaborHojtsy> catch: nothing made it really required to make us have hook_mail() so we should not have introduced it in the first place
<GaborHojtsy> catch: the idea was if we did not change the API and introduce language prominently, people would not care :D :D :D :D
<GaborHojtsy> catch: in retrospect... well... we are people we make mistakes :)
<catch> GaborHojtsy: heh.
<GaborHojtsy> catch: there is no technical requirement for us to have hook_mail, so we can just drop it altogether
<GaborHojtsy> catch: everything else would still work as-is
<catch> hook_mail?
<Druplicon> hook_mail: Prepare a message based on parameters; called from drupal_mail(). => hook_mail($key, &$message, $params) => http://api.drupal.org/api/function/hook_mail/6
<GaborHojtsy> catch: including hook_mail_alter
<catch> system_mail?
<Druplicon> system_mail: Implementation of hook_mail(). => system_mail($key, &$message, $params) => http://api.drupal.org/api/function/system_mail/6
<GaborHojtsy> catch: hook_mail() just creates arrays of other arrays
<GaborHojtsy> catch: and hook_mail alter then alters those arrays again
<catch> GaborHojtsy: so what does it look like if we completely drop that hook?
<catch> drupal_mail?
<Druplicon> drupal_mail: Compose and optionally send an e-mail message. => drupal_mail($module, $key, $to, $language, $params = array(), $from = NULL, $send = TRUE) => http://api.drupal.org/api/function/drupal_mail/6
<GaborHojtsy> catch: well, you'd pass drupal_mail() what was in D7 the output of hook_mail() for the $key
<GaborHojtsy> catch: you'd still need some identifier for the mail for the drupal_alter() stuff
<GaborHojtsy> catch: so I'd guess we'd keep $module and $key
<catch> GaborHojtsy: $key wouldn't be enough? we can tell people to namespace it.
<GaborHojtsy> catch: sure, we can namespace it
<GaborHojtsy> catch: either way, as you can see drupal_mail() just prefills some stuff to the array that hook_mail() continues to fill; we can turn that around and do a += in drupal_mail()
<catch> GaborHojtsy: mind if I copy and paste a few bits of this into an issue?
<GaborHojtsy> catch: feel free to :)