[notmuch] [PATCH v3 6/6] Add 'cat' subcommand
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 27 Mar 2010 20:44:21 +0000 (21:44 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:26 +0000 (09:36 -0800)
0c/63a943a8cf84a38d433e6b7bdfbce398f8fcd4 [new file with mode: 0644]

diff --git a/0c/63a943a8cf84a38d433e6b7bdfbce398f8fcd4 b/0c/63a943a8cf84a38d433e6b7bdfbce398f8fcd4
new file mode 100644 (file)
index 0000000..8ee64c0
--- /dev/null
@@ -0,0 +1,202 @@
+Return-Path: <sojkam1@fel.cvut.cz>\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 EAE8C41733F\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:42 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=ham\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 yeccuoZvhcac for <notmuch@notmuchmail.org>;\r
+       Sat, 27 Mar 2010 13:44:40 -0700 (PDT)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 6CC0A418C25\r
+       for <notmuch@notmuchmail.org>; Sat, 27 Mar 2010 13:44:34 -0700 (PDT)\r
+Received: from localhost (unknown [192.168.200.4])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id CC09D19F3395;\r
+       Sat, 27 Mar 2010 21:44:33 +0100 (CET)\r
+X-Virus-Scanned: IMAP AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+       by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
+       port 10044)\r
+       with ESMTP id xfMwZc49rxFs; Sat, 27 Mar 2010 21:44:32 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id A35DC19F3420;\r
+       Sat, 27 Mar 2010 21:44:31 +0100 (CET)\r
+Received: from steelpick.2x.cz (r5da224.net.upc.cz [86.49.116.224])\r
+       (Authenticated sender: sojkam1)\r
+       by imap.feld.cvut.cz (Postfix) with ESMTPSA id 897DAFA003;\r
+       Sat, 27 Mar 2010 21:44:31 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.71)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1Nvcru-0001o1-9v; Sat, 27 Mar 2010 21:44:30 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Date: Sat, 27 Mar 2010 21:44:21 +0100\r
+Message-Id: <1269722661-6894-6-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 1.7.0.2\r
+In-Reply-To: <8739zlijhp.fsf@steelpick.2x.cz>\r
+References: <8739zlijhp.fsf@steelpick.2x.cz>\r
+Subject: [notmuch] [PATCH v3 6/6] Add 'cat' subcommand\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: Sat, 27 Mar 2010 20:44:43 -0000\r
+\r
+This command dumps raw message identified by filename to standard\r
+output. It uses mail store interface to get the message from the right\r
+place.\r
+\r
+notmuch.el was modified to use this command to access the raw message\r
+content (view/save attachments and view raw message).\r
+\r
+Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>\r
+---\r
+ emacs/notmuch.el |    8 +++++-\r
+ notmuch-client.h |    3 ++\r
+ notmuch-show.c   |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch.c        |    4 +++\r
+ 4 files changed, 75 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 117a365..38ba0e8 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -357,7 +357,11 @@ buffer."\r
+ (defun notmuch-show-view-raw-message ()\r
+   "View the raw email of the current message."\r
+   (interactive)\r
+-  (view-file (notmuch-show-get-filename)))\r
++  (let ((filename (notmuch-show-get-filename)))\r
++    (let ((buf (get-buffer-create (concat "*notmuch-raw-" filename "*"))))\r
++      (switch-to-buffer buf)\r
++      (save-excursion\r
++      (call-process notmuch-command nil t nil "cat" filename)))))\r
\r
+ (defmacro with-current-notmuch-show-message (&rest body)\r
+   "Evaluate body with current buffer set to the text of current message"\r
+@@ -365,7 +369,7 @@ buffer."\r
+      (let ((filename (notmuch-show-get-filename)))\r
+        (let ((buf (generate-new-buffer (concat "*notmuch-msg-" filename "*"))))\r
+          (with-current-buffer buf\r
+-           (insert-file-contents filename nil nil nil t)\r
++          (call-process notmuch-command nil t nil "cat" filename)\r
+            ,@body)\r
+        (kill-buffer buf)))))\r
\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index f5106cd..b9ddad2 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -107,6 +107,9 @@ notmuch_tag_command (void *ctx, int argc, char *argv[]);\r
+ int\r
+ notmuch_search_tags_command (void *ctx, int argc, char *argv[]);\r
\r
++int\r
++notmuch_cat_command (void *ctx, int argc, char *argv[]);\r
++\r
+ const char *\r
+ notmuch_time_relative_date (const void *ctx, time_t then);\r
\r
+diff --git a/notmuch-show.c b/notmuch-show.c\r
+index 0fcaacf..537d2e2 100644\r
+--- a/notmuch-show.c\r
++++ b/notmuch-show.c\r
+@@ -510,3 +510,65 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))\r
\r
+     return 0;\r
+ }\r
++\r
++int\r
++notmuch_cat_command (void *ctx, unused (int argc), unused (char *argv[]))\r
++{\r
++    notmuch_config_t *config;\r
++    notmuch_database_t *notmuch;\r
++    notmuch_mailstore_t *mailstore;\r
++    int i;\r
++    FILE *file;\r
++    const char *filename;\r
++    size_t size;\r
++    char buf[4096];\r
++\r
++    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
++/*    if (STRNCMP_LITERAL (argv[i], "--part=") == 0) { */\r
++/*        part = atoi(argv[i] + sizeof ("--part=") - 1); */\r
++/*    } else { */\r
++          fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
++/*        return 1; */\r
++/*    } */\r
++    }\r
++\r
++    argc -= i;\r
++    argv += i;\r
++\r
++    if (argc == 0) {\r
++      fprintf (stderr, "Error: No filename given\n");\r
++      return 1;\r
++    }\r
++    filename = argv[0];\r
++\r
++    config = notmuch_config_open (ctx, NULL, NULL);\r
++    if (config == NULL)\r
++      return 1;\r
++\r
++    mailstore = notmuch_config_get_mailstore (config);\r
++\r
++    if (mailstore == NULL) {\r
++      fprintf (stderr, "Error: I have no mailstore\n");\r
++      return 1;\r
++    }\r
++\r
++    notmuch = notmuch_database_open (notmuch_config_get_database_path (config),\r
++                                   NOTMUCH_DATABASE_MODE_READ_ONLY,\r
++                                   mailstore);\r
++\r
++    file = notmuch_mailstore_open_file(mailstore, filename);\r
++    if (file == NULL) {\r
++      fprintf (stderr, "Error: Cannot open %s in %s: %s\n", filename,\r
++               notmuch_mailstore_get_type (mailstore), strerror (errno));\r
++      return 1;\r
++    }\r
++    while  (!feof (file)) {\r
++      size = fread(buf, 1, sizeof(buf), file);\r
++      fwrite (buf, size, 1, stdout);\r
++    }\r
++    fclose (file);\r
++\r
++    notmuch_database_close (notmuch);\r
++\r
++    return 0;\r
++}\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 95f057e..f8bb8f5 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -294,6 +294,10 @@ command_t commands[] = {\r
+       "\t\tcontain tags only from messages that match the search-term(s).\n"\r
+       "\n"\r
+       "\t\tIn both cases the list will be alphabetically sorted." },\r
++    { "cat", notmuch_cat_command,\r
++      "<path>",\r
++      "\t\tDumps raw message identified by <path> to standard output.",\r
++      "\n" },\r
+     { "help", notmuch_help_command,\r
+       "[<command>]",\r
+       "\t\tThis message, or more detailed help for the named command.",\r
+-- \r
+1.7.0.2\r
+\r