From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4C55F431FAE for ; Thu, 3 Dec 2009 00:47:09 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oTD5ScB80sJ0 for ; Thu, 3 Dec 2009 00:47:06 -0800 (PST) Received: from e28smtp06.in.ibm.com (e28smtp06.in.ibm.com [122.248.162.6]) by olra.theworths.org (Postfix) with ESMTP id 5910D431FBC for ; Thu, 3 Dec 2009 00:47:04 -0800 (PST) Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by e28smtp06.in.ibm.com (8.14.3/8.13.1) with ESMTP id nB38l2SU032091 for ; Thu, 3 Dec 2009 14:17:02 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nB38l2pO3469340 for ; Thu, 3 Dec 2009 14:17:02 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nB38l1ON022009 for ; Thu, 3 Dec 2009 14:17:02 +0530 Received: from localhost.localdomain ([9.77.193.32]) by d28av01.in.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id nB38kmwA021218; Thu, 3 Dec 2009 14:16:51 +0530 From: "Aneesh Kumar K.V" To: cworth@cworth.org, aneesh.kumar@linux.vnet.ibm.com Date: Thu, 3 Dec 2009 14:16:44 +0530 Message-Id: <1259830005-3439-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.6.5.2.74.g610f9 Cc: "Aneesh Kumar K.V" , notmuch@notmuchmail.org Subject: [PATCH 1/2] notmuch-reply: Add support for replying only to sender X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2009 08:47:09 -0000 From: Aneesh Kumar K.V This patch add --format=sender-only option. Signed-off-by: Aneesh Kumar K.V --- 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