]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
test: Expand multipart test to cover "notmuch reply" as well
[notmuch] / notmuch.c
index 2e98f25d1e2aa9fea9e870099dcf2d96939e6dad..9bb884712dbb86a6dc245219f2d4495dc3faf464 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -32,6 +32,17 @@ typedef struct command {
     const char *documentation;
 } command_t;
 
+#define MAX_ALIAS_SUBSTITUTIONS 2
+
+typedef struct alias {
+    const char *name;
+    const char *substitutions[MAX_ALIAS_SUBSTITUTIONS];
+} alias_t;
+
+alias_t aliases[] = {
+    { "part", { "show", "--format=raw"}}
+};
+
 static int
 notmuch_help_command (void *ctx, int argc, char *argv[]);
 
@@ -115,7 +126,7 @@ static const char search_terms_help[] =
     "\n"
     "\t\t$(date +%%s -d 2009-10-01)..$(date +%%s)\n\n";
 
-command_t commands[] = {
+static command_t commands[] = {
     { "setup", notmuch_setup_command,
       NULL,
       "Interactively setup notmuch for first use.",
@@ -230,7 +241,7 @@ command_t commands[] = {
       "\n"
       "\t--format=(text|json|mbox|raw)\n"
       "\n"
-      "\t\ttext (default)\n"
+      "\t\ttext (default for messages)\n"
       "\n"
       "\t\tThe default plain-text format has all text-content MIME parts\n"
       "\t\tdecoded. Various components in the output, ('message', 'header',\n"
@@ -262,12 +273,17 @@ command_t commands[] = {
       "\n"
       "\t\thttp://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html\n"
       "\n"
-      "\t\traw\n"
+      "\t\traw (default for a single part, see --part)\n"
       "\n"
-      "\t\tThe original, raw content of the email message is displayed.\n"
-      "\t\tConsumers of this format should expect to implement MIME\n"
-      "\t\tdecoding and similar functions. This format must only\n"
-      "\t\tbe used with search terms matching a single message.\n"
+      "\t\tFor a message, the original, raw content of the email\n"
+      "\t\tmessage is output. Consumers of this format should\n"
+      "\t\texpect to implement MIME decoding and similar functions.\n"
+      "\n"
+      "\t\tFor a single part (--part) the raw part content is output\n"
+      "\t\tafter performing any necessary MIME decoding.\n"
+      "\n"
+      "\t\tThe raw format must only be used with search terms matching\n"
+      "\t\tsingle message.\n"
       "\n"
       "\t--part=N\n"
       "\n"
@@ -546,7 +562,9 @@ main (int argc, char *argv[])
 {
     void *local;
     command_t *command;
-    unsigned int i;
+    alias_t *alias;
+    unsigned int i, j;
+    const char **argv_local;
 
     talloc_enable_null_tracking ();
 
@@ -565,6 +583,40 @@ main (int argc, char *argv[])
        return 0;
     }
 
+    for (i = 0; i < ARRAY_SIZE (aliases); i++) {
+       alias = &aliases[i];
+
+       if (strcmp (argv[1], alias->name) == 0)
+       {
+           int substitutions;
+
+           argv_local = talloc_size (local, sizeof (char *) *
+                                     (argc + MAX_ALIAS_SUBSTITUTIONS - 1));
+           if (argv_local == NULL) {
+               fprintf (stderr, "Out of memory.\n");
+               return 1;
+           }
+
+           /* Copy all substution arguments from the alias. */
+           argv_local[0] = argv[0];
+           for (j = 0; j < MAX_ALIAS_SUBSTITUTIONS; j++) {
+               if (alias->substitutions[j] == NULL)
+                   break;
+               argv_local[j+1] = alias->substitutions[j];
+           }
+           substitutions = j;
+
+           /* And copy all original arguments (skipping the argument
+            * that matched the alias of course. */
+           for (j = 2; j < (unsigned) argc; j++) {
+               argv_local[substitutions+j-1] = argv[j];
+           }
+
+           argc += substitutions - 1;
+           argv = (char **) argv_local;
+       }
+    }
+
     for (i = 0; i < ARRAY_SIZE (commands); i++) {
        command = &commands[i];