]> mj.ucw.cz Git - checkmail.git/commitdiff
Show flagged messages if there are no new mails.
authorMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 14:01:38 +0000 (16:01 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 25 Jun 2007 14:01:38 +0000 (16:01 +0200)
README
cm.c

diff --git a/README b/README
index a4d49e7d11dde96dbedbb447f79e2cedd2ff459f..8696017996c122e4c5b936714e75393be5f83857 100644 (file)
--- a/README
+++ b/README
@@ -2,7 +2,7 @@
 
                                 Checkmail @VERSION@
 
-                      (c) 2005 Martin Mares <mj@ucw.cz>
+                   (c) 2005--2007 Martin Mares <mj@ucw.cz>
 
 ================================================================================
 
diff --git a/cm.c b/cm.c
index 3a4630e63762b8e4d582882773665d1c71322dde..cce8c273e4fa6e735761e33a9296cd2f7d09c6bd 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -1,7 +1,7 @@
 /*
  *     Incoming Mail Checker
  *
- *     (c) 2005 Martin Mares <mj@ucw.cz>
+ *     (c) 2005--2007 Martin Mares <mj@ucw.cz>
  */
 
 #include <stdio.h>
@@ -35,6 +35,7 @@ struct options {
   int highlight;
   int beep;
   int snippets;
+  int show_flagged;
 };
 
 struct option_node {
@@ -62,10 +63,11 @@ struct mbox {
   int seen;
   time_t last_time;
   int last_size, last_pos;
-  int total, new;
+  int total, new, flagged;
   int last_total, last_new;
   int last_beep_new;
   int force_refresh;
+  int snippet_is_new;
   char snippet[256];
 };
 
@@ -111,6 +113,7 @@ init_options(struct options *o)
   o->beep = -1;
   o->highlight = -1;
   o->snippets = -1;
+  o->show_flagged = -1;
 }
 
 static void
@@ -128,6 +131,7 @@ setup_options(struct mbox *b)
        MERGE(highlight);
        MERGE(beep);
        MERGE(snippets);
+       MERGE(show_flagged);
       }
 }
 
@@ -364,6 +368,7 @@ scan_mbox(struct mbox *b, struct stat *st)
        }
       b->total = b->new = 0;
       b->last_total = b->last_new = 0;
+      b->snippet_is_new = 0;
     }
   else
     {
@@ -382,6 +387,7 @@ scan_mbox(struct mbox *b, struct stat *st)
        ;
 
       int new = 1;
+      int flagged = 0;
       sender[0] = 0;
       subject[0] = 0;
       for (;;)
@@ -419,6 +425,8 @@ scan_mbox(struct mbox *b, struct stat *st)
            break;
          if (!strncasecmp(buf, "Status:", 7))
            new = 0;
+         else if (!strncasecmp(buf, "X-Status:", 9) && strchr(buf+9, 'F'))
+           flagged = 1;
          else if (!strncasecmp(buf, "From:", 5))
            strcpy(sender, buf+5);
          else if (!strncasecmp(buf, "Subject:", 8))
@@ -427,8 +435,12 @@ scan_mbox(struct mbox *b, struct stat *st)
 
       b->total++;
       if (new)
+       b->new++;
+      if (flagged)
+       b->flagged++;
+      if (new || (flagged && !b->snippet_is_new))
        {
-         b->new++;
+         b->snippet_is_new = new;
          prepare_snippet(b, sender, subject);
        }
 
@@ -538,6 +550,7 @@ enum {
   M_IDLE,
   M_SCAN,
   M_NEW,
+  M_FLAG,
   M_BAD,
   M_MAX
 };
@@ -560,6 +573,8 @@ redraw_line(int i)
        printw("  ");
       if (b->new)
        attrset(attrs[cc][hi][M_NEW]);
+      else if (b->flagged)
+       attrset(attrs[cc][hi][M_FLAG]);
       printw("%-20s ", b->name);
       if (b->scanning < 0)
        ;
@@ -577,6 +592,7 @@ redraw_line(int i)
        {
          attrset(attrs[cc][hi][M_IDLE]);
          printw("%6d ", b->total);
+         int snip = 0;
          if (b->new)
            {
              attrset(attrs[cc][hi][M_NEW]);
@@ -591,14 +607,23 @@ redraw_line(int i)
                printw("%2d hrs  ", age/3600);
              else
                printw("        ");
-             if (b->o.snippets && b->snippet[0])
-               {
-                 int xx, yy;
-                 getyx(stdscr, yy, xx);
-                 int remains = COLS-1-xx;
-                 if (remains > 2)
-                   printw("%-.*s", remains, b->snippet);
-               }
+             snip = 1;
+           }
+         else if (b->flagged)
+           {
+             attrset(attrs[cc][hi][M_FLAG]);
+             printw("%6d  ", b->flagged);
+             attrset(attrs[cc][hi][M_IDLE]);
+             printw("        ");
+             snip = b->o.show_flagged;
+           }
+         if (snip && b->o.snippets && b->snippet[0])
+           {
+             int xx, yy;
+             getyx(stdscr, yy, xx);
+             int remains = COLS-1-xx;
+             if (remains > 2)
+               printw("%-.*s", remains, b->snippet);
            }
        }
     }
