diff --git a/mailcomment.module b/mailcomment.module
index 7ba3b96..4d7a30a 100644
--- a/mailcomment.module
+++ b/mailcomment.module
@@ -270,6 +270,41 @@ function mailcomment_build_messageid($params) {
 }
 
 /**
+ * Parse messageid from email header
+ *
+ * Also used by mailhandler filter plugins and feeds importer source mappings
+ *
+ * @param $header
+ *   An email header containing a mailcomment formatted message id.
+ *   Valid email headers are Message-ID, References and In-Reply-To.
+ *
+ *   Format:
+ *     format: 4 digits and 1 hash divided by dots then an @ symbol then a domain
+ *   Example 1:
+ *     <1234.4666.5056.1486965753.cb17604ac1434f792f04f724d2af7ee6@domain.com>
+ *   Example 2: (References header - only first line is actually line breaked):
+ *     7356
+ *     <4431.5196.7356.1487571103.20e2a3d69bef550a990d7c751beb84de@domain.com>
+ *     <CAPbhD2K4MvcCPqSNRhp33P+CoNkY5xyb+qNqeJBuhMrxeMCBsg@mail.gmail.com>
+ *     <CAPbhD2JZdgQj==1AxDWqaR2N=jrQtvrz3hQ-03b9jkgJg5eoFA@mail.gmail.com>
+ *
+ * @return Message ID
+ *   format: uid.nid.cid.timestamp.hash@domain
+ *   example: 4431.5196.7356.1487271103.30e2a8def550a990d7c751beb84de@domain.com
+ *
+ * @see mailcomment_source_get_source
+ */
+function mailcomment_parse_messageid($header) {
+
+  // format: 4 digits and 1 hash divided by dots then an @ symbol then a domain
+  $valid_message_id = "/\<(\d+[.]\d+[.]\d+[.]\d+[.]\w+\@[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{2,5})\>/";
+  // find the first element that matches format
+  preg_match($valid_message_id, $header, $matches);
+  // return value inside the brackets "()"
+  return $matches[1];
+}
+
+/**
  * Determines whether the mail comment signature exists in the body.
  *
  * @param string $body
@@ -393,14 +428,14 @@ function mailcomment_source_get_source($source, FeedsParserResult $result, $key)
   $item = $result->currentItem();
   $identifier = _mailcomment_get_signature(rawurldecode($item['body_original']));
   if (!$identifier) {
-    // Failed to find signature in body -- replicate mailhandler functionality to find node->threading.
+    // Failed to find signature in body -- replicate mailhandler functionality to find node->threading
     if (!empty($item['header']->references)) {
-      // We want the final element in references header, watching out for white space.
-      $identifier = drupal_substr(strrchr($item['header']->references, '<'), 0);
+      // The first references header found is our original Message-ID.
+      $identifier = mailcomment_parse_messageid($item['header']->references);
     }
     elseif (!empty($item['header']->in_reply_to)) {
       // Some MUAs send more info in this header.
-      $identifier = str_replace(strstr($item['header']->in_reply_to, '>'), '>', $item['header']->in_reply_to);
+      $identifier = mailcomment_parse_messageid($item['header']->in_reply_to);
     }
     if (isset($identifier)) {
       $identifier = rtrim(ltrim($identifier, '<'), '>');
