When views_send actually sends the eMails via cron, there is no $message['id']. If other modules are depending on this ID to be present to do something with those messages (any hook_mail_alter, for example), they'd not be there, which is problematic. I'm thinking they really should be included, should they not?

I hacked views_send.cron.inc to include one for a site I developed. Would be good if this was fixed before the release.

Shawn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hansfn’s picture

Assigned: Unassigned » hansfn

I see what you mean. The message ID is generated when drupal_mail is called in _views_send_prepare_mail, but then the module just ignores it. There is no ID field in the views_send_spool table.

I'll look at it, but D6 is generally low priority since D8 is coming closer. (The D7 version is also ignoring the ID, but at least you have hooks do the same as hook_mail_alter.)

sdsheridan’s picture

Well, here's a patch for the hack I did. It's simplistic, but at least it provides an ID.

Shawn

hansfn’s picture

The patch/hack is harmless enough, but I think we are attacking this wrong.

drupal_mail invokes hook_mail_alter and hook_mail. Views Send calls drupal_mail in the function _views_send_prepare_mail and the id is set to "views_send_direct" inside drupal_mail, so this should work for everyone that wants to modify a message. However, you want to do Mime Mail theming. This should have been done by the call to mimemail in the same function, but in that call to mimemail the mailkey is missing - a bug. Please try the minimal patch attached and see if it works. If not, explain what you are trying to do that didn't work with hook_mail_alter/hook_mail.

hansfn’s picture

Sorry, I mixed up this issue with another. My Mime Mail related patch is correct, but not what you were discussing. Anyway, I don't understand why you can't use hook_mail/hook_mail_alter when drupal_mail is called in in the function _views_send_prepare_mail. Doesn't that work?

sdsheridan’s picture

It doesn't work because that's called before the message is stored in the views_send_spool table for processing by cron later. Cron then retrieves the messages to actually do the eMailing, but there is now no $key, because it's not stored. So, another scheme for preserving the message key is needed. My solution is definitely a hack, because the original message key is lost and a generic 'views_send' one is added to the message array before drupal_mail_send is called.

Now, why do I need the message key at this point you may ask? The use case is that I'm using MailQ to do a similar thing to what views_send already does with it's own eMails, and I've modified MailQ (https://drupal.org/node/2054317) so that it has the ability to look at the message ID / key and where the user has indicated by way of specifying the message ID, not queue the message. Otherwise, I'd have double queuing of eMails from views_send, which seems rather unnecessary.

Shawn

hansfn’s picture

Status: Active » Fixed

No need to repeat the reason the message ID was missing at that point ;-) I just wanted to know the use case.

Fixed in commit 2626d57. (Mostly identical to your patch.)

Status: Fixed » Closed (fixed)

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

ufku’s picture

Version: 6.x-1.0-beta3 » 7.x-1.x-dev
Issue summary: View changes
Status: Closed (fixed) » Active

The fix is missing for 7.x

It prevents Mandrill to apply a specific template for views_send.

hansfn’s picture

Sorry about the late reply.

I'm onto it - ref #1810254: Compatability with views_send. I expect a quick fix - since it's a one-liner.

  • hansfn committed c8350c3 on 7.x-1.x
    Issue #2056883 by hansfn: No message ID
    
hansfn’s picture

Status: Active » Fixed

Fixed for the D7 version in committed c8350c3 - see link above. Sorry about the delay. (It's the same fix as for D6.)

Status: Fixed » Closed (fixed)

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