]> rtime.felk.cvut.cz Git - notmuch.git/commitdiff
Add 'cat' subcommand
authorMichal Sojka <sojkam1@fel.cvut.cz>
Mon, 19 Apr 2010 20:22:44 +0000 (22:22 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Tue, 20 Apr 2010 06:39:13 +0000 (08:39 +0200)
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.

NEWS
notmuch-client.h
notmuch-show.c
notmuch.c

diff --git a/NEWS b/NEWS
index eba0fd5ae5cb5c7f2121827d7e6bcffba16f91b8..1a81e64a4e611543140e91c585e098475c89e47d 100644 (file)
--- 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
index d36b9ec16ce4aba89c782489b0ad91057fb34c8a..0efc41cab7c5c840cfca13729f85ec86a1e67a71 100644 (file)
@@ -110,6 +110,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[]);
+
 int
 notmuch_part_command (void *ctx, int argc, char *argv[]);
 
index 76873a1d9036337868811659c99bb105ad371dfe..bade9bb2aa5e9cafa993fb4fe7933e1fd8c146c5 100644 (file)
@@ -503,6 +503,45 @@ 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[]))
+{
+    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[]))
 {
index 0eea5e11f20c49af89587aaddaa171fd6361c7c0..477d746767c317ffb2da59663918e368e2bfa09a 100644 (file)
--- 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.",