--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id A91D26DE0350\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Apr 2016 23:44:56 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.62\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.62 tagged_above=-999 required=5 tests=[AWL=-0.032, \r
+ SPF_NEUTRAL=0.652] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id GiHOHFxr9M74 for <notmuch@notmuchmail.org>;\r
+ Sun, 10 Apr 2016 23:44:48 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id E4D186DE0317\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Apr 2016 23:44:47 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 28E90100090;\r
+ Mon, 11 Apr 2016 09:44:50 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 2/3] lib: fix handling of one character long directory\r
+ names at top level\r
+In-Reply-To: <1460317403-13714-2-git-send-email-jani@nikula.org>\r
+References: <1460317403-13714-1-git-send-email-jani@nikula.org>\r
+ <1460317403-13714-2-git-send-email-jani@nikula.org>\r
+User-Agent: Notmuch/0.21+99~g7cbc880 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Mon, 11 Apr 2016 09:44:49 +0300\r
+Message-ID: <m2d1pwzlsu.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://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: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 11 Apr 2016 06:44:56 -0000\r
+\r
+On Sun, Apr 10 2016, Jani Nikula <jani@nikula.org> wrote:\r
+\r
+> The code to skip multiple slashes in _notmuch_database_split_path()\r
+> skips back one character too much. This is compensated by a +1 in the\r
+> length parameter to the strndup() call. Mostly this works fine, but if\r
+> the path is to a file under a top level directory with one character\r
+> long name, the directory part is mistaken to be part of the file name\r
+> (slash == path in code). The returned directory name will be the empty\r
+> string and the basename will be the full path, breaking the indexing\r
+> logic in notmuch new.\r
+>\r
+> Fix the multiple slash skipping to keep the slash variable pointing at\r
+> the last slash, and adjust strndup() accordingly.\r
+\r
+Good work. Changes look good. Tests pass...\r
+\r
+... I also debugged this yesterday with an extra debug print:\r
+\r
++++ b/notmuch-new.c\r
+@@ -382,2 +382,3 @@ add_files (notmuch_database_t *notmuch,\r
+ status = notmuch_database_get_directory (notmuch, path, &directory);\r
++ printf("(Z) %s %p %d\n", path, directory, status);\r
+ if (status) {\r
+\r
+Without these changes the %p printing directory value never changed from\r
+(nil) to ... non-nil with one-character directory names (meaning directory\r
+was found in database), after this patch the directory value worked like\r
+with longer directory names.\r
+\r
+Tomi\r
+\r
+>\r
+> The bug was introduced in\r
+>\r
+> commit e890b0cf4011fd9fd77ebd87343379e4a778888b\r
+> Author: Carl Worth <cworth@cworth.org>\r
+> Date: Sat Dec 19 13:20:26 2009 -0800\r
+>\r
+> database: Store the parent ID for each directory document.\r
+>\r
+> just a little over two months after the initial commit in the Notmuch\r
+> code history, making this the longest living bug in Notmuch to date.\r
+> ---\r
+> lib/database.cc | 4 ++--\r
+> test/T050-new.sh | 5 -----\r
+> 2 files changed, 2 insertions(+), 7 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 3b342f136a53..b8486f7d5271 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -1781,7 +1781,7 @@ _notmuch_database_split_path (void *ctx,\r
+> \r
+> /* Finally, skip multiple slashes. */\r
+> while (slash != path) {\r
+> - if (*slash != '/')\r
+> + if (*(slash - 1) != '/')\r
+> break;\r
+> \r
+> --slash;\r
+> @@ -1794,7 +1794,7 @@ _notmuch_database_split_path (void *ctx,\r
+> *basename = path;\r
+> } else {\r
+> if (directory)\r
+> - *directory = talloc_strndup (ctx, path, slash - path + 1);\r
+> + *directory = talloc_strndup (ctx, path, slash - path);\r
+> }\r
+> \r
+> return NOTMUCH_STATUS_SUCCESS;\r
+> diff --git a/test/T050-new.sh b/test/T050-new.sh\r
+> index 174715aa2781..53e02d22c383 100755\r
+> --- a/test/T050-new.sh\r
+> +++ b/test/T050-new.sh\r
+> @@ -170,7 +170,6 @@ test_expect_equal "$output" "(D) add_files, pass 3: queuing leftover directory $\r
+> No new mail. Removed 3 messages."\r
+> \r
+> test_begin_subtest "One character directory at top level"\r
+> -test_subtest_known_broken\r
+> \r
+> generate_message [dir]=A\r
+> generate_message [dir]=A/B\r
+> @@ -179,10 +178,6 @@ generate_message [dir]=A/B/C\r
+> output=$(NOTMUCH_NEW --debug)\r
+> test_expect_equal "$output" "Added 3 new messages to the database."\r
+> \r
+> -# clean up after the broken test to not mess up other tests\r
+> -rm -rf "${MAIL_DIR}"/A\r
+> -NOTMUCH_NEW 2>&1 > /dev/null\r
+> -\r
+> test_begin_subtest "Support single-message mbox"\r
+> cat > "${MAIL_DIR}"/mbox_file1 <<EOF\r
+> From test_suite@notmuchmail.org Fri Jan 5 15:43:57 2001\r
+> -- \r
+> 2.1.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> https://notmuchmail.org/mailman/listinfo/notmuch\r