unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] notmuch-reply: Add support for replying only to sender
@ 2009-12-03  8:46 Aneesh Kumar K.V
  2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Aneesh Kumar K.V @ 2009-12-03  8:46 UTC (permalink / raw)
  To: cworth, aneesh.kumar; +Cc: Aneesh Kumar K.V, notmuch

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

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

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-11 12:46 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-03  8:46 [PATCH 1/2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V
2009-12-03  8:46 ` [PATCH 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
2009-12-04 19:07 ` [PATCH 1/2] notmuch-reply: Add support for replying only to sender Carl Worth
2009-12-04 19:21   ` Jed Brown
2009-12-11  5:31   ` Aneesh Kumar K. V
2010-03-09 18:25     ` Carl Worth
2010-03-10 16:31       ` [PATCH -V3 " Aneesh Kumar K.V
2010-03-11 12:45         ` Michal Sojka
2010-03-10 16:31       ` [PATCH -V3 2/2] notmuch.el: Add support for reply-to sender Aneesh Kumar K.V
2009-12-05  9:37 ` [PATCH -V2] notmuch-reply: Add support for replying only to sender Aneesh Kumar K.V

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).