[PATCH v2 10/20] insert: apply default tags to new message
Peter Wang
novalazy at gmail.com
Sat Nov 24 17:16:36 PST 2012
Apply the new.tags to messages added by 'insert'. This mirrors the
behaviour if the message were delivered by a separate tool followed by
'notmuch new'.
---
notmuch-insert.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/notmuch-insert.c b/notmuch-insert.c
index 022f7cd..362da66 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -170,13 +170,15 @@ copy_fd_data (int fdin, int fdout)
return TRUE;
}
-/* Add the specified message file to the notmuch database.
+/* Add the specified message file to the notmuch database, applying tags.
* The file is renamed to encode notmuch tags as maildir flags. */
static notmuch_bool_t
-add_file_to_database (notmuch_database_t *notmuch, const char *path)
+add_file_to_database (notmuch_database_t *notmuch, const char *path,
+ const char **new_tags)
{
notmuch_message_t *message;
notmuch_status_t status;
+ int i;
status = notmuch_database_add_message (notmuch, path, &message);
switch (status) {
@@ -201,6 +203,16 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path)
return FALSE;
}
+ notmuch_message_freeze (message);
+
+ /* Apply the new.tags, as would happen were the message added by
+ * 'notmuch new'. */
+ for (i = 0; new_tags[i]; i++) {
+ notmuch_message_add_tag (message, new_tags[i]);
+ }
+
+ notmuch_message_thaw (message);
+
notmuch_message_tags_to_maildir_flags (message);
notmuch_message_destroy (message);
@@ -210,7 +222,7 @@ add_file_to_database (notmuch_database_t *notmuch, const char *path)
static notmuch_bool_t
insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
- const char *dir)
+ const char *dir, const char **new_tags)
{
char *tmppath;
char *newpath;
@@ -231,7 +243,7 @@ insert_message (void *ctx, notmuch_database_t *notmuch, int fdin,
return FALSE;
}
- ret = add_file_to_database (notmuch, newpath);
+ ret = add_file_to_database (notmuch, newpath, new_tags);
if (!ret) {
/* XXX maybe there should be an option to keep the file in maildir? */
unlink (newpath);
@@ -247,6 +259,8 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
notmuch_config_t *config;
notmuch_database_t *notmuch;
const char *db_path;
+ const char **new_tags;
+ size_t new_tags_length;
const char *folder = NULL;
char *maildir;
int opt_index;
@@ -270,6 +284,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
return 1;
db_path = notmuch_config_get_database_path (config);
+ new_tags = notmuch_config_get_new_tags (config, &new_tags_length);
if (folder != NULL) {
if (! check_folder_name (folder)) {
@@ -289,7 +304,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much))
return 1;
- ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir);
+ ret = insert_message (ctx, notmuch, STDIN_FILENO, maildir, new_tags);
notmuch_database_destroy (notmuch);
--
1.7.12.1
More information about the notmuch
mailing list