2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
7 * Andreas Krennmair <ak@synflood.at>
9 * This file is part of mutt-ng, see http://www.muttng.org/.
10 * It's licensed under the GNU General Public License,
11 * please see the file GPL in the top level source directory.
14 #include <lib-lib/lib-lib.h>
16 #include <lib-ui/lib-ui.h>
17 #include <lib-ui/enter.h>
18 #include <lib-ui/menu.h>
19 #include <lib-ui/sidebar.h>
20 #include <lib-mx/mx.h>
29 #include "recvattach.h"
33 #include <imap/imap_private.h>
35 #define ISHEADER(x) ((x) == MT_COLOR_HEADER || (x) == MT_COLOR_HDEFAULT)
37 #define IsAttach(x) (x && (x)->bdy)
38 #define IsRecvAttach(x) (x && (x)->bdy && (x)->fp)
39 #define IsSendAttach(x) (x && (x)->bdy && !(x)->fp)
40 #define IsMsgAttach(x) (x && (x)->fp && (x)->bdy && (x)->bdy->hdr)
41 #define IsHeader(x) (x && (x)->hdr && !(x)->bdy)
43 /* hack to return to position when returning from index to same message */
44 static int TopLine = 0;
45 static HEADER *OldHdr = NULL;
47 #define CHECK_MODE(x) \
50 mutt_error _("Not available in this menu."); \
54 #define CHECK_READONLY \
55 if (Context->readonly) { \
57 mutt_error _("Mailbox is read-only."); \
61 #define CHECK_ATTACH \
62 if (option(OPTATTACHMSG)) { \
64 mutt_error _("Function not permitted in attach-message mode."); \
73 struct q_class_t *next, *prev;
74 struct q_class_t *down, *up;
89 struct syntax_t *syntax;
90 struct syntax_t *search;
91 struct q_class_t *quote;
94 #define ANSI_OFF (1<<0)
95 #define ANSI_BLINK (1<<1)
96 #define ANSI_BOLD (1<<2)
97 #define ANSI_UNDERLINE (1<<3)
98 #define ANSI_REVERSE (1<<4)
99 #define ANSI_COLOR (1<<5)
101 typedef struct _ansi_attr {
108 static short InHelp = 0;
110 static struct resize {
116 #define NumSigLines 4
118 static int check_sig(const char *s, struct line_t *info, int n)
122 while (n > 0 && count <= NumSigLines) {
123 if (info[n].type != MT_COLOR_SIGNATURE)
132 if (count > NumSigLines) {
133 /* check for a blank line */
142 resolve_color (struct line_t *lineInfo, int n, int cnt, int flags,
143 int special, ansi_attr * a)
145 int def_color; /* color without syntax hilight */
146 int color; /* final color */
147 static int last_color; /* last color set */
148 int search = 0, i, m;
151 last_color = -1; /* force wattrset(main_w) */
153 if (lineInfo[n].continuation) {
154 if (!cnt && option (OPTMARKERS)) {
155 SETCOLOR(main_w, MT_COLOR_MARKERS);
157 last_color = ColorDefs[MT_COLOR_MARKERS];
159 m = (lineInfo[n].syntax)[0].first;
160 cnt += (lineInfo[n].syntax)[0].last;
165 if (!(flags & M_SHOWCOLOR))
166 def_color = ColorDefs[MT_COLOR_NORMAL];
167 else if (lineInfo[m].type == MT_COLOR_HEADER)
168 def_color = (lineInfo[m].syntax)[0].color;
170 def_color = ColorDefs[lineInfo[m].type];
172 if ((flags & M_SHOWCOLOR) && lineInfo[m].type == MT_COLOR_QUOTED) {
173 struct q_class_t *class = lineInfo[m].quote;
176 def_color = class->color;
178 while (class && class->length > cnt) {
179 def_color = class->color;
186 if (flags & M_SHOWCOLOR) {
187 for (i = 0; i < lineInfo[m].chunks; i++) {
188 /* we assume the chunks are sorted */
189 if (cnt > (lineInfo[m].syntax)[i].last)
191 if (cnt < (lineInfo[m].syntax)[i].first)
193 if (cnt != (lineInfo[m].syntax)[i].last) {
194 color = (lineInfo[m].syntax)[i].color;
197 /* don't break here, as cnt might be in the next chunk as well */
201 if (flags & M_SEARCH) {
202 for (i = 0; i < lineInfo[m].search_cnt; i++) {
203 if (cnt > (lineInfo[m].search)[i].last)
205 if (cnt < (lineInfo[m].search)[i].first)
207 if (cnt != (lineInfo[m].search)[i].last) {
208 color = ColorDefs[MT_COLOR_SEARCH];
215 /* handle "special" bold & underlined characters */
216 if (special || a->attr) {
217 if ((a->attr & ANSI_COLOR)) {
219 a->pair = mutt_alloc_color (a->fg, a->bg);
221 if (a->attr & ANSI_BOLD)
224 if ((special & A_BOLD) || (a->attr & ANSI_BOLD)) {
225 if (ColorDefs[MT_COLOR_BOLD] && !search)
226 color = ColorDefs[MT_COLOR_BOLD];
230 if ((special & A_UNDERLINE) || (a->attr & ANSI_UNDERLINE)) {
231 if (ColorDefs[MT_COLOR_UNDERLINE] && !search)
232 color = ColorDefs[MT_COLOR_UNDERLINE];
234 color ^= A_UNDERLINE;
236 else if (a->attr & ANSI_REVERSE) {
239 else if (a->attr & ANSI_BLINK) {
242 else if (a->attr & ANSI_OFF) {
247 if (color != last_color) {
248 wattrset(main_w, color);
253 static void append_line (struct line_t *lineInfo, int n, int cnt)
257 lineInfo[n + 1].type = lineInfo[n].type;
258 lineInfo[n + 1].syntax[0].color = lineInfo[n].syntax[0].color;
259 lineInfo[n + 1].continuation = 1;
261 /* find the real start of the line */
262 for (m = n; m >= 0; m--)
263 if (lineInfo[m].continuation == 0)
266 (lineInfo[n + 1].syntax)[0].first = m;
267 (lineInfo[n + 1].syntax)[0].last = (lineInfo[n].continuation) ?
268 cnt + (lineInfo[n].syntax)[0].last : cnt;
271 static void new_class_color (struct q_class_t *class, int *q_level)
273 class->index = (*q_level)++;
274 class->color = ColorQuote[class->index % ColorQuoteUsed];
278 shift_class_colors (struct q_class_t *QuoteList, struct q_class_t *new_class,
279 int lindex, int *q_level)
281 struct q_class_t *q_list;
284 new_class->index = -1;
287 if (q_list->index >= lindex) {
289 q_list->color = ColorQuote[q_list->index % ColorQuoteUsed];
292 q_list = q_list->down;
293 else if (q_list->next)
294 q_list = q_list->next;
296 while (!q_list->next) {
302 q_list = q_list->next;
306 new_class->index = lindex;
307 new_class->color = ColorQuote[lindex % ColorQuoteUsed];
311 static void cleanup_quote(struct q_class_t **QuoteList)
314 struct q_class_t *ptr = (*QuoteList)->next;
315 cleanup_quote(&(*QuoteList)->down);
316 p_delete(&(*QuoteList)->prefix);
322 static struct q_class_t *classify_quote (struct q_class_t **QuoteList,
323 const char *qptr, int length,
324 int *force_redraw, int *q_level)
326 struct q_class_t *q_list = *QuoteList;
327 struct q_class_t *class = NULL, *tmp = NULL, *ptr, *save;
329 int offset, tail_lng;
332 if (ColorQuoteUsed <= 1) {
333 /* not much point in classifying quotes... */
335 if (*QuoteList == NULL) {
336 class = p_new(struct q_class_t, 1);
337 class->color = ColorQuote[0];
343 /* Did I mention how much I like emulating Lisp in C? */
345 /* classify quoting prefix */
347 if (length <= q_list->length) {
348 /* case 1: check the top level nodes */
350 if (m_strncmp(qptr, q_list->prefix, length) == 0) {
351 if (length == q_list->length)
352 return q_list; /* same prefix: return the current class */
354 /* found shorter prefix */
356 /* add a node above q_list */
357 tmp = p_new(struct q_class_t, 1);
358 tmp->prefix = p_dupstr(qptr, length);
359 tmp->length = length;
361 /* replace q_list by tmp in the top level list */
363 tmp->next = q_list->next;
364 q_list->next->prev = tmp;
367 tmp->prev = q_list->prev;
368 q_list->prev->next = tmp;
371 /* make q_list a child of tmp */
375 /* q_list has no siblings for now */
379 /* update the root if necessary */
380 if (q_list == *QuoteList)
383 lindex = q_list->index;
385 /* tmp should be the return class too */
388 /* next class to test; if tmp is a shorter prefix for another
389 * node, that node can only be in the top level list, so don't
390 * go down after this point
394 /* found another branch for which tmp is a shorter prefix */
396 /* save the next sibling for later */
399 /* unlink q_list from the top level list */
401 q_list->next->prev = q_list->prev;
403 q_list->prev->next = q_list->next;
405 /* at this point, we have a tmp->down; link q_list to it */
407 /* sibling order is important here, q_list should be linked last */
415 lindex = q_list->index;
417 /* next class to test; as above, we shouldn't go down */
421 /* we found a shorter prefix, so certain quotes have changed classes */
425 /* shorter, but not a substring of the current class: try next */
426 q_list = q_list->next;
430 /* case 2: try subclassing the current top level node */
432 /* tmp != NULL means we already found a shorter prefix at case 1 */
434 && m_strncmp(qptr, q_list->prefix, q_list->length) == 0) {
435 /* ok, it's a subclass somewhere on this branch */
438 offset = q_list->length;
440 q_list = q_list->down;
441 tail_lng = length - offset;
442 tail_qptr = (char *) qptr + offset;
445 if (length <= q_list->length) {
446 if (m_strncmp(tail_qptr, (q_list->prefix) + offset, tail_lng)
448 /* same prefix: return the current class */
449 if (length == q_list->length)
452 /* found shorter common prefix */
454 /* add a node above q_list */
455 tmp = p_new(struct q_class_t, 1);
456 tmp->prefix = p_dupstr(qptr, length);
457 tmp->length = length;
459 /* replace q_list by tmp */
461 tmp->next = q_list->next;
462 q_list->next->prev = tmp;
465 tmp->prev = q_list->prev;
466 q_list->prev->next = tmp;
469 /* make q_list a child of tmp */
471 tmp->up = q_list->up;
473 if (tmp->up->down == q_list)
476 /* q_list has no siblings */
480 lindex = q_list->index;
482 /* tmp should be the return class too */
485 /* next class to test */
488 /* found another branch for which tmp is a shorter prefix */
490 /* save the next sibling for later */
493 /* unlink q_list from the top level list */
495 q_list->next->prev = q_list->prev;
497 q_list->prev->next = q_list->next;
499 /* at this point, we have a tmp->down; link q_list to it */
508 lindex = q_list->index;
510 /* next class to test */
514 /* we found a shorter prefix, so we need a redraw */
518 q_list = q_list->next;
522 /* longer than the current prefix: try subclassing it */
524 && m_strncmp(tail_qptr, (q_list->prefix) + offset,
525 q_list->length - offset) == 0) {
526 /* still a subclass: go down one level */
528 offset = q_list->length;
530 q_list = q_list->down;
531 tail_lng = length - offset;
532 tail_qptr = (char *) qptr + offset;
536 /* nope, try the next prefix */
537 q_list = q_list->next;
543 /* still not found so far: add it as a sibling to the current node */
545 tmp = p_new(struct q_class_t, 1);
546 tmp->prefix = p_dupstr(qptr, length);
547 tmp->length = length;
550 tmp->next = ptr->down;
551 ptr->down->prev = tmp;
556 new_class_color (tmp, q_level);
561 shift_class_colors (*QuoteList, tmp, lindex, q_level);
566 /* nope, try the next prefix */
567 q_list = q_list->next;
574 /* not found so far: add it as a top level class */
575 class = p_new(struct q_class_t, 1);
576 class->prefix = p_dupstr(qptr, length);
577 class->length = length;
578 new_class_color (class, q_level);
581 class->next = *QuoteList;
582 (*QuoteList)->prev = class;
588 shift_class_colors (*QuoteList, tmp, lindex, q_level);
593 static int check_attachment_marker (char *);
596 resolve_types (char *buf, char *rawbuf, struct line_t *lineInfo, int n, int last,
597 struct q_class_t **QuoteList, int *q_level, int *force_redraw,
600 COLOR_LINE *color_line;
601 regmatch_t pmatch[1], smatch[1];
602 int found, offset, null_rx, i;
604 if (n == 0 || ISHEADER (lineInfo[n - 1].type)) {
605 if (buf[0] == '\n') {
606 lineInfo[n].type = MT_COLOR_NORMAL;
608 else if (n > 0 && (buf[0] == ' ' || buf[0] == '\t')) {
609 lineInfo[n].type = lineInfo[n - 1].type; /* wrapped line */
610 (lineInfo[n].syntax)[0].color = (lineInfo[n - 1].syntax)[0].color;
612 lineInfo[n].type = MT_COLOR_HDEFAULT;
613 color_line = ColorHdrList;
615 if (REGEXEC (&color_line->rx, buf) == 0) {
616 lineInfo[n].type = MT_COLOR_HEADER;
617 lineInfo[n].syntax[0].color = color_line->pair;
620 color_line = color_line->next;
624 else if (m_strncmp("\033[0m", rawbuf, 4) == 0) /* a little hack... */
625 lineInfo[n].type = MT_COLOR_NORMAL;
626 else if (check_attachment_marker ((char *) rawbuf) == 0)
627 lineInfo[n].type = MT_COLOR_ATTACHMENT;
628 else if (m_strcmp("-- \n", buf) == 0
629 || m_strcmp("-- \r\n", buf) == 0) {
632 lineInfo[n].type = MT_COLOR_SIGNATURE;
633 while (i < last && check_sig(buf, lineInfo, i - 1) == 0 &&
634 (lineInfo[i].type == MT_COLOR_NORMAL ||
635 lineInfo[i].type == MT_COLOR_QUOTED ||
636 lineInfo[i].type == MT_COLOR_HEADER)) {
638 if (lineInfo[i].chunks) {
639 lineInfo[i].chunks = 0;
640 p_realloc(&(lineInfo[n].syntax), 1);
642 lineInfo[i++].type = MT_COLOR_SIGNATURE;
645 else if (check_sig(buf, lineInfo, n - 1) == 0)
646 lineInfo[n].type = MT_COLOR_SIGNATURE;
647 else if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
648 if (regexec ((regex_t *) Smileys.rx, buf, 1, smatch, 0) == 0) {
649 if (smatch[0].rm_so > 0) {
652 /* hack to avoid making an extra copy of buf */
653 c = buf[smatch[0].rm_so];
654 buf[smatch[0].rm_so] = 0;
656 if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) {
657 if (q_classify && lineInfo[n].quote == NULL)
658 lineInfo[n].quote = classify_quote (QuoteList,
659 buf + pmatch[0].rm_so,
661 pmatch[0].rm_so, force_redraw,
663 lineInfo[n].type = MT_COLOR_QUOTED;
665 lineInfo[n].type = MT_COLOR_NORMAL;
668 buf[smatch[0].rm_so] = c;
670 lineInfo[n].type = MT_COLOR_NORMAL;
673 if (q_classify && lineInfo[n].quote == NULL)
674 lineInfo[n].quote = classify_quote (QuoteList, buf + pmatch[0].rm_so,
675 pmatch[0].rm_eo - pmatch[0].rm_so,
676 force_redraw, q_level);
677 lineInfo[n].type = MT_COLOR_QUOTED;
680 lineInfo[n].type = MT_COLOR_NORMAL;
684 if (lineInfo[n].type == MT_COLOR_NORMAL ||
685 lineInfo[n].type == MT_COLOR_QUOTED) {
689 lineInfo[n].chunks = 0;
696 color_line = ColorBodyList;
698 if (regexec (&color_line->rx, buf + offset, 1, pmatch,
699 (offset ? REG_NOTBOL : 0)) == 0) {
700 if (pmatch[0].rm_eo != pmatch[0].rm_so) {
702 if (++(lineInfo[n].chunks) > 1)
703 p_realloc(&(lineInfo[n].syntax), lineInfo[n].chunks);
705 i = lineInfo[n].chunks - 1;
706 pmatch[0].rm_so += offset;
707 pmatch[0].rm_eo += offset;
709 pmatch[0].rm_so < (lineInfo[n].syntax)[i].first ||
710 (pmatch[0].rm_so == (lineInfo[n].syntax)[i].first &&
711 pmatch[0].rm_eo > (lineInfo[n].syntax)[i].last)) {
712 (lineInfo[n].syntax)[i].color = color_line->pair;
713 (lineInfo[n].syntax)[i].first = pmatch[0].rm_so;
714 (lineInfo[n].syntax)[i].last = pmatch[0].rm_eo;
719 null_rx = 1; /* empty regexp; don't add it, but keep looking */
722 color_line = color_line->next;
726 offset++; /* avoid degenerate cases */
728 offset = lineInfo[n].syntax[i].last;
729 } while (found || null_rx);
733 static int is_ansi(unsigned char *buf)
735 while (isdigit(*buf) || *buf == ';')
737 return (*buf == 'm');
740 static int check_attachment_marker(char *p)
742 char *q = AttachmentMarker;
744 for (; *p == *q && *q && *p && *q != '\a' && *p != '\a'; p++, q++);
745 return (int)(*p - *q);
748 /* trim tail of buf so that it contains complete multibyte characters */
749 static int trim_incomplete_mbyte(unsigned char *buf, size_t len) {
753 p_clear(&mbstate, 1);
754 for (; len > 0; buf += k, len -= k) {
755 k = mbrtowc (NULL, (char *) buf, len, &mbstate);
758 if (k == -1 || k == 0)
767 fill_buffer (FILE * f, off_t *last_pos, off_t offset, unsigned char *buf,
768 unsigned char *fmt, ssize_t blen, int *buf_ready)
771 static int b_read = 0;
773 if (*buf_ready == 0) {
775 if (offset != *last_pos)
776 fseeko (f, offset, 0);
777 if (fgets ((char *) buf, blen - 1, f) == NULL) {
781 *last_pos = ftello (f);
782 b_read = (int) (*last_pos - offset);
785 /* incomplete mbyte characters trigger a segfault in regex processing for
786 * certain versions of glibc. Trim them if necessary. */
787 if (b_read == blen - 2)
788 b_read -= trim_incomplete_mbyte(buf, b_read);
790 /* copy "buf" to "fmt", but without bold and underline controls */
793 if (*p == '\010' && (p > buf)) {
794 if (*(p + 1) == '_') /* underline */
796 else if (*(p + 1)) { /* bold or overstrike */
797 *(fmt - 1) = *(p + 1);
803 else if (*p == '\033' && *(p + 1) == '[' && is_ansi (p + 2)) {
804 while (*p++ != 'm') /* skip ANSI sequence */
807 else if (*p == '\033' && *(p + 1) == ']'
808 && check_attachment_marker ((char *) p) == 0) {
809 while (*p++ != '\a') /* skip pseudo-ANSI sequence */
824 static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
825 int flags, ansi_attr * pa, int cnt,
826 int *pspace, int *pvch, int *pcol, int *pspecial)
828 int space = -1; /* index of the last space or TAB */
829 int col = option (OPTMARKERS) ? (*lineInfo)[n].continuation : 0;
830 int ch, vch, k, last_special = -1, special = 0, t;
834 int wrap_cols = getmaxx(main_w);
836 if (!(flags & (M_SHOWFLAT)))
837 wrap_cols -= WrapMargin;
840 wrap_cols = getmaxx(main_w);
842 /* FIXME: this should come from lineInfo */
843 p_clear(&mbstate, 1);
845 for (ch = 0, vch = 0; ch < cnt; ch += k, vch += k) {
846 /* Handle ANSI sequences */
847 while (cnt - ch >= 2 && buf[ch] == '\033' && buf[ch + 1] == '[' &&
848 is_ansi (buf + ch + 2)) {
849 while (isdigit(buf[ch]) || buf[ch] == ';')
853 while (cnt - ch >= 2 && buf[ch] == '\033' && buf[ch + 1] == ']' &&
854 check_attachment_marker ((char *) buf + ch) == 0) {
855 while (buf[ch++] != '\a')
860 /* is anything left to do? */
864 k = mbrtowc (&wc, (char *) buf + ch, cnt - ch, &mbstate);
865 if (k == -2 || k == -1) {
866 if (col + 4 > wrap_cols)
870 wprintw(main_w, "\\%03o", buf[ch]);
877 /* Handle backspace */
884 while ((wc1 = 0, mbstate1 = mbstate,
886 k + mbrtowc (&wc1, (char *) buf + ch + k, cnt - ch - k,
887 &mbstate1), k1 - k > 0 && wc1 == '\b')
889 mbrtowc (&wc1, (char *) buf + ch + k1, cnt - ch - k1,
890 &mbstate1), k2 > 0 && iswprint(wc1))) {
892 special |= (wc == '_' && special & A_UNDERLINE)
893 ? A_UNDERLINE : A_BOLD;
895 else if (wc == '_' || wc1 == '_') {
896 special |= A_UNDERLINE;
897 wc = (wc1 == '_') ? wc : wc1;
899 /* special = 0; / * overstrike: nothing to do! */
909 ((flags & (M_SHOWCOLOR | M_SEARCH | M_PAGER_MARKER)) ||
910 special || last_special || pa->attr)) {
911 resolve_color (*lineInfo, n, vch, flags, special, pa);
912 last_special = special;
919 if (col + t > wrap_cols)
927 else if (wc == '\t') {
933 for (; col < t; col++)
938 else if (wc < 0x20 || wc == 0x7f) {
939 if (col + 2 > wrap_cols)
943 wprintw(main_w, "^%c", ('@' + wc) & 0x7f);
945 else if (wc < 0x100) {
946 if (col + 4 > wrap_cols)
950 wprintw(main_w, "\\%03o", wc);
952 if (col + 1 > wrap_cols)
956 waddch(main_w, CharsetReplacement);
968 * flags M_SHOWFLAT, show characters (used for displaying help)
969 * M_SHOWCOLOR, show characters in color
970 * otherwise don't show characters
971 * M_HIDE, don't show quoted text
972 * M_SEARCH, resolve search patterns
973 * M_TYPES, compute line's type
974 * M_PAGER_NSKIP, keeps leading whitespace
975 * M_PAGER_MARKER, eventually show markers
979 * 0 normal exit, line was not displayed
980 * >0 normal exit, line was displayed
983 display_line (FILE * f, off_t *last_pos, struct line_t **lineInfo, int n,
984 int *last, int *max, int flags, struct q_class_t **QuoteList,
985 int *q_level, int *force_redraw, regex_t * SearchRE)
987 unsigned char buf[LONG_STRING], fmt[LONG_STRING];
988 unsigned char *buf_ptr = buf;
989 int ch, vch, col, cnt, b_read;
990 int buf_ready = 0, change_last = 0;
995 ansi_attr a = { 0, 0, 0, -1 };
996 regmatch_t pmatch[1];
1003 if (*last == *max) {
1004 p_realloc(lineInfo, *max += LINES);
1005 for (ch = *last; ch < *max; ch++) {
1006 p_clear(&(*lineInfo)[ch], 1);
1007 (*lineInfo)[ch].type = -1;
1008 (*lineInfo)[ch].search_cnt = -1;
1009 (*lineInfo)[ch].syntax = p_new(struct syntax_t, 1);
1010 ((*lineInfo)[ch].syntax)[0].first = ((*lineInfo)[ch].syntax)[0].last =
1015 /* only do color hiliting if we are viewing a message */
1016 if (flags & (M_SHOWCOLOR | M_TYPES)) {
1017 if ((*lineInfo)[n].type == -1) {
1018 /* determine the line class */
1020 (f, last_pos, (*lineInfo)[n].offset, buf, fmt, sizeof (buf),
1027 resolve_types ((char *) fmt, (char *) buf, *lineInfo, n, *last,
1028 QuoteList, q_level, force_redraw, flags & M_SHOWCOLOR);
1030 /* avoid race condition for continuation lines when scrolling up */
1032 m < *last && (*lineInfo)[m].offset && (*lineInfo)[m].continuation;
1034 (*lineInfo)[m].type = (*lineInfo)[n].type;
1037 /* this also prevents searching through the hidden lines */
1038 if ((flags & M_HIDE) && (*lineInfo)[n].type == MT_COLOR_QUOTED)
1039 flags = 0; /* M_NOSHOW */
1042 /* At this point, (*lineInfo[n]).quote may still be undefined. We
1043 * don't want to compute it every time M_TYPES is set, since this
1044 * would slow down the "bottom" function unacceptably. A compromise
1045 * solution is hence to call regexec() again, just to find out the
1046 * length of the quote prefix.
1048 if ((flags & M_SHOWCOLOR) && !(*lineInfo)[n].continuation &&
1049 (*lineInfo)[n].type == MT_COLOR_QUOTED && (*lineInfo)[n].quote == NULL)
1052 (f, last_pos, (*lineInfo)[n].offset, buf, fmt, sizeof (buf),
1058 regexec ((regex_t *) QuoteRegexp.rx, (char *) fmt, 1, pmatch, 0);
1059 (*lineInfo)[n].quote = classify_quote (QuoteList,
1060 (char *) fmt + pmatch[0].rm_so,
1061 pmatch[0].rm_eo - pmatch[0].rm_so,
1062 force_redraw, q_level);
1065 if ((flags & M_SEARCH) && !(*lineInfo)[n].continuation
1066 && (*lineInfo)[n].search_cnt == -1) {
1068 (f, last_pos, (*lineInfo)[n].offset, buf, fmt, sizeof (buf),
1076 (*lineInfo)[n].search_cnt = 0;
1078 (SearchRE, (char *) fmt + offset, 1, pmatch,
1079 (offset ? REG_NOTBOL : 0)) == 0) {
1080 if (++((*lineInfo)[n].search_cnt) > 1)
1081 p_realloc(&(*lineInfo)[n].search, (*lineInfo)[n].search_cnt);
1083 (*lineInfo)[n].search = p_new(struct syntax_t, 1);
1084 pmatch[0].rm_so += offset;
1085 pmatch[0].rm_eo += offset;
1086 ((*lineInfo)[n].search)[(*lineInfo)[n].search_cnt - 1].first =
1088 ((*lineInfo)[n].search)[(*lineInfo)[n].search_cnt - 1].last =
1091 if (pmatch[0].rm_eo == pmatch[0].rm_so)
1092 offset++; /* avoid degenerate cases */
1094 offset = pmatch[0].rm_eo;
1100 if (!(flags & M_SHOW) && (*lineInfo)[n + 1].offset > 0) {
1101 /* we've already scanned this line, so just exit */
1104 if ((flags & M_SHOWCOLOR) && *force_redraw && (*lineInfo)[n + 1].offset > 0) {
1105 /* no need to try to display this line... */
1106 return (1); /* fake display */
1109 if ((b_read = fill_buffer (f, last_pos, (*lineInfo)[n].offset, buf, fmt,
1110 sizeof (buf), &buf_ready)) < 0) {
1116 /* now chose a good place to break the line */
1117 cnt = format_line(lineInfo, n, buf, flags, 0, b_read, &ch, &vch, &col,
1119 buf_ptr = buf + cnt;
1121 /* move the break point only if smart_wrap is set */
1122 if (option (OPTWRAP)) {
1124 if (ch != -1 && buf[cnt] != ' ' && buf[cnt] != '\t' && buf[cnt] != '\n'
1125 && buf[cnt] != '\r') {
1127 /* skip trailing blanks */
1128 while (ch && (buf[ch] == ' ' || buf[ch] == '\t' || buf[ch] == '\r'))
1130 /* a very long word with leading spaces causes infinite wrapping */
1131 if ((!ch) && (flags & M_PAGER_NSKIP))
1132 buf_ptr = buf + cnt;
1136 buf_ptr = buf + cnt; /* a very long word... */
1139 if (!(flags & M_PAGER_NSKIP))
1140 /* skip leading blanks on the next line too */
1141 while (*buf_ptr == ' ' || *buf_ptr == '\t')
1145 if (*buf_ptr == '\r')
1147 if (*buf_ptr == '\n')
1150 if ((int) (buf_ptr - buf) < b_read && !(*lineInfo)[n + 1].continuation)
1151 append_line (*lineInfo, n, (int) (buf_ptr - buf));
1152 (*lineInfo)[n + 1].offset = (*lineInfo)[n].offset + (long) (buf_ptr - buf);
1154 /* if we don't need to display the line we are done */
1155 if (!(flags & M_SHOW))
1158 /* display the line */
1159 format_line (lineInfo, n, buf, flags, &a, cnt, &ch, &vch, &col, &special);
1161 /* end the last color pattern (needed by S-Lang) */
1162 if (special || (col != getmaxx(main_w) && (flags & (M_SHOWCOLOR | M_SEARCH))))
1163 resolve_color(*lineInfo, n, vch, flags, 0, &a);
1166 * Fill the blank space at the end of the line with the prevailing color.
1167 * ncurses does an implicit wclrtoeol(main_w) when you do waddch(main_w,
1168 * '\n') so we have to make sure to reset the color *after* that
1170 if (flags & M_SHOWCOLOR) {
1171 m = ((*lineInfo)[n].continuation) ? ((*lineInfo)[n].syntax)[0].first : n;
1172 if ((*lineInfo)[m].type == MT_COLOR_HEADER)
1173 def_color = ((*lineInfo)[m].syntax)[0].color;
1175 def_color = ColorDefs[(*lineInfo)[m].type];
1177 wattrset(main_w, def_color);
1178 wbkgdset(main_w, def_color | ' ');
1180 waddch(main_w, '\n');
1183 * reset the color back to normal. This *must* come after the
1184 * waddch(main_w, '\n'), otherwise the color for this line will not be
1185 * filled to the right margin.
1187 if (flags & M_SHOWCOLOR) {
1188 SETCOLOR(main_w, MT_COLOR_NORMAL);
1189 BKGDSET(main_w, MT_COLOR_NORMAL);
1192 /* build a return code */
1193 if (!(flags & M_SHOW))
1199 static int upNLines (int nlines, struct line_t *info, int cur, int hiding)
1201 while (cur > 0 && nlines > 0) {
1203 if (!hiding || info[cur].type != MT_COLOR_QUOTED)
1210 /* This pager is actually not so simple as it once was. It now operates in
1211 two modes: one for viewing messages and the other for viewing help. These
1212 can be distinguished by whether or not ``hdr'' is NULL. The ``hdr'' arg
1213 is there so that we can do operations on the current message without the
1214 need to pop back out to the main-menu. */
1216 mutt_pager (const char *banner, const char *fname, int flags, pager_t * extra)
1218 static char searchbuf[STRING];
1219 char buffer[LONG_STRING];
1220 int maxLine, lastLine = 0;
1221 struct line_t *lineInfo;
1222 struct q_class_t *QuoteList = NULL;
1223 int i, j, ch = 0, rc = -1, hideQuoted = 0, q_level = 0, force_redraw = 0;
1224 int lines = 0, curline = 0, topline = 0, oldtopline = 0, err, first = 1;
1226 int redraw = REDRAW_FULL;
1228 off_t last_pos = 0, last_offset = 0;
1229 int old_smart_wrap, old_markers;
1232 int SearchCompiled = 0, SearchFlag = 0, SearchBack = 0;
1233 int has_types = (IsHeader (extra) || (flags & M_SHOWCOLOR)) ? M_TYPES : 0; /* main message or rfc822 attachment */
1235 int bodyoffset = 1; /* offset of first line of real text */
1236 int statusoffset = 0; /* offset for the status bar */
1237 int helpoffset = LINES - 2; /* offset for the help bar. */
1238 int bodylen = LINES - 2 - bodyoffset; /* length of displayable area */
1240 MUTTMENU *pager_index = NULL; /* the Pager Index (PI) */
1241 int indexlen = PagerIndexLines; /* indexlen not always == PIL */
1242 int indicator = indexlen / 3; /* the indicator line of the PI */
1243 int old_PagerIndexLines; /* some people want to resize it
1244 * while inside the pager... */
1250 if (!(flags & M_SHOWCOLOR))
1251 flags |= M_SHOWFLAT;
1253 if ((fp = fopen (fname, "r")) == NULL) {
1254 mutt_perror (fname);
1258 if (stat (fname, &sb) != 0) {
1259 mutt_perror (fname);
1265 /* Initialize variables */
1267 if (IsHeader (extra) && !extra->hdr->read) {
1268 Context->msgnotreadyet = extra->hdr->msgno;
1269 mutt_set_flag (Context, extra->hdr, M_READ, 1);
1272 lineInfo = p_new(struct line_t, maxLine = LINES);
1273 for (i = 0; i < maxLine; i++) {
1274 p_clear(&lineInfo[i], 1);
1275 lineInfo[i].type = -1;
1276 lineInfo[i].search_cnt = -1;
1277 lineInfo[i].syntax = p_new(struct syntax_t, 1);
1278 (lineInfo[i].syntax)[0].first = (lineInfo[i].syntax)[0].last = -1;
1285 if (redraw & REDRAW_FULL) {
1286 SETCOLOR(main_w, MT_COLOR_NORMAL);
1287 /* wclear(main_w) doesn't optimize screen redraws */
1288 wmove(main_w, 0, 0);
1291 if (IsHeader (extra) && Context->vcount + 1 < PagerIndexLines)
1292 indexlen = Context->vcount + 1;
1294 indexlen = PagerIndexLines;
1296 indicator = indexlen / 3;
1298 statusoffset = IsHeader (extra) ? indexlen : 0;
1299 bodyoffset = statusoffset + 1;
1300 helpoffset = LINES - 2;
1301 bodylen = helpoffset - bodyoffset;
1303 SETCOLOR(main_w, MT_COLOR_STATUS);
1304 wmove(main_w, helpoffset, 0);
1305 mutt_paddstr(main_w, getmaxx(main_w), "");
1306 SETCOLOR(main_w, MT_COLOR_NORMAL);
1308 if (Resize != NULL) {
1309 if ((SearchCompiled = Resize->SearchCompiled)) {
1311 (&SearchRE, searchbuf, REG_NEWLINE | mutt_which_case (searchbuf));
1312 SearchFlag = M_SEARCH;
1313 SearchBack = Resize->SearchBack;
1315 lines = Resize->line;
1316 redraw |= REDRAW_SIGWINCH;
1321 if (IsHeader (extra) && PagerIndexLines) {
1322 if (pager_index == NULL) {
1323 /* only allocate the space if/when we need the index.
1324 Initialise the menu as per the main index */
1325 pager_index = mutt_new_menu ();
1326 pager_index->menu = MENU_MAIN;
1327 pager_index->make_entry = index_make_entry;
1328 pager_index->color = index_color;
1329 pager_index->max = Context->vcount;
1330 pager_index->current = extra->hdr->virtual;
1333 SETCOLOR(main_w, MT_COLOR_NORMAL);
1334 pager_index->offset = 1;
1335 pager_index->pagelen = indexlen - 1;
1337 /* some fudge to work out where abouts the indicator should go */
1338 if (pager_index->current - indicator < 0)
1339 pager_index->top = 0;
1340 else if (pager_index->max - pager_index->current < pager_index->pagelen - indicator)
1341 pager_index->top = pager_index->max - pager_index->pagelen;
1343 pager_index->top = pager_index->current - indicator;
1345 menu_redraw_index (pager_index);
1348 redraw |= REDRAW_BODY | REDRAW_INDEX | REDRAW_STATUS;
1352 if (redraw & REDRAW_SIGWINCH) {
1355 while (display_line (fp, &last_pos, &lineInfo, ++i, &lastLine, &maxLine,
1356 has_types | SearchFlag, &QuoteList, &q_level,
1357 &force_redraw, &SearchRE) == 0) {
1358 if (!lineInfo[i].continuation && ++j == lines) {
1363 redraw |= REDRAW_SIDEBAR;
1367 if ((redraw & REDRAW_BODY) || topline != oldtopline) {
1369 wmove(main_w, bodyoffset, 0);
1370 curline = oldtopline = topline;
1374 while (lines < bodylen && lineInfo[curline].offset <= sb.st_size - 1) {
1375 if (display_line (fp, &last_pos, &lineInfo, curline, &lastLine,
1377 (flags & M_DISPLAYFLAGS) | hideQuoted |
1378 SearchFlag, &QuoteList, &q_level, &force_redraw,
1382 wmove(main_w, lines + bodyoffset, 0);
1383 redraw |= REDRAW_SIDEBAR;
1385 last_offset = lineInfo[curline].offset;
1386 } while (force_redraw);
1388 SETCOLOR(main_w, MT_COLOR_TILDE);
1389 BKGDSET(main_w, MT_COLOR_TILDE);
1390 while (lines < bodylen) {
1392 if (option (OPTTILDE))
1393 waddch(main_w, '~');
1394 waddch(main_w, '\n');
1396 wmove(main_w, lines + bodyoffset, 0);
1398 /* We are going to update the pager status bar, so it isn't
1399 * necessary to reset to normal color now. */
1401 redraw |= REDRAW_STATUS; /* need to update the % seen */
1404 if (redraw & REDRAW_STATUS) {
1405 /* print out the pager status bar */
1406 SETCOLOR(main_w, MT_COLOR_STATUS);
1407 BKGDSET(main_w, MT_COLOR_STATUS);
1408 wmove(main_w, statusoffset, 0);
1410 if (IsHeader (extra)) {
1411 size_t l1 = (getmaxx(main_w) - 9) * MB_LEN_MAX;
1412 size_t l2 = sizeof (buffer);
1414 _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
1415 Context, extra->hdr, M_FORMAT_MAKEPRINT);
1417 else if (IsMsgAttach (extra)) {
1418 size_t l1 = (getmaxx(main_w) - 9) * MB_LEN_MAX;
1419 size_t l2 = sizeof (buffer);
1421 _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
1422 Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT);
1424 wmove(main_w, statusoffset, 0);
1425 mutt_paddstr(main_w, getmaxx(main_w) - 10,
1426 IsHeader(extra) || IsMsgAttach(extra) ? buffer : banner);
1428 waddstr(main_w, " -- (");
1429 if (last_pos < sb.st_size - 1)
1430 wprintw(main_w, "%d%%)", (int) (100 * last_offset / sb.st_size));
1432 waddstr(main_w, topline == 0 ? "all)" : "end)");
1433 BKGDSET(main_w, MT_COLOR_NORMAL);
1434 SETCOLOR(main_w, MT_COLOR_NORMAL);
1437 if (redraw & REDRAW_SIDEBAR)
1440 if ((redraw & REDRAW_INDEX) && pager_index) {
1441 /* redraw the pager_index indicator, because the
1442 * flags for this message might have changed. */
1443 menu_redraw_current (pager_index);
1445 /* print out the pager_index status bar */
1446 menu_status_line (buffer, sizeof (buffer), pager_index, NONULL (Status));
1447 wmove(main_w, 0, 0);
1448 SETCOLOR(main_w, MT_COLOR_STATUS);
1449 BKGDSET(main_w, MT_COLOR_STATUS);
1450 mutt_paddstr(main_w, getmaxx(main_w), buffer);
1451 SETCOLOR(main_w, MT_COLOR_NORMAL);
1452 BKGDSET(main_w, MT_COLOR_NORMAL);
1454 /* if we're not using the index, update every time */
1461 if (IsHeader (extra) && OldHdr == extra->hdr && TopLine != topline
1462 && lineInfo[curline].offset < sb.st_size-1) {
1463 if (TopLine - topline > lines)
1472 ch = km_dokey (MENU_PAGER);
1474 mutt_clear_error ();
1485 /* Store current position. */
1487 for (i = 0; i <= topline; i++)
1488 if (!lineInfo[i].continuation)
1491 if (flags & M_PAGER_RETWINCH) {
1492 Resize = p_new(struct resize, 1);
1494 Resize->line = lines;
1495 Resize->SearchCompiled = SearchCompiled;
1496 Resize->SearchBack = SearchBack;
1499 rc = OP_REFORMAT_WINCH;
1501 for (i = 0; i < maxLine; i++) {
1502 lineInfo[i].offset = 0;
1503 lineInfo[i].type = -1;
1504 lineInfo[i].continuation = 0;
1505 lineInfo[i].chunks = 0;
1506 lineInfo[i].search_cnt = -1;
1507 lineInfo[i].quote = NULL;
1509 p_realloc(&lineInfo[i].syntax, 1);
1511 p_delete(&lineInfo[i].search);
1517 redraw = REDRAW_FULL | REDRAW_SIGWINCH;
1537 if (lineInfo[curline].offset < sb.st_size - 1) {
1538 topline = upNLines (PagerContext, lineInfo, curline, hideQuoted);
1540 else if (option (OPTPAGERSTOP)) {
1541 /* emulate "less -q" and don't go on to the next message. */
1542 mutt_error _("Bottom of message is shown.");
1544 /* end of the current message, so display the next message. */
1545 rc = OP_MAIN_NEXT_UNDELETED;
1553 upNLines (bodylen - PagerContext, lineInfo, topline, hideQuoted);
1556 mutt_error _("Top of message is shown.");
1560 if (lineInfo[curline].offset < sb.st_size - 1) {
1563 while (lineInfo[topline].type == MT_COLOR_QUOTED &&
1569 mutt_error _("Bottom of message is shown.");
1574 topline = upNLines (1, lineInfo, topline, hideQuoted);
1576 mutt_error _("Top of message is shown.");
1583 mutt_error _("Top of message is shown.");
1588 topline = upNLines (bodylen / 2, lineInfo, topline, hideQuoted);
1590 mutt_error _("Top of message is shown.");
1594 if (lineInfo[curline].offset < sb.st_size - 1) {
1595 topline = upNLines (bodylen / 2, lineInfo, curline, hideQuoted);
1597 else if (option (OPTPAGERSTOP)) {
1598 /* emulate "less -q" and don't go on to the next message. */
1599 mutt_error _("Bottom of message is shown.");
1601 /* end of the current message, so display the next message. */
1602 rc = OP_MAIN_NEXT_UNDELETED;
1607 case OP_SEARCH_NEXT:
1608 case OP_SEARCH_OPPOSITE:
1609 if (SearchCompiled) {
1611 if ((!SearchBack && ch == OP_SEARCH_NEXT) ||
1612 (SearchBack && ch == OP_SEARCH_OPPOSITE)) {
1613 /* searching forward */
1614 for (i = topline + 1; i < lastLine; i++) {
1615 if ((!hideQuoted || lineInfo[i].type != MT_COLOR_QUOTED) &&
1616 !lineInfo[i].continuation && lineInfo[i].search_cnt > 0)
1623 mutt_error _("Not found.");
1626 /* searching backward */
1627 for (i = topline - 1; i >= 0; i--) {
1628 if ((!hideQuoted || (has_types &&
1629 lineInfo[i].type != MT_COLOR_QUOTED)) &&
1630 !lineInfo[i].continuation && lineInfo[i].search_cnt > 0)
1637 mutt_error _("Not found.");
1640 if (lineInfo[topline].search_cnt > 0)
1641 SearchFlag = M_SEARCH;
1645 /* no previous search pattern, so fall through to search */
1648 case OP_SEARCH_REVERSE:
1649 m_strcpy(buffer, sizeof(buffer), searchbuf);
1650 if (mutt_get_field ((SearchBack ? _("Reverse search: ") :
1651 _("Search: ")), buffer, sizeof (buffer),
1655 if (!m_strcmp (buffer, searchbuf)) {
1656 if (SearchCompiled) {
1657 /* do an implicit search-next */
1658 if (ch == OP_SEARCH)
1659 ch = OP_SEARCH_NEXT;
1661 ch = OP_SEARCH_OPPOSITE;
1670 m_strcpy(searchbuf, sizeof(searchbuf), buffer);
1672 /* leave SearchBack alone if ch == OP_SEARCH_NEXT */
1673 if (ch == OP_SEARCH)
1675 else if (ch == OP_SEARCH_REVERSE)
1678 if (SearchCompiled) {
1679 regfree (&SearchRE);
1680 for (i = 0; i < lastLine; i++) {
1681 p_delete(&lineInfo[i].search);
1682 lineInfo[i].search_cnt = -1;
1687 REGCOMP (&SearchRE, searchbuf,
1688 REG_NEWLINE | mutt_which_case (searchbuf))) != 0) {
1689 regerror (err, &SearchRE, buffer, sizeof (buffer));
1690 mutt_error ("%s", buffer);
1691 regfree (&SearchRE);
1692 for (i = 0; i < maxLine; i++) {
1694 p_delete(&lineInfo[i].search);
1695 lineInfo[i].search_cnt = -1;
1702 /* update the search pointers */
1704 while (display_line (fp, &last_pos, &lineInfo, i, &lastLine,
1705 &maxLine, M_SEARCH | (flags & M_PAGER_NSKIP),
1706 &QuoteList, &q_level,
1707 &force_redraw, &SearchRE) == 0) {
1709 redraw |= REDRAW_SIDEBAR;
1713 /* searching forward */
1714 for (i = topline; i < lastLine; i++) {
1715 if ((!hideQuoted || lineInfo[i].type != MT_COLOR_QUOTED) &&
1716 !lineInfo[i].continuation && lineInfo[i].search_cnt > 0)
1724 /* searching backward */
1725 for (i = topline; i >= 0; i--) {
1726 if ((!hideQuoted || lineInfo[i].type != MT_COLOR_QUOTED) &&
1727 !lineInfo[i].continuation && lineInfo[i].search_cnt > 0)
1735 if (lineInfo[topline].search_cnt == 0) {
1737 mutt_error _("Not found.");
1740 SearchFlag = M_SEARCH;
1742 redraw = REDRAW_BODY;
1745 case OP_SEARCH_TOGGLE:
1746 if (SearchCompiled) {
1747 SearchFlag ^= M_SEARCH;
1748 redraw = REDRAW_BODY;
1753 /* don't let the user enter the help-menu from the help screen! */
1756 mutt_help (MENU_PAGER);
1757 redraw = REDRAW_FULL;
1761 mutt_error _("Help is currently being shown.");
1764 case OP_PAGER_HIDE_QUOTED:
1766 hideQuoted ^= M_HIDE;
1767 if (hideQuoted && lineInfo[topline].type == MT_COLOR_QUOTED)
1768 topline = upNLines (1, lineInfo, topline, hideQuoted);
1770 redraw = REDRAW_BODY;
1774 case OP_PAGER_SKIP_QUOTED:
1777 int new_topline = topline;
1779 while ((new_topline < lastLine ||
1780 (0 == (dretval = display_line (fp, &last_pos, &lineInfo,
1781 new_topline, &lastLine,
1782 &maxLine, M_TYPES, &QuoteList,
1783 &q_level, &force_redraw,
1785 && lineInfo[new_topline].type != MT_COLOR_QUOTED) {
1786 redraw |= REDRAW_SIDEBAR;
1791 mutt_error _("No more quoted text.");
1796 while ((new_topline < lastLine ||
1797 (0 == (dretval = display_line (fp, &last_pos, &lineInfo,
1798 new_topline, &lastLine,
1799 &maxLine, M_TYPES, &QuoteList,
1800 &q_level, &force_redraw,
1802 && lineInfo[new_topline].type == MT_COLOR_QUOTED) {
1804 redraw |= REDRAW_SIDEBAR;
1808 mutt_error _("No more unquoted text after quoted text.");
1812 topline = new_topline;
1816 case OP_PAGER_BOTTOM: /* move to the end of the file */
1817 if (lineInfo[curline].offset < sb.st_size - 1) {
1819 /* make sure the types are defined to the end of file */
1820 while (display_line (fp, &last_pos, &lineInfo, i, &lastLine,
1821 &maxLine, has_types,
1822 &QuoteList, &q_level, &force_redraw,
1825 redraw |= REDRAW_SIDEBAR;
1827 topline = upNLines (bodylen, lineInfo, lastLine, hideQuoted);
1830 mutt_error _("Bottom of message is shown.");
1834 clearok(main_w, TRUE);
1835 redraw = REDRAW_FULL;
1839 km_error_key (MENU_PAGER);
1842 /* --------------------------------------------------------------------
1843 * The following are operations on the current message rather than
1844 * adjusting the view of the message.
1847 case OP_BOUNCE_MESSAGE:
1848 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra))
1850 if (IsMsgAttach (extra))
1851 mutt_attach_bounce (extra->fp, extra->hdr,
1852 extra->idx, extra->idxlen, extra->bdy);
1854 ci_bounce_message (extra->hdr, &redraw);
1858 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra))
1860 if (IsMsgAttach (extra))
1861 mutt_attach_resend (extra->fp, extra->hdr,
1862 extra->idx, extra->idxlen, extra->bdy);
1864 mutt_resend_message (NULL, extra->ctx, extra->hdr);
1865 redraw = REDRAW_FULL;
1868 case OP_CHECK_TRADITIONAL:
1869 CHECK_MODE (IsHeader (extra));
1870 if (!(extra->hdr->security & PGP_TRADITIONAL_CHECKED)) {
1872 rc = OP_CHECK_TRADITIONAL;
1876 case OP_CREATE_ALIAS:
1877 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
1878 if (IsMsgAttach (extra))
1879 mutt_create_alias (extra->bdy->hdr->env, NULL);
1881 mutt_create_alias (extra->hdr->env, NULL);
1882 MAYBE_REDRAW (redraw);
1885 case OP_PURGE_MESSAGE:
1887 CHECK_MODE (IsHeader (extra));
1890 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1892 mutt_set_flag (Context, extra->hdr, M_DELETE, 1);
1893 mutt_set_flag (Context, extra->hdr, M_PURGED,
1894 ch != OP_PURGE_MESSAGE ? 0 : 1);
1895 if (option (OPTDELETEUNTAG))
1896 mutt_set_flag (Context, extra->hdr, M_TAG, 0);
1897 redraw = REDRAW_STATUS | REDRAW_INDEX;
1898 if (option (OPTRESOLVE)) {
1900 rc = OP_MAIN_NEXT_UNDELETED;
1904 case OP_DELETE_THREAD:
1905 case OP_DELETE_SUBTHREAD:
1906 CHECK_MODE (IsHeader (extra));
1909 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1911 r = mutt_thread_set_flag (extra->hdr, M_DELETE, 1,
1912 ch == OP_DELETE_THREAD ? 0 : 1);
1915 if (option (OPTDELETEUNTAG))
1916 mutt_thread_set_flag (extra->hdr, M_TAG, 0,
1917 ch == OP_DELETE_THREAD ? 0 : 1);
1918 if (option (OPTRESOLVE)) {
1919 rc = OP_MAIN_NEXT_UNDELETED;
1923 if (!option (OPTRESOLVE) && PagerIndexLines)
1924 redraw = REDRAW_FULL;
1926 redraw = REDRAW_STATUS | REDRAW_INDEX;
1930 case OP_DISPLAY_ADDRESS:
1931 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
1932 if (IsMsgAttach (extra))
1933 mutt_display_address (extra->bdy->hdr->env);
1935 mutt_display_address (extra->hdr->env);
1938 case OP_ENTER_COMMAND:
1939 old_smart_wrap = option (OPTWRAP);
1940 old_markers = option (OPTMARKERS);
1941 old_PagerIndexLines = PagerIndexLines;
1943 CurrentMenu = MENU_PAGER;
1944 mutt_enter_command ();
1946 if (option (OPTNEEDRESORT)) {
1947 unset_option (OPTNEEDRESORT);
1948 CHECK_MODE (IsHeader (extra));
1949 set_option (OPTNEEDRESORT);
1952 if (old_PagerIndexLines != PagerIndexLines) {
1954 mutt_menuDestroy (&pager_index);
1958 if (option (OPTWRAP) != old_smart_wrap ||
1959 option (OPTMARKERS) != old_markers) {
1960 if (flags & M_PAGER_RETWINCH) {
1962 rc = OP_REFORMAT_WINCH;
1966 /* count the real lines above */
1968 for (i = 0; i <= topline; i++) {
1969 if (!lineInfo[i].continuation)
1973 /* we need to restart the whole thing */
1974 for (i = 0; i < maxLine; i++) {
1975 lineInfo[i].offset = 0;
1976 lineInfo[i].type = -1;
1977 lineInfo[i].continuation = 0;
1978 lineInfo[i].chunks = 0;
1979 lineInfo[i].search_cnt = -1;
1980 lineInfo[i].quote = NULL;
1982 p_realloc(&(lineInfo[i].syntax), 1);
1984 p_delete(&lineInfo[i].search);
1987 if (SearchCompiled) {
1988 regfree (&SearchRE);
1993 /* try to keep the old position */
1996 while (j > 0 && display_line (fp, &last_pos, &lineInfo, topline,
1997 &lastLine, &maxLine,
1998 (has_types ? M_TYPES : 0),
1999 &QuoteList, &q_level, &force_redraw,
2001 redraw |= REDRAW_SIDEBAR;
2002 if (!lineInfo[topline].continuation)
2011 if (option (OPTFORCEREDRAWPAGER))
2012 redraw = REDRAW_FULL;
2013 unset_option (OPTFORCEREDRAWINDEX);
2014 unset_option (OPTFORCEREDRAWPAGER);
2017 case OP_FLAG_MESSAGE:
2018 CHECK_MODE (IsHeader (extra));
2021 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
2023 mutt_set_flag (Context, extra->hdr, M_FLAG, !extra->hdr->flagged);
2024 redraw = REDRAW_STATUS | REDRAW_INDEX;
2025 if (option (OPTRESOLVE)) {
2027 rc = OP_MAIN_NEXT_UNDELETED;
2032 CHECK_MODE (IsHeader (extra) || IsAttach (extra));
2033 if (IsAttach (extra))
2034 mutt_pipe_attachment_list (extra->fp, 0, extra->bdy, 0);
2036 mutt_pipe_message (extra->hdr);
2037 MAYBE_REDRAW (redraw);
2041 CHECK_MODE (IsHeader (extra) || IsAttach (extra));
2042 if (IsAttach (extra))
2043 mutt_print_attachment_list (extra->fp, 0, extra->bdy);
2045 mutt_print_message (extra->hdr);
2049 CHECK_MODE (IsHeader (extra) && !IsAttach (extra));
2051 ci_send_message (0, NULL, NULL, extra->ctx, NULL);
2052 redraw = REDRAW_FULL;
2057 CHECK_MODE (IsHeader (extra) && !IsAttach (extra));
2059 if (extra->ctx && extra->ctx->magic == M_NNTP &&
2060 !((nntp_data_t *) extra->ctx->data)->allowed &&
2061 query_quadoption (OPT_TOMODERATED,
2063 ("Posting to this group not allowed, may be moderated. Continue?"))
2066 ci_send_message (SENDNEWS, NULL, NULL, extra->ctx, NULL);
2067 redraw = REDRAW_FULL;
2070 case OP_FORWARD_TO_GROUP:
2071 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2073 if (extra->ctx && extra->ctx->magic == M_NNTP &&
2074 !((nntp_data_t *) extra->ctx->data)->allowed &&
2075 query_quadoption (OPT_TOMODERATED,
2077 ("Posting to this group not allowed, may be moderated. Continue?"))
2080 if (IsMsgAttach (extra))
2081 mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
2082 extra->idxlen, extra->bdy, SENDNEWS);
2084 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, extra->ctx,
2086 redraw = REDRAW_FULL;
2090 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2093 if (IsMsgAttach (extra))
2094 followup_to = extra->bdy->hdr->env->followup_to;
2096 followup_to = extra->hdr->env->followup_to;
2098 if (!followup_to || m_strcasecmp(followup_to, "poster") ||
2099 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2100 _("Reply by mail as poster prefers?")) != M_YES) {
2101 if (extra->ctx && extra->ctx->magic == M_NNTP
2102 && !((nntp_data_t *) extra->ctx->data)->allowed
2103 && query_quadoption (OPT_TOMODERATED,
2105 ("Posting to this group not allowed, may be moderated. Continue?"))
2108 if (IsMsgAttach (extra))
2109 mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
2110 extra->idxlen, extra->bdy, SENDNEWS | SENDREPLY);
2112 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL,
2113 extra->ctx, extra->hdr);
2114 redraw = REDRAW_FULL;
2120 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2122 if (IsMsgAttach (extra))
2123 mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
2124 extra->idxlen, extra->bdy, SENDREPLY);
2126 ci_send_message (SENDREPLY, NULL, NULL, extra->ctx, extra->hdr);
2127 redraw = REDRAW_FULL;
2130 case OP_RECALL_MESSAGE:
2131 CHECK_MODE (IsHeader (extra) && !IsAttach (extra));
2133 ci_send_message (SENDPOSTPONED, NULL, NULL, extra->ctx, extra->hdr);
2134 redraw = REDRAW_FULL;
2137 case OP_GROUP_REPLY:
2138 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2140 if (IsMsgAttach (extra))
2141 mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
2142 extra->idxlen, extra->bdy,
2143 SENDREPLY | SENDGROUPREPLY);
2145 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, extra->ctx,
2147 redraw = REDRAW_FULL;
2151 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2153 if (IsMsgAttach (extra))
2154 mutt_attach_reply (extra->fp, extra->hdr, extra->idx,
2155 extra->idxlen, extra->bdy,
2156 SENDREPLY | SENDLISTREPLY);
2158 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, extra->ctx,
2160 redraw = REDRAW_FULL;
2163 case OP_FORWARD_MESSAGE:
2164 CHECK_MODE (IsHeader (extra) || IsMsgAttach (extra));
2166 if (IsMsgAttach (extra))
2167 mutt_attach_forward (extra->fp, extra->hdr, extra->idx,
2168 extra->idxlen, extra->bdy, 0);
2170 ci_send_message (SENDFORWARD, NULL, NULL, extra->ctx, extra->hdr);
2171 redraw = REDRAW_FULL;
2174 case OP_DECRYPT_SAVE:
2176 if (IsAttach (extra)) {
2177 mutt_save_attachment_list (extra->fp, 0, extra->bdy, extra->hdr,
2182 case OP_COPY_MESSAGE:
2183 case OP_DECODE_SAVE:
2184 case OP_DECODE_COPY:
2185 case OP_DECRYPT_COPY:
2186 CHECK_MODE (IsHeader (extra));
2187 if (mutt_save_message (extra->hdr,
2188 (ch == OP_DECRYPT_SAVE) ||
2189 (ch == OP_SAVE) || (ch == OP_DECODE_SAVE),
2190 (ch == OP_DECODE_SAVE) || (ch == OP_DECODE_COPY),
2191 (ch == OP_DECRYPT_SAVE)
2192 || (ch == OP_DECRYPT_COPY) || 0, &redraw) == 0
2193 && (ch == OP_SAVE || ch == OP_DECODE_SAVE
2194 || ch == OP_DECRYPT_SAVE)) {
2195 if (option (OPTRESOLVE)) {
2197 rc = OP_MAIN_NEXT_UNDELETED;
2200 redraw |= REDRAW_STATUS | REDRAW_INDEX;
2202 MAYBE_REDRAW (redraw);
2205 case OP_SHELL_ESCAPE:
2206 mutt_shell_escape ();
2207 MAYBE_REDRAW (redraw);
2211 CHECK_MODE (IsHeader (extra));
2212 mutt_set_flag (Context, extra->hdr, M_TAG, !extra->hdr->tagged);
2214 Context->last_tag = extra->hdr->tagged ? extra->hdr :
2215 ((Context->last_tag == extra->hdr && !extra->hdr->tagged)
2216 ? NULL : Context->last_tag);
2218 redraw = REDRAW_STATUS | REDRAW_INDEX;
2219 if (option (OPTRESOLVE)) {
2226 CHECK_MODE (IsHeader (extra));
2229 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
2231 if (extra->hdr->read || extra->hdr->old)
2232 mutt_set_flag (Context, extra->hdr, M_NEW, 1);
2234 mutt_set_flag (Context, extra->hdr, M_READ, 1);
2236 Context->msgnotreadyet = -1;
2237 redraw = REDRAW_STATUS | REDRAW_INDEX;
2238 if (option (OPTRESOLVE)) {
2240 rc = OP_MAIN_NEXT_UNDELETED;
2245 CHECK_MODE (IsHeader (extra));
2248 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2250 mutt_set_flag (Context, extra->hdr, M_DELETE, 0);
2251 mutt_set_flag (Context, extra->hdr, M_PURGED, 0);
2252 redraw = REDRAW_STATUS | REDRAW_INDEX;
2253 if (option (OPTRESOLVE)) {
2259 case OP_UNDELETE_THREAD:
2260 case OP_UNDELETE_SUBTHREAD:
2261 CHECK_MODE (IsHeader (extra));
2264 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2266 r = mutt_thread_set_flag (extra->hdr, M_DELETE, 0,
2267 ch == OP_UNDELETE_THREAD ? 0 : 1)
2268 + mutt_thread_set_flag (extra->hdr, M_PURGED, 0,
2269 ch == OP_UNDELETE_THREAD ? 0 : 1);
2272 if (option (OPTRESOLVE)) {
2273 rc = (ch == OP_DELETE_THREAD) ?
2274 OP_MAIN_NEXT_THREAD : OP_MAIN_NEXT_SUBTHREAD;
2278 if (!option (OPTRESOLVE) && PagerIndexLines)
2279 redraw = REDRAW_FULL;
2281 redraw = REDRAW_STATUS | REDRAW_INDEX;
2290 if (option (OPTFORCEBUFFYCHECK))
2293 redraw |= REDRAW_SIDEBAR;
2296 case OP_VIEW_ATTACHMENTS:
2297 if (flags & M_PAGER_ATTACHMENT) {
2299 rc = OP_ATTACH_COLLAPSE;
2302 CHECK_MODE (IsHeader (extra));
2303 mutt_view_attachments (extra->hdr);
2304 if (extra->hdr->attach_del)
2305 Context->changed = 1;
2306 redraw = REDRAW_FULL;
2309 case OP_EXTRACT_KEYS:
2310 CHECK_MODE (IsHeader (extra));
2311 crypt_extract_keys_from_messages (extra->hdr);
2312 redraw = REDRAW_FULL;
2315 case OP_SIDEBAR_SCROLL_UP:
2316 case OP_SIDEBAR_SCROLL_DOWN:
2317 case OP_SIDEBAR_NEXT:
2318 case OP_SIDEBAR_NEXT_NEW:
2319 case OP_SIDEBAR_PREV:
2320 case OP_SIDEBAR_PREV_NEW:
2321 sidebar_scroll (ch);
2330 if (IsHeader (extra)) {
2331 Context->msgnotreadyet = -1;
2336 OldHdr = extra->hdr;
2340 cleanup_quote(&QuoteList);
2342 for (i = 0; i < maxLine; i++) {
2343 p_delete(&lineInfo[i].syntax);
2345 p_delete(&lineInfo[i].search);
2347 if (SearchCompiled) {
2348 regfree (&SearchRE);
2351 p_delete(&lineInfo);
2353 mutt_menuDestroy (&pager_index);
2354 return (rc != -1 ? rc : 0);
2358 #undef CHECK_READONLY