[notmuch] [PATCH 1/2] notmuch-reply: Add support for replying only to sender

Aneesh Kumar K.V aneesh.kumar at linux.vnet.ibm.com
Thu Dec 3 00:46:44 PST 2009


From: Aneesh Kumar K.V <aneesh.kumar at gmail.com>

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

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

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 9ca1236..9d96ef1 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -354,6 +354,80 @@ 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)
+{
+    GMimeMessage *reply;
+    notmuch_messages_t *messages;
+    notmuch_message_t *message;
+    const char *subject, *recipient, *from_addr = NULL;
+    const char *in_reply_to, *orig_references, *references;
+    char *reply_headers;
+
+    for (messages = notmuch_query_search_messages (query);
+	 notmuch_messages_has_more (messages);
+	 notmuch_messages_advance (messages))
+    {
+	message = notmuch_messages_get (messages);
+
+	/* The 1 means we want headers in a "pretty" order. */
+	reply = g_mime_message_new (1);
+	if (reply == NULL) {
+	    fprintf (stderr, "Out of memory\n");
+	    return 1;
+	}
+
+	subject = notmuch_message_get_header (message, "subject");
+
+	if (strncasecmp (subject, "Re:", 3))
+	    subject = talloc_asprintf (ctx, "Re: %s", subject);
+	g_mime_message_set_subject (reply, subject);
+
+	recipient = notmuch_message_get_header (message, "From");
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+					"To", recipient);
+
+	from_addr = notmuch_config_get_user_primary_email (config);
+	from_addr = talloc_asprintf (ctx, "%s <%s>",
+				     notmuch_config_get_user_name (config),
+				     from_addr);
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "From", from_addr);
+
+	g_mime_object_set_header (GMIME_OBJECT (reply), "Bcc",
+			   notmuch_config_get_user_primary_email (config));
+
+	in_reply_to = talloc_asprintf (ctx, "<%s>",
+			     notmuch_message_get_message_id (message));
+
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "In-Reply-To", in_reply_to);
+
+	orig_references = notmuch_message_get_header (message, "references");
+	references = talloc_asprintf (ctx, "%s%s%s",
+				      orig_references ? orig_references : "",
+				      orig_references ? " " : "",
+				      in_reply_to);
+	g_mime_object_set_header (GMIME_OBJECT (reply),
+				  "References", references);
+
+	reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply));
+	printf ("%s", reply_headers);
+	free (reply_headers);
+
+	g_object_unref (G_OBJECT (reply));
+	reply = NULL;
+
+	printf ("On %s, %s wrote:\n",
+		notmuch_message_get_header (message, "date"),
+		notmuch_message_get_header (message, "from"));
+
+	show_message_body (notmuch_message_get_filename (message), reply_part);
+
+	notmuch_message_destroy (message);
+    }
+    return 0;
+}
 
 int
 notmuch_reply_command (void *ctx, int argc, char *argv[])
@@ -378,6 +452,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



More information about the notmuch mailing list