X-Envelope-From: notmuch-bounces@notmuchmail.org  Wed Aug 12 12:22:35 2026
Return-Path: <notmuch-bounces@notmuchmail.org>
X-Original-To: nmbug@yantan.tethera.net
Delivered-To: nmbug@yantan.tethera.net
Received: from yantan.tethera.net (localhost [127.0.0.1])
	by mail.notmuchmail.org (Postfix) with ESMTP id 6941A5F870;
	Wed, 12 Aug 2026 12:22:35 +0000 (UTC)
X-Greylist: delayed 132572 seconds by postgrey-1.36 at yantan; Wed, 12 Aug 2026 12:22:32 UTC
Received: from phubs.tethera.net (phubs.tethera.net [IPv6:2607:5300:60:3a9d::1])
	by mail.notmuchmail.org (Postfix) with ESMTPS id C9FB85F81A
	for <notmuch@notmuchmail.org>; Wed, 12 Aug 2026 12:22:32 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tethera.net;
 i=@tethera.net; q=dns/txt; s=2024; t=1786537350; h=from : to : cc :
 subject : date : message-id : mime-version : content-transfer-encoding
 : from; bh=61zxeYGJQUWPFHsnMxAYQxSxg3KQZKi3WR/CLQ74Lrg=;
 b=hMlgf6AYZ7ly1bi3FezVPDMrKPnrc4NU8BP6GXj1HO0k3yH7CpXmzQWHoN26ahMksX5Hs
 uTU/PC4IPrCN1ljAxKZo8l2s3a29H9IDiF+9JfFzaerwiuhvj8ddwFmJNejCrIn2qYQGShb
 i+gFNTZsBerNwDHMB3zxnXHaDjA8WCdWuscgTxTmHwdR06XsTDReq6oBiC5Vy5XPcml5J0O
 7VOVmkrAu3nrRqzwG48SNmwi52eHGlylcp7ZPl0+FEA+cLIwv8RImJHLmchpmUHf4pf5o8N
 l2xlcrFBayJ7wKLEO823MSN9GXbNdUOvGYzOrQc9ZsAj73qan/eP3NfZaapA==
Received: from tethera.net (fctnnbsc38w-142-162-53-181.dhcp-dynamic.fibreop.nb.bellaliant.net [142.162.53.181])
	by phubs.tethera.net (Postfix) with ESMTPS id 9ACE91800F7;
	Wed, 12 Aug 2026 09:22:29 -0300 (ADT)
Received: (nullmailer pid 347357 invoked by uid 1000);
	Wed, 12 Aug 2026 12:22:26 -0000
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH] cli/reply: refactor add_recipients_from_message.
Date: Wed, 12 Aug 2026 09:22:22 -0300
Message-ID: <20260812122222.347345-1-david@tethera.net>
X-Mailer: git-send-email 2.53.0
MIME-Version: 1.0
Message-ID-Hash: NA4WPA4EIMBWXJ3NHN45Y4GJKNEB4UNA
X-Message-ID-Hash: NA4WPA4EIMBWXJ3NHN45Y4GJKNEB4UNA
X-MailFrom: bremner@tethera.net
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
X-Mailman-Version: 3.3.3
Precedence: list
List-Id: "Use and development of the notmuch mail system." <notmuch.notmuchmail.org>
List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
List-Owner: <mailto:notmuch-owner@notmuchmail.org>
List-Post: <mailto:notmuch@notmuchmail.org>
List-Subscribe: <mailto:notmuch-join@notmuchmail.org>
List-Unsubscribe: <mailto:notmuch-leave@notmuchmail.org>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

In [1], [2], it was observed that certain versions of gcc miscompiled
the code using reply_map.

In [3] Dick Marius (with help from Tomi Ollila) suggested setting the
map to "static const". As others have reported on IRC, this _seems_ to
work around the gcc bug in question, although I personally have not
understood the details of why that is the case.

Looking at the code I decided to rewrite it a different way, which at
least to my eyes is more understandable. If nothing else, it is
significantly shorter.

[1]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1135526
[2]: GCC PR125252
[3]: id:20260623184003.4144137-2-dick@mrns.nl
---
 notmuch-reply.c | 43 +++++++++----------------------------------
 1 file changed, 9 insertions(+), 34 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 44297251..8830b0e9 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -293,24 +293,6 @@ get_sender (GMimeMessage *message)
     return g_mime_message_get_from (message);
 }
 
-static InternetAddressList *
-get_to (GMimeMessage *message)
-{
-    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO);
-}
-
-static InternetAddressList *
-get_cc (GMimeMessage *message)
-{
-    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_CC);
-}
-
-static InternetAddressList *
-get_bcc (GMimeMessage *message)
-{
-    return g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_BCC);
-}
-
 /* Augment the recipients of 'reply' from the "Reply-to:", "From:",
  * "To:", "Cc:", and "Bcc:" headers of 'message'.
  *
@@ -329,27 +311,18 @@ add_recipients_from_message (GMimeMessage *reply,
 			     GMimeMessage *message,
 			     bool reply_all)
 {
-    struct {
-	InternetAddressList * (*get_header)(GMimeMessage *message);
-	GMimeAddressType recipient_type;
-    } reply_to_map[] = {
-	{ get_sender,   GMIME_ADDRESS_TYPE_TO },
-	{ get_to,       GMIME_ADDRESS_TYPE_TO },
-	{ get_cc,       GMIME_ADDRESS_TYPE_CC },
-	{ get_bcc,      GMIME_ADDRESS_TYPE_BCC },
-    };
+    const GMimeAddressType addr_type[] = { GMIME_ADDRESS_TYPE_TO, GMIME_ADDRESS_TYPE_TO,
+					   GMIME_ADDRESS_TYPE_CC, GMIME_ADDRESS_TYPE_BCC };
+
     const char *from_addr = NULL;
     unsigned int i;
+    InternetAddressList *recipients;
     unsigned int n = 0;
 
-    for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) {
-	InternetAddressList *recipients;
-
-	recipients = reply_to_map[i].get_header (message);
-
-	n += scan_address_list (recipients, notmuch, reply,
-				reply_to_map[i].recipient_type, &from_addr);
+    recipients = get_sender (message);
+    n += scan_address_list (recipients, notmuch, reply, GMIME_ADDRESS_TYPE_TO, &from_addr);
 
+    for (i = 1; i < ARRAY_SIZE (addr_type); i++) {
 	if (! reply_all && n) {
 	    /* Stop adding new recipients in reply-to-sender mode if
 	     * we have added some recipient(s) above.
@@ -365,6 +338,8 @@ add_recipients_from_message (GMimeMessage *reply,
 	    if (from_addr)
 		break;
 	}
+	recipients = g_mime_message_get_addresses (message, addr_type[i]);
+	n += scan_address_list (recipients, notmuch, reply, addr_type[i], &from_addr);
     }
 
     /* If no recipients were added but we found one of the user's
-- 
2.53.0

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org
