It used to be that the 'name' (now 'admin_title') of a mailbox had to be an email address. Now it is suggested, but not required, for this to be the case. The problem is that in the Mail Comment configuration, the admin_title of the selected mailbox is used to set the reply-to address for outgoing emails; if the admin_title is not a valid email, that is a bad thing...

Maybe this option should be a free-input field instead of a select box? The downside is that we can't just set a default based on a mailbox name...

Also, once this is resolved, we may want to edit the mailbox config form to change 'email address' to 'mailbox name' or whatever, to avoid confusion.

Comments

danepowell’s picture

Additionally, it seems that the reply-to address may not be getting set at all- does it default to the site address?

rsbecker’s picture

I have found with Messaging 6.x-2.x and 6.x-4.x, if you use PHPMailer the reply-to address is not set properly. There is a fix for this. I'm not sure it would work with 7.x

If you use PHPMailer, rather than Drupal Mail to send messages you must fix a bug in the messaging_phpmailer.module file to ensure that the reply-to address is set properly in outgoing. Find the following code:

if (!empty($replyto['name']) && !empty($replyto['email'])) {
  $mail->AddReplyTo($replyto['email'], $replyto['name']);
  }

Replace it with:

if(!empty($message['headers']['Reply-To'])) {
    $mail->AddReplyTo($message['headers']['Reply-To']);
  }
danepowell’s picture

@rsbecker See #548864: AddReplyTo method called with invalid parameters. I think the 'fix' that you propose would actually cause a regression of that issue.

danepowell’s picture

@rsbecker I see that you've replied to #1067202: Reply-to header not set correctly when used with phpmailer, please continue discussion of the PHPMailer reply-to issue there.

rsbecker’s picture

You're correct, it is a regression. All I can tell you is that it works and the change to preg_match does not work on 3 sites I have. These sites use messaging 6.x-4.x-dev. I can't explain why this is so.

I am using the phpmailer 5.1 library if that is helpful.

danepowell’s picture

Status: Active » Fixed

Nevermind #1... the reply-to seems to be set just fine. Maybe I was confused because the from address is the site address. Anyway, I changed the reply-to option to be a textfield defaulting to the site email address:

http://drupalcode.org/project/mailcomment.git/commit/b26807f
http://drupalcode.org/project/mailcomment.git/commit/fa44b6b

Status: Fixed » Closed (fixed)

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

MickC’s picture

Issue summary: View changes

I was getting the wrong 'reply-to' - it was defaulting to the 'from' but only for some emails.

More weirdly, if I only sent to some of my subscribers it was ok, but if I sent to all of them, the reply-to would be wrong.
But inconsistently - I had 2 admin users subscribing to check - sometimes one, the other, both, none would have the wrong reply-to.

So I added a line at the end to hard code the reply-to, hence ignoring any if statements wrapped around it earlier on (see bottom of this post)
This works, but not ideal - do you think some of those if conditions need to be reviewed?
Why do we need these conditions? If any fail then quite a few steps won't be done

if ($params ----------------------- OK, so what is the problem if no params?
&& ($reply = variable_get('mailcomment_mailbox', '')) -------------- why do we need this if we set reply-to in the UI?
&& user_access('post comments', $account) ---------------------- doesn't Mailhandler and feeds already do this?
&& (node_load($event->objects['node']->value)->comment == 2) ---- OK I guess just checking that comments are open

function mailcomment_notifications_notifications_message_alter(&$message) {
    $params = array();
    // For now, just for non digested emails
    if (($account = current($message->get_destinations())->get_user()) && $message->digest == FALSE && $message->send_method()->type == 'mail') {
        $event = current($message->events);
        if (($event->type == 'node-post' || $event->type == 'node-comment') && !empty($event->objects['node'])) {
            $node = node_load($event->objects['node']->value);
            $params['uid'] = $node->uid;
            $params['nid'] = $node->nid;
            $params['cid'] = 0;
            $params['time'] = $node->created;
            if ($event->action == 'comment' && !empty($event->objects['comment'])) {
                $comment = comment_load($event->objects['comment']->value);
                $params['uid'] = $comment->uid;
                $params['cid'] = $comment->cid;
                $ancestor_msg_id = mailcomment_mail_comment_ancestor_message_id($params['nid'], $params['cid']);
                $params['time'] = $comment->created;
            }
        }
    }
    // 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.
if ($params && ($reply = variable_get('mailcomment_mailbox', '')) && user_access('post comments', $account) && (node_load($event->objects['node']->value)->comment == 2)) {
        // Alter message subjects
        if (variable_get('mailcomment_alter_subjects', 1)) {
            $subject = $message->get_template()->get_element('subject');
            if (($event->type == 'node' || $event->type == 'node-comment') && !empty($event->objects['node'])) {
                $subject['#markup'] = variable_get('site_name', '') ? '[' . variable_get('site_name', '') . '] ' . node_load($event->objects['node']->value)->title : $subject['#markup'];
            }
            if ($event->action == 'comment') {
                $subject['#markup'] = t('Re:') . ' ' . $subject['#markup'];
            }
            $message->subject = $subject;
        }

        $message->params['mail']['headers']['Message-ID'] = mailcomment_build_messageid($params);
        $message->params['mail']['headers']['Reply-To'] = $reply;
        if (isset($ancestor_msg_id)) {
            $message->params['mail']['headers']['In-Reply-To'] = $ancestor_msg_id;
        }
        // Add marker text into the message header part taking care of already existing text
        $insert_reply_text = variable_get('mailcomment_insert_reply_text', 1);
        $text = variable_get('mailcomment_reply_text', t('((( Reply ABOVE this LINE to POST a COMMENT )))'));
        if ($text && $insert_reply_text) {
            $prefix = array($text);
            $header = $message->get_template()->get_element('header');
            $prefix[] = $header['#markup'];
            $header['#markup'] = implode("\n", $prefix);
            $message->get_template()->add_element('header', $header);
        }
        // Alter $params in order to provide recipient uid in message signature
        $params['uid'] = $account->uid;
        $footer = $message->get_template()->get_element('footer');
        //$footer['mailcomment'] = array('#type' => 'messaging_link', '#text' => 'View original post: ', '#url' =>  url('mailcomment/redirect/' . mailcomment_build_messageid($params), array('absolute' => TRUE)));
        $message->get_template()->add_element('footer', $footer);
    }
  $message->params['mail']['headers']['Reply-To'] = 'myhardcodedemailaddress@mydomain.com';
}
MickC’s picture

UPDATE - ok the hard coding works, but I've noticed a couple of other issues:

  • the 'reply line' was also missing - I now realise that the emails with the wrong reply-to also have missing reply-line
  • this leads me to believe that even in the same notification run, the module isn't taking effect for some emails
  • I can't isolate which conditions are not being met as it's not the same user recipient or sender or even the same mail
  • it's something to do with the combination of factors together which result in some notifications bypassing function mailcomment_notifications_notifications_message_alter

Another thing I noticed in the code is different event types -should they be the same? First line uses 'node-post'

if (($event->type == 'node-post' || $event->type == 'node-comment') && !empty($event->objects['node'])) 
 

Then later it uses 'node'

if (($event->type == 'node' || $event->type == 'node-comment') && !empty($event->objects['node']))