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 529AE4196F2 for ; Tue, 20 Apr 2010 00:16:39 -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 CBDtwRkU1P5h for ; Tue, 20 Apr 2010 00:16:36 -0700 (PDT) Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36]) by olra.theworths.org (Postfix) with ESMTP id 3E93C431FC1 for ; Tue, 20 Apr 2010 00:16:36 -0700 (PDT) Received: from localhost (unknown [192.168.200.4]) by max.feld.cvut.cz (Postfix) with ESMTP id 580D319F333C for ; Tue, 20 Apr 2010 09:16:35 +0200 (CEST) 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 npSYaBTh2DUN for ; Tue, 20 Apr 2010 09:16:33 +0200 (CEST) Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34]) by max.feld.cvut.cz (Postfix) with ESMTP id E5A3419F3349 for ; Tue, 20 Apr 2010 09:16:33 +0200 (CEST) Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30]) (Authenticated sender: sojkam1) by imap.feld.cvut.cz (Postfix) with ESMTPSA id E07EEFA003 for ; Tue, 20 Apr 2010 09:16:33 +0200 (CEST) Received: from wsh by steelpick.2x.cz with local (Exim 4.71) (envelope-from ) id 1O47hB-0004Yt-Ii for notmuch@notmuchmail.org; Tue, 20 Apr 2010 09:16:33 +0200 From: Michal Sojka To: notmuch@notmuchmail.org Subject: [PATCH 1/2] Add 'cat' subcommand Date: Tue, 20 Apr 2010 09:16:32 +0200 Message-Id: <1271747793-17507-1-git-send-email-sojkam1@fel.cvut.cz> X-Mailer: git-send-email 1.7.0.4 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: Tue, 20 Apr 2010 07:16:39 -0000 This command dumps a raw message identified by a filename to the standard output. It allows MUAs to access the messages for piping, attachment manipulation, etc. in the same way as it is done in notmuch-show-mode (through notmuch show subcommand). This will simplify the MUAs when they need to operate with a remote database. Signed-off-by: Michal Sojka --- NEWS | 3 +++ notmuch-client.h | 3 +++ notmuch-show.c | 39 +++++++++++++++++++++++++++++++++++++++ notmuch.c | 4 ++++ 4 files changed, 49 insertions(+), 0 deletions(-) diff --git a/NEWS b/NEWS index eba0fd5..1a81e64 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +A new subcommand 'cat' was added, which simplifies use of Emacs +interface with remote database (accessed over SSH). + Notmuch 0.2 (2010-04-16) ======================== This is the second release of the notmuch mail system, with actual diff --git a/notmuch-client.h b/notmuch-client.h index d36b9ec..0efc41c 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -111,6 +111,9 @@ int notmuch_search_tags_command (void *ctx, int argc, char *argv[]); int +notmuch_cat_command (void *ctx, int argc, char *argv[]); + +int notmuch_part_command (void *ctx, int argc, char *argv[]); const char * diff --git a/notmuch-show.c b/notmuch-show.c index 76873a1..bade9bb 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -504,6 +504,45 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[])) } int +notmuch_cat_command (void *ctx, unused (int argc), unused (char *argv[])) +{ + int i; + FILE *file; + const char *filename; + size_t size; + char buf[4096]; + + (void)ctx; + + for (i = 0; i < argc && argv[i][0] == '-'; i++) { + 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]; + + file = fopen (filename, "r"); + if (file == NULL) { + fprintf (stderr, "Error: Cannot open %s: %s\n", filename, strerror (errno)); + return 1; + } + while (!feof (file)) { + size = fread(buf, 1, sizeof(buf), file); + fwrite (buf, size, 1, stdout); + } + fclose (file); + + return 0; +} + +int notmuch_part_command (void *ctx, unused (int argc), unused (char *argv[])) { notmuch_config_t *config; diff --git a/notmuch.c b/notmuch.c index 0eea5e1..477d746 100644 --- a/notmuch.c +++ b/notmuch.c @@ -296,6 +296,10 @@ command_t commands[] = { "\tcontain tags only from messages that match the search-term(s).\n" "\n" "\tIn both cases the list will be alphabetically sorted." }, + { "cat", notmuch_cat_command, + "", + "Dump raw message identified by path to standard output.", + "" }, { "part", notmuch_part_command, "--part= ", "Output a single MIME part of a message.", -- 1.7.0.4