]> granicus.if.org Git - neomutt/commitdiff
add support to browser
authorKarel Zak <kzak@redhat.com>
Wed, 14 Dec 2011 15:43:07 +0000 (16:43 +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>
browser.c
mutt.h

index 6e737235e940787048661d2e7509bfe83e612104..ca3447f466386fcabb39a213a6b24b3ac096d7be 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -33,6 +33,9 @@
 #ifdef USE_IMAP
 #include "imap.h"
 #endif
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
 
 #include <stdlib.h>
 #include <dirent.h>
@@ -232,6 +235,12 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char *
     case 'f':
     {
       char *s;
+
+#ifdef USE_NOTMUCH
+      if (mx_is_notmuch(folder->ff->name))
+        s = NONULL (folder->ff->desc);
+      else
+#endif
 #ifdef USE_IMAP
       if (folder->ff->imap)
        s = NONULL (folder->ff->desc);
@@ -323,6 +332,14 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char *
          optional = 0;
        break;
       }
+#endif
+#ifdef USE_NOTMUCH
+      if (mx_is_notmuch (folder->ff->name))
+      {
+       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+       snprintf (dest, destlen, tmp, folder->ff->new);
+       break;
+      }
 #endif
       snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
       snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : ' ');
@@ -490,6 +507,33 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
   return 0;
 }
 
+#ifdef USE_NOTMUCH
+static int examine_vfolders (MUTTMENU *menu, struct browser_state *state)
+{
+  BUFFY *tmp = VirtIncoming;
+
+  if (!VirtIncoming)
+    return (-1);
+  mutt_buffy_check (0);
+
+  init_state (state, menu);
+
+  do
+  {
+    if (mx_is_notmuch (tmp->path))
+    {
+      unsigned new = 0, all = 0;
+      nm_get_count(tmp->path, &all, &new);
+      add_folder (menu, state, tmp->path, tmp->desc, NULL, new, all);
+      continue;
+    }
+  }
+  while ((tmp = tmp->next));
+  browser_sort (state);
+  return 0;
+}
+#endif
+
 static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
 {
   struct stat s;
@@ -570,6 +614,19 @@ static void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
       (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
 }
 
+#ifdef USE_NOTMUCH
+static void vfolder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
+{
+  FOLDER folder;
+
+  folder.ff = &((struct folder_file *) menu->data)[num];
+  folder.num = num;
+
+  mutt_FormatString (s, slen, 0, NONULL(VirtFolderFormat), folder_format_str,
+      (unsigned long) &folder, M_FORMAT_ARROWCURSOR);
+}
+#endif
+
 static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
                       size_t titlelen, int buffy)
 {
@@ -635,7 +692,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
   int buffy    = (flags & M_SEL_BUFFY)  ? 1 : 0;
 
   buffy = buffy && folder;
-  
+
   memset (&state, 0, sizeof (struct browser_state));
 
   if (!folder)
@@ -688,13 +745,17 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
     }
 #endif
   }
-  else 
+#ifdef USE_NOTMUCH
+  else if (!(flags & M_SEL_VFOLDER))
+#else
+  else
+#endif
   {
     if (!folder)
       getcwd (LastDir, sizeof (LastDir));
     else if (!LastDir[0])
       strfcpy (LastDir, NONULL(Maildir), sizeof (LastDir));
-    
+
 #ifdef USE_IMAP
     if (!buffy && mx_is_imap (LastDir))
     {
@@ -716,6 +777,12 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
 
   *f = 0;
 
+#ifdef USE_NOTMUCH
+  if (flags & M_SEL_VFOLDER) {
+    if (examine_vfolders (NULL, &state) == -1)
+      goto bail;
+  } else
+#endif
   if (buffy)
   {
     if (examine_mailboxes (NULL, &state) == -1)
@@ -725,11 +792,18 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
 #ifdef USE_IMAP
   if (!state.imap_browse)
 #endif
+  {
   if (examine_directory (NULL, &state, LastDir, prefix) == -1)
     goto bail;
-
+  }
   menu = mutt_new_menu (MENU_FOLDER);
-  menu->make_entry = folder_entry;
+#ifdef USE_NOTMUCH
+  if (flags & M_SEL_VFOLDER)
+    menu->make_entry = vfolder_entry;
+  else
+#endif
+    menu->make_entry = folder_entry;
+
   menu->search = select_file_search;
   menu->title = title;
   menu->data = state.entry;
@@ -883,6 +957,10 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
 #ifdef USE_IMAP
        else if (state.imap_browse)
           strfcpy (f, state.entry[menu->current].name, flen);
+#endif
+#ifdef USE_NOTMUCH
+       else if (mx_is_notmuch(state.entry[menu->current].name))
+         strfcpy (f, state.entry[menu->current].name, flen);
 #endif
        else
          mutt_concat_path (f, LastDir, state.entry[menu->current].name, flen);
@@ -1038,7 +1116,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
         }
         break;
 #endif
-      
+
       case OP_CHANGE_DIRECTORY:
 
        strfcpy (buf, LastDir, sizeof (buf));
diff --git a/mutt.h b/mutt.h
index 6a9647d3b2cebf2bb71a3b955c2ede52e7d8ec54..def2ca894a5c65620a12d053b10dd42ab7288efb 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -314,6 +314,7 @@ enum
 #define M_SEL_BUFFY    (1<<0)
 #define M_SEL_MULTI    (1<<1)
 #define M_SEL_FOLDER   (1<<2)
+#define M_SEL_VFOLDER  (1<<3)
 
 /* flags for parse_spam_list */
 #define M_SPAM          1