]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch show: Add body of message as well.
authorCarl Worth <cworth@cworth.org>
Thu, 29 Oct 2009 16:06:53 +0000 (09:06 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 29 Oct 2009 16:06:53 +0000 (09:06 -0700)
This is just the raw message body for now, (so any MIME parsing will
be up to the consumer). And this will likely change in the future.

message-file.c
message.cc
notmuch-private.h
notmuch.c
notmuch.h

index e8e2843e225be9b3f45a0dcd823d72446e6635a8..0b39dc43e5dc13f127d7e99de4d8258a4c965acf 100644 (file)
@@ -343,8 +343,8 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
     return NULL;
 }
 
-static size_t
-_notmuch_message_file_get_header_size (notmuch_message_file_t *message)
+size_t
+notmuch_message_file_get_header_size (notmuch_message_file_t *message)
 {
     if (! message->parsing_finished)
        notmuch_message_file_get_header (message, NULL);
@@ -359,7 +359,7 @@ const char *
 notmuch_message_file_get_all_headers (notmuch_message_file_t *message)
 {
     char *headers = NULL;
-    size_t header_size = _notmuch_message_file_get_header_size (message);
+    size_t header_size = notmuch_message_file_get_header_size (message);
 
     if (header_size == 0)
        return "";
index dfd55d596e21af0cac4d79416f9029644a5f4d75..e2f1cd31843541f43002cd77eb0bc4576ca7ade4 100644 (file)
@@ -267,6 +267,17 @@ notmuch_message_get_all_headers (notmuch_message_t *message)
     return notmuch_message_file_get_all_headers (message->message_file);
 }
 
+size_t
+notmuch_message_get_header_size (notmuch_message_t *message)
+{
+    _notmuch_message_ensure_message_file (message);
+    if (message->message_file == NULL)
+       return 0;
+
+    return notmuch_message_file_get_header_size (message->message_file);
+
+}
+
 const char *
 notmuch_message_get_thread_id (notmuch_message_t *message)
 {
index 39d5e7579e7c88e2baab30d20044409b845678f1..b67aa9051b85eea1991a46da38089ecabba0096b 100644 (file)
@@ -291,6 +291,13 @@ notmuch_message_file_get_header (notmuch_message_file_t *message,
 const char *
 notmuch_message_file_get_all_headers (notmuch_message_file_t *message);
 
+/* Get the size in bytes of the full header section of 'message'.
+ *
+ * Returns 0 in the case of any error.
+ */
+size_t
+notmuch_message_file_get_header_size (notmuch_message_file_t *message);
+
 /* date.c */
 
 /* Parse an RFC 8222 date string to a time_t value.
index 66b615b2285605cd712852e3eb2060365028d43d..f47e4fcbb65d6ddf805ecbedb07c4fa61a097861 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -806,7 +806,10 @@ show_command (unused (int argc), unused (char *argv[]))
     notmuch_query_t *query = NULL;
     notmuch_message_results_t *messages;
     notmuch_message_t *message;
+    const char *filename;
+    FILE *file;
     int ret = 0;
+    int c;
 
     if (argc != 1) {
        fprintf (stderr, "Error: \"notmuch show\" requires exactly one thread-ID argument.\n");
@@ -847,6 +850,22 @@ show_command (unused (int argc), unused (char *argv[]))
        printf ("%s", notmuch_message_get_all_headers (message));
 
        printf ("%%header}\n");
+
+       filename = notmuch_message_get_filename (message);
+
+       file = fopen (filename, "r");
+       if (file) {
+           size_t header_size = notmuch_message_get_header_size (message);
+           fseek (file, header_size + 1, SEEK_SET);
+           while (1) {
+               c = fgetc (file);
+               if (c == EOF)
+                   break;
+               putchar (c);
+           }
+       }
+       fclose (file);
+
        printf ("%%message}\n");
 
        notmuch_message_destroy (message);
@@ -1206,7 +1225,6 @@ command_t commands[] = {
       "\t\tmarks around any parenthesized expression)." },
     { "show", show_command,
       "<thread-id>\n\n"
-      "\t\tNote: The \"notmuch show\" command is not implemented yet.\n\n"
       "\t\tShow the thread with the given thread ID (see 'search').",
       "\t\tThread ID values are given as the first column in the\n"
       "\t\toutput of the \"notmuch search\" command. These are the\n"
index a17c7020177a5cff0844db28abe30b952e919542..d25f277c87776028411f783b6bec40142d2322d8 100644 (file)
--- a/notmuch.h
+++ b/notmuch.h
@@ -617,6 +617,16 @@ notmuch_message_get_thread_id (notmuch_message_t *message);
 const char *
 notmuch_message_get_filename (notmuch_message_t *message);
 
+/* Get the size in bytes of the full header section of 'message'.
+ *
+ * This is useful in conjunction with notmuch_message_get_filename
+ * for separately parsing the message header and content.
+ *
+ * Returns 0 in the case of any error.
+ */
+size_t
+notmuch_message_get_header_size (notmuch_message_t *message);
+
 /* Get the value of the specified header from 'message'.
  *
  * The value will be read from the actual message file, not from the