unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/2] Add 'cat' subcommand
@ 2010-04-20  7:16 Michal Sojka
  2010-04-20  7:16 ` [PATCH 2/2] emacs: Access raw messages through cat subcommand Michal Sojka
  2010-04-20  7:21 ` [PATCH 1/2] Add 'cat' subcommand David Edmondson
  0 siblings, 2 replies; 16+ messages in thread
From: Michal Sojka @ 2010-04-20  7:16 UTC (permalink / raw)
  To: notmuch

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 <sojkam1@fel.cvut.cz>
---
 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,
+      "<path>",
+      "Dump raw message identified by path to standard output.",
+      "" },
     { "part", notmuch_part_command,
       "--part=<num> <search-terms>",
       "Output a single MIME part of a message.",
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread
* [PATCH 0/2] Notmuch cat v2
@ 2010-10-22  9:28 Michal Sojka
  2010-10-22  9:28 ` [PATCH 1/2] Add 'cat' subcommand Michal Sojka
  0 siblings, 1 reply; 16+ messages in thread
From: Michal Sojka @ 2010-10-22  9:28 UTC (permalink / raw)
  To: notmuch

Hi all,

this is my second attempt to implement notmuch cat subcommand (the
first version was posted in
id:1271747793-17507-1-git-send-email-sojkam1@fel.cvut.cz). This
subcommand outputs the given message to stdout.

In this version the arguments are classical notmuch search terms and
not a filename as in the previous version. Emacs interface then uses
message-id to retrieve the message.

Some people suggested that cat could be implemented as a special
format of show subcommand. That would be possible, but it seems that
show command always constructs threads form the messages which means
that is executes several database queries. I consider this as
unnecessary overhead and for that reason cat is a separate subcommand.

Michal Sojka (2):
  Add 'cat' subcommand
  emacs: Access raw messages via cat subcommand

 emacs/notmuch-show.el |   14 +++++---
 notmuch-client.h      |    3 ++
 notmuch-show.c        |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 notmuch.1             |    4 ++
 notmuch.c             |    4 ++
 test/cat              |   38 ++++++++++++++++++++++
 test/notmuch-test     |    2 +-
 7 files changed, 142 insertions(+), 6 deletions(-)
 create mode 100755 test/cat

-- 
1.7.2.3

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-10-22  9:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-20  7:16 [PATCH 1/2] Add 'cat' subcommand Michal Sojka
2010-04-20  7:16 ` [PATCH 2/2] emacs: Access raw messages through cat subcommand Michal Sojka
2010-04-20  7:21 ` [PATCH 1/2] Add 'cat' subcommand David Edmondson
2010-04-20  8:09   ` Sebastian Spaeth
2010-04-20 10:14     ` Michal Sojka
2010-04-20 10:53       ` David Edmondson
2010-04-20 11:13         ` Michal Sojka
2010-04-20 11:30           ` David Edmondson
2010-04-20 13:32       ` Jameson Rollins
2010-04-22  0:44       ` Carl Worth
2010-04-22  2:37         ` Dirk Hohndel
2010-04-22  3:13           ` Anthony Towns
2010-04-22  6:57             ` Michal Sojka
2010-04-22  6:38         ` Michal Sojka
2010-04-23 19:07           ` Carl Worth
  -- strict thread matches above, loose matches on Subject: below --
2010-10-22  9:28 [PATCH 0/2] Notmuch cat v2 Michal Sojka
2010-10-22  9:28 ` [PATCH 1/2] Add 'cat' subcommand Michal Sojka

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).