Re: Hi all
[notmuch-archives.git] / 62 / 7b8e6495c4eea7f8f544939d9bae836c418d8c
1 Return-Path: <a.amann@ucc.ie>\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 7C780431FB6\r
6         for <notmuch@notmuchmail.org>; Fri, 15 Apr 2011 04:28:09 -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.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\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 2kofIuPdfss6 for <notmuch@notmuchmail.org>;\r
16         Fri, 15 Apr 2011 04:28:09 -0700 (PDT)\r
17 Received: from mail4.ucc.ie (mail4.ucc.ie [143.239.1.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id B54FA431FB5\r
19         for <notmuch@notmuchmail.org>; Fri, 15 Apr 2011 04:28:08 -0700 (PDT)\r
20 Received: from msstf091.ucc.ie (msstf091.ucc.ie [143.239.76.91])\r
21         by mail4.ucc.ie (8.14.4/8.14.4) with ESMTP id p3FBS0Qv014913\r
22         for <notmuch@notmuchmail.org>; Fri, 15 Apr 2011 12:28:05 +0100\r
23 Received: by msstf091.ucc.ie (Postfix, from userid 1000)\r
24         id 7182A62B3C; Fri, 15 Apr 2011 12:28:00 +0100 (IST)\r
25 From: Andreas Amann <a.amann@ucc.ie>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: Re: Problem with "Unexpected output" messages\r
28 In-Reply-To: <87pqozi3q2.fsf@msstf091.ucc.ie>\r
29 References: <87pqozi3q2.fsf@msstf091.ucc.ie>\r
30 User-Agent: Notmuch/0.5-138-g91d61c7 (http://notmuchmail.org) Emacs/24.0.50.1\r
31         (x86_64-unknown-linux-gnu)\r
32 Date: Fri, 15 Apr 2011 12:28:00 +0100\r
33 Message-ID: <8739ljwy7z.fsf@msstf091.ucc.ie>\r
34 MIME-Version: 1.0\r
35 Content-Type: text/plain\r
36 X-MD-NoSA: yes\r
37 X-Scanned-By: MIMEDefang 2.68 on 143.239.1.34\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Fri, 15 Apr 2011 11:28:09 -0000\r
51 \r
52 On Wed, 06 Apr 2011 20:23:17 +0100, Andreas Amann <a.amann@ucc.ie> wrote:\r
53\r
54 > since commit 44d3c57e (emacs: Display any unexpected output from notmuch\r
55 > search) I see a number of messages of the form\r
56\r
57 > Error: Unexpected output from notmuch search:\r
58 > thread:000000000000XXXX \r
59\r
60 > after notmuch-search in emacs. \r
61 \r
62 \r
63 FWIW, the patch below solves the problem for me.\r
64 \r
65 Andreas\r
66 \r
67 ---------------------\r
68 [PATCH] Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search\r
69 \r
70 When a Subject field contained encoded CRLF sequences, these sequences\r
71 would appear unfiltered in the output of notmuch search. This confused\r
72 the notmuch emacs interface leading to "Unexpected Output"\r
73 messages. This is now fixed by replacing all characters with ASCII\r
74 code less than 32 with a question mark.\r
75 ---\r
76  notmuch-search.c |   22 ++++++++++++++++++++--\r
77  1 files changed, 20 insertions(+), 2 deletions(-)\r
78 \r
79 diff --git a/notmuch-search.c b/notmuch-search.c\r
80 index 8b90121..fc13e60 100644\r
81 --- a/notmuch-search.c\r
82 +++ b/notmuch-search.c\r
83 @@ -108,6 +108,20 @@ format_item_id_text (unused (const void *ctx),\r
84      printf ("%s%s", item_type, item_id);\r
85  }\r
86  \r
87 +static char *\r
88 +sanitize_string(const void *ctx, const char *str)\r
89 +{\r
90 +    char *out, *loop;\r
91 +\r
92 +    loop = out = talloc_strdup (ctx, str);\r
93 +\r
94 +    for(;*loop;loop++){\r
95 +       if ((unsigned char)(*loop) < 32)\r
96 +           *loop = '?';\r
97 +    }\r
98 +    return out;\r
99 +}\r
100 +\r
101  static void\r
102  format_thread_text (const void *ctx,\r
103                     const char *thread_id,\r
104 @@ -117,13 +131,17 @@ format_thread_text (const void *ctx,\r
105                     const char *authors,\r
106                     const char *subject)\r
107  {\r
108 +    void *ctx_quote = talloc_new (ctx);\r
109 +\r
110      printf ("thread:%s %12s [%d/%d] %s; %s",\r
111             thread_id,\r
112             notmuch_time_relative_date (ctx, date),\r
113             matched,\r
114             total,\r
115 -           authors,\r
116 -           subject);\r
117 +           sanitize_string(ctx_quote, authors),\r
118 +           sanitize_string(ctx_quote, subject));\r
119 +\r
120 +    talloc_free (ctx_quote);\r
121  }\r
122  \r
123  static void\r
124 -- \r
125 1.7.4.1\r
126 \r