Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 22 / dae6cda48493bb0e724b06e4d0a681642b69f6
1 Return-Path: <jani@nikula.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 73033431FC9\r
6         for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:18 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
13         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id NJF0SZl36TxS for <notmuch@notmuchmail.org>;\r
17         Fri, 11 May 2012 07:33:15 -0700 (PDT)\r
18 Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
19         [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 42CC9431FC2\r
22         for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:13 -0700 (PDT)\r
23 Received: by mail-lb0-f181.google.com with SMTP id gk8so2103376lbb.26\r
24         for <notmuch@notmuchmail.org>; Fri, 11 May 2012 07:33:12 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=google.com; s=20120113;\r
27         h=from:to:subject:date:message-id:x-mailer:in-reply-to:references\r
28         :in-reply-to:references:x-gm-message-state;\r
29         bh=uf3J/2BNiH0c7w0Hf/QKI0Ah/QbJJ/7UU0XhTtHCRqc=;\r
30         b=hpnjEdEpqqYDdTZ4fja/fNAHnkaRb3uCMStFcVGxflHYsyodW4jswmcWGKNFRmX4gt\r
31         GtbTFypMufKkSHxKNsBB15++AVvKEIX5/qFQOcifVafXlWFLNPnsOc0pqHeNVNHwrGW9\r
32         iyTejF0n0cIno3NBxfAZXWQRECSycE7MPjhiw7QlzVAOA1eUQD0I/FA/RYkqlqgsAAj6\r
33         cdzDOCrEDVmw7SG3A3BV/LpSW5c1VRRwDBhRQ5blWO4xTsFadIkiH4Vk5y0RPOg3Vcsj\r
34         K3Z58fGmt9THmSWnCQBG4VXq8Adq7ByEX86CTopKU37apPseBEY5ESiJhA3IqC86PQpk\r
35         SWAg==\r
36 Received: by 10.152.129.74 with SMTP id nu10mr8383309lab.50.1336746792803;\r
37         Fri, 11 May 2012 07:33:12 -0700 (PDT)\r
38 Received: from localhost (dsl-hkibrasgw4-fe50dc00-68.dhcp.inet.fi.\r
39         [80.220.80.68])\r
40         by mx.google.com with ESMTPS id mo3sm9617691lab.2.2012.05.11.07.33.10\r
41         (version=SSLv3 cipher=OTHER); Fri, 11 May 2012 07:33:11 -0700 (PDT)\r
42 From: Jani Nikula <jani@nikula.org>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 2/2] cli: clean up user address matching code in\r
45         guess_from_received_header()\r
46 Date: Fri, 11 May 2012 17:33:05 +0300\r
47 Message-Id:\r
48  <cd73ec6368b3743b0d84ed1696bfa00960124645.1336746187.git.jani@nikula.org>\r
49 X-Mailer: git-send-email 1.7.9.5\r
50 In-Reply-To:\r
51  <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>\r
52 References:\r
53  <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>\r
54 In-Reply-To:\r
55  <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>\r
56 References:\r
57  <bae496e6100a4e4d4a598dcf5c73d67b178f4128.1336746187.git.jani@nikula.org>\r
58 X-Gm-Message-State:\r
59  ALoCoQkR1OgnBJS9MNXUIVUFE3MYLJUenDenR2hY8Gycxf5pNBVw8C4fLxKfO2k5fy5jXFf4WkLf\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Fri, 11 May 2012 14:33:19 -0000\r
73 \r
74 Get rid of user address matching code duplication in\r
75 guess_from_received_header() by using the new address matching\r
76 helpers.\r
77 \r
78 No functional changes.\r
79 \r
80 Signed-off-by: Jani Nikula <jani@nikula.org>\r
81 ---\r
82  notmuch-reply.c |   64 +++++++++++++++++--------------------------------------\r
83  1 file changed, 19 insertions(+), 45 deletions(-)\r
84 \r
85 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
86 index 0c82755..51cb6de 100644\r
87 --- a/notmuch-reply.c\r
88 +++ b/notmuch-reply.c\r
89 @@ -377,20 +377,15 @@ add_recipients_from_message (GMimeMessage *reply,\r
90  static const char *\r
91  guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message)\r
92  {\r
93 -    const char *received,*primary,*by;\r
94 -    const char **other;\r
95 -    char *tohdr;\r
96 +    const char *addr, *received, *by;\r
97      char *mta,*ptr,*token;\r
98      char *domain=NULL;\r
99      char *tld=NULL;\r
100      const char *delim=". \t";\r
101 -    size_t i,j,other_len;\r
102 +    size_t i;\r
103  \r
104      const char *to_headers[] = {"Envelope-to", "X-Original-To"};\r
105  \r
106 -    primary = notmuch_config_get_user_primary_email (config);\r
107 -    other = notmuch_config_get_user_other_email (config, &other_len);\r
108 -\r
109      /* sadly, there is no standard way to find out to which email\r
110       * address a mail was delivered - what is in the headers depends\r
111       * on the MTAs used along the way. So we are trying a number of\r
112 @@ -405,23 +400,13 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
113       *    'by' part of Received headers\r
114       * If none of these work, we give up and return NULL\r
115       */\r
116 -    for (i = 0; i < sizeof(to_headers)/sizeof(*to_headers); i++) {\r
117 -       tohdr = xstrdup(notmuch_message_get_header (message, to_headers[i]));\r
118 -       if (tohdr && *tohdr) {\r
119 -           /* tohdr is potentialy a list of email addresses, so here we\r
120 -            * check if one of the email addresses is a substring of tohdr\r
121 -            */\r
122 -           if (strcasestr(tohdr, primary)) {\r
123 -               free(tohdr);\r
124 -               return primary;\r
125 -           }\r
126 -           for (j = 0; j < other_len; j++)\r
127 -               if (strcasestr (tohdr, other[j])) {\r
128 -                   free(tohdr);\r
129 -                   return other[j];\r
130 -               }\r
131 -           free(tohdr);\r
132 -       }\r
133 +    for (i = 0; i < ARRAY_SIZE (to_headers); i++) {\r
134 +       const char *tohdr = notmuch_message_get_header (message, to_headers[i]);\r
135 +\r
136 +       /* Note: tohdr potentially contains a list of email addresses. */\r
137 +       addr = user_address_in_string (tohdr, config);\r
138 +       if (addr)\r
139 +           return addr;\r
140      }\r
141  \r
142      /* We get the concatenated Received: headers and search from the\r
143 @@ -439,19 +424,12 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
144       * header\r
145       */\r
146      ptr = strstr (received, " for ");\r
147 -    if (ptr) {\r
148 -       /* the text following is potentialy a list of email addresses,\r
149 -        * so again we check if one of the email addresses is a\r
150 -        * substring of ptr\r
151 -        */\r
152 -       if (strcasestr(ptr, primary)) {\r
153 -           return primary;\r
154 -       }\r
155 -       for (i = 0; i < other_len; i++)\r
156 -           if (strcasestr (ptr, other[i])) {\r
157 -               return other[i];\r
158 -           }\r
159 -    }\r
160 +\r
161 +    /* Note: ptr potentially contains a list of email addresses. */\r
162 +    addr = user_address_in_string (ptr, config);\r
163 +    if (addr)\r
164 +       return addr;\r
165 +\r
166      /* Finally, we parse all the " by MTA ..." headers to guess the\r
167       * email address that this was originally delivered to.\r
168       * We extract just the MTA here by removing leading whitespace and\r
169 @@ -492,15 +470,11 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
170              */\r
171             *(tld-1) = '.';\r
172  \r
173 -           if (strcasestr(primary, domain)) {\r
174 -               free(mta);\r
175 -               return primary;\r
176 +           addr = string_in_user_address (domain, config);\r
177 +           if (addr) {\r
178 +               free (mta);\r
179 +               return addr;\r
180             }\r
181 -           for (i = 0; i < other_len; i++)\r
182 -               if (strcasestr (other[i],domain)) {\r
183 -                   free(mta);\r
184 -                   return other[i];\r
185 -               }\r
186         }\r
187         free (mta);\r
188      }\r
189 -- \r
190 1.7.9.5\r
191 \r