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 1CDD2429E25 for ; Thu, 26 May 2011 16:32:37 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.424 X-Spam-Level: * X-Spam-Status: No, score=1.424 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=2.223, FREEMAIL_FROM=0.001, 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 S9jR3Ak2HU7I for ; Thu, 26 May 2011 16:32:35 -0700 (PDT) Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com [74.125.82.45]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id E9F30429E33 for ; Thu, 26 May 2011 16:32:34 -0700 (PDT) Received: by wwi36 with SMTP id 36so1070600wwi.2 for ; Thu, 26 May 2011 16:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=xGtWyzzQPvm5A/tGXug/4AW5/fDDiXblQNMVBweZ5pk=; b=nAGkFjKnPy3wZicovDtMxSwOd66r2o9N8fZR5fuVh35jET0FKf5j3Y4uWhlCkJZCjF BKCpJ1449eS3NWLqX8S7huFcshWXfgiZmdu9QmIuh0AgRl4iOCHlTrjdn7tOr7dwNbwB Iw1liQQ3x+elg5EgVVbpUOs+a040LeUiGb/ho= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=pxXWt/sCSpABRRalM22oyy2H2EeWTg4wgjrtX4d9CeWoAMi+6rdhm02yqALyOumrcy C6NaAMqqa5p2AHfjOvnfCuJnFJ/AqZ8CL+79qj9EssqPqS3r0EOntpvYE+fxX6zayUFo erEaHgI7cKk2l40imqr9Y08AqlAt3zXnWSpLQ= Received: by 10.227.198.10 with SMTP id em10mr1385458wbb.108.1306452753667; Thu, 26 May 2011 16:32:33 -0700 (PDT) Received: from localhost.localdomain (93-97-25-209.zone5.bethere.co.uk [93.97.25.209]) by mx.google.com with ESMTPS id fw15sm804800wbb.27.2011.05.26.16.32.31 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2011 16:32:32 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2 1/3] Adds the option "--reply-to=" to notmuch reply. Date: Fri, 27 May 2011 00:31:55 +0100 Message-Id: <1306452717-19934-2-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <87pqn5cg4g.fsf@yoom.home.cworth.org> References: <87pqn5cg4g.fsf@yoom.home.cworth.org> 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, 26 May 2011 23:32:37 -0000 Possible values are "sender" which replies just to sender and "all" (the default). More precisely reply to sender follows these rules: reply only to sender unless it was the user reply only to all people on the to line unless they were all the user reply to all people on the cc line Implementation details Note we continue parsing addresses beyond the ones we reply to because we want to make sure the from address is correct. (At the very least it is the same as it would be if we replied to all.) We overload the message variable in add_recipients_for_address_list so if it is NULL we parse the address (looking for the users address) but do not add to the message recipients list We add the variable reply_to_all to the function chain to keep track of whether we should reply to everyone. --- notmuch-reply.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 35 insertions(+), 11 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index ab15650..98ae94a 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -191,7 +191,8 @@ add_recipients_for_address_list (GMimeMessage *message, if (ret == NULL) ret = addr; } else { - g_mime_message_add_recipient (message, type, name, addr); + if (message) + g_mime_message_add_recipient (message, type, name, addr); } } } @@ -271,7 +272,8 @@ 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, + int reply_to_all) { struct { const char *header; @@ -311,9 +313,20 @@ add_recipients_from_message (GMimeMessage *reply, recipients = notmuch_message_get_header (message, reply_to_map[i].fallback); - addr = add_recipients_for_string (reply, config, - reply_to_map[i].recipient_type, - recipients); + + /* We add the addresses if we are replying to all or we have not yet found + * a non-user address. We have to keep parsing to make sure we do find the + * correct from address for the user, but we pass a NULL message + */ + if ((reply_to_all) || (g_mime_message_get_all_recipients (reply) == NULL)) + addr = add_recipients_for_string (reply, config, + reply_to_map[i].recipient_type, + recipients); + else + addr = add_recipients_for_string (NULL, config, + reply_to_map[i].recipient_type, + recipients); + if (from_addr == NULL) from_addr = addr; } @@ -453,7 +466,7 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message } static int -notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query) +notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -484,7 +497,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ 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_to_all); if (from_addr == NULL) from_addr = guess_from_received_header (config, message); @@ -531,7 +544,7 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_ /* 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) +notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all) { GMimeMessage *reply; notmuch_messages_t *messages; @@ -571,7 +584,7 @@ notmuch_reply_format_headers_only(void *ctx, notmuch_config_t *config, notmuch_q 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_to_all); reply_headers = g_mime_object_to_string (GMIME_OBJECT (reply)); printf ("%s", reply_headers); @@ -593,7 +606,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_query_t *query; char *opt, *query_string; int i, ret = 0; - int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query); + int reply_to_all = 1; + int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, int reply_to_all); reply_format_func = notmuch_reply_format_default; @@ -612,6 +626,16 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) fprintf (stderr, "Invalid value for --format: %s\n", opt); return 1; } + } else if (STRNCMP_LITERAL (argv[i], "--reply-to=") == 0) { + opt = argv[i] + sizeof ("--reply-to=") - 1; + if (strcmp (opt, "sender") == 0) { + reply_to_all = 0; + } else if (strcmp (opt, "all") == 0) { + reply_to_all = 1; + } else { + fprintf (stderr, "Invalid value for --reply-to: %s\n", opt); + return 1; + } } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; @@ -647,7 +671,7 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) return 1; } - if (reply_format_func (ctx, config, query) != 0) + if (reply_format_func (ctx, config, query, reply_to_all) != 0) return 1; notmuch_query_destroy (query); -- 1.7.2.5