With drupal_mail() you can prepare 100% the message by applying all hooks, alters, processing, but without sending. This can be useful when you want to send messages in 3 (or more) steps: preparation > spooling > sending.

Mime Mail needs this too. The mimemail() mixes message preparation with message sending.

It would be helpful to make a API change so that we can prepare the message 100% with Mime Mail but without sending.

Comments

claudiu.cristea’s picture

Status: Active » Needs review
StatusFileSize
new5.7 KB

With this patch we can use mimemail() for sending or only for preparing like drupal_mail() - see http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail/6.

A new argument $send was appended and 2 wrapper functions were added: mimemail_prepare() & mimemail_send().

Wanna prepare the message but not send it? For example we want to spool and not send it.

$message = mimemail_prepare($sender, $recipient, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);

or

$message = mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey, FALSE);

Wanna send an already prepared message? Example: Send prepared messages from a spool queue

mimemail_send($message);
claudiu.cristea’s picture

StatusFileSize
new12.51 KB

Also reordered functions inside module because they were somehow mixed.

sgabe’s picture

Status: Needs review » Needs work

You can't add a new function named mimemail_prepare() because Drupal core has a hook_prepare(). Please, don't create new functions. Just add a $send parameter to mimemail() and if it's TRUE then return the $message as it is.

claudiu.cristea’s picture

@sgabe,

You can't add a new function named mimemail_prepare() because Drupal core has a hook_prepare().

Good catch! But a "send" wrapper must be added as drupal_mail_send() is for drupal_mail(). If we don't have the second function we cannot send directly a "prepared" messages.

I've integrated Mimemail in Views Send module. Messages are spooled and the module philosophy is to alter/prepare/render everything when adding messages to the queue. On cron the queue is processed and I need only the send part which needs a API function.

Should we leave it as mimemail_send() or rename it as mimemail_mail_send() (for similarity reasons)?

claudiu.cristea’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB

Here's a patch based on #3 and #4.

Switched to classical patch format as is easiest to read and don't want my e-mail listed.

sgabe’s picture

StatusFileSize
new6.05 KB

Well, I would say let's name it mimemail_send_message() and clean things up a little bit. Note that this API change needs to be done in alpha stage and we are very close to move towards a stable release.

claudiu.cristea’s picture

Status: Needs review » Reviewed & tested by the community

Note that now mimemail() really returns the whole $message array as it was already state (but not effective) in phpdoc:

 * @return
 *   An array containing the MIME encoded message, including headers and body.

This is an API change and modules using mimemail()must adapt.

sgabe’s picture

Yeah, I was thinking about to change that behavior to return a bool value when the message is sent directly, but in the other hand I think it would be better to stick with the Drupal core behavior and return the whole message with the result. However, we missed to update the README.txt with this change.

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new7.18 KB

Added also the README.txt and deleted a trailing space somewhere in the last patch.

sgabe’s picture

Thanks, looks good. Now I am thinking about how to handle this major API change. Maybe we should provide patches to the most used modules - like Simplenews and Webform - before committing, so we can make this change as smooth as possible.

claudiu.cristea’s picture

Created a patch for Webform 6.x-3.x-dev here http://drupal.org/node/1087598. I'm not using Simplenews so I cannot test/patch.

sgabe’s picture

Patches attached for Simplenews in #1112310: Mime Mail returns array instead of bool.

sgabe’s picture

Status: Needs review » Fixed

Committed to the development snapshot. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sgabe’s picture

StatusFileSize
new1.63 KB

A minor follow-up to this.

roball’s picture

Title: Split mail preparation from sending » API change: Split mail preparation from sending
Status: Closed (fixed) » Active

So, just to ensure - when upgrading Mime Mail to 6.x-1.0-beta1, Webform has to be >= 6.x-3.11 and Simplenews >= 6.x-2.0-alpha2, right? What about Views send?

sgabe’s picture

Since claudiu.cristea is the maintainer of Views Send and he suggested this change it is already supported by Views Send.

roball’s picture

Status: Active » Fixed

Thank you for making that clear.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.