2 * Incoming Mail Checker
4 * (c) 2005--2010 Martin Mares <mj@ucw.cz>
21 #include <sys/types.h>
24 #ifdef CONFIG_WIDE_CURSES
25 #include <ncursesw/ncurses.h>
34 static int check_interval = 30;
35 static int force_refresh;
36 static int allow_bells = 1;
37 static int allow_osd = 1;
38 static int minimum_priority;
39 static time_t last_scan_time;
40 static char *run_cmd = "mutt -f %s";
69 static clist options, patterns;
70 static struct options global_options = {
83 int last_size, last_pos;
84 int total, new, flagged;
85 int last_total, last_new, last_flagged;
89 char sender_snippet[128];
90 char subject_snippet[128];
94 static struct mbox **mbox_array;
95 static int num_mboxes, mbox_array_size;
103 static clist osd_opts;
105 static void redraw_line(int i);
106 static void rethink_display(int notify);
109 add_pattern(char *patt)
111 struct pattern_node *n = xmalloc(sizeof(*n) + strlen(patt));
112 strcpy(n->pattern, patt);
113 if (patt = strchr(n->pattern, '='))
120 clist_add_tail(&patterns, &n->n);
126 struct passwd *p = getpwuid(getuid());
128 die("You don't exist, go away!");
129 char buf[sizeof("/var/mail/") + strlen(p->pw_name) + 7];
130 sprintf(buf, "/var/mail/%s=INBOX", p->pw_name);
135 init_options(struct options *o)
139 o->hide_if_empty = -1;
143 o->show_flagged = -1;
144 o->sender_personal = -1;
152 setup_options(struct mbox *b)
154 b->o = global_options;
155 CLIST_FOR_EACH(struct option_node *, n, options)
156 if (!fnmatch(n->pattern, b->name, 0))
158 debug("\tApplied options %s\n", n->pattern);
159 #define MERGE(f) if (n->o.f >= 0) b->o.f = n->o.f
162 MERGE(hide_if_empty);
167 MERGE(sender_personal);
176 add_osd_opt(char *arg)
178 struct osd_opt_node *n = xmalloc(sizeof(*n) + strlen(arg));
180 n->val = strchr(n->key, '=');
182 die("Malformed OSD option");
184 clist_add_tail(&osd_opts, &n->n);
188 mbox_name(char *path)
190 char *c = strrchr(path, '/');
191 return c ? (c+1) : path;
195 add_mbox(clist *l, char *path, char *name)
197 struct mbox *b = xmalloc(sizeof(*b));
198 bzero(b, sizeof(*b));
199 b->path = xstrdup(path);
200 b->name = xstrdup(name);
204 cnode *prev = l->head.prev;
205 while (prev != &l->head && strcmp(((struct mbox *)prev)->name, name) > 0)
207 clist_insert_after(&b->n, prev);
210 clist_add_tail(l, &b->n);
216 del_mbox(struct mbox *b)
225 find_mbox(clist *l, char *path)
227 CLIST_FOR_EACH(struct mbox *, b, *l)
228 if (!strcmp(b->path, path))
234 mbox_active_p(struct mbox *b)
236 if (b->o.priority < minimum_priority)
244 mbox_visible_p(struct mbox *b)
246 if (!mbox_active_p(b))
250 if (b->o.hide_if_empty && !b->total)
256 prepare_snippets(struct mbox *b, char *sender, char *subject)
260 while (*sender == ' ' || *sender == '\t')
262 while (*subject == ' ' || *subject == '\t')
265 pos = b->sender_snippet;
266 term = pos + sizeof(b->sender_snippet) - 1;
267 if (sender[0] && (b->o.sender_mbox || b->o.sender_personal))
268 add_addr_snippet(&pos, term, sender, b->o.sender_mbox, b->o.sender_personal);
272 pos = b->subject_snippet;
273 term = pos + sizeof(b->subject_snippet) - 1;
275 add_subject_snippet(&pos, term, subject);
277 add_snippet_raw(&pos, term, "No subject");
281 build_snippet(char *buf, char *term, struct mbox *b)
283 if (b->sender_snippet[0])
285 add_snippet(&buf, term, b->sender_snippet);
286 add_snippet_raw(&buf, term, ": ");
288 add_snippet(&buf, term, b->subject_snippet);
291 static int mb_fd, mb_pos;
292 static unsigned char mb_buf[4096], *mb_cc, *mb_end;
297 mb_cc = mb_end = mb_buf;
304 lseek(mb_fd, pos, SEEK_SET);
311 return mb_pos - (mb_end - mb_cc);
317 int len = read(mb_fd, mb_buf, sizeof(mb_buf));
326 mb_end = mb_buf + len;
335 return (mb_cc < mb_end) ? *mb_cc++ : mb_ll_get();
346 mb_check(const char *p, int len)
350 if (mb_get() != *p++)
357 scan_mbox(struct mbox *b, struct stat *st)
359 char buf[1024], sender[1024], subject[1024];
362 const char from[] = "\nFrom ";
366 b->total = b->new = b->flagged = 0;
371 /* FIXME: Should we do some locking? */
373 mb_fd = open(b->path, O_RDONLY);
376 debug("[open failed: %m] ");
377 b->total = b->new = b->flagged = -1;
382 c = read(mb_fd, signature, 2);
383 lseek(mb_fd, 0, SEEK_SET);
385 if (c == 2 && !memcmp(signature, "\037\213", 2)) //gzip
387 debug("[decompressing] ");
390 die("pipe failed: %m");
393 die("fork failed: %m");
396 if (dup2(mb_fd, 0) < 0 || dup2(fds[1], 1) < 0)
397 die("dup2 failed: %m");
401 execlp("gzip", "gzip", "-cd", NULL);
402 die("Cannot execute gzip: %m");
412 if (b->last_size && b->last_pos && st->st_size > b->last_size && !b->force_refresh && !compressed)
414 mb_seek(b->last_pos);
415 if (mb_check(from, 6))
417 debug("[incremental] ");
422 debug("[incremental failed] ");
428 if (!mb_check(from+1, 5))
430 debug("[inconsistent] ");
431 b->total = b->new = b->flagged = -1;
434 b->total = b->new = b->flagged = 0;
435 b->last_total = b->last_new = b->last_flagged = 0;
436 b->snippet_is_new = 0;
440 b->total = b->last_total;
441 b->new = b->last_new;
442 b->flagged = b->last_flagged;
447 b->last_pos = mb_tell() - 5;
449 b->last_pos--; // last_pos should be the previous \n character
450 b->last_total = b->total;
451 b->last_new = b->new;
452 b->last_flagged = b->flagged;
453 while ((c = mb_get()) >= 0 && c != '\n')
468 debug("[truncated] ");
479 while (c == ' ' || c == '\t');
487 if (i < sizeof(buf) - 1)
493 if (!strncasecmp(buf, "Status:", 7))
495 else if (!strncasecmp(buf, "X-Status:", 9) && strchr(buf+9, 'F'))
497 else if (!strncasecmp(buf, "From:", 5))
498 strcpy(sender, buf+5);
499 else if (!strncasecmp(buf, "Subject:", 8))
500 strcpy(subject, buf+8);
509 debug("new=%d flagged=%d sender=<%s> subject=<%s>\n", new, flagged, sender, subject);
510 if (new || (flagged && !b->snippet_is_new))
512 b->snippet_is_new = new;
513 prepare_snippets(b, sender, subject);
532 if (wait(&status) < 0 || !WIFEXITED(status) || WEXITSTATUS(status))
533 b->total = b->new = b->flagged = -1;
540 debug("Searching for mailboxes (notify=%d)...\n", notify);
541 last_scan_time = time(NULL);
542 CLIST_FOR_EACH(struct pattern_node *, p, patterns)
544 debug("Trying pattern %s (name %s)\n", p->pattern, p->name);
546 int err = glob(p->pattern, GLOB_ERR | GLOB_NOSORT | GLOB_TILDE | GLOB_TILDE_CHECK, NULL, &g);
547 if (err && err != GLOB_NOMATCH)
548 die("Failed to glob %s: %m", p->pattern);
549 for (uns i=0; i<g.gl_pathc; i++)
551 char *name = g.gl_pathv[i];
552 struct mbox *b = find_mbox(&mboxes, name);
555 b = add_mbox(&mboxes, name, (p->name ? p->name : mbox_name(name)));
556 debug("Discovered mailbox %s (%s)\n", b->name, b->path);
566 CLIST_FOR_EACH_DELSAFE(struct mbox *, b, mboxes, tmp)
572 debug("Lost mailbox %s\n", b->name);
579 debug("Scanning mailboxes...\n");
580 CLIST_FOR_EACH(struct mbox *, b, mboxes)
583 debug("%s: ", b->name);
584 if (!mbox_active_p(b))
590 b->force_refresh = 1;
591 if (stat(b->path, &st) < 0)
593 b->total = b->new = b->flagged = -1;
596 else if (!b->last_time || st.st_mtime != b->last_time || st.st_size != b->last_size || b->force_refresh)
599 redraw_line(b->index);
603 b->last_time = st.st_mtime;
604 b->last_size = st.st_size;
605 debug("%d %d %d (stopped at %d of %d)\n", b->total, b->new, b->flagged, b->last_pos, b->last_size);
608 redraw_line(b->index);
612 debug("not changed\n");
613 b->force_refresh = 0;
617 debug("Scan finished\n");
618 last_scan_time = time(NULL);
619 rethink_display(notify);
624 #include <X11/Xlib.h>
625 #include <X11/Xatom.h>
627 static Display *x11_dpy;
628 static unsigned leds_care, leds_have, leds_want;
631 static unsigned osd_care;
632 #define OSD_MSG_SIZE 1024
633 static char osd_last_msg[OSD_MSG_SIZE];
638 leds_care = (global_options.led >= 0 ? (1 << global_options.led) : 0);
639 osd_care = (global_options.osd >= 0);
640 CLIST_FOR_EACH(struct option_node *, o, options)
643 leds_care |= (1 << o->o.led);
648 if (!leds_care && !osd_care)
650 debug("X11: No mailbox wants LEDs or OSD\n");
653 if (!getenv("DISPLAY"))
655 debug("X11: Do not have X display\n");
658 if (!(x11_dpy = XOpenDisplay(NULL)))
659 die("Cannot open X display, although the DISPLAY variable is set");
663 osd_pty = XInternAtom(x11_dpy, "OSD_QUEUE", False);
665 die("Cannot intern OSD_QUEUE atom");
667 // If OSD options contain no message, add one
669 CLIST_FOR_EACH(struct osd_opt_node *, n, osd_opts)
674 add_osd_opt("=%40f");
675 add_osd_opt("=%40s");
677 add_osd_opt("=(and %m more)");
682 debug("X11: Initialized\n");
688 if (leds_want == leds_have)
691 debug("LEDS: have %02x, want %02x, care %02x\n", leds_have, leds_want, leds_care);
692 for (int i=1; i<10; i++)
693 if (leds_care & (leds_have ^ leds_want) & (1 << i))
697 cc.led_mode = (leds_want & (1 << i)) ? LedModeOn : LedModeOff;
698 XChangeKeyboardControl(x11_dpy, KBLed | KBLedMode, &cc);
701 leds_have = leds_want;
707 if (!leds_care || !x11_dpy)
711 CLIST_FOR_EACH(struct mbox *, b, mboxes)
712 if (b->o.led > 0 && b->new)
713 leds_want |= (1 << b->o.led);
723 format_osd_string(char *dest, char *src, struct osd_params *par)
725 char *stop = dest + OSD_MSG_SIZE - 1;
728 while (*src && dest < stop)
734 while (*src >= '0' && *src <= '9')
735 size = 10*size + *src++ - '0';
736 if (!size || size > stop-dest)
747 arg = par->mbox->sender_snippet;
750 arg = par->mbox->subject_snippet;
753 snprintf(numbuf, sizeof(numbuf), "%d", par->total_new);
756 if (par->total_new < 2)
758 snprintf(numbuf, sizeof(numbuf), "%d", par->total_new - 1);
782 format_osd(char *msg, struct osd_params *par)
791 unsigned have_text = 0;
792 CLIST_FOR_EACH(struct osd_opt_node *, n, osd_opts)
794 char buf[OSD_MSG_SIZE];
795 if (!format_osd_string(buf, n->val, par))
797 if (!n->key[0] && buf[0])
799 pos += snprintf(msg+pos, OSD_MSG_SIZE-pos-1, "%s:%s\n", n->key, buf);
800 if (pos > OSD_MSG_SIZE-1)
802 pos = sprintf(msg, "OSD message too long!\n");
814 debug_osd_msg(char *msg)
818 fprintf(stderr, "OSD: <");
821 fputc((*msg != '\n' ? *msg : '|'), stderr);
824 fprintf(stderr, ">\n");
828 rethink_osd(int notify)
830 if (!osd_care || !x11_dpy || !allow_osd)
836 struct osd_params p = { .mbox = NULL, .total_new = 0 };
837 CLIST_FOR_EACH(struct mbox *, b, mboxes)
840 p.total_new += b->new;
841 if (b->new && (!p.mbox || p.mbox->o.priority < b->o.priority))
845 char new_msg[OSD_MSG_SIZE];
846 format_osd(new_msg, &p);
847 debug_osd_msg(new_msg);
848 if (strcmp(new_msg, osd_last_msg))
850 strcpy(osd_last_msg, new_msg);
851 if (notify && new_msg[0])
853 debug("OSD: Sending to daemon\n");
854 XChangeProperty(x11_dpy, DefaultRootWindow(x11_dpy), osd_pty, XA_STRING, 8, PropModeAppend, (unsigned char *) new_msg, strlen(new_msg));
858 debug("OSD: No changes\n");
874 static void x11_init(void) { }
875 static void rethink_leds(void) { }
876 static void rethink_osd(int notify UNUSED) { }
877 static void x11_cleanup(void) { }
881 static int cursor_at, cursor_max;
883 static unsigned is_active, is_pos; // incremental search
884 static char is_buf[64];
895 static int attrs[3][2][M_MAX]; // active (2=incsearch), hilite, status
903 struct mbox *b = mbox_array[i];
904 int cc = (cursor_at == i ? (is_active ? 2 : 1) : 0);
905 int hi = b->o.highlight;
906 unsigned namepos = 0;
907 unsigned namelen = strlen(b->name);
909 attrset(attrs[cc][hi][M_IDLE]);
911 printw("%c ", b->o.hotkey);
918 attrset(attrs[cc][hi][M_INCSEARCH]);
919 for (namepos=0; namepos < is_pos && namepos < 20; namepos++)
920 addch(is_buf[namepos]);
923 attrset(attrs[cc][hi][M_NEW]);
924 else if (b->flagged && b->o.show_flagged)
925 attrset(attrs[cc][hi][M_FLAG]);
927 attrset(attrs[cc][hi][M_IDLE]);
928 while (namepos < namelen)
929 addch(b->name[namepos++]);
930 while (namepos++ < 20)
934 else if (b->scanning)
936 attrset(attrs[cc][hi][M_SCAN]);
937 printw("[SCANNING]");
939 else if (b->total < 0)
941 attrset(attrs[cc][hi][M_BAD]);
946 attrset(attrs[cc][hi][M_IDLE]);
947 printw("%6d ", b->total);
951 attrset(attrs[cc][hi][M_NEW]);
952 printw("%6d ", b->new);
953 attrset(attrs[cc][hi][M_IDLE]);
954 int age = (last_scan_time - b->last_time);
958 printw("%2d min ", age/60);
959 else if (age < 86400)
960 printw("%2d hr%c ", age/3600, (age >= 7200 ? 's' : ' '));
965 else if (b->flagged && b->o.show_flagged)
967 attrset(attrs[cc][hi][M_FLAG]);
968 printw("%6d ", b->flagged);
969 attrset(attrs[cc][hi][M_IDLE]);
971 attrset(attrs[cc][0][M_FLAG]); /* We avoid the highlight intentionally */
974 if (snip && b->o.snippets)
977 getyx(stdscr, yy, xx);
978 int remains = COLS-1-xx;
981 build_snippet(snip, snip + sizeof(snip) - 1, b);
983 if (snip[0] && remains > 2)
985 #ifdef CONFIG_WIDE_CURSES
986 size_t len = strlen(snip)+1;
988 mbstowcs(snip2, snip, len);
989 addnwstr(snip2, remains);
991 printw("%-.*s", remains, snip);
997 attrset(attrs[0][0][M_IDLE]);
1004 cursor_max = num_mboxes;
1005 if (cursor_max > LINES-1)
1006 cursor_max = LINES-1;
1007 if (cursor_at >= cursor_max)
1008 cursor_at = cursor_max - 1;
1012 for (int i=0; i<cursor_max; i++)
1014 move(cursor_max, 0);
1017 printw("(no mailboxes found)");
1025 rethink_display(int notify)
1030 CLIST_FOR_EACH(struct mbox *, b, mboxes)
1031 if (mbox_visible_p(b))
1034 if (i >= num_mboxes || mbox_array[i] != b)
1037 if (i >= mbox_array_size)
1039 mbox_array_size = (mbox_array_size ? 2*mbox_array_size : 16);
1040 mbox_array = xrealloc(mbox_array, sizeof(struct mbox *) * mbox_array_size);
1044 if (b->o.beep && b->new > b->last_beep_new)
1046 b->last_beep_new = b->new;
1049 if (i != num_mboxes)
1059 rethink_osd(notify);
1060 if (beeeep && allow_bells && notify)
1071 intrflush(stdscr, FALSE);
1072 keypad(stdscr, TRUE);
1075 static const int attrs_mono[2][M_MAX] = {
1076 [0] = { [M_IDLE] = 0,
1081 [M_INCSEARCH] = A_REVERSE },
1082 [1] = { [M_IDLE] = 0,
1084 [M_NEW] = A_REVERSE | A_BOLD,
1085 [M_FLAG] = A_REVERSE,
1087 [M_INCSEARCH] = A_REVERSE },
1089 for (int i=0; i<2; i++)
1090 for (int j=0; j<M_MAX; j++)
1092 attrs[0][i][j] = attrs_mono[i][j];
1093 attrs[1][i][j] = attrs_mono[i][j] | A_UNDERLINE;
1094 attrs[2][i][j] = attrs_mono[i][j] | A_UNDERLINE;
1100 if (COLOR_PAIRS >= 12)
1102 init_pair(1, COLOR_YELLOW, COLOR_BLACK);
1103 init_pair(2, COLOR_RED, COLOR_BLACK);
1104 init_pair(3, COLOR_WHITE, COLOR_BLUE);
1105 init_pair(4, COLOR_YELLOW, COLOR_BLUE);
1106 init_pair(5, COLOR_RED, COLOR_BLUE);
1107 init_pair(6, COLOR_GREEN, COLOR_BLACK);
1108 init_pair(7, COLOR_GREEN, COLOR_BLUE);
1109 init_pair(8, COLOR_WHITE, COLOR_MAGENTA);
1110 init_pair(9, COLOR_YELLOW, COLOR_MAGENTA);
1111 init_pair(10, COLOR_GREEN, COLOR_MAGENTA);
1112 init_pair(11, COLOR_RED, COLOR_MAGENTA);
1113 init_pair(12, COLOR_BLACK, COLOR_YELLOW);
1114 static const int attrs_color[3][2][M_MAX] = {
1115 [0][0] = { [M_IDLE] = 0,
1116 [M_SCAN] = COLOR_PAIR(1),
1117 [M_NEW] = COLOR_PAIR(1),
1118 [M_FLAG] = COLOR_PAIR(6),
1119 [M_BAD] = COLOR_PAIR(2) },
1120 [0][1] = { [M_IDLE] = A_BOLD,
1121 [M_SCAN] = COLOR_PAIR(1),
1122 [M_NEW] = COLOR_PAIR(1) | A_BOLD,
1123 [M_FLAG] = COLOR_PAIR(6) | A_BOLD,
1124 [M_BAD] = COLOR_PAIR(2) | A_BOLD },
1125 [1][0] = { [M_IDLE] = COLOR_PAIR(3),
1126 [M_SCAN] = COLOR_PAIR(4),
1127 [M_NEW] = COLOR_PAIR(4),
1128 [M_FLAG] = COLOR_PAIR(7),
1129 [M_BAD] = COLOR_PAIR(5) },
1130 [1][1] = { [M_IDLE] = COLOR_PAIR(3) | A_BOLD,
1131 [M_SCAN] = COLOR_PAIR(4),
1132 [M_NEW] = COLOR_PAIR(4) | A_BOLD,
1133 [M_FLAG] = COLOR_PAIR(7) | A_BOLD,
1134 [M_BAD] = COLOR_PAIR(5) | A_BOLD },
1135 [2][0] = { [M_IDLE] = COLOR_PAIR(8),
1136 [M_SCAN] = COLOR_PAIR(9),
1137 [M_NEW] = COLOR_PAIR(9),
1138 [M_FLAG] = COLOR_PAIR(10),
1139 [M_BAD] = COLOR_PAIR(11),
1140 [M_INCSEARCH] = COLOR_PAIR(12) | A_DIM },
1141 [2][1] = { [M_IDLE] = COLOR_PAIR(8) | A_BOLD,
1142 [M_SCAN] = COLOR_PAIR(9),
1143 [M_NEW] = COLOR_PAIR(9) | A_BOLD,
1144 [M_FLAG] = COLOR_PAIR(10) | A_BOLD,
1145 [M_BAD] = COLOR_PAIR(11) | A_BOLD,
1146 [M_INCSEARCH] = COLOR_PAIR(12) },
1148 memcpy(attrs, attrs_color, sizeof(attrs));
1160 print_status(char *status)
1164 printw("%s", status);
1170 scan_and_redraw(int notify)
1172 print_status("Busy...");
1180 if (i >= 0 && i < cursor_max && i != cursor_at)
1182 int old = cursor_at;
1190 next_active(int since, int step)
1194 since = (since+cursor_max) % cursor_max;
1195 step = (step+cursor_max) % cursor_max;
1201 struct mbox *b = mbox_array[i];
1202 if (b->new && b->o.priority > bestp)
1205 bestp = b->o.priority;
1207 i = (i+step) % cursor_max;
1215 mbox_run(struct mbox *b)
1217 char cmd[strlen(run_cmd) + strlen(b->path) + 16];
1218 sprintf(cmd, run_cmd, b->path);
1224 b->force_refresh = 1;
1229 enter_incsearch(void)
1231 print_status("Incremental search...");
1234 redraw_line(cursor_at);
1238 handle_incsearch(int ch)
1240 if ((ch == KEY_BACKSPACE || ch == KEY_DC) && is_pos)
1242 else if (ch >= ' ' && ch <= '~')
1244 if (is_pos < sizeof(is_buf) - 1)
1245 is_buf[is_pos++] = ch;
1252 redraw_line(cursor_at);
1257 for (int i=0; i<cursor_max; i++)
1259 struct mbox *b = mbox_array[i];
1260 if (!strncmp(b->name, is_buf, is_pos))
1271 redraw_line(cursor_at);
1276 #define STR(c) STR2(c)
1281 fprintf(stderr, "Usage: cm [<options>] [<mbox-pattern> | <mbox>[=<name>]] ...\n\
1284 -c <interval>\t\tScan mailboxes every <interval> seconds (default is 30)\n\
1285 -d\t\t\tLog debug messages to stderr\n\
1286 -i\t\t\tInclude user's INBOX\n\
1287 -m <cmd>\t\tCommand to run on the selected mailbox, %%s gets replaced by mailbox path\n\
1288 -o <pattern>=<opts>\tSet mailbox options\n\
1289 -o <opts>\t\tSet default options for all mailboxes\n\
1290 -p <pri>\t\tSet minimum priority to show\n\
1291 -s <key>=<val>\t\tSet on-screen display options (consult OSDD docs)\n\
1293 Mailbox options (set with `-o', use upper case to negate):\n\
1294 0-9\t\t\tSet mailbox priority (0=default)\n\
1295 b\t\t\tBeep when a message arrives\n\
1296 d\t\t\tSend an on-screen-display message (requires OSDD)\n\
1297 e\t\t\tHide from display if empty\n\
1298 f\t\t\tShow flagged messages if there are no new ones\n\
1299 h\t\t\tHide from display\n\
1300 l<led>\t\t\tLight a keyboard led (1-9) if running on X display\n\
1301 m\t\t\tShow mailbox name of the sender\n\
1302 p\t\t\tShow personal info (full name) of the sender\n\
1303 s\t\t\tShow message snippets\n\
1304 t\t\t\tHighlight the entry\n\
1305 !<key>\t\t\tSet hot key\n\
1307 CheckMail " STR(VERSION) ", (c) " STR(YEAR) " Martin Mares <mj@ucw.cz>\n\
1308 It can be freely distributed and used according to the GNU GPL v2.\n\
1314 parse_options(char *c)
1318 if (sep = strchr(c, '='))
1320 struct option_node *n = xmalloc(sizeof(*n) + sep-c);
1321 memcpy(n->pattern, c, sep-c);
1322 n->pattern[sep-c] = 0;
1323 clist_add_tail(&options, &n->n);
1329 o = &global_options;
1333 if (x >= '0' && x <= '9')
1334 o->priority = x - '0';
1335 else if (x == '!' && *c)
1337 else if (x == 'l' && *c >= '1' && *c <= '9')
1338 o->led = *c++ - '0';
1341 int value = !!islower(x);
1351 o->hide_if_empty = value;
1354 o->show_flagged = value;
1360 o->sender_mbox = value;
1363 o->sender_personal = value;
1366 o->snippets = value;
1369 o->highlight = value;
1372 fprintf(stderr, "Invalid mailbox option `%c'\n", x);
1379 main(int argc, char **argv)
1381 clist_init(&mboxes);
1382 clist_init(&options);
1383 clist_init(&patterns);
1384 clist_init(&osd_opts);
1387 while ((c = getopt(argc, argv, "c:dim:o:p:s:")) >= 0)
1391 check_interval = atol(optarg);
1392 if (check_interval <= 0)
1405 parse_options(optarg);
1408 minimum_priority = atol(optarg);
1411 add_osd_opt(optarg);
1416 while (optind < argc)
1417 add_pattern(argv[optind++]);
1425 int should_exit = 0;
1427 while (!should_exit)
1429 time_t now = time(NULL);
1430 int remains = last_scan_time + check_interval - now;
1438 halfdelay((remains > 255) ? 255 : remains);
1442 if (is_active && handle_incsearch(ch))
1447 for (int i=0; i<num_mboxes; i++)
1448 if (ch == mbox_array[i]->o.hotkey)
1452 mbox_run(mbox_array[i]);
1462 move_cursor(cursor_at+1);
1466 move_cursor(cursor_at-1);
1476 move_cursor(cursor_max-1);
1479 next_active(cursor_at+1, 1);
1482 next_active(cursor_at-1, -1);
1486 if (cursor_at < cursor_max)
1487 mbox_run(mbox_array[cursor_at]);
1490 clearok(stdscr, TRUE);
1499 print_status("Bells and whistles are now enabled. Toot!");
1503 print_status("Bells and whistles are now disabled. Pssst!");
1507 print_status("On-screen display is now enabled.");
1511 print_status("On-screen display is now disabled. Watch your step.");
1517 if (ch >= '0' && ch <= '9')
1519 minimum_priority = ch - '0';
1523 debug("Pressed unknown key %d\n", ch);