]> mj.ucw.cz Git - checkmail.git/blobdiff - cm.c
Avoid repeating the same mail in OSD announcements
[checkmail.git] / cm.c
diff --git a/cm.c b/cm.c
index e7b2e63cf34c71777d74894c8839ab70c3177b0d..e14c8fa2ba937dbadf6a2d64331c05b9dc4fc27c 100644 (file)
--- a/cm.c
+++ b/cm.c
@@ -80,6 +80,7 @@ struct mbox {
   int scanning;
   int seen;
   time_t last_time;
+  time_t display_valid_until;
   int last_size, last_pos;
   int total, new, flagged;
   int last_total, last_new, last_flagged;
@@ -274,7 +275,7 @@ prepare_snippets(struct mbox *b, char *sender, char *subject)
   if (subject[0])
     add_subject_snippet(&pos, term, subject);
   else
-    add_snippet(&pos, term, "No subject");
+    add_snippet_raw(&pos, term, "No subject");
 }
 
 static void
@@ -283,7 +284,7 @@ build_snippet(char *buf, char *term, struct mbox *b)
   if (b->sender_snippet[0])
     {
       add_snippet(&buf, term, b->sender_snippet);
-      add_snippet(&buf, term, ": ");
+      add_snippet_raw(&buf, term, ": ");
     }
   add_snippet(&buf, term, b->subject_snippet);
 }
@@ -608,6 +609,11 @@ scan(int notify)
          redraw_line(b->index);
          refresh();
        }
+      else if (b->display_valid_until <= last_scan_time)
+       {
+         debug("not changed, but needs redraw\n");
+         redraw_line(b->index);
+       }
       else
        debug("not changed\n");
       b->force_refresh = 0;
@@ -631,6 +637,7 @@ static Atom osd_pty;
 static unsigned osd_care;
 #define OSD_MSG_SIZE 1024
 static char osd_last_msg[OSD_MSG_SIZE];
+static time_t osd_last_time;
 
 static void
 x11_init(void)
@@ -838,7 +845,7 @@ rethink_osd(int notify)
     if (b->o.osd > 0)
       {
        p.total_new += b->new;
-       if (b->new && (!p.mbox || p.mbox->o.priority < b->o.priority))
+       if (b->new && b->last_time > osd_last_time && (!p.mbox || p.mbox->o.priority < b->o.priority))
          p.mbox = b;
       }
 
@@ -856,6 +863,7 @@ rethink_osd(int notify)
        }
       else
        debug("OSD: No changes\n");
+      osd_last_time = time(NULL);
     }
 }
 
@@ -905,6 +913,7 @@ redraw_line(int i)
       int hi = b->o.highlight;
       unsigned namepos = 0;
       unsigned namelen = strlen(b->name);
+      int valid = 3600;
 
       attrset(attrs[cc][hi][M_IDLE]);
       if (b->o.hotkey)
@@ -955,9 +964,12 @@ redraw_line(int i)
              if (age < 0)
                age = 0;
              if (age < 3600)
-               printw("%2d min  ", age/60);
+               {
+                 printw("%2d min  ", age/60);
+                 valid = 60;
+               }
              else if (age < 86400)
-               printw("%2d hrs  ", age/3600);
+               printw("%2d hr%c  ", age/3600, (age >= 7200 ? 's' : ' '));
              else
                printw("        ");
              snip = 1;
@@ -976,6 +988,7 @@ redraw_line(int i)
              int xx, yy;
              getyx(stdscr, yy, xx);
              int remains = COLS-1-xx;
+             (void) yy;
 
              char snip[256];
              build_snippet(snip, snip + sizeof(snip) - 1, b);
@@ -993,6 +1006,7 @@ redraw_line(int i)
                }
            }
        }
+      b->display_valid_until = last_scan_time + valid;
     }
   attrset(attrs[0][0][M_IDLE]);
   clrtoeol();