Regarding line 398 of mailcomment.module:

// we want the final element in references header, watching out for white space
identifier = drupal_substr(strrchr($item['header']->references, '<'), 0);

Not sure why we want the final element in the header. When someone replies to an email, the 'In-Reply-To' header is appended to the end of the references header like so:

<1.4626.5056.1486935753.bb17604ac1434f712f04f724d2af7ee6@example.com> <CAPbhD2K7FvcCPqSNRhp33P+CoNkY5xyb+qNqeJBuhMrxeMCBsg@mail.gmail.com>

The original Message ID that can be used by Mail Comment is the first one. If this email were to be replied to, Mail Comment / Feeds will fail to import this email reply.

Patch coming soon that gets the first message element in the header. Great for longer email chains. Someone can now reply to a notification email, then reply to that email that they just sent in response to the notification email, and that 2nd reply still gets imported by Feeds.

Comments

Maedi created an issue. See original summary.

maedi’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Issue summary: View changes
StatusFileSize
new865 bytes
maedi’s picture

After failing because of odd references headers in the wild I think regex is the answer:

// we want the first element in references header
// format: 4 digits seperated by dots followed by an @ symbol then a domain
// example: <1233.4666.5456.1486965753.bb1ds04ac1434f792f04f724d2af7ee6@example.com>
$valid_message_id = "/\<(\d+[.]\d+[.]\d+[.]\d+[.]\w+\@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5})\>/";
preg_match($valid_message_id, $item['header']->references, $matches);
$identifier = $matches[1];

Patch coming soon.

maedi’s picture

StatusFileSize
new2.88 KB

Here's the patch. It has its own little mailcomment_parse_messageid() function to accompany mailcomment_build_messageid(). It uses regex and works on oddly formatted references headers found in the wild.

maedi’s picture

Title: Bug fix: References header for long email chains » Patch: Better parse Message-ID
maedi’s picture

StatusFileSize
new3.73 KB

3rd revision of patch. Battle tested, validates values before returning them. Puts valid messageid regex into global constant so that Mailhandler filters can access it.

See also:
#1370286: 'Node' filter rejecting forwarded emails

alfthecat’s picture

StatusFileSize
new51.06 KB
new32.4 KB

After updating to the latest dev and applying this patch, only replies from Gmail are imported. Other email providers result in the infamous "Unable to create comment with empty NID."

I've been working for many months to get this system to work, with great pain, and now I'm stuck on this issue with forwarded emails.

The only way I can get incoming replies to work from all email providers is to match the parent node via the email subject (using feeds tamper to remove RE: ,etc). I know this isn't the perfect way of doing it, but nothing else seems to work consistently accross email providers.

Does this patch or the latest dev change anything in this regard? Is there anyone who can share a working feeds importer mapping setup that work?

Attached is my current mapping and tamper setup.

Thanks in advance for any help!