Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 9a / 77af956c874296a034ef71aa758dd8890cee26
1 Return-Path: <flo@chaoflow.net>\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 31F04429E28\r
6         for <notmuch@notmuchmail.org>; Fri,  6 May 2011 16:17:57 -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: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 L5bqgtIDs76y for <notmuch@notmuchmail.org>;\r
16         Fri,  6 May 2011 16:17:54 -0700 (PDT)\r
17 Received: from tesla.chaoflow.net (tesla.chaoflow.net [188.40.54.22])\r
18         (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 7BFCA429E21\r
21         for <notmuch@notmuchmail.org>; Fri,  6 May 2011 16:17:54 -0700 (PDT)\r
22 Received: from eve.chaoflow.net (ppp-93-104-187-164.dynamic.mnet-online.de\r
23         [93.104.187.164])\r
24         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
25         (No client certificate requested)\r
26         (Authenticated sender: flo@chaoflow.net)\r
27         by tesla.chaoflow.net (Postfix) with ESMTPSA id 09778CD45;\r
28         Sat,  7 May 2011 01:17:53 +0200 (CEST)\r
29 Received: from eve.fritz.box (eve.chaoflow.net [127.0.0.1])\r
30         by eve.chaoflow.net (Postfix) with ESMTP id A58082AA; Fri,\r
31         6 May 2011 23:17:52 +0000 (Local time zone must be set--see zic manual\r
32         page)\r
33 From: Florian Friesdorf <flo@chaoflow.net>\r
34 To: notmuch@notmuchmail.org\r
35 Subject: [PATCH] implement search --format=sanitized_text + emacs UI to use it\r
36 Date: Sat,  7 May 2011 01:17:26 +0200\r
37 Message-Id: <1304723846-29134-2-git-send-email-flo@chaoflow.net>\r
38 X-Mailer: git-send-email 1.7.5.1\r
39 In-Reply-To: <1304723846-29134-1-git-send-email-flo@chaoflow.net>\r
40 References: <1304723846-29134-1-git-send-email-flo@chaoflow.net>\r
41 X-Virus-Scanned: clamav-milter 0.96.5 at tesla\r
42 X-Virus-Status: Clean\r
43 Cc: a.amann@ucc.ie\r
44 X-BeenThere: notmuch@notmuchmail.org\r
45 X-Mailman-Version: 2.1.13\r
46 Precedence: list\r
47 List-Id: "Use and development of the notmuch mail system."\r
48         <notmuch.notmuchmail.org>\r
49 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
51 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
52 List-Post: <mailto:notmuch@notmuchmail.org>\r
53 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
54 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
56 X-List-Received-Date: Fri, 06 May 2011 23:17:57 -0000\r
57 \r
58 Sanitize "Subject:" and "Author:" fields to not contain control\r
59 characters for sanitized_text format.\r
60 \r
61 When a Subject field contains encoded CRLF sequences, these sequences\r
62 would appear unfiltered in the output of notmuch search. This confused\r
63 the notmuch emacs interface leading to "Unexpected Output"\r
64 messages. This is now fixed by replacing all characters with ASCII\r
65 code less than 32 with a question mark for the sanitized_text\r
66 format. The emacs UI uses this format.\r
67 \r
68 Thank you to Andreas Amann <a.amann@ucc.ie>, who wrote the initial\r
69 patch, I just turned it into a new format.\r
70 \r
71 missing:\r
72 - man page update\r
73 - test, (works for me)\r
74 - investigate initialization warning:\r
75 CC -O2 notmuch-search.o\r
76 notmuch-search.c:98:1: warning: missing initializer\r
77 notmuch-search.c:98:1: warning: (near initialization for\r
78 'format_sanitized_text.results_null')\r
79 ---\r
80  emacs/notmuch.el |    3 +-\r
81  notmuch-search.c |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
82  2 files changed, 60 insertions(+), 1 deletions(-)\r
83 \r
84 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
85 index 1d683f8..9d7c212 100644\r
86 --- a/emacs/notmuch.el\r
87 +++ b/emacs/notmuch.el\r
88 @@ -879,7 +879,8 @@ The optional parameters are used as follows:\r
89                      (if oldest-first\r
90                          "--sort=oldest-first"\r
91                        "--sort=newest-first")\r
92 -                    query)))\r
93 +                     "--format=sanitized_text"\r
94 +                     query)))\r
95           (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
96           (set-process-filter proc 'notmuch-search-process-filter))))\r
97      (run-hooks 'notmuch-search-hook)))\r
98 diff --git a/notmuch-search.c b/notmuch-search.c\r
99 index 5e39511..d59dc44 100644\r
100 --- a/notmuch-search.c\r
101 +++ b/notmuch-search.c\r
102 @@ -78,6 +78,26 @@ static const search_format_t format_text = {\r
103  };\r
104  \r
105  static void\r
106 +format_thread_sanitized_text (const void *ctx,\r
107 +                             const char *thread_id,\r
108 +                             const time_t date,\r
109 +                             const int matched,\r
110 +                             const int total,\r
111 +                             const char *authors,\r
112 +                             const char *subject);\r
113 +static const search_format_t format_sanitized_text = {\r
114 +    "",\r
115 +       "",\r
116 +           format_item_id_text,\r
117 +           format_thread_sanitized_text,\r
118 +           " (",\r
119 +               "%s", " ",\r
120 +           ")", "\n",\r
121 +       "",\r
122 +    "",\r
123 +};\r
124 +\r
125 +static void\r
126  format_item_id_json (const void *ctx,\r
127                      const char *item_type,\r
128                      const char *item_id);\r
129 @@ -129,6 +149,42 @@ format_thread_text (const void *ctx,\r
130             subject);\r
131  }\r
132  \r
133 +static char *\r
134 +sanitize_string(const void *ctx, const char *str)\r
135 +{\r
136 +    char *out, *loop;\r
137 +\r
138 +    loop = out = talloc_strdup (ctx, str);\r
139 +\r
140 +    for(;*loop;loop++){\r
141 +       if ((unsigned char)(*loop) < 32)\r
142 +           *loop = '?';\r
143 +    }\r
144 +    return out;\r
145 +}\r
146 +\r
147 +static void\r
148 +format_thread_sanitized_text (const void *ctx,\r
149 +                             const char *thread_id,\r
150 +                             const time_t date,\r
151 +                             const int matched,\r
152 +                             const int total,\r
153 +                             const char *authors,\r
154 +                             const char *subject)\r
155 +{\r
156 +    void *ctx_quote = talloc_new (ctx);\r
157 +\r
158 +    printf ("thread:%s %12s [%d/%d] %s; %s",\r
159 +           thread_id,\r
160 +           notmuch_time_relative_date (ctx, date),\r
161 +           matched,\r
162 +           total,\r
163 +           sanitize_string(ctx_quote, authors),\r
164 +           sanitize_string(ctx_quote, subject));\r
165 +\r
166 +    talloc_free (ctx_quote);\r
167 +}\r
168 +\r
169  static void\r
170  format_item_id_json (const void *ctx,\r
171                      unused (const char *item_type),\r
172 @@ -378,6 +434,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])\r
173             opt = argv[i] + sizeof ("--format=") - 1;\r
174             if (strcmp (opt, "text") == 0) {\r
175                 format = &format_text;\r
176 +           } else if (strcmp (opt, "sanitized_text") == 0) {\r
177 +               format = &format_sanitized_text;\r
178             } else if (strcmp (opt, "json") == 0) {\r
179                 format = &format_json;\r
180             } else {\r
181 -- \r
182 1.7.5.1\r
183 \r