From 612bb930615ca7826910b2e0a2321448bdb822f9 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Fri, 11 May 2012 17:33:05 +0300 Subject: [PATCH] [PATCH 2/2] cli: clean up user address matching code in guess_from_received_header() --- 22/dae6cda48493bb0e724b06e4d0a681642b69f6 | 191 ++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 22/dae6cda48493bb0e724b06e4d0a681642b69f6 diff --git a/22/dae6cda48493bb0e724b06e4d0a681642b69f6 b/22/dae6cda48493bb0e724b06e4d0a681642b69f6 new file mode 100644 index 000000000..c101db48e --- /dev/null +++ b/22/dae6cda48493bb0e724b06e4d0a681642b69f6 @@ -0,0 +1,191 @@ +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 73033431FC9 + for ; Fri, 11 May 2012 07:33:18 -0700 (PDT) +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 NJF0SZl36TxS for ; + Fri, 11 May 2012 07:33:15 -0700 (PDT) +Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com + [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 42CC9431FC2 + for ; Fri, 11 May 2012 07:33:13 -0700 (PDT) +Received: by mail-lb0-f181.google.com with SMTP id gk8so2103376lbb.26 + for ; Fri, 11 May 2012 07:33:12 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=from:to:subject:date:message-id:x-mailer:in-reply-to:references + :in-reply-to:references:x-gm-message-state; + bh=uf3J/2BNiH0c7w0Hf/QKI0Ah/QbJJ/7UU0XhTtHCRqc=; + b=hpnjEdEpqqYDdTZ4fja/fNAHnkaRb3uCMStFcVGxflHYsyodW4jswmcWGKNFRmX4gt + GtbTFypMufKkSHxKNsBB15++AVvKEIX5/qFQOcifVafXlWFLNPnsOc0pqHeNVNHwrGW9 + iyTejF0n0cIno3NBxfAZXWQRECSycE7MPjhiw7QlzVAOA1eUQD0I/FA/RYkqlqgsAAj6 + cdzDOCrEDVmw7SG3A3BV/LpSW5c1VRRwDBhRQ5blWO4xTsFadIkiH4Vk5y0RPOg3Vcsj + K3Z58fGmt9THmSWnCQBG4VXq8Adq7ByEX86CTopKU37apPseBEY5ESiJhA3IqC86PQpk + SWAg== +Received: by 10.152.129.74 with SMTP id nu10mr8383309lab.50.1336746792803; + Fri, 11 May 2012 07:33:12 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi. + [80.220.80.68]) + by mx.google.com with ESMTPS id mo3sm9617691lab.2.2012.05.11.07.33.10 + (version=SSLv3 cipher=OTHER); Fri, 11 May 2012 07:33:11 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] cli: clean up user address matching code in + guess_from_received_header() +Date: Fri, 11 May 2012 17:33:05 +0300 +Message-Id: + +X-Mailer: git-send-email 1.7.9.5 +In-Reply-To: + +References: + +In-Reply-To: + +References: + +X-Gm-Message-State: + ALoCoQkR1OgnBJS9MNXUIVUFE3MYLJUenDenR2hY8Gycxf5pNBVw8C4fLxKfO2k5fy5jXFf4WkLf +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: Fri, 11 May 2012 14:33:19 -0000 + +Get rid of user address matching code duplication in +guess_from_received_header() by using the new address matching +helpers. + +No functional changes. + +Signed-off-by: Jani Nikula +--- + notmuch-reply.c | 64 +++++++++++++++++-------------------------------------- + 1 file changed, 19 insertions(+), 45 deletions(-) + +diff --git a/notmuch-reply.c b/notmuch-reply.c +index 0c82755..51cb6de 100644 +--- a/notmuch-reply.c ++++ b/notmuch-reply.c +@@ -377,20 +377,15 @@ add_recipients_from_message (GMimeMessage *reply, + static const char * + guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message) + { +- const char *received,*primary,*by; +- const char **other; +- char *tohdr; ++ const char *addr, *received, *by; + char *mta,*ptr,*token; + char *domain=NULL; + char *tld=NULL; + const char *delim=". \t"; +- size_t i,j,other_len; ++ size_t i; + + const char *to_headers[] = {"Envelope-to", "X-Original-To"}; + +- primary = notmuch_config_get_user_primary_email (config); +- other = notmuch_config_get_user_other_email (config, &other_len); +- + /* sadly, there is no standard way to find out to which email + * address a mail was delivered - what is in the headers depends + * on the MTAs used along the way. So we are trying a number of +@@ -405,23 +400,13 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message + * 'by' part of Received headers + * If none of these work, we give up and return NULL + */ +- for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) { +- tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i])); +- if (tohdr && *tohdr) { +- /* tohdr is potentialy a list of email addresses, so here we +- * check if one of the email addresses is a substring of tohdr +- */ +- if (strcasestr(tohdr, primary)) { +- free(tohdr); +- return primary; +- } +- for (j = 0; j < other_len; j++) +- if (strcasestr (tohdr, other[j])) { +- free(tohdr); +- return other[j]; +- } +- free(tohdr); +- } ++ for (i = 0; i < ARRAY_SIZE (to_headers); i++) { ++ const char *tohdr = notmuch_message_get_header (message, to_headers[i]); ++ ++ /* Note: tohdr potentially contains a list of email addresses. */ ++ addr = user_address_in_string (tohdr, config); ++ if (addr) ++ return addr; + } + + /* We get the concatenated Received: headers and search from the +@@ -439,19 +424,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message + * header + */ + ptr = strstr (received, " for "); +- if (ptr) { +- /* the text following is potentialy a list of email addresses, +- * so again we check if one of the email addresses is a +- * substring of ptr +- */ +- if (strcasestr(ptr, primary)) { +- return primary; +- } +- for (i = 0; i < other_len; i++) +- if (strcasestr (ptr, other[i])) { +- return other[i]; +- } +- } ++ ++ /* Note: ptr potentially contains a list of email addresses. */ ++ addr = user_address_in_string (ptr, config); ++ if (addr) ++ return addr; ++ + /* Finally, we parse all the " by MTA ..." headers to guess the + * email address that this was originally delivered to. + * We extract just the MTA here by removing leading whitespace and +@@ -492,15 +470,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message + */ + *(tld-1) = '.'; + +- if (strcasestr(primary, domain)) { +- free(mta); +- return primary; ++ addr = string_in_user_address (domain, config); ++ if (addr) { ++ free (mta); ++ return addr; + } +- for (i = 0; i < other_len; i++) +- if (strcasestr (other[i],domain)) { +- free(mta); +- return other[i]; +- } + } + free (mta); + } +-- +1.7.9.5 + -- 2.26.2