From 44dd379c34397c469c587ea622c5e34d9b46fa30 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 25 Jun 2007 16:01:38 +0200 Subject: [PATCH] Show flagged messages if there are no new mails. --- README | 2 +- cm.c | 65 +++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/README b/README index a4d49e7..8696017 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ Checkmail @VERSION@ - (c) 2005 Martin Mares + (c) 2005--2007 Martin Mares ================================================================================ diff --git a/cm.c b/cm.c index 3a4630e..cce8c27 100644 --- a/cm.c +++ b/cm.c @@ -1,7 +1,7 @@ /* * Incoming Mail Checker * - * (c) 2005 Martin Mares + * (c) 2005--2007 Martin Mares */ #include @@ -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; jhide_if_empty = value; break; + case 'f': + o->show_flagged = value; + break; case 'h': o->hide = value; break; -- 2.39.2