Re: [PATCH 1/2] Automatic tagging based on maildir
authorJani Nikula <jani@nikula.org>
Fri, 26 Oct 2012 17:14:31 +0000 (20:14 +0300)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:03 +0000 (09:50 -0800)
29/c7d3a6196ee4965d743e0a70c205e93bc354a1 [new file with mode: 0644]

diff --git a/29/c7d3a6196ee4965d743e0a70c205e93bc354a1 b/29/c7d3a6196ee4965d743e0a70c205e93bc354a1
new file mode 100644 (file)
index 0000000..1eea194
--- /dev/null
@@ -0,0 +1,581 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 61B72431FAF\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 10:14:34 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ZqzrwqcPbOGl for <notmuch@notmuchmail.org>;\r
+       Fri, 26 Oct 2012 10:14:33 -0700 (PDT)\r
+Received: from mail-ob0-f181.google.com (mail-ob0-f181.google.com\r
+       [209.85.214.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id F35FC431FAE\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 10:14:32 -0700 (PDT)\r
+Received: by mail-ob0-f181.google.com with SMTP id un3so3081399obb.26\r
+       for <notmuch@notmuchmail.org>; Fri, 26 Oct 2012 10:14:31 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=google.com; s=20120113;\r
+       h=mime-version:in-reply-to:references:date:message-id:subject:from:to\r
+       :cc:content-type:x-gm-message-state;\r
+       bh=VP7UzhUSvG9AYMn9UO4VwqLWX8Fm/t/v0hElru5OhM8=;\r
+       b=a/wOg+d3jHke03w4CqVgBHvz8K6aizQ7ZHosGwGxEW0Ff9DOFbgvc0ax9oTOnR2YIu\r
+       yMEKwdtxJWe1S8AxxRCw52YLSZPI7gLIznydSRthh2rtyVD9AuJu1s2e/Ny3lZgxlMqh\r
+       vs4kJ7bZcgm2axyc407oloIusR6/AGDU/c2+EblZLeOJJN+3IBHum1+gS013sf4G6D+l\r
+       cLSX3dNlsQGt130VP6xY3U+Ajdp7DZnZ2xXBKzQYpJ1ZDvLDWNwVs6UE0UwCmqzutlEV\r
+       yLPpoM5Zg+vLAQe9TqQviqo0++L17OQoFKuEiWkkP9HQxzNxXbuC84e4x+hWwQRFY8Tg\r
+       HWlA==\r
+MIME-Version: 1.0\r
+Received: by 10.182.31.50 with SMTP id x18mr18624613obh.56.1351271671492; Fri,\r
+       26 Oct 2012 10:14:31 -0700 (PDT)\r
+Received: by 10.76.69.138 with HTTP; Fri, 26 Oct 2012 10:14:31 -0700 (PDT)\r
+Received: by 10.76.69.138 with HTTP; Fri, 26 Oct 2012 10:14:31 -0700 (PDT)\r
+In-Reply-To: <1351208039-32293-2-git-send-email-taesoo@mit.edu>\r
+References: <1351208039-32293-1-git-send-email-taesoo@mit.edu>\r
+       <1351208039-32293-2-git-send-email-taesoo@mit.edu>\r
+Date: Fri, 26 Oct 2012 20:14:31 +0300\r
+Message-ID:\r
+ <CAB+hUn8d9pOYHSw_r=7NJeFv-wGe-Bycom0d6TCod3R3DETAzg@mail.gmail.com>\r
+Subject: Re: [PATCH 1/2] Automatic tagging based on maildir\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Taesoo Kim <taesoo@mit.edu>\r
+Content-Type: multipart/alternative; boundary=14dae93b56d4f9726104ccf97331\r
+X-Gm-Message-State:\r
+ ALoCoQnH3kjb5Z1/tHGvBcpClbYFMXaziGQxpGRpiQ8uP/LiExwoJMoYoIQu1N20oaaQerc1jbOU\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 26 Oct 2012 17:14:34 -0000\r
+\r
+--14dae93b56d4f9726104ccf97331\r
+Content-Type: text/plain; charset=UTF-8\r
+\r
+On Oct 26, 2012 8:46 AM, "Taesoo Kim" <taesoo@mit.edu> wrote:\r
+>\r
+> Since gmail will provide labels as imap sub/folders, notmuch also can\r
+> take advantage of labels as tags, when maildir.add_as_tag_flags is\r
+> specified.\r
+\r
+Why not use the folder: prefix? What does your patch do that can't be\r
+achieved with that?\r
+\r
+BR,\r
+Jani.\r
+\r
+>\r
+> Signed-off-by: Taesoo Kim <taesoo@mit.edu>\r
+> ---\r
+>  notmuch-client.h |  7 +++++++\r
+>  notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++----\r
+>  notmuch-new.c    | 32 ++++++++++++++++++++++++++++++++\r
+>  3 files changed, 77 insertions(+), 4 deletions(-)\r
+>\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index ae9344b..ce05e52 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -265,6 +265,13 @@ void\r
+>  notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config,\r
+>                                               notmuch_bool_t\r
+synchronize_flags);\r
+>\r
+> +notmuch_bool_t\r
+> +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config);\r
+> +\r
+> +void\r
+> +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,\r
+> +                                            notmuch_bool_t\r
+add_as_tag_flags);\r
+> +\r
+>  const char **\r
+>  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t\r
+*length);\r
+>\r
+> diff --git a/notmuch-config.c b/notmuch-config.c\r
+> index 3e37a2d..c95f9dd 100644\r
+> --- a/notmuch-config.c\r
+> +++ b/notmuch-config.c\r
+> @@ -88,7 +88,16 @@ static const char maildir_config_comment[] =\r
+>      "\n"\r
+>      "\tThe \"notmuch new\" command will notice flag changes in\r
+filenames\n"\r
+>      "\tand update tags, while the \"notmuch tag\" and \"notmuch\r
+restore\"\n"\r
+> -    "\tcommands will notice tag changes and update flags in filenames\n";\r
+> +    "\tcommands will notice tag changes and update flags in filenames\n"\r
+> +    "\n"\r
+> +    "\tadd_as_tag_flags       Valid values are true and false.\n"\r
+> +    "\n"\r
+> +    "\nIf ture, then add the lower-cased name of maildirs"\r
+> +    "\n(also deliminated by .) as tags"\r
+> +    "\n"\r
+> +    "\n\te.g. Life              -> life"\r
+> +    "\n\te.g. MIT.CSAIL         -> mit, csail"\r
+> +    "\n\te.g. Mailing.OSS.Linux -> mailing, oss, linux";\r
+>\r
+>  static const char search_config_comment[] =\r
+>      " Search configuration\n"\r
+> @@ -114,6 +123,7 @@ struct _notmuch_config {\r
+>      const char **new_ignore;\r
+>      size_t new_ignore_length;\r
+>      notmuch_bool_t maildir_synchronize_flags;\r
+> +    notmuch_bool_t maildir_add_as_tag_flags;\r
+>      const char **search_exclude_tags;\r
+>      size_t search_exclude_tags_length;\r
+>  };\r
+> @@ -251,7 +261,7 @@ notmuch_config_open (void *ctx,\r
+>         fprintf (stderr, "Out of memory.\n");\r
+>         return NULL;\r
+>      }\r
+> -\r
+> +\r
+>      talloc_set_destructor (config, notmuch_config_destructor);\r
+>\r
+>      if (filename) {\r
+> @@ -393,6 +403,14 @@ notmuch_config_open (void *ctx,\r
+>         g_error_free (error);\r
+>      }\r
+>\r
+> +    config->maildir_add_as_tag_flags =\r
+> +       g_key_file_get_boolean (config->key_file,\r
+> +                               "maildir", "add_as_tag_flags", &error);\r
+> +    if (error) {\r
+> +       notmuch_config_set_maildir_add_as_tag_flags (config, FALSE);\r
+> +       g_error_free (error);\r
+> +    }\r
+> +\r
+>      /* Whenever we know of configuration sections that don't appear in\r
+>       * the configuration file, we add some comments to help the user\r
+>       * understand what can be done. */\r
+> @@ -438,7 +456,7 @@ notmuch_config_open (void *ctx,\r
+>  }\r
+>\r
+>  /* Close the given notmuch_config_t object, freeing all resources.\r
+> - *\r
+> + *\r
+>   * Note: Any changes made to the configuration are *not* saved by this\r
+>   * function. To save changes, call notmuch_config_save before\r
+>   * notmuch_config_close.\r
+> @@ -720,7 +738,7 @@ notmuch_config_command_get (void *ctx, char *item)\r
+>      } else if (strcmp(item, "user.other_email") == 0) {\r
+>         const char **other_email;\r
+>         size_t i, length;\r
+> -\r
+> +\r
+>         other_email = notmuch_config_get_user_other_email (config,\r
+&length);\r
+>         for (i = 0; i < length; i++)\r
+>             printf ("%s\n", other_email[i]);\r
+> @@ -891,3 +909,19 @@ notmuch_config_set_maildir_synchronize_flags\r
+(notmuch_config_t *config,\r
+>                             "maildir", "synchronize_flags",\r
+synchronize_flags);\r
+>      config->maildir_synchronize_flags = synchronize_flags;\r
+>  }\r
+> +\r
+> +\r
+> +notmuch_bool_t\r
+> +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config)\r
+> +{\r
+> +    return config->maildir_add_as_tag_flags;\r
+> +}\r
+> +\r
+> +void\r
+> +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config,\r
+> +                                            notmuch_bool_t\r
+add_as_tag_flags)\r
+> +{\r
+> +    g_key_file_set_boolean (config->key_file,\r
+> +                           "maildir", "add_as_tag_flags",\r
+add_as_tag_flags);\r
+> +    config->maildir_add_as_tag_flags = add_as_tag_flags;\r
+> +}\r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index 56c4a6f..9ec983f 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -20,6 +20,7 @@\r
+>\r
+>  #include "notmuch-client.h"\r
+>\r
+> +#include <ctype.h>\r
+>  #include <unistd.h>\r
+>\r
+>  typedef struct _filename_node {\r
+> @@ -53,6 +54,7 @@ typedef struct {\r
+>      _filename_list_t *directory_mtimes;\r
+>\r
+>      notmuch_bool_t synchronize_flags;\r
+> +    notmuch_bool_t add_as_tag_flags;\r
+>  } add_files_state_t;\r
+>\r
+>  static volatile sig_atomic_t do_print_progress = 0;\r
+> @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry,\r
+add_files_state_t *state)\r
+>      return FALSE;\r
+>  }\r
+>\r
+> +static void\r
+> +_add_maildir_as_tag(notmuch_database_t *notmuch,\r
+> +                   notmuch_message_t *msg, const char *path)\r
+> +{\r
+> +    char *tok = talloc_strdup (notmuch, path);\r
+> +    int len = strlen(tok);\r
+> +\r
+> +    /* asserts path ends with /cur|/tmp|/new */\r
+> +    if (len > 4 && tok[len - 4] == '/') {\r
+> +       char *iter = tok + len - 4;\r
+> +       *iter = '\0';\r
+> +       while (-- iter && iter >= tok) {\r
+> +           char c = *iter;\r
+> +           if (c == '/' || c == '.') {\r
+> +               *iter = '\0';\r
+> +               notmuch_message_add_tag (msg, iter + 1);\r
+> +               if (c == '/') {\r
+> +                   break;\r
+> +               }\r
+> +           }\r
+> +           *iter = tolower(*iter);\r
+> +       }\r
+> +    }\r
+> +    talloc_free (tok);\r
+> +}\r
+> +\r
+>  /* Examine 'path' recursively as follows:\r
+>   *\r
+>   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+> @@ -508,6 +536,9 @@ add_files (notmuch_database_t *notmuch,\r
+>             notmuch_message_freeze (message);\r
+>             for (tag=state->new_tags; *tag != NULL; tag++)\r
+>                 notmuch_message_add_tag (message, *tag);\r
+> +           if (state->add_as_tag_flags == TRUE) {\r
+> +               _add_maildir_as_tag(notmuch, message, path);\r
+> +           }\r
+>             if (state->synchronize_flags == TRUE)\r
+>                 notmuch_message_maildir_flags_to_tags (message);\r
+>             notmuch_message_thaw (message);\r
+> @@ -878,6 +909,7 @@ notmuch_new_command (void *ctx, int argc, char\r
+*argv[])\r
+>      add_files_state.new_tags = notmuch_config_get_new_tags (config,\r
+&add_files_state.new_tags_length);\r
+>      add_files_state.new_ignore = notmuch_config_get_new_ignore (config,\r
+&add_files_state.new_ignore_length);\r
+>      add_files_state.synchronize_flags =\r
+notmuch_config_get_maildir_synchronize_flags (config);\r
+> +    add_files_state.add_as_tag_flags =\r
+notmuch_config_get_maildir_add_as_tag_flags (config);\r
+>      db_path = notmuch_config_get_database_path (config);\r
+>\r
+>      if (run_hooks) {\r
+> --\r
+> 1.8.0\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r
+\r
+--14dae93b56d4f9726104ccf97331\r
+Content-Type: text/html; charset=UTF-8\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+<p><br>\r
+On Oct 26, 2012 8:46 AM, &quot;Taesoo Kim&quot; &lt;<a href=3D"mailto:taeso=\r
+o@mit.edu">taesoo@mit.edu</a>&gt; wrote:<br>\r
+&gt;<br>\r
+&gt; Since gmail will provide labels as imap sub/folders, notmuch also can<=\r
+br>\r
+&gt; take advantage of labels as tags, when maildir.add_as_tag_flags is<br>\r
+&gt; specified.</p>\r
+<p>Why not use the folder: prefix? What does your patch do that can&#39;t b=\r
+e achieved with that?</p>\r
+<p>BR,<br>\r
+Jani.<br></p>\r
+<p>&gt;<br>\r
+&gt; Signed-off-by: Taesoo Kim &lt;<a href=3D"mailto:taesoo@mit.edu">taesoo=\r
+@mit.edu</a>&gt;<br>\r
+&gt; ---<br>\r
+&gt; =C2=A0notmuch-client.h | =C2=A07 +++++++<br>\r
+&gt; =C2=A0notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++----=\r
+<br>\r
+&gt; =C2=A0notmuch-new.c =C2=A0 =C2=A0| 32 ++++++++++++++++++++++++++++++++=\r
+<br>\r
+&gt; =C2=A03 files changed, 77 insertions(+), 4 deletions(-)<br>\r
+&gt;<br>\r
+&gt; diff --git a/notmuch-client.h b/notmuch-client.h<br>\r
+&gt; index ae9344b..ce05e52 100644<br>\r
+&gt; --- a/notmuch-client.h<br>\r
+&gt; +++ b/notmuch-client.h<br>\r
+&gt; @@ -265,6 +265,13 @@ void<br>\r
+&gt; =C2=A0notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *=\r
+config,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
+=A0 =C2=A0 =C2=A0 notmuch_bool_t synchronize_flags);<br>\r
+&gt;<br>\r
+&gt; +notmuch_bool_t<br>\r
+&gt; +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config=\r
+);<br>\r
+&gt; +<br>\r
+&gt; +void<br>\r
+&gt; +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config=\r
+,<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
+=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0notmuch_bool_t add_as_tag_flags);<br>\r
+&gt; +<br>\r
+&gt; =C2=A0const char **<br>\r
+&gt; =C2=A0notmuch_config_get_search_exclude_tags (notmuch_config_t *config=\r
+, size_t *length);<br>\r
+&gt;<br>\r
+&gt; diff --git a/notmuch-config.c b/notmuch-config.c<br>\r
+&gt; index 3e37a2d..c95f9dd 100644<br>\r
+&gt; --- a/notmuch-config.c<br>\r
+&gt; +++ b/notmuch-config.c<br>\r
+&gt; @@ -88,7 +88,16 @@ static const char maildir_config_comment[] =3D<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0&quot;\n&quot;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0&quot;\tThe \&quot;notmuch new\&quot; command will=\r
+ notice flag changes in filenames\n&quot;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0&quot;\tand update tags, while the \&quot;notmuch =\r
+tag\&quot; and \&quot;notmuch restore\&quot;\n&quot;<br>\r
+&gt; - =C2=A0 =C2=A0&quot;\tcommands will notice tag changes and update fla=\r
+gs in filenames\n&quot;;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\tcommands will notice tag changes and update fla=\r
+gs in filenames\n&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\tadd_as_tag_flags =C2=A0 =C2=A0 =C2=A0 Valid val=\r
+ues are true and false.\n&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\nIf ture, then add the lower-cased name of maild=\r
+irs&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n(also deliminated by .) as tags&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n\te.g. Life =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0-&gt; life&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n\te.g. MIT.CSAIL =C2=A0 =C2=A0 =C2=A0 =C2=A0 -&=\r
+gt; mit, csail&quot;<br>\r
+&gt; + =C2=A0 =C2=A0&quot;\n\te.g. Mailing.OSS.Linux -&gt; mailing, oss, li=\r
+nux&quot;;<br>\r
+&gt;<br>\r
+&gt; =C2=A0static const char search_config_comment[] =3D<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0&quot; Search configuration\n&quot;<br>\r
+&gt; @@ -114,6 +123,7 @@ struct _notmuch_config {<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0const char **new_ignore;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0size_t new_ignore_length;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0notmuch_bool_t maildir_synchronize_flags;<br>\r
+&gt; + =C2=A0 =C2=A0notmuch_bool_t maildir_add_as_tag_flags;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0const char **search_exclude_tags;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0size_t search_exclude_tags_length;<br>\r
+&gt; =C2=A0};<br>\r
+&gt; @@ -251,7 +261,7 @@ notmuch_config_open (void *ctx,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, &quot;Out of memory.\n&qu=\r
+ot;);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 return NULL;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0}<br>\r
+&gt; -<br>\r
+&gt; +<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0talloc_set_destructor (config, notmuch_config_dest=\r
+ructor);<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0if (filename) {<br>\r
+&gt; @@ -393,6 +403,14 @@ notmuch_config_open (void *ctx,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_error_free (error);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0}<br>\r
+&gt;<br>\r
+&gt; + =C2=A0 =C2=A0config-&gt;maildir_add_as_tag_flags =3D<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 g_key_file_get_boolean (config-&gt;key_file,<br=\r
+>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
+=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &quot;maildir&quot;, &quot;add_as_ta=\r
+g_flags&quot;, &amp;error);<br>\r
+&gt; + =C2=A0 =C2=A0if (error) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 notmuch_config_set_maildir_add_as_tag_flags (co=\r
+nfig, FALSE);<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 g_error_free (error);<br>\r
+&gt; + =C2=A0 =C2=A0}<br>\r
+&gt; +<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0/* Whenever we know of configuration sections that=\r
+ don&#39;t appear in<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 * the configuration file, we add some comments to=\r
+ help the user<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 * understand what can be done. */<br>\r
+&gt; @@ -438,7 +456,7 @@ notmuch_config_open (void *ctx,<br>\r
+&gt; =C2=A0}<br>\r
+&gt;<br>\r
+&gt; =C2=A0/* Close the given notmuch_config_t object, freeing all resource=\r
+s.<br>\r
+&gt; - *<br>\r
+&gt; + *<br>\r
+&gt; =C2=A0 * Note: Any changes made to the configuration are *not* saved b=\r
+y this<br>\r
+&gt; =C2=A0 * function. To save changes, call notmuch_config_save before<br=\r
+>\r
+&gt; =C2=A0 * notmuch_config_close.<br>\r
+&gt; @@ -720,7 +738,7 @@ notmuch_config_command_get (void *ctx, char *item)=\r
+<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0} else if (strcmp(item, &quot;user.other_email&quo=\r
+t;) =3D=3D 0) {<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 const char **other_email;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 size_t i, length;<br>\r
+&gt; -<br>\r
+&gt; +<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 other_email =3D notmuch_config_get_user_ot=\r
+her_email (config, &amp;length);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (i =3D 0; i &lt; length; i++)<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 printf (&quot;%s\n&quot;, ot=\r
+her_email[i]);<br>\r
+&gt; @@ -891,3 +909,19 @@ notmuch_config_set_maildir_synchronize_flags (not=\r
+much_config_t *config,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 &quot;maildir&quot;, &quot;synchronize_flags&qu=\r
+ot;, synchronize_flags);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0config-&gt;maildir_synchronize_flags =3D synchroni=\r
+ze_flags;<br>\r
+&gt; =C2=A0}<br>\r
+&gt; +<br>\r
+&gt; +<br>\r
+&gt; +notmuch_bool_t<br>\r
+&gt; +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config=\r
+)<br>\r
+&gt; +{<br>\r
+&gt; + =C2=A0 =C2=A0return config-&gt;maildir_add_as_tag_flags;<br>\r
+&gt; +}<br>\r
+&gt; +<br>\r
+&gt; +void<br>\r
+&gt; +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config=\r
+,<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
+=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =\r
+=C2=A0 =C2=A0notmuch_bool_t add_as_tag_flags)<br>\r
+&gt; +{<br>\r
+&gt; + =C2=A0 =C2=A0g_key_file_set_boolean (config-&gt;key_file,<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=\r
+=A0 =C2=A0 =C2=A0 =C2=A0 &quot;maildir&quot;, &quot;add_as_tag_flags&quot;,=\r
+ add_as_tag_flags);<br>\r
+&gt; + =C2=A0 =C2=A0config-&gt;maildir_add_as_tag_flags =3D add_as_tag_flag=\r
+s;<br>\r
+&gt; +}<br>\r
+&gt; diff --git a/notmuch-new.c b/notmuch-new.c<br>\r
+&gt; index 56c4a6f..9ec983f 100644<br>\r
+&gt; --- a/notmuch-new.c<br>\r
+&gt; +++ b/notmuch-new.c<br>\r
+&gt; @@ -20,6 +20,7 @@<br>\r
+&gt;<br>\r
+&gt; =C2=A0#include &quot;notmuch-client.h&quot;<br>\r
+&gt;<br>\r
+&gt; +#include &lt;ctype.h&gt;<br>\r
+&gt; =C2=A0#include &lt;unistd.h&gt;<br>\r
+&gt;<br>\r
+&gt; =C2=A0typedef struct _filename_node {<br>\r
+&gt; @@ -53,6 +54,7 @@ typedef struct {<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0_filename_list_t *directory_mtimes;<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0notmuch_bool_t synchronize_flags;<br>\r
+&gt; + =C2=A0 =C2=A0notmuch_bool_t add_as_tag_flags;<br>\r
+&gt; =C2=A0} add_files_state_t;<br>\r
+&gt;<br>\r
+&gt; =C2=A0static volatile sig_atomic_t do_print_progress =3D 0;<br>\r
+&gt; @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry, add_fil=\r
+es_state_t *state)<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0return FALSE;<br>\r
+&gt; =C2=A0}<br>\r
+&gt;<br>\r
+&gt; +static void<br>\r
+&gt; +_add_maildir_as_tag(notmuch_database_t *notmuch,<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmu=\r
+ch_message_t *msg, const char *path)<br>\r
+&gt; +{<br>\r
+&gt; + =C2=A0 =C2=A0char *tok =3D talloc_strdup (notmuch, path);<br>\r
+&gt; + =C2=A0 =C2=A0int len =3D strlen(tok);<br>\r
+&gt; +<br>\r
+&gt; + =C2=A0 =C2=A0/* asserts path ends with /cur|/tmp|/new */<br>\r
+&gt; + =C2=A0 =C2=A0if (len &gt; 4 &amp;&amp; tok[len - 4] =3D=3D &#39;/&#3=\r
+9;) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 char *iter =3D tok + len - 4;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 *iter =3D &#39;\0&#39;;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 while (-- iter &amp;&amp; iter &gt;=3D tok) {<b=\r
+r>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 char c =3D *iter;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (c =3D=3D &#39;/&#39; || c =3D=\r
+=3D &#39;.&#39;) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *iter =3D &#39;\0&#=\r
+39;;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_message_add=\r
+_tag (msg, iter + 1);<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (c =3D=3D &#39;/=\r
+&#39;) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break=\r
+;<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *iter =3D tolower(*iter);<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 }<br>\r
+&gt; + =C2=A0 =C2=A0}<br>\r
+&gt; + =C2=A0 =C2=A0talloc_free (tok);<br>\r
+&gt; +}<br>\r
+&gt; +<br>\r
+&gt; =C2=A0/* Examine &#39;path&#39; recursively as follows:<br>\r
+&gt; =C2=A0 *<br>\r
+&gt; =C2=A0 * =C2=A0 o Ask the filesystem for the mtime of &#39;path&#39; (=\r
+fs_mtime)<br>\r
+&gt; @@ -508,6 +536,9 @@ add_files (notmuch_database_t *notmuch,<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_message_freeze (mess=\r
+age);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for (tag=3Dstate-&gt;new_tag=\r
+s; *tag !=3D NULL; tag++)<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_messag=\r
+e_add_tag (message, *tag);<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (state-&gt;add_as_tag_flags =\r
+=3D=3D TRUE) {<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 _add_maildir_as_tag=\r
+(notmuch, message, path);<br>\r
+&gt; + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (state-&gt;synchronize_fl=\r
+ags =3D=3D TRUE)<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_messag=\r
+e_maildir_flags_to_tags (message);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 notmuch_message_thaw (messag=\r
+e);<br>\r
+&gt; @@ -878,6 +909,7 @@ notmuch_new_command (void *ctx, int argc, char *ar=\r
+gv[])<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0add_files_state.new_tags =3D notmuch_config_get_ne=\r
+w_tags (config, &amp;add_files_state.new_tags_length);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0add_files_state.new_ignore =3D notmuch_config_get_=\r
+new_ignore (config, &amp;add_files_state.new_ignore_length);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0add_files_state.synchronize_flags =3D notmuch_conf=\r
+ig_get_maildir_synchronize_flags (config);<br>\r
+&gt; + =C2=A0 =C2=A0add_files_state.add_as_tag_flags =3D notmuch_config_get=\r
+_maildir_add_as_tag_flags (config);<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0db_path =3D notmuch_config_get_database_path (conf=\r
+ig);<br>\r
+&gt;<br>\r
+&gt; =C2=A0 =C2=A0 =C2=A0if (run_hooks) {<br>\r
+&gt; --<br>\r
+&gt; 1.8.0<br>\r
+&gt;<br>\r
+&gt; _______________________________________________<br>\r
+&gt; notmuch mailing list<br>\r
+&gt; <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=\r
+<br>\r
+&gt; <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=\r
+muchmail.org/mailman/listinfo/notmuch</a><br>\r
+</p>\r
+\r
+--14dae93b56d4f9726104ccf97331--\r