]> granicus.if.org Git - neomutt/commitdiff
add 'virtual-mailboxes' parser
authorKarel Zak <kzak@redhat.com>
Wed, 14 Dec 2011 12:16:44 +0000 (13:16 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 14 Mar 2016 23:11:40 +0000 (23:11 +0000)
Signed-off-by: Karel Zak <kzak@redhat.com>
README.notmuch
buffy.c
buffy.h
init.h
protos.h

index 989029e5174c50ab1e2ee4f651b4f7b62c575a60..1a5f3b75968d2841b8010004bda23ec61ece305d 100644 (file)
@@ -5,6 +5,7 @@ notmuch support for mutt
  * notmuch is e-email library for e-mail fulltext indexing and tagging; see
    http://notmuchmail.org/ for more information.
 
+
  * compile:
 
   $ git clone git://github.com/karelzak/mutt-kz.git
@@ -13,3 +14,17 @@ notmuch support for mutt
   $ ./configure --enable-notmuch
   $ make
 
+
+ * virtual mailboxes
+
+   .muttrc:
+
+     synopsis:
+
+      virtual-mailboxes <desciption> <uri> [ ...]
+
+     example:
+
+       virtual-mailboxes "Linux Kernel" "notmuch:///whereis/db?query=tag:lkml&limit=1000" \
+                         "Filesystems"  "notmuch:///whereis/db?query=tag:fs" \
+                         "Music"        "notmuch:///another/db?query=tag:hard and tag:heavy"
diff --git a/buffy.c b/buffy.c
index 82d6fc93729a781106468c4d2d7fcce563823a7d..aaf462208ccb3aea4229f997d6f25e9a0cd2ed05 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -219,6 +219,8 @@ static BUFFY *buffy_new (const char *path)
 
 static void buffy_free (BUFFY **mailbox)
 {
+  if (mailbox && *mailbox)
+    FREE (&(*mailbox)->desc);
   FREE (mailbox); /* __FREE_CHECKED__ */
 }
 
@@ -377,6 +379,46 @@ static int buffy_maildir_dir_hasnew(BUFFY* mailbox, const char *dir_name)
   return rc;
 }
 
+#ifdef USE_NOTMUCH
+int mutt_parse_virtual_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  BUFFY **tmp;
+  char buf[_POSIX_PATH_MAX];
+
+  while (MoreArgs (s))
+  {
+    mutt_extract_token (path, s, 0);
+    strfcpy (buf, path->data, sizeof (buf));
+
+    /* Skip empty tokens. */
+    if(!*buf) continue;
+
+    /* avoid duplicates */
+    for (tmp = &VirtIncoming; *tmp; tmp = &((*tmp)->next))
+    {
+      if (mutt_strcmp (buf, (*tmp)->path) == 0)
+      {
+       dprint(3,(debugfile,"vistual mailbox '%s' already registered as '%s'\n", buf, (*tmp)->path));
+       break;
+      }
+    }
+
+    if (!*tmp)
+      *tmp = buffy_new (buf);
+
+    mutt_extract_token (path, s, 0);
+    if (path->data && *path->data)
+      (*tmp)->desc = safe_strdup( path->data);
+
+    (*tmp)->new = 0;
+    (*tmp)->notified = 1;
+    (*tmp)->newly_created = 0;
+    (*tmp)->size = 0;
+  }
+  return 0;
+}
+#endif
+
 /* returns 1 if maildir has new mail */
 static int buffy_maildir_hasnew (BUFFY* mailbox)
 {
diff --git a/buffy.h b/buffy.h
index 38dc4c1abec8cee44bbbff8cf4d5af61c592421f..9e3053c7f3f39f5bb727a0cdc420c84bac3bd813 100644 (file)
--- a/buffy.h
+++ b/buffy.h
@@ -26,6 +26,7 @@ typedef struct buffy_t
 #ifdef USE_SIDEBAR
   char realpath[_POSIX_PATH_MAX];
 #endif
+  char *desc;
   off_t size;
   struct buffy_t *next;
 #ifdef USE_SIDEBAR
@@ -51,6 +52,10 @@ BUFFY;
 WHERE BUFFY *Incoming INITVAL (0);
 WHERE short BuffyTimeout INITVAL (3);
 
+#ifdef USE_NOTMUCH
+WHERE BUFFY *VirtIncoming INITVAL (0);
+#endif
+
 extern time_t BuffyDoneTime;   /* last time we knew for sure how much mail there was */
 
 BUFFY *mutt_find_mailbox (const char *path);
diff --git a/init.h b/init.h
index 04f329a240d36214a09c8f10b0f386a74ff0bda3..bbc115c71fdada02f29b66dcaa5fb498862d353f 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3818,6 +3818,9 @@ const struct command_t Commands[] = {
   { "macro",           mutt_parse_macro,       0 },
   { "mailboxes",       mutt_parse_mailboxes,   M_MAILBOXES },
   { "unmailboxes",     mutt_parse_mailboxes,   M_UNMAILBOXES },
+#ifdef USE_NOTMUCH
+  { "virtual-mailboxes",mutt_parse_virtual_mailboxes, 0 },
+#endif
   { "message-hook",    mutt_parse_hook,        M_MESSAGEHOOK },
   { "mbox-hook",       mutt_parse_hook,        M_MBOXHOOK },
   { "mime_lookup",     parse_list,     UL &MimeLookupList },
index 931a2e1f5952362cea585d0af164f58c1dcd483d..b1d20daebc4a5a20f24b0963d1b469c3a1530f09 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -80,6 +80,9 @@ void mutt_generate_boundary (PARAMETER **);
 void mutt_delete_parameter (const char *attribute, PARAMETER **p);
 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);
+#endif
 
 FILE *mutt_open_read (const char *, pid_t *);