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