]> granicus.if.org Git - neomutt/commitdiff
notmuch: add "virtual-unmailboxes" command
authorRichard Russon <rich@flatcap.org>
Sat, 23 Jul 2016 22:08:53 +0000 (23:08 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 26 Dec 2016 15:18:15 +0000 (15:18 +0000)
This new command removes virtual mailboxes (notmuch queries).

Closes: karelzak/mutt-kz#76
Closes: karelzak/mutt-kz#144
buffy.c
doc/manual.xml.head
init.h
protos.h

diff --git a/buffy.c b/buffy.c
index 4c97602664429c9d7d89f84251584f8b4d1c584c..25c68d72aa3d057d65f01fb83bd486a50ebd7157 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -506,12 +506,66 @@ int mutt_parse_virtual_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, B
     if (!*tmp)
       *tmp = buffy_new (buf);
 
+    (*tmp)->magic = MUTT_NOTMUCH;
     (*tmp)->new = 0;
     (*tmp)->notified = 1;
     (*tmp)->newly_created = 0;
     (*tmp)->size = 0;
     (*tmp)->desc = desc;
+#ifdef USE_SIDEBAR
+    mutt_sb_notify_mailbox (*tmp, 1);
+#endif
+  }
+#ifdef USE_SIDEBAR
+  mutt_sb_draw();
+#endif
+  return 0;
+}
+
+int mutt_parse_unvirtual_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  BUFFY **tmp, *tmp1;
+
+  while (MoreArgs (s))
+  {
+    mutt_extract_token (path, s, 0);
+
+    if (mutt_strcmp (path->data, "*") == 0)
+    {
+      for (tmp = &VirtIncoming; *tmp;)
+      {
+        tmp1 = (*tmp)->next;
+#ifdef USE_SIDEBAR
+        mutt_sb_notify_mailbox (*tmp, 0);
+#endif
+        buffy_free (tmp);
+        *tmp = tmp1;
+      }
+#ifdef USE_SIDEBAR
+      mutt_sb_draw();
+#endif
+      return 0;
+    }
+
+    for (tmp = &VirtIncoming; *tmp; tmp = &((*tmp)->next))
+    {
+      if ((mutt_strcasecmp (path->data, (*tmp)->path) == 0) ||
+          (mutt_strcasecmp (path->data, (*tmp)->desc) == 0))
+      {
+        tmp1 = (*tmp)->next;
+#ifdef USE_SIDEBAR
+        mutt_sb_notify_mailbox (*tmp, 0);
+#endif
+        buffy_free (tmp);
+        *tmp = tmp1;
+        break;
+      }
+    }
   }
+
+#ifdef USE_SIDEBAR
+  mutt_sb_draw();
+#endif
   return 0;
 }
 #endif
index 58b16a87ad91ef408374e7bc887c0a5dba26f7c5..a62f4716bbadd4124724170d943c88dc6b89edf4 100644 (file)
@@ -12247,6 +12247,16 @@ virtual-mailboxes "My INBOX" "notmuch://?query=tag:inbox"
         </arg>
       </group>
 
+      <command>unvirtual-mailboxes</command>
+      <group choice="req">
+        <arg choice="plain">
+          <replaceable class="parameter">*</replaceable>
+        </arg>
+        <arg choice="plain" rep="repeat">
+          <replaceable class="parameter">mailbox</replaceable>
+        </arg>
+      </group>
+
       <command>tag-transforms</command>
       <arg choice="plain">
         <replaceable class="parameter">tag</replaceable>
@@ -12392,6 +12402,8 @@ bind index,pager \eX vfolder-from-query
 # virtual-mailboxes description notmuch-URI { description notmuch-URI ...}
 # virtual-mailboxes &quot;Climbing&quot; &quot;notmuch://?query=climbing&quot;
 
+# unvirtual-mailboxes { * | mailbox ...}
+
 # Replace some tags with icons
 # tag-transforms tag transformed-string { tag transformed-string ...}
 # tag-transforms &quot;inbox&quot;   &quot;i&quot;   \
diff --git a/init.h b/init.h
index 4135dbf10fd75649c2010883921544117e734e45..0229bf9b1ddc135a62de8197ff3e628afd3b56c0 100644 (file)
--- a/init.h
+++ b/init.h
@@ -4401,6 +4401,7 @@ const struct command_t Commands[] = {
   { "unmailboxes",     mutt_parse_mailboxes,   MUTT_UNMAILBOXES },
 #ifdef USE_NOTMUCH
   { "virtual-mailboxes",mutt_parse_virtual_mailboxes, 0 },
+  { "unvirtual-mailboxes",mutt_parse_unvirtual_mailboxes, 0 },
   { "tag-transforms",  parse_tag_transforms,   0 },
   { "tag-formats",     parse_tag_formats,      0 },
 #endif
index f9cd30976d5e14a95f6e8f2c2b06a88cd5713d3d..72eb5e6e764ce3808786df4e13fcefb44fc454fd 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -87,6 +87,7 @@ void mutt_set_parameter (const char *, const char *, PARAMETER **);
 
 #ifdef USE_NOTMUCH
 int mutt_parse_virtual_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *err);
+int mutt_parse_unvirtual_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *err);
 #endif
 
 FILE *mutt_open_read (const char *, pid_t *);