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