+/* Some mailing lists munge the Reply-To header despite it being A Bad
+ * Thing, see http://www.unicom.com/pw/reply-to-harmful.html
+ *
+ * This function detects such munging so that reasonable headers can be
+ * generated anyway. Returns 1 if munged, else 0.
+ *
+ * The current logic is fairly naive, Reply-To is diagnosed as munged if
+ * it contains exactly one address, and this address is also present in
+ * the To or Cc fields.
+ */
+static int
+mailing_list_munged_reply_to (notmuch_message_t *message)
+{
+ const char *header, *addr;
+ InternetAddressList *list;
+ InternetAddress *address;
+ InternetAddressMailbox *mailbox;
+
+ header = notmuch_message_get_header (message, "reply-to");
+ if (*header == '\0')
+ return 0;
+
+ list = internet_address_list_parse_string (header);
+
+ if (internet_address_list_length (list) != 1)
+ return 0;
+
+ address = internet_address_list_get_address (list, 0);
+ if (INTERNET_ADDRESS_IS_GROUP (address))
+ return 0;
+
+ mailbox = INTERNET_ADDRESS_MAILBOX (address);
+ addr = internet_address_mailbox_get_addr (mailbox);
+
+ if (strstr (notmuch_message_get_header (message, "to"), addr) != 0 ||
+ strstr (notmuch_message_get_header (message, "cc"), addr) != 0)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+