X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.c;h=f9d66297f044971b034521d2e5c916b4a5aee77f;hp=2e98f25d1e2aa9fea9e870099dcf2d96939e6dad;hb=bff30540d86c77aacbc2c133c83aa7ccee823b48;hpb=2f8871df6ea3c0b44f85a0fc1b4f58a6b70b0a0e diff --git a/notmuch.c b/notmuch.c index 2e98f25d..f9d66297 100644 --- a/notmuch.c +++ b/notmuch.c @@ -32,11 +32,23 @@ typedef struct command { const char *documentation; } command_t; +#define MAX_ALIAS_SUBSTITUTIONS 3 + +typedef struct alias { + const char *name; + const char *substitutions[MAX_ALIAS_SUBSTITUTIONS]; +} alias_t; + +alias_t aliases[] = { + { "part", { "show", "--format=raw"}}, + { "search-tags", {"search", "--output=tags", "*"}} +}; + static int notmuch_help_command (void *ctx, int argc, char *argv[]); static const char search_terms_help[] = - "\tSeveral notmuch commands accept a comman syntax for search\n" + "\tSeveral notmuch commands accept a common syntax for search\n" "\tterms.\n" "\n" "\tThe search terms can consist of free-form text (and quoted\n" @@ -115,7 +127,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 +242,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 +274,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\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\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 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" @@ -277,6 +294,22 @@ command_t commands[] = { "\t\tmessage MIME structure, and are identified in the 'json' or\n" "\t\t'text' output formats.\n" "\n" + "\t--verify\n" + "\n" + "\t\tCompute and report the validity of any MIME cryptographic\n" + "\t\tsignatures found in the selected content (ie.\n" + "\t\t\"multipart/signed\" parts). Status of the signature will be\n" + "\t\treported (currently only supported with --format=json) and\n" + "\t\tthe multipart/signed part will be replaced by the signed data.\n" + "\n" + "\t--decrypt\n" + "\n" + "\t\tDecrypt any MIME encrypted parts found in the selected content\n" + "\t\t(ie. \"multipart/encrypted\" parts). Status of the decryption\n" + "\t\twill be reported (currently only supported with --format=json)\n" + "\t\tand the multipart/encrypted part will be replaced by the\n" + "\t\tdecrypted content.\n" + "\n" "\n" "\tA common use of \"notmuch show\" is to display a single\n" "\tthread of email messages. For this, use a search term of\n" @@ -358,15 +391,6 @@ command_t commands[] = { "\tSo if you've previously been using sup for mail, then the\n" "\t\"notmuch restore\" command provides you a way to import\n" "\tall of your tags (or labels as sup calls them)." }, - { "search-tags", notmuch_search_tags_command, - "[ [...] ]", - "List all tags found in the database or matching messages.", - "\tRun this command without any search-term(s) to obtain a list\n" - "\tof all tags found in the database. If you provide one or more\n" - "\tsearch-terms as argument(s) then the resulting list will\n" - "\tcontain tags only from messages that match the search-term(s).\n" - "\n" - "\tIn both cases the list will be alphabetically sorted." }, { "config", notmuch_config_command, "[get|set]
. [value ...]", "Get or set settings in the notmuch configuration file.", @@ -546,13 +570,16 @@ 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 (); local = talloc_new (NULL); g_mime_init (0); + g_type_init (); if (argc == 1) return notmuch (local); @@ -565,6 +592,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];