]> granicus.if.org Git - neomutt/commitdiff
Add error handling for ^ and other empty mailbox shortcuts.
authorKevin McCarthy <kevin@8t8.us>
Wed, 29 Jul 2015 16:07:51 +0000 (09:07 -0700)
committerKevin McCarthy <kevin@8t8.us>
Wed, 29 Jul 2015 16:07:51 +0000 (09:07 -0700)
(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.

doc/manual.xml.head
hook.c

index b88f8769bb4e1b41f7d395b8d2ba4632e1dc76cc..79c6468cd8d57e22324cb54babb3cfd62475d660 100644 (file)
@@ -5613,13 +5613,17 @@ folder-hook @imap.example.com "set sort=threads"
 
 # 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 --git a/hook.c b/hook.c
index 664b1e4599f448039d7cde5fc452ddca39883021..a89b615231c6e48698ca13f8cf3123eef35277b2 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -86,8 +86,25 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
 
   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);