]> granicus.if.org Git - neomutt/commitdiff
Add browser sort by description, message count and new message count
authorTim Stoakes <tim@stoakes.net>
Sun, 16 Sep 2012 07:31:54 +0000 (09:31 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:32:55 +0000 (03:32 +0100)
Now the browser can sort by mail folder description, (all) message count, and
new message count.

browser.c
browser.h
init.h
sort.h

index 46919a0b8efd73f1a86c9c7a9df7a5bb80de38d6..3d21ab19b4283b9620705423eacfb94808aded63 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -29,6 +29,7 @@
 #include "sort.h"
 #include "mailbox.h"
 #include "browser.h"
+#include "mx.h"
 #ifdef USE_IMAP
 #include "imap.h"
 #endif
@@ -86,6 +87,16 @@ static int browser_compare_subject (const void *a, const void *b)
   return ((BrowserSort & SORT_REVERSE) ? -r : r);
 }
 
+static int browser_compare_desc (const void *a, const void *b)
+{
+  struct folder_file *pa = (struct folder_file *) a;
+  struct folder_file *pb = (struct folder_file *) b;
+
+  int r = mutt_strcoll (pa->desc, pb->desc);
+
+  return ((BrowserSort & SORT_REVERSE) ? -r : r);
+}
+
 static int browser_compare_date (const void *a, const void *b)
 {
   struct folder_file *pa = (struct folder_file *) a;
@@ -106,6 +117,26 @@ static int browser_compare_size (const void *a, const void *b)
   return ((BrowserSort & SORT_REVERSE) ? -r : r);
 }
 
+static int browser_compare_count (const void *a, const void *b)
+{
+  struct folder_file *pa = (struct folder_file *) a;
+  struct folder_file *pb = (struct folder_file *) b;
+
+  int r = pa->all - pb->all;
+
+  return ((BrowserSort & SORT_REVERSE) ? -r : r);
+}
+
+static int browser_compare_count_new (const void *a, const void *b)
+{
+  struct folder_file *pa = (struct folder_file *) a;
+  struct folder_file *pb = (struct folder_file *) b;
+
+  int r = pa->new - pb->new;
+
+  return ((BrowserSort & SORT_REVERSE) ? -r : r);
+}
+
 static void browser_sort (struct browser_state *state)
 {
   int (*f) (const void *, const void *);
@@ -120,6 +151,15 @@ static void browser_sort (struct browser_state *state)
     case SORT_SIZE:
       f = browser_compare_size;
       break;
+    case SORT_DESC:
+      f = browser_compare_desc;
+      break;
+    case SORT_COUNT:
+      f = browser_compare_count;
+      break;
+    case SORT_COUNT_NEW:
+      f = browser_compare_count_new;
+      break;
     case SORT_SUBJECT:
     default:
       f = browser_compare_subject;
@@ -260,7 +300,16 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char *
       else
        mutt_format_s (dest, destlen, fmt, "");
       break;
-      
+
+    case 'n':
+      if (!optional) {
+       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+       snprintf (dest, destlen, tmp, folder->ff->all);
+      } else if (!folder->ff->all) {
+       optional = 0;
+      }
+      break;
+
     case 'N':
 #ifdef USE_IMAP
       if (mx_is_imap (folder->ff->desc))
@@ -325,7 +374,8 @@ folder_format_str (char *dest, size_t destlen, size_t col, char op, const char *
 }
 
 static void add_folder (MUTTMENU *m, struct browser_state *state,
-                       const char *name, const struct stat *s, unsigned int new)
+                       const char *name, const char *desc,
+                       const struct stat *s, unsigned int new, unsigned int all)
 {
   if (state->entrylen == state->entrymax)
   {
@@ -349,8 +399,9 @@ static void add_folder (MUTTMENU *m, struct browser_state *state,
   }
 
   (state->entry)[state->entrylen].new = new;
+  (state->entry)[state->entrylen].all = all;
   (state->entry)[state->entrylen].name = safe_strdup (name);
-  (state->entry)[state->entrylen].desc = safe_strdup (name);
+  (state->entry)[state->entrylen].desc = safe_strdup(desc ? desc : name);
 #ifdef USE_IMAP
   (state->entry)[state->entrylen].imap = 0;
 #endif
@@ -432,7 +483,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
     tmp = Incoming;
     while (tmp && mutt_strcmp (buffer, tmp->path))
       tmp = tmp->next;
-    add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0);
+    add_folder (menu, state, de->d_name, NULL, &s, (tmp) ? tmp->new : 0, 0);
   }
   closedir (dp);  
   browser_sort (state);
