- parse_references (message, parents, in_reply_to);
- _notmuch_message_add_term (message, "replyto",
- parse_message_id (message, in_reply_to, NULL));
+ parse_references (message, notmuch_message_get_message_id (message),
+ parents, in_reply_to);
+
+ /* Carefully avoid adding any self-referential in-reply-to term. */
+ in_reply_to_message_id = _parse_message_id (message, in_reply_to, NULL);
+ if (in_reply_to_message_id &&
+ strcmp (in_reply_to_message_id,
+ notmuch_message_get_message_id (message)))
+ {
+ _notmuch_message_add_term (message, "replyto",
+ _parse_message_id (message, in_reply_to, NULL));
+ }