]> mj.ucw.cz Git - checkmail.git/blobdiff - cm.c
Better rules for coloring of flagged messages.
[checkmail.git] / cm.c
diff --git a/cm.c b/cm.c
index cce8c273e4fa6e735761e33a9296cd2f7d09c6bd..a3bba1853305c46e21b595475157a6ec37ff5b0a 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -20,6 +20,7 @@
 
 #include "util.h"
 #include "clists.h"
+#include "charset.h"
 
 static int check_interval = 30;
 static int force_refresh;
@@ -36,6 +37,8 @@ struct options {
   int beep;
   int snippets;
   int show_flagged;
+  int sender_personal;
+  int sender_mbox;
 };
 
 struct option_node {
@@ -51,7 +54,9 @@ struct pattern_node {
 };
 
 static clist options, patterns;
-static struct options global_options;
+static struct options global_options = {
+  .sender_personal = 1
+};
 
 struct mbox {
   cnode n;
@@ -64,7 +69,7 @@ struct mbox {
   time_t last_time;
   int last_size, last_pos;
   int total, new, flagged;
-  int last_total, last_new;
+  int last_total, last_new, last_flagged;
   int last_beep_new;
   int force_refresh;
   int snippet_is_new;
@@ -114,6 +119,8 @@ init_options(struct options *o)
   o->highlight = -1;
   o->snippets = -1;
   o->show_flagged = -1;
+  o->sender_personal = -1;
+  o->sender_mbox = -1;
 }
 
 static void
@@ -132,6 +139,8 @@ setup_options(struct mbox *b)
        MERGE(beep);
        MERGE(snippets);
        MERGE(show_flagged);
+       MERGE(sender_personal);
+       MERGE(sender_mbox);
       }
 }
 
@@ -203,35 +212,6 @@ mbox_visible_p(struct mbox *b)
   return 1;
 }
 
-static void
-add_snippet(char **ppos, char *term, unsigned char *add)
-{
-  char *pos = *ppos;
-  int space = 1;
-  while (*add && pos < term)
-    {
-      if (*add <= ' ')
-       {
-         if (!space)
-           *pos++ = ' ';
-         space = 1;
-       }
-      else if (*add >= 0x7f)
-       {
-         *pos++ = '?';
-         space = 0;
-       }
-      else
-       {
-         *pos++ = *add;
-         space = 0;
-       }
-      add++;
-    }
-  *ppos = pos;
-  *pos = 0;
-}
-
 static void
 prepare_snippet(struct mbox *b, char *sender, char *subject)
 {
@@ -242,13 +222,13 @@ prepare_snippet(struct mbox *b, char *sender, char *subject)
 
   char *pos = b->snippet;
   char *term = b->snippet + sizeof(b->snippet) - 1;
-  if (sender[0])
+  if (sender[0] && (b->o.sender_mbox || b->o.sender_personal))
     {
-      add_snippet(&pos, term, sender);
+      add_addr_snippet(&pos, term, sender, b->o.sender_mbox, b->o.sender_personal);
       add_snippet(&pos, term, ": ");
     }
   if (subject[0])
-    add_snippet(&pos, term, subject);
+    add_subject_snippet(&pos, term, subject);
   else
     add_snippet(&pos, term, "No subject");
 }
@@ -327,7 +307,7 @@ scan_mbox(struct mbox *b, struct stat *st)
 
   if (!st->st_size)
     {
-      b->total = b->new = 0;
+      b->total = b->new = b->flagged = 0;
       b->last_pos = 0;
       return;
     }
@@ -338,7 +318,7 @@ scan_mbox(struct mbox *b, struct stat *st)
   if (mb_fd < 0)
     {
       debug("[open failed: %m] ");
-      b->total = b->new = -1;
+      b->total = b->new = b->flagged = -1;
       return;
     }
   mb_reset(0);
@@ -363,17 +343,18 @@ scan_mbox(struct mbox *b, struct stat *st)
       if (!mb_check(from+1, 5))
        {
          debug("[inconsistent] ");
-         b->total = b->new = -1;
+         b->total = b->new = b->flagged = -1;
          goto done;
        }
-      b->total = b->new = 0;
-      b->last_total = b->last_new = 0;
+      b->total = b->new = b->flagged = 0;
+      b->last_total = b->last_new = b->last_flagged = 0;
       b->snippet_is_new = 0;
     }
   else
     {
       b->total = b->last_total;
       b->new = b->last_new;
+      b->flagged = b->last_flagged;
     }
 
   for(;;)
@@ -383,6 +364,7 @@ scan_mbox(struct mbox *b, struct stat *st)
        b->last_pos--;          // last_pos should be the previous \n character
       b->last_total = b->total;
       b->last_new = b->new;
+      b->last_flagged = b->flagged;
       while ((c = mb_get()) >= 0 && c != '\n')
        ;
 
@@ -515,7 +497,7 @@ scan(void)
        b->force_refresh = 1;
       if (stat(b->path, &st) < 0)
        {
-         b->total = b->new = -1;
+         b->total = b->new = b->flagged = -1;
          debug("%m\n");
        }
       else if (!b->last_time || st.st_mtime != b->last_time || st.st_size != b->last_size || b->force_refresh)
@@ -527,7 +509,7 @@ scan(void)
          scan_mbox(b, &st);
          b->last_time = st.st_mtime;
          b->last_size = st.st_size;
-         debug("%d %d (stopped at %d of %d)\n", b->total, b->new, b->last_pos, b->last_size);
+         debug("%d %d %d (stopped at %d of %d)\n", b->total, b->new, b->flagged, b->last_pos, b->last_size);
 
          b->scanning = 0;
          redraw_line(b->index);
@@ -615,6 +597,7 @@ redraw_line(int i)
              printw("%6d  ", b->flagged);
              attrset(attrs[cc][hi][M_IDLE]);
              printw("        ");
+             attrset(attrs[cc][0][M_FLAG]);    /* We avoid the highlight intentionally */
              snip = b->o.show_flagged;
            }
          if (snip && b->o.snippets && b->snippet[0])
@@ -821,6 +804,8 @@ 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\
+m\t\t\tShow mailbox name of the sender\n\
+p\t\t\tShow personal info (full name) of the sender\n\
 s\t\t\tShow message snippets\n\
 t\t\t\tHighlight the entry\n\
 \n\
@@ -869,6 +854,12 @@ parse_options(char *c)
          case 'h':
            o->hide = value;
            break;
+         case 'm':
+           o->sender_mbox = value;
+           break;
+         case 'p':
+           o->sender_personal = value;
+           break;
          case 's':
            o->snippets = value;
            break;
@@ -919,6 +910,7 @@ main(int argc, char **argv)
   while (optind < argc)
     add_pattern(argv[optind++]);
 
+  charset_init();
   term_init();
   scan_and_redraw();
   next_active(0, 1);