@@ -460,14 +511,14 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
     if (mx_is_imap (tmp->path))
     {
       imap_mailbox_state (tmp->path, &mbox);
-      add_folder (menu, state, tmp->path, NULL, mbox.new);
+      add_folder (menu, state, tmp->path, NULL, NULL, mbox.new, mbox.messages);
       continue;
     }
 #endif
 #ifdef USE_POP
     if (mx_is_pop (tmp->path))
     {
-      add_folder (menu, state, tmp->path, NULL, tmp->new);
+      add_folder (menu, state, tmp->path, NULL, NULL, tmp->new, 0);
       continue;
     }
 #endif
@@ -496,7 +547,7 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
     strfcpy (buffer, NONULL(tmp->path), sizeof (buffer));
     mutt_pretty_mailbox (buffer, sizeof (buffer));
 
-    add_folder (menu, state, buffer, &s, tmp->new);
+    add_folder (menu, state, buffer, NULL, &s, tmp->new, 0);
   }
   while ((tmp = tmp->next));
   browser_sort (state);
@@ -1136,9 +1187,9 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
          int reverse = (i == OP_SORT_REVERSE);
          
          switch (mutt_multi_choice ((reverse) ?
-             _("Reverse sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? ") :
-             _("Sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? "),
-             _("dazn")))
+             _("Reverse sort by (d)ate, (a)lpha, si(z)e, d(e)scription, (c)ount, ne(w) count, or do(n)'t sort? ") :
+             _("Sort by (d)ate, (a)lpha, si(z)e, d(e)scription, (c)ount, ne(w) count, or do(n)'t sort? "),
+             _("dazecwn")))
          {
            case -1: /* abort */
              resort = 0;
@@ -1156,7 +1207,19 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
              BrowserSort = SORT_SIZE;
              break;
 
-            case 4: /* do(n)'t sort */
+            case 4: /* d(e)scription */
+             BrowserSort = SORT_DESC;
+             break;
+
+            case 5: /* (c)ount */
+             BrowserSort = SORT_COUNT;
+             break;
+
+            case 6: /* ne(w) count */
+             BrowserSort = SORT_COUNT_NEW;
+             break;
+
+            case 7: /* do(n)'t sort */
              BrowserSort = SORT_ORDER;
              resort = 0;
              break;
index 515d69f1add69de2df1c61dcb6c47281919ef4d8..e0cf72f26683d4df96f1bdd10544e7db2a5ba23c 100644 (file)
--- a/browser.h
+++ b/browser.h
@@ -30,6 +30,8 @@ struct folder_file
   char *desc;
 
   unsigned int new;
+  unsigned int all;
+
 #ifdef USE_IMAP
   char delim;
   
diff --git a/init.h b/init.h
index 5a12ec0d06b7267b630e858b8393704ff85fb5cd..5e6f9d17b8ea7d22f0002930b4a3fa19713f3eb9 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3046,7 +3046,10 @@ struct option_t MuttVars[] = {
   ** entries are sorted alphabetically.  Valid values:
   ** .il
   ** .dd alpha (alphabetically)
+  ** .dd count (all message count)
   ** .dd date
+  ** .dd desc (description)
+  ** .dd new (new message count)
   ** .dd size
   ** .dd unsorted
   ** .ie
@@ -3631,7 +3634,10 @@ const struct mapping_t SortAuxMethods[] = {
 
 const struct mapping_t SortBrowserMethods[] = {
   { "alpha",   SORT_SUBJECT },
+  { "count",   SORT_COUNT },
   { "date",    SORT_DATE },
+  { "desc",    SORT_DESC },
+  { "new",     SORT_COUNT_NEW },
   { "size",    SORT_SIZE },
   { "unsorted",        SORT_ORDER },
   { NULL,       0 }
diff --git a/sort.h b/sort.h
index f2832b21ea28de06f4955be60bb2504f1e0d9272..5f66f79ea1004c2bbe0cf2854e3ab53799e5b067 100644 (file)
--- a/sort.h
+++ b/sort.h
@@ -31,6 +31,9 @@
 #define SORT_KEYID     12
 #define SORT_TRUST     13
 #define SORT_SPAM      14
+#define SORT_DESC      15
+#define SORT_COUNT     16
+#define SORT_COUNT_NEW 17
 /* dgc: Sort & SortAux are shorts, so I'm bumping these bitflags up from
  * bits 4 & 5 to bits 8 & 9 to make room for more sort keys in the future. */
 #define SORT_MASK      0xff