On my site I have a custom module which implements the message_alter hook. It had been working perfect for several months on messaging 1.1 but since upgrading to 2.0 it's not working.

I suspect something in the $messaging object has changed. I've spent several hours trying to debug this without any success.

Here's the custom code:

<?php
/** hook_message_alter - allows us to alter email messages sent from the site */
function mailnode_message_alter(&$message, $info) {
$info_str_org = var_export($info, true);
# For now, just for non digested emails
$params = Array();
$account = $message->account;
$posterid = -1;
if (!empty($message->notifications) && empty($message->notifications['digest']) && $info['group'] == 'mail') {
$event = array_shift($message->notifications['events']);
if ($event->type == 'node' && !empty($event->objects['node'])) {
$params['uid'] = $account->uid;
$params['nid'] = $event->objects['node']->nid;
$posterid = $event->objects['node']->uid;
if ($event->action == 'comment' && !empty($event->objects['comment'])) {
$params['cid'] = $event->objects['comment']->cid;
$posterid = $event->objects['comment']->uid;
}
}
}
# If we've got some params out of the message, embed them into the message id for emails only
# and only if the recipient of the message is allowed to post comments.
$reply = $account->mail;
if (empty($reply)) {
$reply = variable_get("mailnode_noreply_email", t("no-reply@" . variable_get("mailnode_server_string", "example.com")));
}
$groups = array_values($event->objects['node']->og_groups_both);
if (!empty($groups)) {
$groupname = strtolower(str_replace(' ', '-', $groups[0]));
}
if ($groupname && $params && user_access('post comments', $account)) {
$poster = user_load($posterid);
$message->params['mail']['headers']['From'] = $groupname . '@island.byu.edu';
$message->params['mail']['headers']['Reply-To'] = $groupname . '@island.byu.edu';
$message->params['mail']['headers']['Message-ID'] = mailnode_build_messageid($params);
# get the text of the message so we can modify it
# Add reply separator for the reply
$separator = variable_get('mailnode_reply_text', t("=-=-=-=-=- Reply above this line -=-=-=-=-=
"));
$prefix = array($separator);
if (!empty($message->body['#prefix'])) {
$prefix[] = $message->body['#prefix'];
}
$prefix[] = "

";
# add the "user wrote:" part
$fullpostername = blueprint_username($poster);
if ($fullpostername) {
# $prefix[] = $fullpostername . ' (' . $poster->mail . ') wrote:
';
$prefix[] = $fullpostername . ' wrote:
';
}elseif ($poster) {
# $prefix[] = $poster->name . ' (' . $poster->mail . ') wrote:
';
$prefix[] = $poster->name . ' wrote:
';
}
# This glue text is a best guess, may cause trouble though, also with filtering (?).
# So we better explicitly set glue text for all sending methods
$info += array('glue' => "

");
$message->body['#prefix'] = implode($info['glue'], $prefix);
# This is a simple solution to mail clients that strip out the messageid and/or in-reply-to headers.
# We insert the messageid in the footer to use as a back-up to the header info
# see http:#drupal.org/node/290214
$message->body['#footer'] .= t('

MessageID='.$message->params['mail']['headers']['Message-ID']);
}
}

Comments

kyle_mathews’s picture

Title: $messaging object change? » $message object change?
jose reyero’s picture

Category: bug » support
Status: Active » Fixed

This seems to be written after the mail2web module, check out the latest version of that one.

Also it may depend on og, check out that one too.

Status: Fixed » Closed (fixed)

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

kyle_mathews’s picture

Thanks Jose -- a diff on the mail2web showed that the line 135 had changed from:
$event = array_shift($message->notifications['events']);
to
$event = current($message->notifications['events']);

Once I made that change, everything started working again.

Thanks for the help.