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[]);
"\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.",
"\t\teasily-parsed markers. Each marker consists of a Control-L\n"
"\t\tcharacter (ASCII decimal 12), the name of the marker, and\n"
"\t\tthen either an opening or closing brace, '{' or '}' to\n"
- "\t\teither open or close the component.\n"
+ "\t\teither open or close the component. For a multipart MIME\n"
+ "\t\tmessage, these parts will be nested.\n"
"\n"
"\t\tjson\n"
"\n"
"\t\tThe output is formatted with Javascript Object Notation\n"
"\t\t(JSON). This format is more robust than the text format\n"
- "\t\tfor automated processing. JSON output always includes all\n"
- "\t\tmessages in a matching thread; in effect '--format=json'\n"
- "\t\timplies '--entire-thread'\n"
+ "\t\tfor automated processing. The nested structure of multipart\n"
+ "\t\tMIME messages is reflected in nested JSON output. JSON\n"
+ "\t\toutput always includes all messages in a matching thread;\n"
+ "\t\tin effect '--format=json' implies '--entire-thread'\n"
"\n"
"\t\tmbox\n"
"\n"
"\t\tdecoding and similar functions. This format must only\n"
"\t\tbe used with search terms matching a single message.\n"
"\n"
+ "\t--part=N\n"
+ "\n"
+ "\t\tOutput the single decoded MIME part N of a single message.\n"
+ "\t\tThe search terms must match only a single message.\n"
+ "\t\tMessage parts are numbered in a depth-first walk of the\n"
+ "\t\tmessage MIME structure, and are identified in the 'json' or\n"
+ "\t\t'text' output formats.\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"
"\t\"thread:<thread-id>\" as can be seen in the first column\n"
"\tcontain tags only from messages that match the search-term(s).\n"
"\n"
"\tIn both cases the list will be alphabetically sorted." },
- { "part", notmuch_part_command,
- "--part=<num> <search-terms>",
- "Output a single MIME part of a message.",
- "\tA single decoded MIME part, with no encoding or framing,\n"
- "\tis output to stdout. The search terms must match only a single\n"
- "\tmessage, otherwise this command will fail.\n"
- "\n"
- "\tThe part number should match the part \"id\" field output\n"
- "\tby the \"--format=json\" option of \"notmuch show\". If the\n"
- "\tmessage specified by the search terms does not include a\n"
- "\tpart with the specified \"id\" there will be no output." },
{ "config", notmuch_config_command,
"[get|set] <section>.<item> [value ...]",
"Get or set settings in the notmuch configuration file.",
{
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);
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];