]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.c
Fix double free in guess_from_received_header().
[notmuch] / notmuch.c
index e92f14c546daaeb88a933432bd193fec17138bd8..93f319442c20a24dbf57497de9c4e9d02fc717e5 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -32,6 +32,18 @@ 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[]);
 
@@ -58,6 +70,7 @@ static const char search_terms_help[] =
     "\t\ttag:<tag> (or is:<tag>)\n"
     "\t\tid:<message-id>\n"
     "\t\tthread:<thread-id>\n"
+    "\t\tfolder:<directory-path>\n"
     "\n"
     "\tThe from: prefix is used to match the name or address of\n"
     "\tthe sender of an email message.\n"
@@ -82,6 +95,11 @@ static const char search_terms_help[] =
     "\tmessages). These thread ID values can be seen in the first\n"
     "\tcolumn of output from \"notmuch search\".\n"
     "\n"
+    "\tThe folder: prefix can be used to search for email message\n"
+    "\tfiles that are contained within particular directories within\n"
+    "\tthe mail store. Only the directory components below the top-level\n"
+    "\tmail database path are available to be searched.\n"
+    "\n"
     "\tIn addition to individual terms, multiple terms can be\n"
     "\tcombined with Boolean operators (\"and\", \"or\", \"not\", etc.).\n"
     "\tEach term in the query will be implicitly connected by a\n"
@@ -109,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.",
@@ -165,7 +183,7 @@ command_t commands[] = {
       "\t\tPresents the results in either JSON or\n"
       "\t\tplain-text (default)\n"
       "\n"
-      "\t--output=(summary|threads|messages|tags)\n"
+      "\t--output=(summary|threads|messages|files|tags)\n"
       "\n"
       "\t\tsummary (default)\n"
       "\n"
@@ -186,6 +204,12 @@ command_t commands[] = {
       "\t\tterms, either one per line (--format=text) or as a JSON array\n"
       "\t\t(--format=json).\n"
       "\n"
+      "\t\tfiles\n"
+      "\n"
+      "\t\tOutput the filenames of all messages matching the search\n"
+      "\t\tterms, either one per line (--format=text) or as a JSON array\n"
+      "\t\t(--format=json).\n"
+      "\n"
       "\t\ttags\n"
       "\n"
       "\t\tOutput all tags that appear on any message matching the search\n"
@@ -216,9 +240,9 @@ command_t commands[] = {
       "\t\tall messages in the same thread as any matched\n"
       "\t\tmessage will be displayed.\n"
       "\n"
-      "\t--format=(text|json|mbox)\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"
@@ -226,15 +250,17 @@ command_t commands[] = {
       "\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"
@@ -248,6 +274,43 @@ command_t commands[] = {
       "\n"
       "\t\thttp://homepage.ntlworld.com/jonathan.deboynepollard/FGA/mail-mbox-formats.html\n"
       "\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\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"
+      "\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"
+      "\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"
       "\t\"thread:<thread-id>\" as can be seen in the first column\n"
@@ -328,26 +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,
-      "[<search-terms> [...] ]",
-      "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." },
-    { "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.",
@@ -527,7 +570,11 @@ 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);
 
@@ -544,6 +591,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];