changeset: 6475:75e398daa94c
user:      Kevin McCarthy <[email protected]>
date:      Wed Jul 29 09:07:51 2015 -0700
link:      http://dev.mutt.org/hg/mutt/rev/75e398daa94c

Add error handling for ^ and other empty mailbox shortcuts.

(closes #2402) (closes #3735)

Explicitly mention the ^ example in the documentation added in 6d733cab6b45.

Add an error message for ^ when CurrentFolder is not set.  Add checks
for other mailbox shortcuts that expand to the empty string.  This
could happen if the @alias shortcut was accidentally used, or the value
referenced by a shortcut isn't set yet.

diffs (52 lines):

diff -r 6d733cab6b45 -r 75e398daa94c doc/manual.xml.head
--- a/doc/manual.xml.head       Mon Jul 27 14:09:55 2015 -0700
+++ b/doc/manual.xml.head       Wed Jul 29 09:07:51 2015 -0700
@@ -5613,13 +5613,17 @@
 
 # A workaround is to use parenthesis or a backslash:
 folder-hook (@imap.example.com) "set sort=threads"
-folder-hook \@imap.example.com "set sort=threads"
+folder-hook '\@imap.example.com' "set sort=threads"
 </screen>
 
 <para>
 Keep in mind that mailbox shortcut expansion on the regexp parameter
 takes place when the hook is initially parsed, not when the hook is
-matching against a mailbox.
+matching against a mailbox.  When Mutt starts up and is reading the
+.muttrc, some mailbox shortcuts may not be usable.  For example, the
+"current mailbox" shortcut, ^, will expand to an empty string because no
+mailbox has been opened yet.  Mutt will issue an error for this case or
+if the mailbox shortcut results in an empty regexp.
 </para>
 
 </sect2>
diff -r 6d733cab6b45 -r 75e398daa94c hook.c
--- a/hook.c    Mon Jul 27 14:09:55 2015 -0700
+++ b/hook.c    Wed Jul 29 09:07:51 2015 -0700
@@ -86,8 +86,25 @@
 
   if (data & (M_FOLDERHOOK | M_MBOXHOOK))
   {
+    /* Accidentally using the ^ mailbox shortcut in the .muttrc is a
+     * common mistake */
+    if ((*pattern.data == '^') && (! CurrentFolder))
+    {
+      strfcpy (err->data, _("current mailbox shortcut '^' is unset"), 
err->dsize);
+      goto error;
+    }
+
     strfcpy (path, pattern.data, sizeof (path));
     _mutt_expand_path (path, sizeof (path), 1);
+
+    /* Check for other mailbox shortcuts that expand to the empty string.
+     * This is likely a mistake too */
+    if (!*path && *pattern.data)
+    {
+      strfcpy (err->data, _("mailbox shortcut expanded to empty regexp"), 
err->dsize);
+      goto error;
+    }
+
     FREE (&pattern.data);
     memset (&pattern, 0, sizeof (pattern));
     pattern.data = safe_strdup (path);

Reply via email to