Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 7a / 368c775814b38e173827242e8f6a4e2f4ae9d2
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 1A6C0431FBD\r
6         for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:51 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 G+QcboqBNLoT for <notmuch@notmuchmail.org>;\r
16         Wed, 18 Apr 2012 06:06:46 -0700 (PDT)\r
17 Received: from mail-qa0-f43.google.com (mail-qa0-f43.google.com\r
18         [209.85.216.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 30F8A431FBC\r
21         for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:46 -0700 (PDT)\r
22 Received: by qadb15 with SMTP id b15so544175qad.2\r
23         for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:44 -0700 (PDT)\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
25         d=google.com; s=20120113;\r
26         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
27         :message-id:mime-version:content-type:content-transfer-encoding\r
28         :x-gm-message-state;\r
29         bh=bjQOCkJKFIaRW96o2Nkla2pgMZ4NiqsmX1leez/D3BE=;\r
30         b=W0OPDhhbJa4sofwvssC+RLw0/nZxCnnApvuZGVjqrNptq7CROzsglsRjkxM1yN0TXc\r
31         zdgV4bHOE2/WCuMDzCHoL8AmglGD/0r3MK4D3k6UelfO3Cwgrwew8Xi+NREaY4vHDJa/\r
32         J93Xt/vBqu6CeShk+tuhzQALjKL157NVcEGWiTcURtrQsRcbp/bn5IPjd2J7TJnpHgHO\r
33         ojvd46nCdzfI6S/AX20poz+G/bgwEdm2h9yTQht+a+eV1lX9pVZsu4HvAoMs+5ut4GOM\r
34         hArt0Yz7HN3eizqpqa8yHXZX3iB4gX3Y+ex35p4ZtzdegMh3d84XiSoS7KrqZHHVBsVb\r
35         8tYw==\r
36 Received: by 10.229.137.70 with SMTP id v6mr819028qct.76.1334754404422;\r
37         Wed, 18 Apr 2012 06:06:44 -0700 (PDT)\r
38 Received: from localhost (nikula.org. [92.243.24.172])\r
39         by mx.google.com with ESMTPS id gv4sm46014685qab.1.2012.04.18.06.06.34\r
40         (version=SSLv3 cipher=OTHER); Wed, 18 Apr 2012 06:06:43 -0700 (PDT)\r
41 From: Jani Nikula <jani@nikula.org>\r
42 To: Felipe Contreras <felipe.contreras@gmail.com>, notmuch@notmuchmail.org\r
43 Subject: Re: [PATCH v2 1/3] Add 'compose' command\r
44 In-Reply-To: <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com>\r
45 References: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com>\r
46         <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com>\r
47 User-Agent: Notmuch/0.11.1+222~ga47a98c (http://notmuchmail.org) Emacs/23.1.1\r
48         (i686-pc-linux-gnu)\r
49 Date: Wed, 18 Apr 2012 13:06:32 +0000\r
50 Message-ID: <873981chpj.fsf@nikula.org>\r
51 MIME-Version: 1.0\r
52 Content-Type: text/plain; charset=utf-8\r
53 Content-Transfer-Encoding: quoted-printable\r
54 X-Gm-Message-State:\r
55  ALoCoQmwLPIGAFbMWRWJvo+gxkPHKzQWZBQ2uNY88SnSY1p9nICd5B+H33TqCU0TBfoQOMrj1T0L\r
56 Cc: Felipe Contreras <felipe.contreras@ngmail.com>\r
57 X-BeenThere: notmuch@notmuchmail.org\r
58 X-Mailman-Version: 2.1.13\r
59 Precedence: list\r
60 List-Id: "Use and development of the notmuch mail system."\r
61         <notmuch.notmuchmail.org>\r
62 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
64 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
65 List-Post: <mailto:notmuch@notmuchmail.org>\r
66 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
67 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
68         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
69 X-List-Received-Date: Wed, 18 Apr 2012 13:06:51 -0000\r
70 \r
71 On Wed, 18 Apr 2012 15:39:11 +0300, Felipe Contreras <felipe.contreras@gmai=\r
72 l.com> wrote:\r
73 > Signed-off-by: Felipe Contreras <felipe.contreras@ngmail.com>\r
74 > ---\r
75 >  Makefile.local    |    1 +\r
76 >  notmuch-client.h  |    3 ++\r
77 >  notmuch-compose.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++=\r
78 ++++++\r
79 >  notmuch.c         |    5 +++\r
80 >  4 files changed, 120 insertions(+)\r
81 >  create mode 100644 notmuch-compose.c\r
82 >=20\r
83 > diff --git a/Makefile.local b/Makefile.local\r
84 > index 53b4a0d..2c15ec2 100644\r
85 > --- a/Makefile.local\r
86 > +++ b/Makefile.local\r
87 > @@ -279,6 +279,7 @@ notmuch_client_srcs =3D           \\r
88 >       gmime-filter-headers.c  \\r
89 >       hooks.c                 \\r
90 >       notmuch.c               \\r
91 > +     notmuch-compose.c       \\r
92 >       notmuch-config.c        \\r
93 >       notmuch-count.c         \\r
94 >       notmuch-dump.c          \\r
95 > diff --git a/notmuch-client.h b/notmuch-client.h\r
96 > index 19b7f01..1146cd1 100644\r
97 > --- a/notmuch-client.h\r
98 > +++ b/notmuch-client.h\r
99 > @@ -126,6 +126,9 @@ int\r
100 >  notmuch_reply_command (void *ctx, int argc, char *argv[]);\r
101 >=20=20\r
102 >  int\r
103 > +notmuch_compose_command (void *ctx, int argc, char *argv[]);\r
104 > +\r
105 > +int\r
106 >  notmuch_restore_command (void *ctx, int argc, char *argv[]);\r
107 >=20=20\r
108 >  int\r
109 > diff --git a/notmuch-compose.c b/notmuch-compose.c\r
110 > new file mode 100644\r
111 > index 0000000..ac5ea95\r
112 > --- /dev/null\r
113 > +++ b/notmuch-compose.c\r
114 > @@ -0,0 +1,111 @@\r
115 > +/* notmuch - Not much of an email program, (just index and search)\r
116 > + *\r
117 > + * Copyright =C2=A9 2009 Carl Worth\r
118 > + * Copyright =C2=A9 2009 Keith Packard\r
119 > + *\r
120 > + * This program is free software: you can redistribute it and/or modify\r
121 > + * it under the terms of the GNU General Public License as published by\r
122 > + * the Free Software Foundation, either version 3 of the License, or\r
123 > + * (at your option) any later version.\r
124 > + *\r
125 > + * This program is distributed in the hope that it will be useful,\r
126 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
127 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
128 > + * GNU General Public License for more details.\r
129 > + *\r
130 > + * You should have received a copy of the GNU General Public License\r
131 > + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
132 > + *\r
133 > + * Authors: Carl Worth <cworth@cworth.org>\r
134 > + *       Keith Packard <keithp@keithp.com>\r
135 > + *       Felipe Contreras <felipe.contreras@gmail.com>\r
136 > + */\r
137 > +\r
138 > +#include "notmuch-client.h"\r
139 > +#include "gmime-filter-headers.h"\r
140 > +\r
141 > +static void\r
142 > +show_message_headers (GMimeMessage *message)\r
143 > +{\r
144 > +    GMimeStream *stream_stdout =3D NULL, *stream_filter =3D NULL;\r
145 > +\r
146 > +    stream_stdout =3D g_mime_stream_file_new (stdout);\r
147 > +    if (stream_stdout) {\r
148 > +     g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);\r
149 > +     stream_filter =3D g_mime_stream_filter_new(stream_stdout);\r
150 > +     if (stream_filter) {\r
151 > +             g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),\r
152 > +                                      g_mime_filter_headers_new());\r
153 > +             g_mime_object_write_to_stream(GMIME_OBJECT(message), stream_filter);\r
154 > +             g_object_unref(stream_filter);\r
155 > +     }\r
156 > +     g_object_unref(stream_stdout);\r
157 > +    }\r
158 > +}\r
159 > +\r
160 > +static int\r
161 > +notmuch_compose (void *ctx, notmuch_config_t *config)\r
162 > +{\r
163 > +    GMimeMessage *msg;\r
164 > +    const char *from_addr =3D NULL;\r
165 > +    const char *message_id, *user_agent;\r
166 > +    char *simple_from;\r
167 > +\r
168 > +    /* The 1 means we want headers in a "pretty" order. */\r
169 > +    msg =3D g_mime_message_new (1);\r
170 > +    if (msg =3D=3D NULL) {\r
171 > +     fprintf (stderr, "Out of memory\n");\r
172 > +     return 1;\r
173 > +    }\r
174 > +\r
175 > +    g_mime_message_set_subject (msg, "");\r
176 > +\r
177 > +    g_mime_object_set_header (GMIME_OBJECT (msg), "To", "");\r
178 > +\r
179 > +    if (from_addr =3D=3D NULL)\r
180 > +     from_addr =3D notmuch_config_get_user_primary_email (config);\r
181 > +\r
182 > +    simple_from =3D talloc_strdup (ctx, from_addr);\r
183 > +\r
184 > +    from_addr =3D talloc_asprintf (ctx, "%s <%s>",\r
185 > +                              notmuch_config_get_user_name (config),\r
186 > +                              from_addr);\r
187 > +    g_mime_object_set_header (GMIME_OBJECT (msg),\r
188 > +                           "From", from_addr);\r
189 > +\r
190 > +    g_mime_object_set_header (GMIME_OBJECT (msg), "Bcc",\r
191 > +                           notmuch_config_get_user_primary_email (config));\r
192 > +\r
193 > +    user_agent =3D talloc_asprintf (ctx, "notmuch %s",\r
194 > +                               STRINGIFY(NOTMUCH_VERSION));\r
195 > +    g_mime_object_set_header (GMIME_OBJECT (msg),\r
196 > +                           "User-Agent", user_agent);\r
197 > +\r
198 > +    message_id =3D talloc_asprintf (ctx, "<%lu-notmuch-%s>",\r
199 > +                               time(NULL),\r
200 > +                               simple_from);\r
201 \r
202 Running "notmuch compose" more than once within a second would result in\r
203 identical message ids for the messages, which is not a good idea. That's\r
204 not likely in interactive use, but the notmuch cli is highly scriptable,\r
205 so someone is bound to hit this.\r
206 \r
207 Some paranoid might also be worried about "leaking" the time you run\r
208 "notmuch compose"... which may be different from the actual time you\r
209 send the message.\r
210 \r
211 \r
212 BR,\r
213 Jani.\r
214 \r
215 > +    g_mime_object_set_header (GMIME_OBJECT (msg),\r
216 > +                           "Message-ID", message_id);\r
217 > +    talloc_free (simple_from);\r
218 > +\r
219 > +    show_message_headers (msg);\r
220 > +\r
221 > +    g_object_unref (G_OBJECT (msg));\r
222 > +\r
223 > +    return 0;\r
224 > +}\r
225 > +\r
226 > +int\r
227 > +notmuch_compose_command (void *ctx, unused (int argc), unused (char *arg=\r
228 v[]))\r
229 > +{\r
230 > +    notmuch_config_t *config;\r
231 > +    int ret =3D 0;\r
232 > +\r
233 > +    config =3D notmuch_config_open (ctx, NULL, NULL);\r
234 > +    if (config =3D=3D NULL)\r
235 > +     return 1;\r
236 > +\r
237 > +    ret =3D notmuch_compose (ctx, config);\r
238 > +\r
239 > +    return ret;\r
240 > +}\r
241 > diff --git a/notmuch.c b/notmuch.c\r
242 > index 477a09c..2b500d7 100644\r
243 > --- a/notmuch.c\r
244 > +++ b/notmuch.c\r
245 > @@ -65,6 +65,11 @@ static command_t commands[] =3D {\r
246 >      { "reply", notmuch_reply_command,\r
247 >        "[options...] <search-terms> [...]",\r
248 >        "Construct a reply template for a set of messages." },\r
249 > +    { "compose", notmuch_compose_command,\r
250 > +     NULL,\r
251 > +     "Constructs an empty message.",\r
252 > +     "\tConstructs a new empty message filling basic headers such as\n"\r
253 > +     "\tFrom:, User-Agent: and Message-ID:." },\r
254 >      { "tag", notmuch_tag_command,\r
255 >        "+<tag>|-<tag> [...] [--] <search-terms> [...]" ,\r
256 >        "Add/remove tags for all messages matching the search terms." },\r
257 > --=20\r
258 > 1.7.10\r
259 >=20\r
260 > _______________________________________________\r
261 > notmuch mailing list\r
262 > notmuch@notmuchmail.org\r
263 > http://notmuchmail.org/mailman/listinfo/notmuch\r