From: Aneesh Kumar K.V <aneesh.ku...@gmail.com>

This patch add --format=sender-only option.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar at gmail.com>
---
 notmuch-reply.c |   54 ++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 0cda72d..859b725 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -23,15 +23,23 @@
 #include "notmuch-client.h"
 #include "gmime-filter-reply.h"

-static const struct {
+struct reply_map {
     const char *header;
     const char *fallback;
     GMimeRecipientType recipient_type;
-} reply_to_map[] = {
+};
+
+static const struct reply_map reply_to_all_map[] = {
     { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
     { "to",         NULL, GMIME_RECIPIENT_TYPE_TO  },
     { "cc",         NULL, GMIME_RECIPIENT_TYPE_CC  },
-    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC }
+    { "bcc",        NULL, GMIME_RECIPIENT_TYPE_BCC },
+    { NULL,         NULL, 0}
+};
+
+static const struct reply_map reply_to_sender_map[] = {
+    { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO  },
+    { NULL,         NULL, 0}
 };

 static void
@@ -200,7 +208,8 @@ add_recipients_for_string (GMimeMessage *message,
 }

 static int
-notmuch_reply_format_default(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
+__notmuch_reply(void *ctx, notmuch_config_t *config,
+               notmuch_query_t *query, const struct reply_map *map)
 {
     GMimeMessage *reply;
     notmuch_messages_t *messages;
@@ -229,17 +238,19 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t 
*config, notmuch_query_
            subject = talloc_asprintf (ctx, "Re: %s", subject);
        g_mime_message_set_subject (reply, subject);

-       for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+       for (i = 0;; i++) {
            const char *addr;

+           if (!map[i].header)
+                   break;
            recipients = notmuch_message_get_header (message,
-                                                    reply_to_map[i].header);
-           if ((recipients == NULL || recipients[0] == '\0') && 
reply_to_map[i].fallback)
+                                                   map[i].header);
+           if ((recipients == NULL || recipients[0] == '\0') && 
map[i].fallback)
                recipients = notmuch_message_get_header (message,
-                                                        
reply_to_map[i].fallback);
+                                                        map[i].fallback);

            addr = add_recipients_for_string (reply, config,
-                                             reply_to_map[i].recipient_type,
+                                             map[i].recipient_type,
                                              recipients);
            if (from_addr == NULL)
                from_addr = addr;
@@ -289,6 +300,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t 
*config, notmuch_query_
     return 0;
 }

+static int
+notmuch_reply_format_default(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
+{
+       return __notmuch_reply(ctx, config, query, reply_to_all_map);
+}
+
 /* This format is currently tuned for a git send-email --notmuch hook */
 static int
 notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
@@ -332,17 +349,18 @@ notmuch_reply_format_headers_only(void *ctx, 
notmuch_config_t *config, notmuch_q
        g_mime_object_set_header (GMIME_OBJECT (reply),
                                  "References", references);

-       for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
+       for (i = 0; i < ARRAY_SIZE (reply_to_all_map); i++) {
            const char *addr;

            recipients = notmuch_message_get_header (message,
-                                                    reply_to_map[i].header);
-           if ((recipients == NULL || recipients[0] == '\0') && 
reply_to_map[i].fallback)
+                                                    
reply_to_all_map[i].header);
+           if ((recipients == NULL || recipients[0] == '\0') &&
+                                       reply_to_all_map[i].fallback)
                recipients = notmuch_message_get_header (message,
-                                                        
reply_to_map[i].fallback);
+                                                reply_to_all_map[i].fallback);

            addr = add_recipients_for_string (reply, config,
-                                             reply_to_map[i].recipient_type,
+                                             
reply_to_all_map[i].recipient_type,
                                              recipients);
        }

@@ -361,6 +379,12 @@ notmuch_reply_format_headers_only(void *ctx, 
notmuch_config_t *config, notmuch_q
     return 0;
 }

+static int
+notmuch_reply_format_sender_only(void *ctx, notmuch_config_t *config, 
notmuch_query_t *query)
+{
+       return __notmuch_reply(ctx, config, query, reply_to_sender_map);
+}
+
 int
 notmuch_reply_command (void *ctx, int argc, char *argv[])
 {
@@ -384,6 +408,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[])
                reply_format_func = notmuch_reply_format_default;
            } else if (strcmp (opt, "headers-only") == 0) {
                reply_format_func = notmuch_reply_format_headers_only;
+           } else if (strcmp (opt, "sender-only") == 0) {
+               reply_format_func = notmuch_reply_format_sender_only;
            } else {
                fprintf (stderr, "Invalid value for --format: %s\n", opt);
                return 1;
-- 
1.6.5.2.74.g610f9

Reply via email to