[PATCH v2 1/3] Add 'compose' command
authorFelipe Contreras <felipe.contreras@gmail.com>
Wed, 18 Apr 2012 12:39:11 +0000 (15:39 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:31 +0000 (09:46 -0800)
b8/a9961eb2a320e0725b854d7e75d70001b980ba [new file with mode: 0644]

diff --git a/b8/a9961eb2a320e0725b854d7e75d70001b980ba b/b8/a9961eb2a320e0725b854d7e75d70001b980ba
new file mode 100644 (file)
index 0000000..bed5340
--- /dev/null
@@ -0,0 +1,237 @@
+Return-Path: <felipe.contreras@gmail.com>\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 1A14D431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 05:39:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, 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 iUj6WZ0qMbjg for <notmuch@notmuchmail.org>;\r
+       Wed, 18 Apr 2012 05:39:51 -0700 (PDT)\r
+Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com\r
+       [209.85.217.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 1ABAC431FC3\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 05:39:43 -0700 (PDT)\r
+Received: by lbdb5 with SMTP id b5so2794488lbd.26\r
+       for <notmuch@notmuchmail.org>; Wed, 18 Apr 2012 05:39:42 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references\r
+       :mime-version:content-type:content-transfer-encoding;\r
+       bh=DgLDlP4+izCFtyi+8mjMYjPEp4dtu4IPoIsktFOF0MM=;\r
+       b=n3b2/Xh3KAIM/rz3iUyRdazdOyFxyEhFlu/xb6biFqefdlMtqMjeBA2v9amr/tPqzU\r
+       fCucKgD3qHMVF30TYdkrB5naqewT1+qm6v2LYY89tYItbSC+76ILWzP4Ezd96ZN2h1pF\r
+       6ImhadJK4DtF0Reb8aNhpzDdn4ZB/Q7QwfHteZvCL3anU4kRv06o65lKfeob3gMYBztO\r
+       n4gUVw7ddprX/0QuLl1HbP+Zjer+F3yGG8MNvhEcX4NhsKChhlGf88y3tSSqGVXvZaun\r
+       MG/zwsIEo7i3O17HwaS1hLss0T1mOeQCi9J4Vk7KuXlyPhz1bySwSKH4kLah0e/kLqKU\r
+       zisw==\r
+Received: by 10.112.26.10 with SMTP id h10mr949974lbg.79.1334752782437;\r
+       Wed, 18 Apr 2012 05:39:42 -0700 (PDT)\r
+Received: from localhost (85-156-70-103.elisa-mobile.fi. [85.156.70.103])\r
+       by mx.google.com with ESMTPS id o2sm7352895lbd.7.2012.04.18.05.39.40\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 18 Apr 2012 05:39:41 -0700 (PDT)\r
+From: Felipe Contreras <felipe.contreras@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: =?UTF-8?q?=5BPATCH=20v2=201/3=5D=20Add=20=27compose=27=20command?=\r
+Date: Wed, 18 Apr 2012 15:39:11 +0300\r
+Message-Id: <1334752753-23970-2-git-send-email-felipe.contreras@gmail.com>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com>\r
+References: <1334752753-23970-1-git-send-email-felipe.contreras@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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 12:39:56 -0000\r
+\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
+ notmuch.c         |    5 +++\r
+ 4 files changed, 120 insertions(+)\r
+ create mode 100644 notmuch-compose.c\r
+\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 =              \\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
+ \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
+ \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 © 2009 Carl Worth\r
++ * Copyright © 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 = NULL, *stream_filter = NULL;\r
++\r
++    stream_stdout = 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 = 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 = 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 = g_mime_message_new (1);\r
++    if (msg == 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 == NULL)\r
++      from_addr = notmuch_config_get_user_primary_email (config);\r
++\r
++    simple_from = talloc_strdup (ctx, from_addr);\r
++\r
++    from_addr = 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 = 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 = talloc_asprintf (ctx, "<%lu-notmuch-%s>",\r
++                                time(NULL),\r
++                                simple_from);\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 *argv[]))\r
++{\r
++    notmuch_config_t *config;\r
++    int ret = 0;\r
++\r
++    config = notmuch_config_open (ctx, NULL, NULL);\r
++    if (config == NULL)\r
++      return 1;\r
++\r
++    ret = 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[] = {\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
+-- \r
+1.7.10\r
+\r