Re: [PATCH] added support for user-specified files & directories to ignore
authorAustin Clements <amdragon@MIT.EDU>
Wed, 1 Feb 2012 16:30:52 +0000 (11:30 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:54 +0000 (09:43 -0800)
7e/503f6ed8435c609a384b0dff441408389d576f [new file with mode: 0644]

diff --git a/7e/503f6ed8435c609a384b0dff441408389d576f b/7e/503f6ed8435c609a384b0dff441408389d576f
new file mode 100644 (file)
index 0000000..ef14b55
--- /dev/null
@@ -0,0 +1,369 @@
+Return-Path: <amdragon@mit.edu>\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 0149B429E34\r
+       for <notmuch@notmuchmail.org>; Wed,  1 Feb 2012 08:31:52 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 oAmebpKagPhl for <notmuch@notmuchmail.org>;\r
+       Wed,  1 Feb 2012 08:31:51 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+       [18.9.25.14])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9AC2B431E64\r
+       for <notmuch@notmuchmail.org>; Wed,  1 Feb 2012 08:31:51 -0800 (PST)\r
+X-AuditID: 1209190e-b7f7c6d0000008c3-98-4f2968f78472\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 61.C8.02243.7F8692F4; Wed,  1 Feb 2012 11:31:51 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q11GVoqT004266; \r
+       Wed, 1 Feb 2012 11:31:51 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q11GVmIb008656\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Wed, 1 Feb 2012 11:31:49 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1Rsd5A-00062D-7e; Wed, 01 Feb 2012 11:30:52 -0500\r
+Date: Wed, 1 Feb 2012 11:30:52 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Tomi Ollila <tomi.ollila@iki.fi>\r
+Subject: Re: [PATCH] added support for user-specified files & directories to\r
+       ignore\r
+Message-ID: <20120201163052.GG10898@mit.edu>\r
+References: <1315949524-4948-1-git-send-email-tomi.ollila@iki.fi>\r
+       <20120131-new-ignore-1-git-send-email-too@iki.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <20120131-new-ignore-1-git-send-email-too@iki.fi>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFmpgleLIzCtJLcpLzFFi42IRYrdT1/2eoelv8HMmh8X1mzOZLd6snMfq\r
+       wORx+OtCFo9nq24xBzBFcdmkpOZklqUW6dslcGXcmyxZMCuwYu8/9wbGp3ZdjBwcEgImEs03\r
+       s7oYOYFMMYkL99azgdhCAvsYJSYvSOli5AKy1zNKrN22kxHCOcEkceXHPxYIZwmjxOO/RxlB\r
+       WlgEVCQ+v7/JDGKzCWhIbNu/HCwuAhR/0LaeFcRmFpCW+Pa7mQnEFhYIlejYdgKsnldAR2J/\r
+       33lmiNWlEhsenmeEiAtKnJz5hAWiV0vixr+XTCBXg8xZ/o8DJMwpYCex7NdtsHJRoFVTTm5j\r
+       m8AoNAtJ9ywk3bMQuhcwMq9ilE3JrdLNTczMKU5N1i1OTszLSy3SNdbLzSzRS00p3cQICmhO\r
+       Sb4djF8PKh1iFOBgVOLh3SWt4S/EmlhWXJl7iFGSg0lJlPdpqqa/EF9SfkplRmJxRnxRaU5q\r
+       8SFGCQ5mJRHeidFAOd6UxMqq1KJ8mJQ0B4uSOK+a1js/IYH0xJLU7NTUgtQimKwMB4eSBK8L\r
+       MHKFBItS01Mr0jJzShDSTBycIMN5gIZ7gNTwFhck5hZnpkPkTzEqSonzBoEkBEASGaV5cL2w\r
+       hPOKURzoFWHeuHSgKh5gsoLrfgU0mAloMIMF2OCSRISUVAOjxtFzd6aYnueLYL/kbWp4OWH6\r
+       /wv/MjW0bzmH1GxL5FvuvnXy1OTFp9hPVPxKa9qxdukypoprrLpsNocDFJ4nLi8TcN98+LmP\r
+       +alTzqczNx7tL6+cfsv5u2t0IsuP9WJsHezaPZu6FJfOVLkR7JZ+PL+Ys/0h+8bZT0/8SddJ\r
+       YVWKjdv/f7WZEktxRqKhFnNRcSIA2evvkxMDAAA=\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: Wed, 01 Feb 2012 16:31:53 -0000\r
+\r
+Quoth Tomi Ollila on Jan 31 at  6:28 pm:\r
+> A new configuration key 'new.ignore' is used to determine which\r
+> files and directories user wants not to be scanned as new mails.\r
+> \r
+> This work merges my previous attempts and Andreas Amann's work\r
+> in id:"ylp7hi23mw8.fsf@tyndall.ie"\r
+> \r
+> See notes in id:"20120131-new-ignore-1-git-send-email-too@iki.fi"\r
+> ---\r
+> Notes\r
+> \r
+> 1) Currently there is comment for new.ignore in newly created configuration\r
+> file but as the list is initially empty there will be not tag in place.\r
+> \r
+> 2) Whenever some already existing directory is added to the exclude list\r
+> and the parent directory timestamp has not changed, notmuch new will not\r
+> notice the directory has gone (as it still is there), user needs to 'touch'\r
+> the parent directory before next 'notmuch new' no make notmuch notice.\r
+> \r
+> 2012-01-26: could notmuch track mtime of the configuration file and if\r
+> that changes, ignore mail directory timestamps ?\r
+> \r
+> \r
+> 3) in id:"1327572718-13411-2-git-send-email-tomi.ollila@iki.fi" dropped...\r
+> \r
+>  notmuch-client.h |    8 ++++++++\r
+>  notmuch-config.c |   35 +++++++++++++++++++++++++++++++++--\r
+>  notmuch-new.c    |   45 +++++++++++++++++++++++++++++++++------------\r
+>  3 files changed, 74 insertions(+), 14 deletions(-)\r
+> \r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index e0eb594..c62ce78 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -250,6 +250,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+>                           const char *new_tags[],\r
+>                           size_t length);\r
+>  \r
+> +const char **\r
+> +notmuch_config_get_new_ignore (notmuch_config_t *config,\r
+> +                           size_t *length);\r
+\r
+Missing blank line.\r
+\r
+> +void\r
+> +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
+> +                           const char *new_ignore[],\r
+> +                           size_t length);\r
+> +\r
+>  notmuch_bool_t\r
+>  notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);\r
+>  \r
+> diff --git a/notmuch-config.c b/notmuch-config.c\r
+> index a124e34..f1cc5c2 100644\r
+> --- a/notmuch-config.c\r
+> +++ b/notmuch-config.c\r
+> @@ -44,7 +44,10 @@ static const char new_config_comment[] =\r
+>      " The following options are supported here:\n"\r
+>      "\n"\r
+>      "\ttags A list (separated by ';') of the tags that will be\n"\r
+> -    "\t     added to all messages incorporated by \"notmuch new\".\n";\r
+> +    "\t     added to all messages incorporated by \"notmuch new\".\n"\r
+> +    "\n"\r
+> +    "\tignore       A list (separated by ';') of files and directories that"\r
+> +    "\t     will not be searched for messages by \"notmuch new\".\n";\r
+\r
+This can be interpreted in a lot of ways (e.g., absolute paths, paths\r
+relative to database.path, etc) but is expecting something very\r
+specific.  Maybe "file and directory names"?\r
+\r
+>  \r
+>  static const char user_config_comment[] =\r
+>      " User configuration\n"\r
+> @@ -105,6 +108,8 @@ struct _notmuch_config {\r
+>      size_t user_other_email_length;\r
+>      const char **new_tags;\r
+>      size_t new_tags_length;\r
+> +    const char **new_ignore;\r
+> +    size_t new_ignore_length;\r
+>      notmuch_bool_t maildir_synchronize_flags;\r
+>      const char **search_exclude_tags;\r
+>      size_t search_exclude_tags_length;\r
+> @@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,\r
+>      config->user_other_email_length = 0;\r
+>      config->new_tags = NULL;\r
+>      config->new_tags_length = 0;\r
+> +    config->new_ignore = NULL;\r
+> +    config->new_ignore_length = 0;\r
+>      config->maildir_synchronize_flags = TRUE;\r
+>      config->search_exclude_tags = NULL;\r
+>      config->search_exclude_tags_length = 0;\r
+> @@ -360,7 +367,11 @@ notmuch_config_open (void *ctx,\r
+>          const char *tags[] = { "unread", "inbox" };\r
+>      notmuch_config_set_new_tags (config, tags, 2);\r
+>      }\r
+> -\r
+\r
+Looks like you lost a blank line.\r
+\r
+> +#if 0 /* No point setting empty list -- it's not written */\r
+> +    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {\r
+> +    notmuch_config_set_new_ignore (config, NULL, 0);\r
+> +    }\r
+> +#endif\r
+\r
+This *does* matter.  It affects whether or not this key appears in\r
+saved configuration files (both updated ones and new ones).  For\r
+discoverability's sake (especially since we don't have a way to update\r
+the section's comment), it should appear, even though it's blank.\r
+\r
+(For the record, I think 'notmuch config set's behavior of removing a\r
+key if given no arguments is broken; because of how we handle\r
+defaults, this is completely asymmetric behavior, plus it seems to\r
+screw up group comments.)\r
+\r
+Also, there should be another blank line after the if.\r
+\r
+>      if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {\r
+>      if (is_new) {\r
+>          const char *tags[] = { "deleted", "spam" };\r
+> @@ -609,6 +620,15 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)\r
+>                           &(config->new_tags_length), length);\r
+>  }\r
+>  \r
+> +const char **\r
+> +notmuch_config_get_new_ignore (notmuch_config_t *config,   size_t *length)\r
+> +{\r
+> +    return _config_get_list (config, "new", "ignore",\r
+> +                         &(config->new_ignore),\r
+> +                         &(config->new_ignore_length), length);\r
+> +}\r
+> +\r
+> +\r
+\r
+One extra blank line.\r
+\r
+>  void\r
+>  notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+>                                   const char *list[],\r
+> @@ -627,6 +647,17 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+>                   &(config->new_tags));\r
+>  }\r
+>  \r
+> +#if 0 /* UNNEEDED SO FAR */\r
+\r
+Include this, even if we don't need it.\r
+\r
+> +void\r
+> +notmuch_config_set_new_ignore (notmuch_config_t *config,\r
+> +                           const char *list[],\r
+> +                           size_t length)\r
+> +{\r
+> +    _config_set_list (config, "new", "ignore", list, length,\r
+> +                 &(config->new_ignore));\r
+> +}\r
+> +#endif\r
+> +\r
+>  const char **\r
+>  notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)\r
+>  {\r
+> diff --git a/notmuch-new.c b/notmuch-new.c\r
+> index a569a54..36d5c5d 100644\r
+> --- a/notmuch-new.c\r
+> +++ b/notmuch-new.c\r
+> @@ -39,6 +39,8 @@ typedef struct {\r
+>      int verbose;\r
+>      const char **new_tags;\r
+>      size_t new_tags_length;\r
+> +    const char **new_ignore;\r
+> +    size_t new_ignore_length;\r
+>  \r
+>      int total_files;\r
+>      int processed_files;\r
+> @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+>      return 0;\r
+>  }\r
+>  \r
+> +/* Check if user asked to ignore these files/directories */\r
+> +\r
+\r
+No blank line.\r
+\r
+> +static int\r
+\r
+Could be notmuch_bool_t (and TRUE and FALSE below).  Up to you.\r
+\r
+> +_entry_in_ignore_list (const char *entry, add_files_state_t *state)\r
+> +{\r
+> +    size_t i, ignore_length = state->new_ignore_length;\r
+> +\r
+> +    for (i = 0; i < ignore_length; i++)\r
+> +    if (strcmp (entry, state->new_ignore[i]) == 0)\r
+> +        return 1;\r
+> +\r
+> +    return 0;\r
+> +}\r
+> +\r
+>  /* Examine 'path' recursively as follows:\r
+>   *\r
+>   *   o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+> @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>      }\r
+>  \r
+>      /* Ignore special directories to avoid infinite recursion.\r
+> -     * Also ignore the .notmuch directory and any "tmp" directory\r
+> -     * that appears within a maildir.\r
+> +     * Also ignore the .notmuch directory, any "tmp" directory\r
+> +     * that appears within a maildir and files/directories\r
+> +     * user have configured to be ignored.\r
+\r
+s/user have/the user has/\r
+\r
+>       */\r
+> -    /* XXX: Eventually we'll want more sophistication to let the\r
+> -     * user specify files to be ignored. */\r
+>      if (strcmp (entry->d_name, ".") == 0 ||\r
+>          strcmp (entry->d_name, "..") == 0 ||\r
+>          (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
+> -        strcmp (entry->d_name, ".notmuch") ==0)\r
+> +        strcmp (entry->d_name, ".notmuch") == 0 ||\r
+> +        _entry_in_ignore_list (entry->d_name, state))\r
+\r
+Ah, nice simplification.\r
+\r
+>      {\r
+>          continue;\r
+>      }\r
+> @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+>  \r
+>          entry = fs_entries[i];\r
+>  \r
+> +    /* Ignore files & directories user has configured to be ignored */\r
+> +    if (_entry_in_ignore_list (entry->d_name, state))\r
+> +        continue;\r
+> +\r
+>      /* Check if we've walked past any names in db_files or\r
+>       * db_subdirs. If so, these have been deleted. */\r
+>      while (notmuch_filenames_valid (db_files) &&\r
+> @@ -648,7 +668,7 @@ add_files (notmuch_database_t *notmuch,\r
+>   * initialized to zero by the top-level caller before calling\r
+>   * count_files). */\r
+>  static void\r
+> -count_files (const char *path, int *count)\r
+> +count_files (const char *path, int *count, add_files_state_t *state)\r
+>  {\r
+>      struct dirent *entry = NULL;\r
+>      char *next;\r
+> @@ -670,13 +690,13 @@ count_files (const char *path, int *count)\r
+>          entry = fs_entries[i++];\r
+>  \r
+>      /* Ignore special directories to avoid infinite recursion.\r
+> -     * Also ignore the .notmuch directory.\r
+> +     * Also ignore the .notmuch directory and files/directories\r
+> +     * user have configured to be ignored.\r
+>       */\r
+> -    /* XXX: Eventually we'll want more sophistication to let the\r
+> -     * user specify files to be ignored. */\r
+>      if (strcmp (entry->d_name, ".") == 0 ||\r
+>          strcmp (entry->d_name, "..") == 0 ||\r
+> -        strcmp (entry->d_name, ".notmuch") == 0)\r
+> +        strcmp (entry->d_name, ".notmuch") == 0 ||\r
+> +        _entry_in_ignore_list (entry->d_name, state))\r
+>      {\r
+>          continue;\r
+>      }\r
+> @@ -697,7 +717,7 @@ count_files (const char *path, int *count)\r
+>              fflush (stdout);\r
+>          }\r
+>      } else if (S_ISDIR (st.st_mode)) {\r
+> -        count_files (next, count);\r
+> +        count_files (next, count, state);\r
+>      }\r
+>  \r
+>      free (next);\r
+> @@ -837,6 +857,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+>      return 1;\r
+>  \r
+>      add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
+> +    add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
+>      add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+>      db_path = notmuch_config_get_database_path (config);\r
+>  \r
+> @@ -852,7 +873,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+>      int count;\r
+>  \r
+>      count = 0;\r
+> -    count_files (db_path, &count);\r
+> +    count_files (db_path, &count, &add_files_state);\r
+>      if (interrupted)\r
+>          return 1;\r
+>  \r