--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1A6C0431FBD\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:51 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id G+QcboqBNLoT for <notmuch@notmuchmail.org>;\r
+ Wed, 18 Apr 2012 06:06:46 -0700 (PDT)\r
+Received: from mail-qa0-f43.google.com (mail-qa0-f43.google.com\r
+ [209.85.216.43]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 30F8A431FBC\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:46 -0700 (PDT)\r
+Received: by qadb15 with SMTP id b15so544175qad.2\r
+ for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 06:06:44 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=google.com; s=20120113;\r
+ h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
+ :message-id:mime-version:content-type:content-transfer-encoding\r
+ :x-gm-message-state;\r
+ bh=bjQOCkJKFIaRW96o2Nkla2pgMZ4NiqsmX1leez/D3BE=;\r
+ b=W0OPDhhbJa4sofwvssC+RLw0/nZxCnnApvuZGVjqrNptq7CROzsglsRjkxM1yN0TXc\r
+ zdgV4bHOE2/WCuMDzCHoL8AmglGD/0r3MK4D3k6UelfO3Cwgrwew8Xi+NREaY4vHDJa/\r
+ J93Xt/vBqu6CeShk+tuhzQALjKL157NVcEGWiTcURtrQsRcbp/bn5IPjd2J7TJnpHgHO\r
+ ojvd46nCdzfI6S/AX20poz+G/bgwEdm2h9yTQht+a+eV1lX9pVZsu4HvAoMs+5ut4GOM\r
+ hArt0Yz7HN3eizqpqa8yHXZX3iB4gX3Y+ex35p4ZtzdegMh3d84XiSoS7KrqZHHVBsVb\r
+ 8tYw==\r
+Received: by 10.229.137.70 with SMTP id v6mr819028qct.76.1334754404422;\r
+ Wed, 18 Apr 2012 06:06:44 -0700 (PDT)\r
+Received: from localhost (nikula.org. [92.243.24.172])\r
+ by mx.google.com with ESMTPS id gv4sm46014685qab.1.2012.04.18.06.06.34\r
+ (version=SSLv3 cipher=OTHER); Wed, 18 Apr 2012 06:06:43 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Felipe Contreras <felipe.contreras@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v2 1/3] Add 'compose' command\r
+In-Reply-To: <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com>\r
+References: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com>\r
+ <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com>\r
+User-Agent: Notmuch/0.11.1+222~ga47a98c (http://notmuchmail.org) Emacs/23.1.1\r
+ (i686-pc-linux-gnu)\r
+Date: Wed, 18 Apr 2012 13:06:32 +0000\r
+Message-ID: <873981chpj.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=utf-8\r
+Content-Transfer-Encoding: quoted-printable\r
+X-Gm-Message-State:\r
+ ALoCoQmwLPIGAFbMWRWJvo+gxkPHKzQWZBQ2uNY88SnSY1p9nICd5B+H33TqCU0TBfoQOMrj1T0L\r
+Cc: Felipe Contreras <felipe.contreras@ngmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 18 Apr 2012 13:06:51 -0000\r
+\r
+On Wed, 18 Apr 2012 15:39:11 +0300, Felipe Contreras <felipe.contreras@gmai=\r
+l.com> wrote:\r
+> Signed-off-by: Felipe Contreras <felipe.contreras@ngmail.com>\r
+> ---\r
+> Makefile.local | 1 +\r
+> notmuch-client.h | 3 ++\r
+> notmuch-compose.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++=\r
+++++++\r
+> notmuch.c | 5 +++\r
+> 4 files changed, 120 insertions(+)\r
+> create mode 100644 notmuch-compose.c\r
+>=20\r
+> diff --git a/Makefile.local b/Makefile.local\r
+> index 53b4a0d..2c15ec2 100644\r
+> --- a/Makefile.local\r
+> +++ b/Makefile.local\r
+> @@ -279,6 +279,7 @@ notmuch_client_srcs =3D \\r
+> gmime-filter-headers.c \\r
+> hooks.c \\r
+> notmuch.c \\r
+> + notmuch-compose.c \\r
+> notmuch-config.c \\r
+> notmuch-count.c \\r
+> notmuch-dump.c \\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index 19b7f01..1146cd1 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -126,6 +126,9 @@ int\r
+> notmuch_reply_command (void *ctx, int argc, char *argv[]);\r
+>=20=20\r
+> int\r
+> +notmuch_compose_command (void *ctx, int argc, char *argv[]);\r
+> +\r
+> +int\r
+> notmuch_restore_command (void *ctx, int argc, char *argv[]);\r
+>=20=20\r
+> int\r
+> diff --git a/notmuch-compose.c b/notmuch-compose.c\r
+> new file mode 100644\r
+> index 0000000..ac5ea95\r
+> --- /dev/null\r
+> +++ b/notmuch-compose.c\r
+> @@ -0,0 +1,111 @@\r
+> +/* notmuch - Not much of an email program, (just index and search)\r
+> + *\r
+> + * Copyright =C2=A9 2009 Carl Worth\r
+> + * Copyright =C2=A9 2009 Keith Packard\r
+> + *\r
+> + * This program is free software: you can redistribute it and/or modify\r
+> + * it under the terms of the GNU General Public License as published by\r
+> + * the Free Software Foundation, either version 3 of the License, or\r
+> + * (at your option) any later version.\r
+> + *\r
+> + * This program is distributed in the hope that it will be useful,\r
+> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+> + * GNU General Public License for more details.\r
+> + *\r
+> + * You should have received a copy of the GNU General Public License\r
+> + * along with this program. If not, see http://www.gnu.org/licenses/ .\r
+> + *\r
+> + * Authors: Carl Worth <cworth@cworth.org>\r
+> + * Keith Packard <keithp@keithp.com>\r
+> + * Felipe Contreras <felipe.contreras@gmail.com>\r
+> + */\r
+> +\r
+> +#include "notmuch-client.h"\r
+> +#include "gmime-filter-headers.h"\r
+> +\r
+> +static void\r
+> +show_message_headers (GMimeMessage *message)\r
+> +{\r
+> + GMimeStream *stream_stdout =3D NULL, *stream_filter =3D NULL;\r
+> +\r
+> + stream_stdout =3D g_mime_stream_file_new (stdout);\r
+> + if (stream_stdout) {\r
+> + g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);\r
+> + stream_filter =3D g_mime_stream_filter_new(stream_stdout);\r
+> + if (stream_filter) {\r
+> + g_mime_stream_filter_add(GMIME_STREAM_FILTER(stream_filter),\r
+> + g_mime_filter_headers_new());\r
+> + g_mime_object_write_to_stream(GMIME_OBJECT(message), stream_filter);\r
+> + g_object_unref(stream_filter);\r
+> + }\r
+> + g_object_unref(stream_stdout);\r
+> + }\r
+> +}\r
+> +\r
+> +static int\r
+> +notmuch_compose (void *ctx, notmuch_config_t *config)\r
+> +{\r
+> + GMimeMessage *msg;\r
+> + const char *from_addr =3D NULL;\r
+> + const char *message_id, *user_agent;\r
+> + char *simple_from;\r
+> +\r
+> + /* The 1 means we want headers in a "pretty" order. */\r
+> + msg =3D g_mime_message_new (1);\r
+> + if (msg =3D=3D NULL) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + return 1;\r
+> + }\r
+> +\r
+> + g_mime_message_set_subject (msg, "");\r
+> +\r
+> + g_mime_object_set_header (GMIME_OBJECT (msg), "To", "");\r
+> +\r
+> + if (from_addr =3D=3D NULL)\r
+> + from_addr =3D notmuch_config_get_user_primary_email (config);\r
+> +\r
+> + simple_from =3D talloc_strdup (ctx, from_addr);\r
+> +\r
+> + from_addr =3D talloc_asprintf (ctx, "%s <%s>",\r
+> + notmuch_config_get_user_name (config),\r
+> + from_addr);\r
+> + g_mime_object_set_header (GMIME_OBJECT (msg),\r
+> + "From", from_addr);\r
+> +\r
+> + g_mime_object_set_header (GMIME_OBJECT (msg), "Bcc",\r
+> + notmuch_config_get_user_primary_email (config));\r
+> +\r
+> + user_agent =3D talloc_asprintf (ctx, "notmuch %s",\r
+> + STRINGIFY(NOTMUCH_VERSION));\r
+> + g_mime_object_set_header (GMIME_OBJECT (msg),\r
+> + "User-Agent", user_agent);\r
+> +\r
+> + message_id =3D talloc_asprintf (ctx, "<%lu-notmuch-%s>",\r
+> + time(NULL),\r
+> + simple_from);\r
+\r
+Running "notmuch compose" more than once within a second would result in\r
+identical message ids for the messages, which is not a good idea. That's\r
+not likely in interactive use, but the notmuch cli is highly scriptable,\r
+so someone is bound to hit this.\r
+\r
+Some paranoid might also be worried about "leaking" the time you run\r
+"notmuch compose"... which may be different from the actual time you\r
+send the message.\r
+\r
+\r
+BR,\r
+Jani.\r
+\r
+> + g_mime_object_set_header (GMIME_OBJECT (msg),\r
+> + "Message-ID", message_id);\r
+> + talloc_free (simple_from);\r
+> +\r
+> + show_message_headers (msg);\r
+> +\r
+> + g_object_unref (G_OBJECT (msg));\r
+> +\r
+> + return 0;\r
+> +}\r
+> +\r
+> +int\r
+> +notmuch_compose_command (void *ctx, unused (int argc), unused (char *arg=\r
+v[]))\r
+> +{\r
+> + notmuch_config_t *config;\r
+> + int ret =3D 0;\r
+> +\r
+> + config =3D notmuch_config_open (ctx, NULL, NULL);\r
+> + if (config =3D=3D NULL)\r
+> + return 1;\r
+> +\r
+> + ret =3D notmuch_compose (ctx, config);\r
+> +\r
+> + return ret;\r
+> +}\r
+> diff --git a/notmuch.c b/notmuch.c\r
+> index 477a09c..2b500d7 100644\r
+> --- a/notmuch.c\r
+> +++ b/notmuch.c\r
+> @@ -65,6 +65,11 @@ static command_t commands[] =3D {\r
+> { "reply", notmuch_reply_command,\r
+> "[options...] <search-terms> [...]",\r
+> "Construct a reply template for a set of messages." },\r
+> + { "compose", notmuch_compose_command,\r
+> + NULL,\r
+> + "Constructs an empty message.",\r
+> + "\tConstructs a new empty message filling basic headers such as\n"\r
+> + "\tFrom:, User-Agent: and Message-ID:." },\r
+> { "tag", notmuch_tag_command,\r
+> "+<tag>|-<tag> [...] [--] <search-terms> [...]" ,\r
+> "Add/remove tags for all messages matching the search terms." },\r
+> --=20\r
+> 1.7.10\r
+>=20\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r