+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");
+}
+
+static const char *get_bcc(notmuch_message_t *message)
+{
+ return notmuch_message_get_header (message, "bcc");
+}
+
+/* Augment the recipients of 'reply' from the "Reply-to:", "From:",
+ * "To:", "Cc:", and "Bcc:" headers of 'message'.
+ *
+ * If 'reply_all' is true, use sender and all recipients, otherwise
+ * scan the headers for the first that contains something other than
+ * the user's addresses and add the recipients from this header
+ * (typically this would be reply-to-sender, but also handles reply to
+ * user's own message in a sensible way).