]> mj.ucw.cz Git - checkmail.git/blobdiff - cm.c
Use Content-Length to determine mail length if available
[checkmail.git] / cm.c
diff --git a/cm.c b/cm.c
index e1ed5029980d318d1b8f727456ab0a3339faf38b..9a38a1d7a0252e2444009d7a3152676ac5a62663 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);
 }
@@ -353,6 +354,27 @@ mb_check(const char *p, int len)
   return 1;
 }
 
+static void
+mb_skip(int len)
+{
+  while (len)
+    {
+      int avail = mb_end - mb_cc;
+      if (!avail)
+       {
+         if (mb_ll_get() < 0)
+           return;
+         len--;
+       }
+      else
+       {
+         int next = (avail < len) ? avail : len;
+         len -= next;
+         mb_cc += next;
+       }
+    }
+}
+
 static void
 scan_mbox(struct mbox *b, struct stat *st)
 {
@@ -453,6 +475,7 @@ scan_mbox(struct mbox *b, struct stat *st)
       while ((c = mb_get()) >= 0 && c != '\n')
        ;
 
+      int content_length = -1;
       int new = 1;
       int flagged = 0;
       sender[0] = 0;
@@ -498,6 +521,8 @@ scan_mbox(struct mbox *b, struct stat *st)
            strcpy(sender, buf+5);
          else if (!strncasecmp(buf, "Subject:", 8))
            strcpy(subject, buf+8);
+         else if (!strncasecmp(buf, "Content-Length:", 15))
+           content_length = atoi(buf + 15);
        }
 
       b->total++;
@@ -505,12 +530,17 @@ scan_mbox(struct mbox *b, struct stat *st)
        b->new++;
       if (flagged)
        b->flagged++;
+      if (debug_mode > 1)
+       debug("new=%d flagged=%d len=%d sender=<%s> subject=<%s>\n", new, flagged, content_length, sender, subject);
       if (new || (flagged && !b->snippet_is_new))
        {
          b->snippet_is_new = new;
          prepare_snippets(b, sender, subject);
        }
 
+      if (content_length >= 0)
+       mb_skip(content_length);
+
       int ct = 1;
       while (from[ct])
        {
@@ -606,6 +636,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;
@@ -629,6 +664,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)
@@ -836,7 +872,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;
       }
 
@@ -854,6 +890,7 @@ rethink_osd(int notify)
        }
       else
        debug("OSD: No changes\n");
+      osd_last_time = time(NULL);
     }
 }
 
@@ -903,6 +940,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)
@@ -953,9 +991,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;
@@ -974,6 +1015,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);
@@ -991,6 +1033,7 @@ redraw_line(int i)
                }
            }
        }
+      b->display_valid_until = last_scan_time + valid;
     }
   attrset(attrs[0][0][M_IDLE]);
   clrtoeol();