From bed17ddc332dbede496e58f83c092c0f885e39fc Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 29 Jul 2015 09:07:51 -0700 Subject: [PATCH] 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. --- doc/manual.xml.head | 8 ++++++-- hook.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/manual.xml.head b/doc/manual.xml.head index b88f8769b..79c6468cd 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -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" 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. diff --git a/hook.c b/hook.c index 664b1e459..a89b61523 100644 --- 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); -- 2.40.0