Allow the new message to be inserted into a folder within the Maildir
hierarchy instead of the top-level folder.
---
 notmuch-insert.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/notmuch-insert.c b/notmuch-insert.c
index b0ac174..ba8cf5a 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -236,11 +236,25 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
     size_t new_tags_length;
     tag_op_list_t *tag_ops;
     char *query_string = NULL;
+    const char *folder = NULL;
     char *maildir;
-    int opt_index = 1;
+    int opt_index;
     unsigned int i;
     notmuch_bool_t ret;

+    notmuch_opt_desc_t options[] = {
+       { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
+       { NOTMUCH_OPT_END, 0, 0, 0, 0 }
+    };
+
+    opt_index = parse_arguments (argc, argv, options, 1);
+
+    if (opt_index < 0) {
+       fprintf (stderr, "Error: bad argument to notmuch insert: %s\n",
+                argv[-opt_index]);
+       return 1;
+    }
+
     config = notmuch_config_open (ctx, NULL, NULL);
     if (config == NULL)
        return 1;
@@ -267,7 +281,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
        return 1;
     }

-    maildir = talloc_asprintf (ctx, "%s", db_path);
+    if (folder != NULL) {
+       maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder);
+    } else {
+       maildir = talloc_asprintf (ctx, "%s", db_path);
+    }
     if (! maildir) {
        fprintf (stderr, "Out of memory\n");
        return 1;
-- 
1.7.12.1

Reply via email to