Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 3C108421186 for ; Thu, 5 Jan 2012 12:25:36 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 tiULzZBrSQXN for ; Thu, 5 Jan 2012 12:25:33 -0800 (PST) Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 921F742117B for ; Thu, 5 Jan 2012 12:25:30 -0800 (PST) Received: by mail-ee0-f53.google.com with SMTP id d41so756745eek.26 for ; Thu, 05 Jan 2012 12:25:30 -0800 (PST) Received: by 10.213.32.76 with SMTP id b12mr716985ebd.6.1325795130164; Thu, 05 Jan 2012 12:25:30 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id 13sm238065664eeu.1.2012.01.05.12.25.28 (version=SSLv3 cipher=OTHER); Thu, 05 Jan 2012 12:25:29 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org, david@tethera.net Subject: [PATCH 3/4] cli: add support for replying just to the sender in "notmuch reply" Date: Thu, 5 Jan 2012 22:25:14 +0200 Message-Id: <5fd10003b5c515c83cd298ea30f27b01f9233380.1325794371.git.jani@nikula.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: References: In-Reply-To: References: X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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, 05 Jan 2012 20:25:37 -0000 Add new option --no-reply-all to "notmuch reply" to reply just to the sender instead of sender and all recipients. Signed-off-by: Jani Nikula --- notmuch-reply.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 32 insertions(+), 20 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 000f6da..57458ec 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -170,7 +170,7 @@ address_is_users (const char *address, notmuch_config_t *config) /* For each address in 'list' that is not configured as one of the * user's addresses in 'config', add that address to 'message' as an - * address of 'type'. + * address of 'type', if 'add' is true. * * The first address encountered that *is* the user's address will be * returned, (otherwise NULL is returned). @@ -179,7 +179,8 @@ static const char * add_recipients_for_address_list (GMimeMessage *message, notmuch_config_t *config, GMimeRecipientType type, - InternetAddressList *list) + InternetAddressList *list, + notmuch_bool_t add) { InternetAddress *address; int i; @@ -197,7 +198,7 @@ add_recipients_for_address_list (GMimeMessage *message, continue; add_recipients_for_address_list (message, config, - type, group_list); + type, group_list, add); } else { InternetAddressMailbox *mailbox; const char *name; @@ -211,7 +212,7 @@ add_recipients_for_address_list (GMimeMessage *message, if (address_is_users (addr, config)) { if (ret == NULL) ret = addr; - } else { + } else if (add) { g_mime_message_add_recipient (message, type, name, addr); } } @@ -222,7 +223,7 @@ add_recipients_for_address_list (GMimeMessage *message, /* For each address in 'recipients' that is not configured as one of * the user's addresses in 'config', add that address to 'message' as - * an address of 'type'. + * an address of 'type', if 'add' is true. * * The first address encountered that *is* the user's address will be * returned, (otherwise NULL is returned). @@ -231,7 +232,8 @@ static const char * add_recipients_for_string (GMimeMessage *message, notmuch_config_t *config, GMimeRecipientType type, - const char *recipients) + const char *recipients, + notmuch_bool_t add) { InternetAddressList *list; @@ -242,7 +244,7 @@ add_recipients_for_string (GMimeMessage *message, if (list == NULL) return NULL; - return add_recipients_for_address_list (message, config, type, list); + return add_recipients_for_address_list (message, config, type, list, add); } /* Does the address in the Reply-To header of 'message' already appear @@ -284,7 +286,9 @@ reply_to_header_is_redundant (notmuch_message_t *message) return 0; } -/* Augments the recipients of reply from the headers of message. +/* Augments the recipients of reply from the headers of message. If 'reply_all' + * is true, use sender and all recipients, otherwise use just the sender + * ("reply-to" or "from" headers). * * If any of the user's addresses were found in these headers, the first * of these returned, otherwise NULL is returned. @@ -292,17 +296,19 @@ reply_to_header_is_redundant (notmuch_message_t *message) static const char * add_recipients_from_message (GMimeMessage *reply, notmuch_config_t *config, - notmuch_message_t *message) + notmuch_message_t *message, + notmuch_bool_t reply_all) { struct { const char *header; const char *fallback; GMimeRecipientType recipient_type; + notmuch_bool_t always; /* use entry when not reply_all */ } reply_to_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 } + { "reply-to", "from", GMIME_RECIPIENT_TYPE_TO, TRUE }, + { "to", NULL, GMIME_RECIPIENT_TYPE_TO, FALSE }, + { "cc", NULL, GMIME_RECIPIENT_TYPE_CC, FALSE }, + { "bcc", NULL, GMIME_RECIPIENT_TYPE_BCC, FALSE } }; const char *from_addr = NULL; unsigned int i; @@ -334,7 +340,8 @@ add_recipients_from_message (GMimeMessage *reply, addr = add_recipients_for_string (reply, config, reply_to_map[i].recipient_type, - recipients); + recipients, + reply_all || reply_to_map[i].always); if (from_addr == NULL) from_addr = addr; } @@ -480,7 +487,8 @@ static int notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, - notmuch_show_params_t *params) + notmuch_show_params_t *params, + notmuch_bool_t reply_all) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -509,7 +517,8 @@ notmuch_reply_format_default(void *ctx, g_mime_message_set_subject (reply, subject); } - from_addr = add_recipients_from_message (reply, config, message); + from_addr = add_recipients_from_message (reply, config, message, + reply_all); if (from_addr == NULL) from_addr = guess_from_received_header (config, message); @@ -558,7 +567,8 @@ static int notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, - unused (notmuch_show_params_t *params)) + unused (notmuch_show_params_t *params), + notmuch_bool_t reply_all) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -598,7 +608,7 @@ notmuch_reply_format_headers_only(void *ctx, g_mime_object_set_header (GMIME_OBJECT (reply), "References", references); - (void)add_recipients_from_message (reply, config, message); + (void)add_recipients_from_message (reply, config, message, reply_all); reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply)); printf ("%s", reply_headers); @@ -625,10 +635,11 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_query_t *query; char *query_string; int opt_index, ret = 0; - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params); + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all); notmuch_show_params_t params = { .part = -1 }; int format = FORMAT_DEFAULT; notmuch_bool_t decrypt = FALSE; + notmuch_bool_t no_reply_all = FALSE; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &format, "format", 'f', @@ -636,6 +647,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) { "headers-only", FORMAT_HEADERS_ONLY }, { 0, 0 } } }, { NOTMUCH_OPT_BOOLEAN, &decrypt, "decrypt", 'd', 0 }, + { NOTMUCH_OPT_BOOLEAN, &no_reply_all, "no-reply-all", 'r', 0 }, { 0, 0, 0, 0, 0 } }; @@ -688,7 +700,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - if (reply_format_func (ctx, config, query, ¶ms) != 0) + if (reply_format_func (ctx, config, query, ¶ms, !no_reply_all) != 0) return 1; notmuch_query_destroy (query); -- 1.7.5.4