Re: [PATCH] lib: reword comment about XFOLDER: prefix
[notmuch-archives.git] / ec / 443cb25ab1b84d92035bea302c4ab8c4c85695
1 Return-Path: <BATV+bfcd26d6da2a49b2fc9f+2418+infradead.org+hohndel@bombadil.srs.infradead.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 B12334196F0\r
6         for <notmuch@notmuchmail.org>; Wed,  7 Apr 2010 13:38:33 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.301\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.301 tagged_above=-999 required=5\r
12         tests=[BAYES_20=-0.001, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id EyTOgAS7En-g for <notmuch@notmuchmail.org>;\r
16         Wed,  7 Apr 2010 13:38:32 -0700 (PDT)\r
17 Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 91454431FC1\r
19         for <notmuch@notmuchmail.org>; Wed,  7 Apr 2010 13:38:32 -0700 (PDT)\r
20 Received: from localhost ([::1] helo=localhost.localdomain)\r
21         by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux))\r
22         id 1Nzc17-0002KG-UF\r
23         for notmuch@notmuchmail.org; Wed, 07 Apr 2010 20:38:31 +0000\r
24 Received: by localhost.localdomain (Postfix, from userid 500)\r
25         id 5E185C00DC; Wed,  7 Apr 2010 13:38:29 -0700 (PDT)\r
26 From: Dirk Hohndel <hohndel@infradead.org>\r
27 To: <notmuch@notmuchmail.org>\r
28 Subject: [PATCH] Fix code extracting the MTA from Received: headers\r
29 Date: Wed, 07 Apr 2010 13:38:29 -0700\r
30 Message-ID: <m31verxaka.fsf@x200.gr8dns.org>\r
31 MIME-Version: 1.0\r
32 Content-Type: text/plain; charset=us-ascii\r
33 X-SRS-Rewrite: SMTP reverse-path rewritten from <hohndel@infradead.org> by\r
34         bombadil.infradead.org See http://www.infradead.org/rpr.html\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Wed, 07 Apr 2010 20:38:33 -0000\r
48 \r
49 \r
50 The previous code made too many assumptions about the (sadly not\r
51 standardized) format of the Received headers. This version should\r
52 be more robust to deal with different variations.\r
53 \r
54 Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
55 ---\r
56  notmuch-reply.c |   23 +++++++++--------------\r
57  1 files changed, 9 insertions(+), 14 deletions(-)\r
58 \r
59 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
60 index 8eb4754..39377e1 100644\r
61 --- a/notmuch-reply.c\r
62 +++ b/notmuch-reply.c\r
63 @@ -296,28 +296,23 @@ guess_from_received_header (notmuch_config_t *config, notmuch_message_t *message\r
64      received = notmuch_message_get_header (message, "received");\r
65      by = strstr (received, " by ");\r
66      if (by && *(by+4)) {\r
67 -       /* we know that there are 4 characters after by - either the 4th one\r
68 -        * is '\0' (broken header) or it is the first letter of the hostname \r
69 -        * that last received this email - which we'll use to guess the right\r
70 -        * from email address\r
71 +       /* sadly, the format of Received: headers is a bit inconsistent,\r
72 +        * depending on the MTA used. So we try to extract just the MTA\r
73 +        * here by removing leading whitespace and assuming that the MTA\r
74 +        * name ends at the next whitespace\r
75 +        * we test for *(by+4) to be non-'\0' to make sure there's something\r
76 +        * there at all - and then assume that the first whitespace delimited\r
77 +        * token that follows is the last receiving server\r
78          */\r
79         mta = strdup (by+4);\r
80         if (mta == NULL)\r
81             return NULL;\r
82 -\r
83 -       /* After the MTA comes its IP address (or HELO response) in parenthesis.\r
84 -        * so let's terminate the string there\r
85 -        */\r
86 -       if ((ptr = strchr (mta, '(')) == NULL) {\r
87 -           free (mta);\r
88 +       token = strtok(mta," \t");\r
89 +       if (token == NULL)\r
90             return NULL;\r
91 -       }\r
92 -       *ptr = '\0';\r
93 -\r
94         /* Now extract the last two components of the MTA host name\r
95          * as domain and tld\r
96          */\r
97 -       token = mta;\r
98         while ((ptr = strsep (&token, delim)) != NULL) {\r
99             if (*ptr == '\0')\r
100                 continue;\r
101 -- \r
102 1.6.6.1\r
103 \r
104 \r
105 -- \r
106 Dirk Hohndel\r
107 Intel Open Source Technology Center\r