I have multiple email addresses that mailhandler is retrieving mail from. Only one of these addresses is configured to be checked by mailcomment. However, if I turn off the "passthru to mailhandler" option in mailcomment, any email sent to the *other* email addresses (that aren't assigned to mailcomment) gets rejected. The log messages show that it is mailcomment rejecting them.

Looking at the code, I can confirm that this is what's happening. In mailcomment's mailhandler hook, if a message belongs to a mailbox that's not set for mailcomment, then either it passes through to mailhandler (if it's set to do that), or it rejects it.

Mailcomment should do the check on which mailbox the message belongs to first, and if that mailbox isn't a mailcomment box, it should just pass the message through, regardless of the "passthru" option, don't you think?

Comments

greggles’s picture

Status: Active » Postponed (maintainer needs more info)

So, if you you look at the Mailhandler settings for these you have something like mailbox1@example.com configured in Mailhandler to use MailComment authentication.

You also have mailbox2@example.com which is currently being authenticated by mailcomment, but you wish it weren't. What is the authentication setting on that mailbox in mailhandler?

chadwick wood’s picture

All my mailboxes are set to use mailhandler authentication. But what I'm talking about is in the Mail Comment configuration section, only one of my mailboxes is set to be Mail-comment enabled. So Mail Comment should be ignoring all mail coming into all those other mailboxes, regardless of whether Mail Comment's passthru setting is activated. Yet, Mail Comment is processing incoming mail for all mailboxes.

If you look at the code for mailcomment_mailhandler(), you'll see that the big "if" that determines whether mailcomment processes an incoming message includes a variable $matched. Any mailboxes that aren't mail comment enabled will give a $matched value of FALSE... then, the "else" part of that if statement is ONLY going to pass the message through if the "passthru" setting is turned on, and will return a "no parameters" error otherwise. This code will get run on all messages that come in through mailhandler, so in effect, if passthru is turned off, mailcomment is hi-jacking all incoming mailhandler mail, for all mailboxes.

chadwick wood’s picture

Line 360 has this comment:

// If we reach here, there has been an error. Check error code or send a generic one.

... but that's not true. You ALSO reach that point in the function if the message being processed belongs to a mailbox that is NOT Mail Comment enabled. So there's obviously a flaw in the logic there.

chadwick wood’s picture

I think if you put this before line 318, it would fix the problem:

if (!$matched) {
  return $node;
}

That should passthru any messages belonging to mailboxes not configured for Mail Comment.

ejort’s picture

The issue as described is also occuring for me. I independently read the code trying to find the problem and came to the same conclusion as Chadwick in #3.

Is there any reason to not check that the $mailbox the message is from is one that this module should operate on at the start of mailcomment_mailhandler()?

greggles’s picture

Status: Postponed (maintainer needs more info) » Active

@ejort could you try out the idea in #4 and perhaps turn it into a patch - http://drupal.org/patch/create ?

If that works for you I'd be happy to review the setup.

Here is my understanding of the bug:

0. Set mailcomment to not passthru to mailhandler
1. Create a mailhandler mailbox that is mailcomment enabled
2. Create a mailhandler mailbox that is NOT mailcomment enabled
3. Send a mail to mailbox from step 2
4. See that it is rejected by mailcomment

Expected results:
In step 4 it should not be processed at all by mailcomment.

Ian Ward’s picture

Status: Active » Needs review
StatusFileSize
new2.17 KB

The reason why there's a setting is because of the explanation here http://drupal.org/cvs?commit=192578 ... basically, if you're *only* using mailcomment on your site it prevents mailhandler from ever doing anything else if information is accidentally stripped out of the email meant to be processed by mailcomment. It creates the possibility to bail-out, or not, and leaves it up to the site admin to decide.

The reason why it cannot just check whether the mailbox is a mailcomment mailbox or not is because if the mailbox is a catchall address it's not possible to tell whether or not the email is a mailcomment email address.

For example, if your catchall is *@example.com which you use with mailcomment and you also have an info@example.com address which you use with just mailhandler, if someone sends to foo@example.com you do not know for sure whether they're sending to the catchall or not.

That said, we could assume that if the email is being processed by mailhandler/mailcomment and its full "to" address (foo@example.com) does not match any mailhandler address but its domain (example.com) matches a mailhandler address which is mailcomment enabled, that mailcomment should handle it. Otherwise, mailcomment should not handle it and nor should mailhandler.

As for the order of:

  }
  // If we reach here, there has been an error. Check error code or send a generic one.
  // This part doesn't return a node so it won't be further processed by mailhandler
  if (count($node->mailcomment['params']) > 1 && $header->toaddress == $mbox_name) {
    mailcomment_error($node->mailcomment['params']['error'], $node, $header);
  }
  // If there are no params, return the node back to mailhandler, regardless of to address.
  else {
    if (variable_get('mailcomment_passthru', 0) == 1) {
      return $node;
    }
    else {
      mailcomment_error(MAILCOMMENT_ERROR_PARAMS, $node, $header);
    }

The sequence is important:

* First make sure params existed but error found, if so, send error
* If no params, must not be for mailcomment afterall, so pass through
* If passthru is not enabled then throw an error since mailcomment could not handle the incoming message and mailhandler is not supposed to handle it.

Maybe there's a nicer way to write this though.

Finally, $mbox_name should actually be $matched. $mbox_name is old and removed. This is in the patch.

It would be great to get review of this to make sure I understood the issue completely and that the patch actually works.

Ian Ward’s picture

StatusFileSize
new2.18 KB

Patch in #7 had var names mixed up. Here's a new patch

linitrex’s picture

I applied the patch but nothing happened

Can you provide you complete configuration for Mailhandler box1, Mail handler box 2 and Mailcomment setting...

socialnicheguru’s picture

this patch did not work for me either. (the patch in #8)

danepowell’s picture

Status: Needs review » Closed (won't fix)

Sorry, Mail Comment 6.x-1.x is no longer supported. Please upgrade to 6.x-2.x and re-open if still an issue. Thanks!