<p><br>
On Oct 26, 2012 8:46 AM, "Taesoo Kim" <<a href="mailto:taesoo@mit.edu">taesoo@mit.edu</a>> wrote:<br>
><br>
> Since gmail will provide labels as imap sub/folders, notmuch also can<br>
> take advantage of labels as tags, when maildir.add_as_tag_flags is<br>
> specified.</p>
<p>Why not use the folder: prefix? What does your patch do that can't be achieved with that?</p>
<p>BR,<br>
Jani.<br></p>
<p>><br>
> Signed-off-by: Taesoo Kim <<a href="mailto:taesoo@mit.edu">taesoo@mit.edu</a>><br>
> ---<br>
> notmuch-client.h | 7 +++++++<br>
> notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++----<br>
> notmuch-new.c | 32 ++++++++++++++++++++++++++++++++<br>
> 3 files changed, 77 insertions(+), 4 deletions(-)<br>
><br>
> diff --git a/notmuch-client.h b/notmuch-client.h<br>
> index ae9344b..ce05e52 100644<br>
> --- a/notmuch-client.h<br>
> +++ b/notmuch-client.h<br>
> @@ -265,6 +265,13 @@ void<br>
> notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,<br>
> notmuch_bool_t synchronize_flags);<br>
><br>
> +notmuch_bool_t<br>
> +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config);<br>
> +<br>
> +void<br>
> +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,<br>
> + notmuch_bool_t add_as_tag_flags);<br>
> +<br>
> const char **<br>
> notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length);<br>
><br>
> diff --git a/notmuch-config.c b/notmuch-config.c<br>
> index 3e37a2d..c95f9dd 100644<br>
> --- a/notmuch-config.c<br>
> +++ b/notmuch-config.c<br>
> @@ -88,7 +88,16 @@ static const char maildir_config_comment[] =<br>
> "\n"<br>
> "\tThe \"notmuch new\" command will notice flag changes in filenames\n"<br>
> "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n"<br>
> - "\tcommands will notice tag changes and update flags in filenames\n";<br>
> + "\tcommands will notice tag changes and update flags in filenames\n"<br>
> + "\n"<br>
> + "\tadd_as_tag_flags Valid values are true and false.\n"<br>
> + "\n"<br>
> + "\nIf ture, then add the lower-cased name of maildirs"<br>
> + "\n(also deliminated by .) as tags"<br>
> + "\n"<br>
> + "\n\te.g. Life -> life"<br>
> + "\n\te.g. MIT.CSAIL -> mit, csail"<br>
> + "\n\te.g. Mailing.OSS.Linux -> mailing, oss, linux";<br>
><br>
> static const char search_config_comment[] =<br>
> " Search configuration\n"<br>
> @@ -114,6 +123,7 @@ struct _notmuch_config {<br>
> const char **new_ignore;<br>
> size_t new_ignore_length;<br>
> notmuch_bool_t maildir_synchronize_flags;<br>
> + notmuch_bool_t maildir_add_as_tag_flags;<br>
> const char **search_exclude_tags;<br>
> size_t search_exclude_tags_length;<br>
> };<br>
> @@ -251,7 +261,7 @@ notmuch_config_open (void *ctx,<br>
> fprintf (stderr, "Out of memory.\n");<br>
> return NULL;<br>
> }<br>
> -<br>
> +<br>
> talloc_set_destructor (config, notmuch_config_destructor);<br>
><br>
> if (filename) {<br>
> @@ -393,6 +403,14 @@ notmuch_config_open (void *ctx,<br>
> g_error_free (error);<br>
> }<br>
><br>
> + config->maildir_add_as_tag_flags =<br>
> + g_key_file_get_boolean (config->key_file,<br>
> + "maildir", "add_as_tag_flags", &error);<br>
> + if (error) {<br>
> + notmuch_config_set_maildir_add_as_tag_flags (config, FALSE);<br>
> + g_error_free (error);<br>
> + }<br>
> +<br>
> /* Whenever we know of configuration sections that don't appear in<br>
> * the configuration file, we add some comments to help the user<br>
> * understand what can be done. */<br>
> @@ -438,7 +456,7 @@ notmuch_config_open (void *ctx,<br>
> }<br>
><br>
> /* Close the given notmuch_config_t object, freeing all resources.<br>
> - *<br>
> + *<br>
> * Note: Any changes made to the configuration are *not* saved by this<br>
> * function. To save changes, call notmuch_config_save before<br>
> * notmuch_config_close.<br>
> @@ -720,7 +738,7 @@ notmuch_config_command_get (void *ctx, char *item)<br>
> } else if (strcmp(item, "user.other_email") == 0) {<br>
> const char **other_email;<br>
> size_t i, length;<br>
> -<br>
> +<br>
> other_email = notmuch_config_get_user_other_email (config, &length);<br>
> for (i = 0; i < length; i++)<br>
> printf ("%s\n", other_email[i]);<br>
> @@ -891,3 +909,19 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,<br>
> "maildir", "synchronize_flags", synchronize_flags);<br>
> config->maildir_synchronize_flags = synchronize_flags;<br>
> }<br>
> +<br>
> +<br>
> +notmuch_bool_t<br>
> +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config)<br>
> +{<br>
> + return config->maildir_add_as_tag_flags;<br>
> +}<br>
> +<br>
> +void<br>
> +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,<br>
> + notmuch_bool_t add_as_tag_flags)<br>
> +{<br>
> + g_key_file_set_boolean (config->key_file,<br>
> + "maildir", "add_as_tag_flags", add_as_tag_flags);<br>
> + config->maildir_add_as_tag_flags = add_as_tag_flags;<br>
> +}<br>
> diff --git a/notmuch-new.c b/notmuch-new.c<br>
> index 56c4a6f..9ec983f 100644<br>
> --- a/notmuch-new.c<br>
> +++ b/notmuch-new.c<br>
> @@ -20,6 +20,7 @@<br>
><br>
> #include "notmuch-client.h"<br>
><br>
> +#include <ctype.h><br>
> #include <unistd.h><br>
><br>
> typedef struct _filename_node {<br>
> @@ -53,6 +54,7 @@ typedef struct {<br>
> _filename_list_t *directory_mtimes;<br>
><br>
> notmuch_bool_t synchronize_flags;<br>
> + notmuch_bool_t add_as_tag_flags;<br>
> } add_files_state_t;<br>
><br>
> static volatile sig_atomic_t do_print_progress = 0;<br>
> @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state)<br>
> return FALSE;<br>
> }<br>
><br>
> +static void<br>
> +_add_maildir_as_tag(notmuch_database_t *notmuch,<br>
> + notmuch_message_t *msg, const char *path)<br>
> +{<br>
> + char *tok = talloc_strdup (notmuch, path);<br>
> + int len = strlen(tok);<br>
> +<br>
> + /* asserts path ends with /cur|/tmp|/new */<br>
> + if (len > 4 && tok[len - 4] == '/') {<br>
> + char *iter = tok + len - 4;<br>
> + *iter = '\0';<br>
> + while (-- iter && iter >= tok) {<br>
> + char c = *iter;<br>
> + if (c == '/' || c == '.') {<br>
> + *iter = '\0';<br>
> + notmuch_message_add_tag (msg, iter + 1);<br>
> + if (c == '/') {<br>
> + break;<br>
> + }<br>
> + }<br>
> + *iter = tolower(*iter);<br>
> + }<br>
> + }<br>
> + talloc_free (tok);<br>
> +}<br>
> +<br>
> /* Examine 'path' recursively as follows:<br>
> *<br>
> * o Ask the filesystem for the mtime of 'path' (fs_mtime)<br>
> @@ -508,6 +536,9 @@ add_files (notmuch_database_t *notmuch,<br>
> notmuch_message_freeze (message);<br>
> for (tag=state->new_tags; *tag != NULL; tag++)<br>
> notmuch_message_add_tag (message, *tag);<br>
> + if (state->add_as_tag_flags == TRUE) {<br>
> + _add_maildir_as_tag(notmuch, message, path);<br>
> + }<br>
> if (state->synchronize_flags == TRUE)<br>
> notmuch_message_maildir_flags_to_tags (message);<br>
> notmuch_message_thaw (message);<br>
> @@ -878,6 +909,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])<br>
> add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);<br>
> add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);<br>
> add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);<br>
> + add_files_state.add_as_tag_flags = notmuch_config_get_maildir_add_as_tag_flags (config);<br>
> db_path = notmuch_config_get_database_path (config);<br>
><br>
> if (run_hooks) {<br>
> --<br>
> 1.8.0<br>
><br>
> _______________________________________________<br>
> notmuch mailing list<br>
> <a href="mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a><br>
> <a href="http://notmuchmail.org/mailman/listinfo/notmuch">http://notmuchmail.org/mailman/listinfo/notmuch</a><br>
</p>