Vincent Lefevre wrote: > On 2015-07-28 06:47:20 -0700, Kevin J. McCarthy wrote: > > I agree it is surprising. Peeking in main.c, it looks like > > CurrentFolder is set far below where the initialization files are > > read. One idea would be to fall back on SpoolFile when CurrentFolder > > isn't set, but this is incorrect if the -f flag is passed to mutt. > > SpoolFile may be empty, so that it wouldn't be a solution either. > > Perhaps the empty string is OK, but an error should be generated > when ^ expands to the empty string. The advantage is that the user > would be aware of the error.
Here's a proposed patch. It adds a bit more explanation to the manual and adds error checking for these two cases: - When '^' is used and the CurrentFolder is NULL. - When a mailbox shortcut expansion returns an empty string. Ticket 3735 has a patch which rejects all empty regexp/pattern parameters. This might be a good idea, but might break some configs. (Currently, "folder-hook '' 'set sort=date'" is valid and equivalent to "folder-hook '.' 'set sort=date'".) This patch still allows an explicit empty regexp/pattern parameter, but not a non-empty regexp that expands to an empty one. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA http://www.8t8.us/configs/gpg-key-transition-statement.txt
# HG changeset patch # User Kevin McCarthy <[email protected]> # Date 1438135326 25200 # Tue Jul 28 19:02:06 2015 -0700 # Node ID aa98cb11f0451a073c08f3a33b7ef87b58072208 # Parent 6d733cab6b45c582ea9b4f19ab302013646c6f62 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. diff --git a/doc/manual.xml.head b/doc/manual.xml.head --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -5608,23 +5608,27 @@ folder-hook (^/home/user/Mail/bar) "set sort=threads" # This will expand to the default save folder for the alias "imap.example.com", which # is probably not what you want: 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> </sect1> <sect1 id="query"> <title>External Address Queries</title> diff --git a/hook.c b/hook.c --- a/hook.c +++ b/hook.c @@ -81,18 +81,35 @@ if (MoreArgs (s)) { strfcpy (err->data, _("too many arguments"), err->dsize); goto error; } 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); } else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ICONVHOOK | M_ACCOUNTHOOK)) && (!WithCrypto || !(data & M_CRYPTHOOK)) ) {
signature.asc
Description: PGP signature
