From: Kevin McCarthy <[email protected]>

This function is used by mx_get_magic() to check if a path is a
maildir mailbox.  I believe it was only looking for "cur" to save on
stat calls.

However, this can cause misbehavior in some cases.  The browser won't
enter a (non-maildir) directory that contains only a subdirectory
"cur".  On the other other hand, mutt relies on the "tmp" and "new"
subdirectories existing or fails operations, such as append to
mailbox, or postponing mail.
---
Just going through some branches I'd accumulated over the  past few years.

I'm sure I don't need to ask for feedback, but this is a tradeoff of a
couple stat calls for correct behavior in some less common situations.
Thoughts?

 mh.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/mh.c b/mh.c
index 45beb7b8..b048a791 100644
--- a/mh.c
+++ b/mh.c
@@ -2749,10 +2749,22 @@ int mx_is_maildir (const char *path)
   int rc = 0;
 
   tmp = mutt_buffer_pool_get ();
-  mutt_buffer_printf (tmp, "%s/cur", path);
-  if (stat (mutt_b2s (tmp), &st) == 0 && S_ISDIR (st.st_mode))
-    rc = 1;
 
+  mutt_buffer_printf (tmp, "%s/cur", path);
+  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
+    goto out;
+
+  mutt_buffer_printf (tmp, "%s/new", path);
+  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
+    goto out;
+
+  mutt_buffer_printf (tmp, "%s/tmp", path);
+  if (stat (mutt_b2s (tmp), &st) != 0 || !S_ISDIR (st.st_mode))
+    goto out;
+
+  rc = 1;
+
+out:
   mutt_buffer_pool_release (&tmp);
   return rc;
 }
-- 
2.52.0

Reply via email to