]> granicus.if.org Git - neomutt/commitdiff
folder-hook: try matching on description
authorAustin Ray <austin@austinray.io>
Fri, 4 Jan 2019 02:20:21 +0000 (21:20 -0500)
committerRichard Russon <rich@flatcap.org>
Sat, 5 Jan 2019 11:50:52 +0000 (11:50 +0000)
Use the description, in addition to the path, when determining to
execute a `folder-hook`. Since `named-mailboxes` and `virtual-mailboxes`
use descriptions to hide ugliness of raw paths, the description may
differ from the path and/or contain information not included in the
path.

The inclusion of description checking makes `folder-hook`s improves its
ergonomics. `notmuch` users were particularly affect by poor
`folder-hook` ergonomics since `virtual-mailboxes` paths often had large
overlap, making it hard to craft a good regex. A workaround was to add a
unique dummy key.

hook.c
hook.h
index.c
main.c
sendlib.c

diff --git a/hook.c b/hook.c
index ec09a195c0897578b60c233797aa59a685542c10..c70f604d367edf0f84e87be614c6469cd76c1f86 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -369,10 +369,14 @@ enum CommandResult mutt_parse_unhook(struct Buffer *buf, struct Buffer *s,
 
 /**
  * mutt_folder_hook - Perform a folder hook
- * @param path Path to match
+ * @param path Path to potentially match
+ * @param desc Description to potentially match
  */
-void mutt_folder_hook(const char *path)
+void mutt_folder_hook(const char *path, const char *desc)
 {
+  if (!path && !desc)
+    return;
+
   struct Hook *tmp = NULL;
   struct Buffer err, token;
 
@@ -389,7 +393,8 @@ void mutt_folder_hook(const char *path)
 
     if (tmp->type & MUTT_FOLDER_HOOK)
     {
-      if ((regexec(tmp->regex.regex, path, 0, NULL, 0) == 0) ^ tmp->regex.not)
+      if ((path && (regexec(tmp->regex.regex, path, 0, NULL, 0) == 0) ^ tmp->regex.not) ||
+          (desc && (regexec(tmp->regex.regex, desc, 0, NULL, 0) == 0) ^ tmp->regex.not))
       {
         if (mutt_parse_rc_line(tmp->command, &token, &err) == MUTT_CMD_ERROR)
         {
diff --git a/hook.h b/hook.h
index d30c2197e0caa8de77f9b9def68450e23c25f6b8..07344086107ecab524cfb4a59b7025f187949c86 100644 (file)
--- a/hook.h
+++ b/hook.h
@@ -66,7 +66,7 @@ void  mutt_crypt_hook(struct ListHead *list, struct Address *addr);
 void  mutt_default_save(char *path, size_t pathlen, struct Email *e);
 void  mutt_delete_hooks(int type);
 char *mutt_find_hook(int type, const char *pat);
-void  mutt_folder_hook(const char *path);
+void  mutt_folder_hook(const char *path, const char *desc);
 void  mutt_message_hook(struct Mailbox *m, struct Email *e, int type);
 enum CommandResult mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 enum CommandResult mutt_parse_unhook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
diff --git a/index.c b/index.c
index 091dcd82896399808a43c25dc22e0ad66486bb5a..071b24ebd1a69064981bc298beb0341259c96cb6 100644 (file)
--- a/index.c
+++ b/index.c
@@ -633,7 +633,7 @@ static int main_change_folder(struct Menu *menu, int op, struct Mailbox *m,
    * mutt_push/pop_current_menu() functions.  If that changes, the menu
    * would need to be reset here, and the pager cleanup code after the
    * switch statement would need to be run. */
-  mutt_folder_hook(buf);
+  mutt_folder_hook(buf, m->desc);
 
   const int flags =
       (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0;
diff --git a/main.c b/main.c
index 74c442839fbc495da93942c057e86d5ba2646712..1ba423bd9608ebbcbf5d01b27ee443845210e098 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1202,7 +1202,7 @@ int main(int argc, char *argv[], char *envp[])
       }
     }
 
-    mutt_folder_hook(folder);
+    mutt_folder_hook(folder, NULL);
     mutt_startup_shutdown_hook(MUTT_STARTUP_HOOK);
 
     repeat_error = true;
index 93a14f2e160937310cf4a9fd32200bb1234de0b0..22b364c214c921947d3c190086fec06a994ed0a1 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -3180,7 +3180,7 @@ int mutt_write_fcc(const char *path, struct Email *e, const char *msgid,
     set_noconv_flags(e->content, true);
 
 #ifdef RECORD_FOLDER_HOOK
-  mutt_folder_hook(path);
+  mutt_folder_hook(path, NULL);
 #endif
   struct Context *f = mx_mbox_open(NULL, path, MUTT_APPEND | MUTT_QUIET);
   if (!f)
@@ -3377,7 +3377,7 @@ done:
   /* We ran a folder hook for the destination mailbox,
    * now we run it for the user's current mailbox */
   if (Context && Context->mailbox->path)
-    mutt_folder_hook(Context->mailbox->path);
+    mutt_folder_hook(Context->mailbox->path, Context->mailbox->desc);
 #endif
 
   return rc;