]> mj.ucw.cz Git - checkmail.git/blobdiff - cm.c
Added sort order option
[checkmail.git] / cm.c
diff --git a/cm.c b/cm.c
index a2c27d28bcbab90ecd9ce366190819c18be12970..aa300f6f1b2e5d11cb5b7037c48e60f051f998ec 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -55,6 +55,7 @@ struct options {
   int led;
   int osd;
   int unread_is_new;
   int led;
   int osd;
   int unread_is_new;
+  int sort_order;
 };
 
 struct option_node {
 };
 
 struct option_node {
@@ -71,7 +72,8 @@ struct pattern_node {
 
 static clist options, patterns;
 static struct options global_options = {
 
 static clist options, patterns;
 static struct options global_options = {
-  .sender_personal = 1
+  .sender_personal = 1,
+  .sort_order = 1000,
 };
 
 #define MDIR_MAX_NAME_LEN 128
 };
 
 #define MDIR_MAX_NAME_LEN 128
@@ -155,6 +157,7 @@ init_options(struct options *o)
   o->led = -1;
   o->osd = -1;
   o->unread_is_new = -1;
   o->led = -1;
   o->osd = -1;
   o->unread_is_new = -1;
+  o->sort_order = -1;
 }
 
 static void
 }
 
 static void
@@ -179,6 +182,7 @@ setup_options(struct mbox *b)
        MERGE(led);
        MERGE(osd);
        MERGE(unread_is_new);
        MERGE(led);
        MERGE(osd);
        MERGE(unread_is_new);
+       MERGE(sort_order);
       }
 }
 
       }
 }
 
@@ -202,24 +206,30 @@ mbox_name(char *path)
 }
 
 static struct mbox *
 }
 
 static struct mbox *
-add_mbox(clist *l, char *path, char *name)
+new_mbox(char *path, char *name)
 {
   struct mbox *b = xmalloc(sizeof(*b));
   bzero(b, sizeof(*b));
   b->path = xstrdup(path);
   b->name = xstrdup(name);
 {
   struct mbox *b = xmalloc(sizeof(*b));
   bzero(b, sizeof(*b));
   b->path = xstrdup(path);
   b->name = xstrdup(name);
+  return b;
+}
 
 
-  if (name)
+static void
+add_mbox(clist *l, struct mbox *b)
+{
+  if (b->name)
     {
       cnode *prev = l->head.prev;
     {
       cnode *prev = l->head.prev;
-      while (prev != &l->head && strcmp(((struct mbox *)prev)->name, name) > 0)
+      struct mbox *prev_mbox;
+      while (prev != &l->head &&
+         ((prev_mbox = (struct mbox *)prev)->o.sort_order > b->o.sort_order ||
+          prev_mbox->o.sort_order == b->o.sort_order && strcmp(((struct mbox *)prev)->name, b->name) > 0))
        prev = prev->prev;
       clist_insert_after(&b->n, prev);
     }
   else
     clist_add_tail(l, &b->n);
        prev = prev->prev;
       clist_insert_after(&b->n, prev);
     }
   else
     clist_add_tail(l, &b->n);
-
-  return b;
 }
 
 static void
 }
 
 static void
@@ -747,9 +757,10 @@ scan(int notify)
          struct mbox *b = find_mbox(&mboxes, name);
          if (!b)
            {
          struct mbox *b = find_mbox(&mboxes, name);
          if (!b)
            {
-             b = add_mbox(&mboxes, name, (p->name ? p->name : mbox_name(name)));
+             b = new_mbox(name, (p->name ? p->name : mbox_name(name)));
              debug("Discovered mailbox %s (%s)\n", b->name, b->path);
              setup_options(b);
              debug("Discovered mailbox %s (%s)\n", b->name, b->path);
              setup_options(b);
+             add_mbox(&mboxes, b);
              b->scanning = -1;
            }
          b->seen = 1;
              b->scanning = -1;
            }
          b->seen = 1;
@@ -1551,6 +1562,7 @@ l<led>\t\t\tLight a keyboard led (1-9) if running on X display\n\
 m\t\t\tShow mailbox name of the sender\n\
 o\t\t\tCount old, but unread messages as new\n\
 p\t\t\tShow personal info (full name) of the sender\n\
 m\t\t\tShow mailbox name of the sender\n\
 o\t\t\tCount old, but unread messages as new\n\
 p\t\t\tShow personal info (full name) of the sender\n\
+r<int>\t\t\tSort order (default=1000)\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
 !<key>\t\t\tSet hot key\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
 !<key>\t\t\tSet hot key\n\
@@ -1587,6 +1599,12 @@ parse_options(char *c)
       o->hotkey = *c++;
     else if (x == 'l' && *c >= '1' && *c <= '9')
       o->led = *c++ - '0';
       o->hotkey = *c++;
     else if (x == 'l' && *c >= '1' && *c <= '9')
       o->led = *c++ - '0';
+    else if (x == 'r' && *c >= '0' && *c <= '9')
+      {
+       o->sort_order = 0;
+       while (*c >= '0' && *c <= '9')
+         o->sort_order = 10*o->sort_order + *c++ - '0';
+      }
     else
       {
        int value = !!islower(x);
     else
       {
        int value = !!islower(x);