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 8D990421167 for ; Sat, 14 Jan 2012 06:46:39 -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 5sJjWHjz2tsI for ; Sat, 14 Jan 2012 06:46:35 -0800 (PST) Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id ECE6C429E4E for ; Sat, 14 Jan 2012 06:46:28 -0800 (PST) Received: by eaah10 with SMTP id h10so716669eaa.26 for ; Sat, 14 Jan 2012 06:46:27 -0800 (PST) Received: by 10.213.11.12 with SMTP id r12mr752498ebr.87.1326552387256; Sat, 14 Jan 2012 06:46:27 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id y12sm44609338eeb.11.2012.01.14.06.46.25 (version=SSLv3 cipher=OTHER); Sat, 14 Jan 2012 06:46:26 -0800 (PST) From: Jani Nikula To: notmuch@notmuchmail.org Subject: [PATCH v5 1/5] cli: slightly refactor "notmuch reply" address scanning functions Date: Sat, 14 Jan 2012 16:46:15 +0200 Message-Id: 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: Sat, 14 Jan 2012 14:46:40 -0000 Slightly refactor "notmuch reply" recipient and user from address scanning functions in preparation for reply-to-sender feature. Add support for not adding recipients at all (just scan for user from address), and returning the number of recipients added. No externally visible functional changes. Signed-off-by: Jani Nikula --- notmuch-reply.c | 76 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 40 insertions(+), 36 deletions(-) diff --git a/notmuch-reply.c b/notmuch-reply.c index 000f6da..a8d6a94 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -168,22 +168,29 @@ address_is_users (const char *address, notmuch_config_t *config) return 0; } -/* 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'. +/* Scan addresses in 'list'. * - * The first address encountered that *is* the user's address will be - * returned, (otherwise NULL is returned). + * If 'message' is non-NULL, then 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'. + * + * If 'user_from' is non-NULL and *user_from is NULL, *user_from will + * be set to the first address encountered in 'list' that is the + * user's address. + * + * Return the number of addresses added to 'message'. (If 'message' is + * NULL, the function returns 0 by definition.) */ -static const char * -add_recipients_for_address_list (GMimeMessage *message, - notmuch_config_t *config, - GMimeRecipientType type, - InternetAddressList *list) +static unsigned int +scan_address_list (InternetAddressList *list, + notmuch_config_t *config, + GMimeMessage *message, + GMimeRecipientType type, + const char **user_from) { InternetAddress *address; int i; - const char *ret = NULL; + unsigned int n = 0; for (i = 0; i < internet_address_list_length (list); i++) { address = internet_address_list_get_address (list, i); @@ -196,8 +203,7 @@ add_recipients_for_address_list (GMimeMessage *message, if (group_list == NULL) continue; - add_recipients_for_address_list (message, config, - type, group_list); + n += scan_address_list (group_list, config, message, type, NULL); } else { InternetAddressMailbox *mailbox; const char *name; @@ -209,40 +215,41 @@ add_recipients_for_address_list (GMimeMessage *message, addr = internet_address_mailbox_get_addr (mailbox); if (address_is_users (addr, config)) { - if (ret == NULL) - ret = addr; - } else { + if (user_from && *user_from == NULL) + *user_from = addr; + } else if (message) { g_mime_message_add_recipient (message, type, name, addr); + n++; } } } - return ret; + return n; } -/* 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'. +/* Scan addresses in 'recipients'. * - * The first address encountered that *is* the user's address will be - * returned, (otherwise NULL is returned). + * See the documentation of scan_address_list() above. This function + * does exactly the same, but converts 'recipients' to an + * InternetAddressList first. */ -static const char * -add_recipients_for_string (GMimeMessage *message, - notmuch_config_t *config, - GMimeRecipientType type, - const char *recipients) +static unsigned int +scan_address_string (const char *recipients, + notmuch_config_t *config, + GMimeMessage *message, + GMimeRecipientType type, + const char **user_from) { InternetAddressList *list; if (recipients == NULL) - return NULL; + return 0; list = internet_address_list_parse_string (recipients); if (list == NULL) - return NULL; + return 0; - return add_recipients_for_address_list (message, config, type, list); + return scan_address_list (list, config, message, type, user_from); } /* Does the address in the Reply-To header of 'message' already appear @@ -324,7 +331,7 @@ add_recipients_from_message (GMimeMessage *reply, } for (i = 0; i < ARRAY_SIZE (reply_to_map); i++) { - const char *addr, *recipients; + const char *recipients; recipients = notmuch_message_get_header (message, reply_to_map[i].header); @@ -332,11 +339,8 @@ 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); - if (from_addr == NULL) - from_addr = addr; + scan_address_string (recipients, config, reply, + reply_to_map[i].recipient_type, &from_addr); } return from_addr; -- 1.7.5.4