@@ -679,8 +704,8 @@ term_init(void)
   curs_set(0);
 
   static const int attrs_mono[2][M_MAX] = {
-    [0] = { [M_IDLE] = 0, [M_SCAN] = A_BOLD, [M_NEW] = A_BOLD, [M_BAD] = A_DIM },
-    [1] = { [M_IDLE] = 0, [M_SCAN] = A_BOLD, [M_NEW] = A_REVERSE | A_BOLD, [M_BAD] = A_DIM },
+    [0] = { [M_IDLE] = 0, [M_SCAN] = A_BOLD, [M_NEW] = A_BOLD, [M_FLAG] = 0, [M_BAD] = A_DIM },
+    [1] = { [M_IDLE] = 0, [M_SCAN] = A_BOLD, [M_NEW] = A_REVERSE | A_BOLD, [M_FLAG] = A_REVERSE, [M_BAD] = A_DIM },
   };
   for (int i=0; i<2; i++)
     for (int j=0; j<M_MAX; j++)
@@ -699,11 +724,13 @@ term_init(void)
          init_pair(3, COLOR_WHITE, COLOR_BLUE);
          init_pair(4, COLOR_YELLOW, COLOR_BLUE);
          init_pair(5, COLOR_RED, COLOR_BLUE);
+         init_pair(6, COLOR_GREEN, COLOR_BLACK);
+         init_pair(7, COLOR_GREEN, COLOR_BLUE);
          static const int attrs_color[2][2][M_MAX] = {
-           [0][0] = { [M_IDLE] = 0, [M_SCAN] = COLOR_PAIR(1), [M_NEW] = COLOR_PAIR(1), [M_BAD] = COLOR_PAIR(2) },
-           [0][1] = { [M_IDLE] = A_BOLD, [M_SCAN] = COLOR_PAIR(1), [M_NEW] = COLOR_PAIR(1) | A_BOLD, [M_BAD] = COLOR_PAIR(2) | A_BOLD },
-           [1][0] = { [M_IDLE] = COLOR_PAIR(3), [M_SCAN] = COLOR_PAIR(4), [M_NEW] = COLOR_PAIR(4), [M_BAD] = COLOR_PAIR(5) },
-           [1][1] = { [M_IDLE] = COLOR_PAIR(3) | A_BOLD, [M_SCAN] = COLOR_PAIR(4), [M_NEW] = COLOR_PAIR(4) | A_BOLD, [M_BAD] = COLOR_PAIR(5) | A_BOLD },
+           [0][0] = { [M_IDLE] = 0, [M_SCAN] = COLOR_PAIR(1), [M_NEW] = COLOR_PAIR(1), [M_FLAG] = COLOR_PAIR(6), [M_BAD] = COLOR_PAIR(2) },
+           [0][1] = { [M_IDLE] = A_BOLD, [M_SCAN] = COLOR_PAIR(1), [M_NEW] = COLOR_PAIR(1) | A_BOLD, [M_FLAG] = COLOR_PAIR(6) | A_BOLD, [M_BAD] = COLOR_PAIR(2) | A_BOLD },
+           [1][0] = { [M_IDLE] = COLOR_PAIR(3), [M_SCAN] = COLOR_PAIR(4), [M_NEW] = COLOR_PAIR(4), [M_FLAG] = COLOR_PAIR(7), [M_BAD] = COLOR_PAIR(5) },
+           [1][1] = { [M_IDLE] = COLOR_PAIR(3) | A_BOLD, [M_SCAN] = COLOR_PAIR(4), [M_NEW] = COLOR_PAIR(4) | A_BOLD, [M_FLAG] = COLOR_PAIR(7) | A_BOLD, [M_BAD] = COLOR_PAIR(5) | A_BOLD },
          };
          memcpy(attrs, attrs_color, sizeof(attrs));
        }
@@ -792,6 +819,7 @@ Mailbox options (set with `-o', use upper case to negate):\n\
 0-9\t\t\tSet mailbox priority (0=default)\n\
 b\t\t\tBeep when a message arrives\n\
 e\t\t\tHide from display if empty\n\
+f\t\t\tShow flagged messages if there are no new ones\n\
 h\t\t\tHide from display\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
@@ -835,6 +863,9 @@ parse_options(char *c)
          case 'e':
            o->hide_if_empty = value;
            break;
+         case 'f':
+           o->show_flagged = value;
+           break;
          case 'h':
            o->hide = value;
            break;