[PATCH 2/3] cli: make sure notmuch new and insert don't add invalid tags
authorJani Nikula <jani@nikula.org>
Sun, 23 Feb 2014 16:55:22 +0000 (18:55 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:00:12 +0000 (10:00 -0800)
99/74d434cdc7457beadb089d9e0bfefa6fd7f1e0 [new file with mode: 0644]

diff --git a/99/74d434cdc7457beadb089d9e0bfefa6fd7f1e0 b/99/74d434cdc7457beadb089d9e0bfefa6fd7f1e0
new file mode 100644 (file)
index 0000000..cc5dbec
--- /dev/null
@@ -0,0 +1,141 @@
+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 1589D431FD8\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Feb 2014 08:55:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\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 g0qgZNhmr3CF for <notmuch@notmuchmail.org>;\r
+       Sun, 23 Feb 2014 08:55:36 -0800 (PST)\r
+Received: from mail-ea0-f178.google.com (mail-ea0-f178.google.com\r
+       [209.85.215.178]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A35BB431FCF\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Feb 2014 08:55:34 -0800 (PST)\r
+Received: by mail-ea0-f178.google.com with SMTP id a15so2666338eae.9\r
+       for <notmuch@notmuchmail.org>; Sun, 23 Feb 2014 08:55:33 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=OB8U3rnc4byZ/F8Qgg13Ryn/sMPT1BP5kACnOYLMxmo=;\r
+       b=TcQBP6voiX/8XUj2cEofd4qpnuUF0apy+qYI2yx5gH++zh6kaWMYpznqjBtmsxcdeg\r
+       JbpBLCcpnx9TzlLwORi8hs1JJuamrTRzaFtuswgaeEkvO//n0hVwUfRNFt73FzjPYLQU\r
+       4nq2jDEJMr+BtiUugd5S0RRB/4TXruwx3Nf5bsKETU+8vf9ylNFLTKZWvThhHdJpd1fr\r
+       JcJbiq9NM4ueEQxJ0pBpnXIm00PEcgrJUIeQs8seIz1sQDU2Tqd6NxD+cZGwIQil/SXr\r
+       xzigiAH1SzBcGgXTwG3G/NDoEN5x+IRnbtauAkHbgdfG/t9rNXjo9xO0VgrPZhIX48F/\r
+       kjWw==\r
+X-Gm-Message-State:\r
+ ALoCoQmwRBpooXm2DaU7ugFfRyTD7KhyNrQhJ5VcuVn8VYGrU5yg+4ZrqjtOmU/Oktjk2UaO0bJw\r
+X-Received: by 10.14.193.193 with SMTP id k41mr19874863een.112.1393174532253; \r
+       Sun, 23 Feb 2014 08:55:32 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+       [88.195.111.91]) by mx.google.com with ESMTPSA id\r
+       j41sm53050533eey.15.2014.02.23.08.55.30 for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 23 Feb 2014 08:55:31 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org,\r
+       Rob Browning <rlb@defaultvalue.org>\r
+Subject: [PATCH 2/3] cli: make sure notmuch new and insert don't add invalid\r
+       tags\r
+Date: Sun, 23 Feb 2014 18:55:22 +0200\r
+Message-Id:\r
+ <edc2bc900f75bb2e72be2037e2df9105be7f0273.1393174108.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.8.5.3\r
+In-Reply-To: <cover.1393174108.git.jani@nikula.org>\r
+References: <87ha7qfto7.fsf@trouble.defaultvalue.org>\r
+       <cover.1393174108.git.jani@nikula.org>\r
+In-Reply-To: <cover.1393174108.git.jani@nikula.org>\r
+References: <cover.1393174108.git.jani@nikula.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: Sun, 23 Feb 2014 16:55:40 -0000\r
+\r
+Check new.tags configuration values before doing anything, and bail\r
+out on invalid values.\r
+---\r
+ notmuch-insert.c |  9 +++++++++\r
+ notmuch-new.c    | 14 +++++++++++++-\r
+ 2 files changed, 22 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/notmuch-insert.c b/notmuch-insert.c\r
+index cd6de88f6891..6752fc8de255 100644\r
+--- a/notmuch-insert.c\r
++++ b/notmuch-insert.c\r
+@@ -431,6 +431,15 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])\r
+       return EXIT_FAILURE;\r
+     }\r
+     for (i = 0; i < new_tags_length; i++) {\r
++      const char *error_msg;\r
++\r
++      error_msg = illegal_tag (new_tags[i], FALSE);\r
++      if (error_msg) {\r
++          fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",\r
++                   new_tags[i],  error_msg);\r
++          return EXIT_FAILURE;\r
++      }\r
++\r
+       if (tag_op_list_append (tag_ops, new_tags[i], FALSE))\r
+           return EXIT_FAILURE;\r
+     }\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 8529fdd3eac7..82acf695353e 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -19,6 +19,7 @@\r
+  */\r
\r
+ #include "notmuch-client.h"\r
++#include "tag-util.h"\r
\r
+ #include <unistd.h>\r
\r
+@@ -918,7 +919,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     struct sigaction action;\r
+     _filename_node_t *f;\r
+     int opt_index;\r
+-    int i;\r
++    unsigned int i;\r
+     notmuch_bool_t timer_is_active = FALSE;\r
+     notmuch_bool_t no_hooks = FALSE;\r
+     notmuch_bool_t quiet = FALSE, verbose = FALSE;\r
+@@ -950,6 +951,17 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+     db_path = notmuch_config_get_database_path (config);\r
\r
++    for (i = 0; i < add_files_state.new_tags_length; i++) {\r
++      const char *error_msg;\r
++\r
++      error_msg = illegal_tag (add_files_state.new_tags[i], FALSE);\r
++      if (error_msg) {\r
++          fprintf (stderr, "Error: tag '%s' in new.tags: %s\n",\r
++                   add_files_state.new_tags[i], error_msg);\r
++          return EXIT_FAILURE;\r
++      }\r
++    }\r
++\r
+     if (!no_hooks) {\r
+       ret = notmuch_run_hook (db_path, "pre-new");\r
+       if (ret)\r
+-- \r
+1.8.5.3\r
+\r