-
Notifications
You must be signed in to change notification settings - Fork 51
/
curs_main.c
2704 lines (2339 loc) · 62 KB
/
curs_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 1996-2000,2002,2010,2012-2013 Michael R. Elkins <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mailbox.h"
#include "mapping.h"
#include "sort.h"
#include "buffy.h"
#include "mx.h"
#ifdef USE_SIDEBAR
#include "sidebar.h"
#endif
#ifdef USE_POP
#include "pop.h"
#endif
#ifdef USE_IMAP
#include "imap_private.h"
#endif
#ifdef USE_NOTMUCH
#include "mutt_notmuch.h"
#endif
#include "mutt_crypt.h"
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <assert.h>
static const char *No_mailbox_is_open = N_("No mailbox is open.");
static const char *There_are_no_messages = N_("There are no messages.");
static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode.");
static const char *No_visible = N_("No visible messages.");
#define CHECK_IN_MAILBOX if (!Context) \
{ \
mutt_flushinp (); \
mutt_error _(No_mailbox_is_open); \
break; \
}
#define CHECK_MSGCOUNT if (!Context) \
{ \
mutt_flushinp (); \
mutt_error _(No_mailbox_is_open); \
break; \
} \
else if (!Context->msgcount) \
{ \
mutt_flushinp (); \
mutt_error _(There_are_no_messages); \
break; \
}
#define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
{\
mutt_flushinp (); \
mutt_error _(No_visible); \
break; \
}
#define CHECK_READONLY if (Context->readonly) \
{ \
mutt_flushinp (); \
mutt_error _(Mailbox_is_read_only); \
break; \
}
#define CHECK_ACL(aclbit,action) \
if (!mutt_bit_isset(Context->rights,aclbit)) { \
mutt_flushinp(); \
/* L10N: %s is one of the CHECK_ACL entries below. */ \
mutt_error (_("%s: Operation not permitted by ACL"), action); \
break; \
}
#define CHECK_ATTACH if(option(OPTATTACHMSG)) \
{\
mutt_flushinp (); \
mutt_error _(Function_not_permitted_in_attach_message_mode); \
break; \
}
#define CURHDR Context->hdrs[Context->v2r[menu->current]]
#define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
#define UNREAD(h) mutt_thread_contains_unread (Context, h)
/* de facto standard escapes for tsl/fsl */
static char *tsl = "\033]0;";
static char *fsl = "\007";
/* terminal status capability check. terminfo must have been initialized. */
short mutt_ts_capability(void)
{
char *term = getenv("TERM");
char *tcaps;
#ifdef HAVE_USE_EXTENDED_NAMES
int tcapi;
#endif
char **termp;
char *known[] = {
"color-xterm",
"cygwin",
"eterm",
"kterm",
"nxterm",
"putty",
"rxvt",
"screen",
"xterm",
NULL
};
/* If tsl is set, then terminfo says that status lines work. */
tcaps = tigetstr("tsl");
if (tcaps && tcaps != (char *)-1 && *tcaps)
{
/* update the static defns of tsl/fsl from terminfo */
tsl = safe_strdup(tcaps);
tcaps = tigetstr("fsl");
if (tcaps && tcaps != (char *)-1 && *tcaps)
fsl = safe_strdup(tcaps);
return 1;
}
/* If XT (boolean) is set, then this terminal supports the standard escape. */
/* Beware: tigetflag returns -1 if XT is invalid or not a boolean. */
#ifdef HAVE_USE_EXTENDED_NAMES
use_extended_names (TRUE);
tcapi = tigetflag("XT");
if (tcapi == 1)
return 1;
#endif /* HAVE_USE_EXTENDED_NAMES */
/* Check term types that are known to support the standard escape without
* necessarily asserting it in terminfo. */
for (termp = known; termp; termp++)
{
if (term && *termp && mutt_strncasecmp (term, *termp, strlen(*termp)))
return 1;
}
/* not supported */
return 0;
}
void mutt_ts_status(char *str)
{
/* If empty, do not set. To clear, use a single space. */
if (str == NULL || *str == '\0')
return;
fprintf(stderr, "%s%s%s", tsl, str, fsl);
}
void mutt_ts_icon(char *str)
{
/* If empty, do not set. To clear, use a single space. */
if (str == NULL || *str == '\0')
return;
/* icon setting is not supported in terminfo, so hardcode the escape - yuck */
fprintf(stderr, "\033]1;%s\007", str);
}
void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
{
format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
int edgemsgno, reverse = Sort & SORT_REVERSE;
HEADER *h = Context->hdrs[Context->v2r[num]];
THREAD *tmp;
if ((Sort & SORT_MASK) == SORT_THREADS && h->tree)
{
flag |= M_FORMAT_TREE; /* display the thread tree */
if (h->display_subject)
flag |= M_FORMAT_FORCESUBJ;
else
{
if (reverse)
{
if (menu->top + menu->pagelen > menu->max)
edgemsgno = Context->v2r[menu->max - 1];
else
edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
}
else
edgemsgno = Context->v2r[menu->top];
for (tmp = h->thread->parent; tmp; tmp = tmp->parent)
{
if (!tmp->message)
continue;
/* if no ancestor is visible on current screen, provisionally force
* subject... */
if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
{
flag |= M_FORMAT_FORCESUBJ;
break;
}
else if (tmp->message->virtual >= 0)
break;
}
if (flag & M_FORMAT_FORCESUBJ)
{
for (tmp = h->thread->prev; tmp; tmp = tmp->prev)
{
if (!tmp->message)
continue;
/* ...but if a previous sibling is available, don't force it */
if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
break;
else if (tmp->message->virtual >= 0)
{
flag &= ~M_FORMAT_FORCESUBJ;
break;
}
}
}
}
}
_mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
}
int index_color (int index_no)
{
HEADER *h = Context->hdrs[Context->v2r[index_no]];
if (h && h->pair)
return h->pair;
mutt_set_header_color (Context, h);
return h->pair;
}
static int ci_next_undeleted (int msgno)
{
int i;
for (i=msgno+1; i < Context->vcount; i++)
if (! Context->hdrs[Context->v2r[i]]->deleted)
return (i);
return (-1);
}
static int ci_previous_undeleted (int msgno)
{
int i;
for (i=msgno-1; i>=0; i--)
if (! Context->hdrs[Context->v2r[i]]->deleted)
return (i);
return (-1);
}
/* Return the index of the first new message, or failing that, the first
* unread message.
*/
static int ci_first_message (void)
{
int old = -1, i;
if (Context && Context->msgcount)
{
for (i=0; i < Context->vcount; i++)
{
if (! Context->hdrs[Context->v2r[i]]->read &&
! Context->hdrs[Context->v2r[i]]->deleted)
{
if (! Context->hdrs[Context->v2r[i]]->old)
return (i);
else if (old == -1)
old = i;
}
}
if (old != -1)
return (old);
/* If Sort is reverse and not threaded, the latest message is first.
* If Sort is threaded, the latest message is first iff exactly one
* of Sort and SortAux are reverse.
*/
if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
((Sort & SORT_MASK) == SORT_THREADS &&
((Sort ^ SortAux) & SORT_REVERSE)))
return 0;
else
return (Context->vcount ? Context->vcount - 1 : 0);
}
return 0;
}
/* This should be in mx.c, but it only gets used here. */
static int mx_toggle_write (CONTEXT *ctx)
{
if (!ctx)
return -1;
if (ctx->readonly)
{
mutt_error _("Cannot toggle write on a readonly mailbox!");
return -1;
}
if (ctx->dontwrite)
{
ctx->dontwrite = 0;
mutt_message _("Changes to folder will be written on folder exit.");
}
else
{
ctx->dontwrite = 1;
mutt_message _("Changes to folder will not be written.");
}
return 0;
}
static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
int oldcount, int index_hint)
{
/* store pointers to the newly added messages */
HEADER **save_new = NULL;
int j;
/* take note of the current message */
if (oldcount)
{
if (menu->current < ctx->vcount)
menu->oldcurrent = index_hint;
else
oldcount = 0; /* invalid message number! */
}
/* We are in a limited view. Check if the new message(s) satisfy
* the limit criteria. If they do, set their virtual msgno so that
* they will be visible in the limited view */
if (ctx->pattern)
{
#define THIS_BODY ctx->hdrs[j]->content
for (j = (check == M_REOPENED) ? 0 : oldcount; j < ctx->msgcount; j++)
{
if (!j)
ctx->vcount = 0;
if (mutt_pattern_exec (ctx->limit_pattern,
M_MATCH_FULL_ADDRESS,
ctx, ctx->hdrs[j]))
{
assert (ctx->vcount < ctx->msgcount);
ctx->hdrs[j]->virtual = ctx->vcount;
ctx->v2r[ctx->vcount] = j;
ctx->hdrs[j]->limited = 1;
ctx->vcount++;
ctx->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
}
}
#undef THIS_BODY
}
/* save the list of new messages */
if (oldcount && check != M_REOPENED
&& ((Sort & SORT_MASK) == SORT_THREADS))
{
save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (ctx->msgcount - oldcount));
for (j = oldcount; j < ctx->msgcount; j++)
save_new[j-oldcount] = ctx->hdrs[j];
}
/* if the mailbox was reopened, need to rethread from scratch */
mutt_sort_headers (ctx, (check == M_REOPENED));
/* uncollapse threads with new mail */
if ((Sort & SORT_MASK) == SORT_THREADS)
{
if (check == M_REOPENED)
{
THREAD *h, *j;
ctx->collapsed = 0;
for (h = ctx->tree; h; h = h->next)
{
for (j = h; !j->message; j = j->child)
;
mutt_uncollapse_thread (ctx, j->message);
}
mutt_set_virtual (ctx);
}
else if (oldcount)
{
for (j = 0; j < ctx->msgcount - oldcount; j++)
{
int k;
for (k = 0; k < ctx->msgcount; k++)
{
HEADER *h = ctx->hdrs[k];
if (h == save_new[j] && (!ctx->pattern || h->limited))
mutt_uncollapse_thread (ctx, h);
}
}
FREE (&save_new);
mutt_set_virtual (ctx);
}
}
menu->current = -1;
if (oldcount)
{
/* restore the current message to the message it was pointing to */
for (j = 0; j < ctx->vcount; j++)
{
if (ctx->hdrs[ctx->v2r[j]]->index == menu->oldcurrent)
{
menu->current = j;
break;
}
}
}
if (menu->current < 0)
menu->current = ci_first_message ();
}
static void resort_index (MUTTMENU *menu)
{
int i;
HEADER *current = CURHDR;
menu->current = -1;
mutt_sort_headers (Context, 0);
/* Restore the current message */
for (i = 0; i < Context->vcount; i++)
{
if (Context->hdrs[Context->v2r[i]] == current)
{
menu->current = i;
break;
}
}
if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
menu->current = mutt_parent_message (Context, current);
if (menu->current < 0)
menu->current = ci_first_message ();
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
}
/**
* mutt_draw_statusline - XXX
*/
void
mutt_draw_statusline (int cols, char *inbuf)
{
int i = 0;
int cnt = 0;
int last_color = 0;
int color = 0;
int offset = 0;
int found = 0;
int null_rx = 0;
char buf[2048];
struct line_t {
short chunks;
struct syntax_t {
int color;
int first;
int last;
} *syntax;
} lineInfo = { 0, NULL };
mutt_format_string (buf, sizeof (buf), cols, cols, 0, ' ', inbuf, mutt_strlen (inbuf), 0);
lineInfo.syntax = safe_malloc (sizeof (struct syntax_t));
lineInfo.syntax[0].first = -1;
lineInfo.syntax[0].last = -1;
lineInfo.syntax[0].color = ColorDefs[MT_COLOR_STATUS];
lineInfo.chunks = 1;
do {
found = 0;
null_rx = 0;
COLOR_LINE *color_line = ColorStatusList;
if (!buf[offset])
break;
while (color_line) {
regmatch_t pmatch[color_line->match + 1];
if (regexec (&color_line->rx, buf + offset, color_line->match + 1, pmatch, (offset ? REG_NOTBOL : 0)) == 0) {
if (pmatch[color_line->match].rm_eo != pmatch[color_line->match].rm_so) {
if (!found) {
if (++(lineInfo.chunks) > 1) {
safe_realloc (&(lineInfo.syntax), (lineInfo.chunks) * sizeof (struct syntax_t));
}
}
i = lineInfo.chunks - 1;
pmatch[color_line->match].rm_so += offset;
pmatch[color_line->match].rm_eo += offset;
if (!found ||
(pmatch[color_line->match].rm_so < (lineInfo.syntax)[i].first) ||
((pmatch[color_line->match].rm_so == (lineInfo.syntax)[i].first) &&
(pmatch[color_line->match].rm_eo > (lineInfo.syntax)[i].last))) {
(lineInfo.syntax)[i].color = color_line->pair;
(lineInfo.syntax)[i].first = pmatch[color_line->match].rm_so;
(lineInfo.syntax)[i].last = pmatch[color_line->match].rm_eo;
}
found = 1;
null_rx = 0;
} else {
null_rx = 1; /* empty regexp; don't add it, but keep looking */
}
}
color_line = color_line->next;
}
if (null_rx)
offset++; /* avoid degenerate cases */
else
offset = (lineInfo.syntax)[i].last;
} while (found || null_rx);
for (cnt = 0; cnt < mutt_strlen (buf); cnt++) {
color = lineInfo.syntax[0].color;
for (i = 0; i < lineInfo.chunks; i++) {
/* we assume the chunks are sorted */
if (cnt > (lineInfo.syntax)[i].last)
continue;
if (cnt < (lineInfo.syntax)[i].first)
break;
if (cnt != (lineInfo.syntax)[i].last) {
color = (lineInfo.syntax)[i].color;
break;
}
/* don't break here, as cnt might be in the next chunk as well */
}
if (color != last_color) {
attrset (color);
last_color = color;
}
/* XXX more than one char at a time? */
addch ((unsigned char)buf[cnt]);
#if 0
waddnstr (stdscr, tgbuf, 10);
SETCOLOR (MT_COLOR_NORMAL);
waddnstr (stdscr, tgbuf + 10, -1);
#endif
}
safe_free (&lineInfo.syntax);
}
static int main_change_folder(MUTTMENU *menu, int op, char *buf, size_t bufsz,
int *oldcount, int *index_hint)
{
mutt_expand_path (buf, bufsz);
#ifdef USE_SIDEBAR
sb_set_open_buffy (buf);
#endif
if (mx_get_magic (buf) <= 0)
{
mutt_error (_("%s is not a mailbox."), buf);
return -1;
}
mutt_str_replace (&CurrentFolder, buf);
/* keepalive failure in mutt_enter_fname may kill connection. #3028 */
if (Context && !Context->path)
FREE (&Context);
if (Context)
{
int check;
mutt_str_replace (&LastFolder, Context->path);
*oldcount = Context ? Context->msgcount : 0;
if ((check = mx_close_mailbox (Context, index_hint)) != 0)
{
if (check == M_NEW_MAIL || check == M_REOPENED)
update_index (menu, Context, check, *oldcount, *index_hint);
set_option (OPTSEARCHINVALID);
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
return 0;
}
FREE (&Context);
}
mutt_sleep (0);
/* Set CurrentMenu to MENU_MAIN before executing any folder
* hooks so that all the index menu functions are available to
* the exec command.
*/
CurrentMenu = MENU_MAIN;
mutt_folder_hook (buf);
if ((Context = mx_open_mailbox (buf,
(option (OPTREADONLY) || op == OP_MAIN_CHANGE_FOLDER_READONLY) ?
M_READONLY : 0, NULL)) != NULL)
{
menu->current = ci_first_message ();
}
else
menu->current = 0;
mutt_clear_error ();
mutt_buffy_check(1); /* force the buffy check after we have changed the folder */
menu->redraw = REDRAW_FULL;
set_option (OPTSEARCHINVALID);
return 0;
}
static const struct mapping_t IndexHelp[] = {
{ N_("Quit"), OP_QUIT },
{ N_("Del"), OP_DELETE },
{ N_("Undel"), OP_UNDELETE },
{ N_("Save"), OP_SAVE },
{ N_("Mail"), OP_MAIL },
{ N_("Reply"), OP_REPLY },
{ N_("Group"), OP_GROUP_REPLY },
{ N_("Help"), OP_HELP },
{ NULL, 0 }
};
/* This function handles the message index window as well as commands returned
* from the pager (MENU_PAGER).
*/
int mutt_index_menu (void)
{
char buf[LONG_STRING], helpstr[LONG_STRING];
int op = OP_NULL;
int done = 0; /* controls when to exit the "event" loop */
int i = 0, j;
int tag = 0; /* has the tag-prefix command been pressed? */
int newcount = -1;
int oldcount = -1;
int rc = -1;
MUTTMENU *menu;
char *cp; /* temporary variable. */
int index_hint; /* used to restore cursor position */
int do_buffy_notify = 1;
int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
int attach_msg = option(OPTATTACHMSG);
menu = mutt_new_menu (MENU_MAIN);
menu->offset = 1;
menu->pagelen = LINES - 3;
menu->make_entry = index_make_entry;
menu->color = index_color;
menu->current = ci_first_message ();
menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN, IndexHelp);
if (!attach_msg)
mutt_buffy_check(1); /* force the buffy check after we enter the folder */
FOREVER
{
tag = 0; /* clear the tag-prefix */
/* check if we need to resort the index because just about
* any 'op' below could do mutt_enter_command(), either here or
* from any new menu launched, and change $sort/$sort_aux
*/
if (option (OPTNEEDRESORT) && Context && Context->msgcount && menu->current >= 0)
resort_index (menu);
menu->max = Context ? Context->vcount : 0;
oldcount = Context ? Context->msgcount : 0;
if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
{
mutt_draw_tree (Context);
menu->redraw |= REDRAW_STATUS;
unset_option (OPTREDRAWTREE);
}
if (Context && !attach_msg)
{
int check;
/* check for new mail in the mailbox. If nonzero, then something has
* changed about the file (either we got new mail or the file was
* modified underneath us.)
*/
index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0;
if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0)
{
if (!Context->path)
{
/* fatal error occurred */
FREE (&Context);
menu->redraw = REDRAW_FULL;
}
set_option (OPTSEARCHINVALID);
}
else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS)
{
update_index (menu, Context, check, oldcount, index_hint);
/* notify the user of new mail */
if (check == M_REOPENED)
mutt_error _("Mailbox was externally modified. Flags may be wrong.");
else if (check == M_NEW_MAIL)
{
mutt_message _("New mail in this mailbox.");
if (option (OPTBEEPNEW))
beep ();
} else if (check == M_FLAGS)
mutt_message _("Mailbox was externally modified.");
/* avoid the message being overwritten by buffy */
do_buffy_notify = 0;
menu->redraw = REDRAW_FULL;
menu->max = Context->vcount;
set_option (OPTSEARCHINVALID);
}
}
if (!attach_msg)
{
/* check for new mail in the incoming folders */
oldcount = newcount;
if ((newcount = mutt_buffy_check (0)) != oldcount)
menu->redraw |= REDRAW_STATUS;
if (do_buffy_notify)
{
if (mutt_buffy_notify())
{
menu->redraw |= REDRAW_STATUS;
if (option (OPTBEEPNEW))
beep();
}
}
else
do_buffy_notify = 1;
}
#ifdef USE_SIDEBAR
if (option (OPTSIDEBAR))
menu->redraw |= REDRAW_SIDEBAR;
#endif
if (op != -1)
mutt_curs_set (0);
if (menu->redraw & REDRAW_FULL)
{
menu_redraw_full (menu);
#ifdef USE_SIDEBAR
sb_draw();
#endif
mutt_show_error ();
}
#ifdef USE_SIDEBAR
else if (menu->redraw & REDRAW_SIDEBAR) {
sb_draw();
menu->redraw &= ~REDRAW_SIDEBAR;
}
#endif
if (menu->menu == MENU_MAIN)
{
if (Context && Context->hdrs && !(menu->current >= Context->vcount))
{
menu_check_recenter (menu);
if (menu->redraw & REDRAW_INDEX)
{
menu_redraw_index (menu);
menu->redraw |= REDRAW_STATUS;
}
else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
menu_redraw_motion (menu);
else if (menu->redraw & REDRAW_CURRENT)
menu_redraw_current (menu);
}
if (menu->redraw & REDRAW_STATUS)
{
#ifdef USE_SIDEBAR
/* Temporarily lie about the sidebar width */
short sw = SidebarWidth;
SidebarWidth = 0;
#endif
menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
#ifdef USE_SIDEBAR
SidebarWidth = sw; /* Restore the sidebar width */
#endif
move (option (OPTSTATUSONTOP) ? 0 : LINES-2, 0);
SETCOLOR (MT_COLOR_STATUS);
#ifdef USE_SIDEBAR
sb_set_buffystats (Context);
#endif
mutt_draw_statusline (COLS, buf);
NORMAL_COLOR;
menu->redraw &= ~REDRAW_STATUS;
if (option(OPTTSENABLED) && TSSupported)
{
menu_status_line (buf, sizeof (buf), menu, NONULL (TSStatusFormat));
mutt_ts_status(buf);
menu_status_line (buf, sizeof (buf), menu, NONULL (TSIconFormat));
mutt_ts_icon(buf);
}
}
menu->redraw = 0;
if (menu->current < menu->max)
menu->oldcurrent = menu->current;
else
menu->oldcurrent = -1;
if (option (OPTARROWCURSOR))
move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
else if (option (OPTBRAILLEFRIENDLY))
move (menu->current - menu->top + menu->offset, 0);
else
move (menu->current - menu->top + menu->offset, COLS - 1);
mutt_refresh ();
#if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
if (SigWinch)
{
mutt_flushinp ();
mutt_resize_screen ();
menu->redraw = REDRAW_FULL;
menu->menu = MENU_MAIN;
SigWinch = 0;
menu->top = 0; /* so we scroll the right amount */
/*
* force a real complete redraw. clrtobot() doesn't seem to be able
* to handle every case without this.
*/
clearok(stdscr,TRUE);
continue;
}
#endif
op = km_dokey (MENU_MAIN);
dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
if (op == -1)
continue; /* either user abort or timeout */
mutt_curs_set (1);
/* special handling for the tag-prefix function */
if (op == OP_TAG_PREFIX)
{
if (!Context)
{
mutt_error _("No mailbox is open.");
continue;
}
if (!Context->tagged)
{
mutt_error _("No tagged messages.");
continue;
}
tag = 1;
/* give visual indication that the next command is a tag- command */
mvaddstr (LINES - 1, 0, "tag-");
clrtoeol ();
/* get the real command */
if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
{
/* abort tag sequence */
CLEARLINE (LINES-1);
continue;
}
}
else if (option (OPTAUTOTAG) && Context && Context->tagged)
tag = 1;
if (op == OP_TAG_PREFIX_COND)
{
if (!Context)
{
mutt_error _("No mailbox is open.");
continue;
}
if (!Context->tagged)
{
mutt_flush_macro_to_endcond ();
mutt_message _("Nothing to do.");
continue;
}
tag = 1;
/* give visual indication that the next command is a tag- command */
mvaddstr (LINES - 1, 0, "tag-");
clrtoeol ();
/* get the real command */
if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
{
/* abort tag sequence */
CLEARLINE (LINES-1);
continue;
}
}
mutt_clear_error ();
}
else
{
if (menu->current < menu->max)
menu->oldcurrent = menu->current;
else
menu->oldcurrent = -1;
mutt_curs_set (1); /* fallback from the pager */
}
#ifdef USE_NOTMUCH
if (Context)
nm_debug_check(Context);
#endif
switch (op)
{
/* ----------------------------------------------------------------------
* movement commands
*/
case OP_BOTTOM_PAGE:
menu_bottom_page (menu);
break;
case OP_FIRST_ENTRY:
menu_first_entry (menu);
break;
case OP_MIDDLE_PAGE:
menu_middle_page (menu);
break;
case OP_HALF_UP:
menu_half_up (menu);
break;
case OP_HALF_DOWN:
menu_half_down (menu);
break;
case OP_NEXT_LINE:
menu_next_line (menu);
break;