+ return 0;
+
+ return scan_address_list (list, config, message, type, user_from);
+}
+
+/* Does the address in the Reply-To header of 'message' already appear
+ * in either the 'To' or 'Cc' header of the message?
+ */
+static int
+reply_to_header_is_redundant (notmuch_message_t *message, const char *reply_to)
+{
+ const char *to, *cc, *addr;
+ InternetAddressList *list;
+ InternetAddress *address;
+ InternetAddressMailbox *mailbox;
+
+ list = internet_address_list_parse_string (reply_to);
+
+ 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);
+
+ to = notmuch_message_get_header (message, "to");
+ cc = notmuch_message_get_header (message, "cc");
+
+ if ((to && strstr (to, addr) != 0) ||
+ (cc && strstr (cc, addr) != 0))
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+static const char *get_sender(notmuch_message_t *message)
+{
+ const char *reply_to;
+
+ reply_to = notmuch_message_get_header (message, "reply-to");
+ if (reply_to && *reply_to) {
+ /*
+ * Some mailing lists munge the Reply-To header despite it
+ * being A Bad Thing, see
+ * http://marc.merlins.org/netrants/reply-to-harmful.html
+ *
+ * The munging is easy to detect, because it results in a
+ * redundant reply-to header, (with an address that already
+ * exists in either To or Cc). So in this case, we ignore the
+ * Reply-To field and use the From header. This ensures the
+ * original sender will get the reply even if not subscribed
+ * to the list. Note that the address in the Reply-To header
+ * will always appear in the reply if reply_all is true.
+ */
+ if (! reply_to_header_is_redundant (message, reply_to))
+ return reply_to;
+ }
+
+ return notmuch_message_get_header (message, "from");
+}
+
+static const char *get_to(notmuch_message_t *message)
+{
+ return notmuch_message_get_header (message, "to");
+}
+
+static const char *get_cc(notmuch_message_t *message)
+{
+ return notmuch_message_get_header (message, "cc");
+}