Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 71 / 1e1a8bab71cd05a30c5b86813e3624f3cb827d
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 arlo.cworth.org (Postfix) with ESMTP id BAC2C6DE2D92\r
6  for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:40:38 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.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.266\r
11 X-Spam-Level: \r
12 X-Spam-Status: No, score=0.266 tagged_above=-999 required=5 tests=[AWL=0.986, \r
13  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7,\r
14  RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id no16u5ptnUoX for <notmuch@notmuchmail.org>;\r
18  Sat, 13 Aug 2016 04:40:30 -0700 (PDT)\r
19 Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com\r
20  [74.125.82.66]) by arlo.cworth.org (Postfix) with ESMTPS id 031126DE390F for\r
21  <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:16 -0700 (PDT)\r
22 Received: by mail-wm0-f66.google.com with SMTP id i138so2004422wmf.3\r
23  for <notmuch@notmuchmail.org>; Sat, 13 Aug 2016 04:39:15 -0700 (PDT)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25  d=nikula-org.20150623.gappssmtp.com; s=20150623;\r
26  h=from:to:cc:subject:date:message-id:in-reply-to:references\r
27  :in-reply-to:references;\r
28  bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=;\r
29  b=htlnE83+aAr53bHBjx7OtYwDtc5YcNbk+NIxrvCW80wSIEdpWUya8aPU0ioOGH408x\r
30  fF4elBuwXya3ebLEKH9Cca0lHlmkzbb9g9lp3BUfOX5T+VlVvSgEUU/3BTkkHtU/Uvfy\r
31  uIQ/NLk4LUjQsX2j4UwrZmwj3Rdg1+Suq4LanpeoP/SPuHtCX6YIvsrzP7WprBXA7E0e\r
32  /qKQnC1oviKypiwE8Pk4QzGtXMlH9biQTFnUsNYZjABF81LTLix0TcHxeNpdJas0VFIM\r
33  FXQoOuGT+Yqtu/Lg+Bq09lfiGSWEOjWeGYBD5Revvn53MQZKg8olUaWU0fexMpSqMipW\r
34  V9MQ==\r
35 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
36  d=1e100.net; s=20130820;\r
37  h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
38  :references:in-reply-to:references;\r
39  bh=qK/Sq8a9u1XpVLQESV5pNaTbGcGNCTZCBIEd//Ix38A=;\r
40  b=JOMpAavi5mC3mtUZ8uFinfGqtBfEGNVuzg1ZuFabXvk0uSdAas5rsM2+to92UbQ0+Y\r
41  tYd8m2brxLXb+NJpsN9xyJfHuZlUmwihaA+/K9pd5F9EkWvLgyTE0nynzI2B0em41BTI\r
42  IOyBcyLbE6RZQ33ntMJZPhzZU2c70l7Ze0SWWgNLGaeebx1vrl1b06l6kodI0WtfYZKG\r
43  8ypuuzkn44MOa43882cqOAoyXc3rqfh5zzxZRnhJVrRxlTIab1T5jCkYBcimfN4I0FjA\r
44  znbV+OY9KKx6SfYrf0T/05yvQGNYcczUIyA61KefGZtHalK59DJ741aXYOrcnWY3MGu7\r
45  NZiA==\r
46 X-Gm-Message-State:\r
47  AEkoousVtvX3PGZlVYAoTwI4PbUvtc6pz4rNRYF+ciEi6Tm2paGhHrQCIY0yzp9eQAahfA==\r
48 X-Received: by 10.194.148.81 with SMTP id tq17mr19703366wjb.67.1471088354427; \r
49  Sat, 13 Aug 2016 04:39:14 -0700 (PDT)\r
50 Received: from localhost (dsl-hkibrasgw2-58c368-70.dhcp.inet.fi.\r
51  [88.195.104.70])\r
52  by smtp.gmail.com with ESMTPSA id o4sm11781593wjd.15.2016.08.13.04.39.13\r
53  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
54  Sat, 13 Aug 2016 04:39:14 -0700 (PDT)\r
55 From: Jani Nikula <jani@nikula.org>\r
56 To: notmuch@notmuchmail.org\r
57 Cc: Daniel Kahn Gillmor <dkg@fifthhorseman.net>,\r
58         jani@nikula.org\r
59 Subject: [PATCH v2 08/14] cli/reply: reduce the reply format abstractions\r
60 Date: Sat, 13 Aug 2016 14:37:32 +0300\r
61 Message-Id:\r
62  <b72a0561fb90053ac39e5835e919f58ff457a33a.1471088022.git.jani@nikula.org>\r
63 X-Mailer: git-send-email 2.1.4\r
64 In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
65 References: <cover.1471088022.git.jani@nikula.org>\r
66 In-Reply-To: <cover.1471088022.git.jani@nikula.org>\r
67 References: <cover.1471088022.git.jani@nikula.org>\r
68 X-BeenThere: notmuch@notmuchmail.org\r
69 X-Mailman-Version: 2.1.20\r
70 Precedence: list\r
71 List-Id: "Use and development of the notmuch mail system."\r
72  <notmuch.notmuchmail.org>\r
73 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
74  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
75 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
76 List-Post: <mailto:notmuch@notmuchmail.org>\r
77 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
78 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
79  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
80 X-List-Received-Date: Sat, 13 Aug 2016 11:40:38 -0000\r
81 \r
82 Now that we've made the various reply formats quite similar to each\r
83 other, there's no point in keeping the abstractions. They are now\r
84 close enough to be put in one function.\r
85 \r
86 For now, a mime node will be uselessly created for the headers-only\r
87 case, but this is insignificant, and may change in the future.\r
88 ---\r
89  notmuch-reply.c | 145 ++++++++++++++------------------------------------------\r
90  1 file changed, 36 insertions(+), 109 deletions(-)\r
91 \r
92 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
93 index daad453efb09..b380678e7204 100644\r
94 --- a/notmuch-reply.c\r
95 +++ b/notmuch-reply.c\r
96 @@ -599,92 +599,6 @@ create_reply_message(void *ctx,\r
97      return reply;\r
98  }\r
99  \r
100 -static int\r
101 -notmuch_reply_format_default(void *ctx,\r
102 -                            notmuch_config_t *config,\r
103 -                            notmuch_message_t *message,\r
104 -                            notmuch_show_params_t *params,\r
105 -                            notmuch_bool_t reply_all,\r
106 -                            unused (sprinter_t *sp))\r
107 -{\r
108 -    GMimeMessage *reply;\r
109 -    mime_node_t *node;\r
110 -\r
111 -    if (mime_node_open (ctx, message, &params->crypto, &node))\r
112 -       return 1;\r
113 -\r
114 -    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
115 -    if (!reply)\r
116 -       return 1;\r
117 -\r
118 -    show_reply_headers (reply);\r
119 -    format_part_reply (node);\r
120 -\r
121 -    g_object_unref (G_OBJECT (reply));\r
122 -    talloc_free (node);\r
123 -\r
124 -    return 0;\r
125 -}\r
126 -\r
127 -static int\r
128 -notmuch_reply_format_sprinter(void *ctx,\r
129 -                             notmuch_config_t *config,\r
130 -                             notmuch_message_t *message,\r
131 -                             notmuch_show_params_t *params,\r
132 -                             notmuch_bool_t reply_all,\r
133 -                             sprinter_t *sp)\r
134 -{\r
135 -    GMimeMessage *reply;\r
136 -    mime_node_t *node;\r
137 -\r
138 -    if (mime_node_open (ctx, message, &params->crypto, &node))\r
139 -       return 1;\r
140 -\r
141 -    reply = create_reply_message (ctx, config, message, reply_all, FALSE);\r
142 -    if (!reply)\r
143 -       return 1;\r
144 -\r
145 -    sp->begin_map (sp);\r
146 -\r
147 -    /* The headers of the reply message we've created */\r
148 -    sp->map_key (sp, "reply-headers");\r
149 -    format_headers_sprinter (sp, reply, TRUE);\r
150 -\r
151 -    /* Start the original */\r
152 -    sp->map_key (sp, "original");\r
153 -    format_part_sprinter (ctx, sp, node, TRUE, TRUE, FALSE);\r
154 -\r
155 -    /* End */\r
156 -    sp->end (sp);\r
157 -\r
158 -    g_object_unref (G_OBJECT (reply));\r
159 -    talloc_free (node);\r
160 -\r
161 -    return 0;\r
162 -}\r
163 -\r
164 -/* This format is currently tuned for a git send-email --notmuch hook */\r
165 -static int\r
166 -notmuch_reply_format_headers_only(void *ctx,\r
167 -                                 notmuch_config_t *config,\r
168 -                                 notmuch_message_t *message,\r
169 -                                 unused (notmuch_show_params_t *params),\r
170 -                                 notmuch_bool_t reply_all,\r
171 -                                 unused (sprinter_t *sp))\r
172 -{\r
173 -    GMimeMessage *reply;\r
174 -\r
175 -    reply = create_reply_message (ctx, config, message, reply_all, TRUE);\r
176 -    if (!reply)\r
177 -       return 1;\r
178 -\r
179 -    show_reply_headers (reply);\r
180 -\r
181 -    g_object_unref (G_OBJECT (reply));\r
182 -\r
183 -    return 0;\r
184 -}\r
185 -\r
186  enum {\r
187      FORMAT_DEFAULT,\r
188      FORMAT_JSON,\r
189 @@ -698,17 +612,12 @@ static int do_reply(notmuch_config_t *config,\r
190                     int format,\r
191                     notmuch_bool_t reply_all)\r
192  {\r
193 +    GMimeMessage *reply;\r
194 +    mime_node_t *node;\r
195      notmuch_messages_t *messages;\r
196      notmuch_message_t *message;\r
197      notmuch_status_t status;\r
198      struct sprinter *sp = NULL;\r
199 -    int ret = 0;\r
200 -    int (*reply_format_func) (void *ctx,\r
201 -                             notmuch_config_t *config,\r
202 -                             notmuch_message_t *message,\r
203 -                             notmuch_show_params_t *params,\r
204 -                             notmuch_bool_t reply_all,\r
205 -                             struct sprinter *sp);\r
206  \r
207      if (format == FORMAT_JSON || format == FORMAT_SEXP) {\r
208         unsigned count;\r
209 @@ -721,18 +630,11 @@ static int do_reply(notmuch_config_t *config,\r
210             fprintf (stderr, "Error: search term did not match precisely one message (matched %d messages).\n", count);\r
211             return 1;\r
212         }\r
213 -    }\r
214  \r
215 -    if (format == FORMAT_HEADERS_ONLY) {\r
216 -       reply_format_func = notmuch_reply_format_headers_only;\r
217 -    } else if (format == FORMAT_JSON) {\r
218 -       reply_format_func = notmuch_reply_format_sprinter;\r
219 -       sp = sprinter_json_create (config, stdout);\r
220 -    } else if (format == FORMAT_SEXP) {\r
221 -       reply_format_func = notmuch_reply_format_sprinter;\r
222 -       sp = sprinter_sexp_create (config, stdout);\r
223 -    } else {\r
224 -       reply_format_func = notmuch_reply_format_default;\r
225 +       if (format == FORMAT_JSON)\r
226 +           sp = sprinter_json_create (config, stdout);\r
227 +       else\r
228 +           sp = sprinter_sexp_create (config, stdout);\r
229      }\r
230  \r
231      status = notmuch_query_search_messages_st (query, &messages);\r
232 @@ -745,15 +647,40 @@ static int do_reply(notmuch_config_t *config,\r
233      {\r
234         message = notmuch_messages_get (messages);\r
235  \r
236 -       ret = reply_format_func(config, config, message, params, reply_all, sp);\r
237 +       if (mime_node_open (config, message, &params->crypto, &node))\r
238 +           return 1;\r
239  \r
240 -       notmuch_message_destroy (message);\r
241 +       reply = create_reply_message (config, config, message, reply_all,\r
242 +                                     format == FORMAT_HEADERS_ONLY);\r
243 +       if (!reply)\r
244 +           return 1;\r
245  \r
246 -       if (ret)\r
247 -           break;\r
248 +       if (format == FORMAT_JSON || format == FORMAT_SEXP) {\r
249 +           sp->begin_map (sp);\r
250 +\r
251 +           /* The headers of the reply message we've created */\r
252 +           sp->map_key (sp, "reply-headers");\r
253 +           format_headers_sprinter (sp, reply, TRUE);\r
254 +\r
255 +           /* Start the original */\r
256 +           sp->map_key (sp, "original");\r
257 +           format_part_sprinter (config, sp, node, TRUE, TRUE, FALSE);\r
258 +\r
259 +           /* End */\r
260 +           sp->end (sp);\r
261 +       } else {\r
262 +           show_reply_headers (reply);\r
263 +           if (format == FORMAT_DEFAULT)\r
264 +               format_part_reply (node);\r
265 +       }\r
266 +\r
267 +       g_object_unref (G_OBJECT (reply));\r
268 +       talloc_free (node);\r
269 +\r
270 +       notmuch_message_destroy (message);\r
271      }\r
272  \r
273 -    return ret;\r
274 +    return 0;\r
275  }\r
276  \r
277  int\r
278 -- \r
279 2.1.4\r
280 \r