NeoMutt  2023-05-17-56-ga67199
Teaching an old dog new tricks
DOXYGEN
dlg_index.c
Go to the documentation of this file.
1
55#include "config.h"
56#include <assert.h>
57#include <stdbool.h>
58#include <stdio.h>
59#include "private.h"
60#include "mutt/lib.h"
61#include "config/lib.h"
62#include "email/lib.h"
63#include "core/lib.h"
64#include "conn/lib.h"
65#include "gui/lib.h"
66#include "lib.h"
67#include "color/lib.h"
68#include "menu/lib.h"
69#include "pager/lib.h"
70#include "pattern/lib.h"
71#include "format_flags.h"
72#include "functions.h"
73#include "globals.h" // IWYU pragma: keep
74#include "hdrline.h"
75#include "hook.h"
76#include "keymap.h"
77#include "mutt_logging.h"
78#include "mutt_mailbox.h"
79#include "mutt_thread.h"
80#include "mview.h"
81#include "mx.h"
82#include "opcodes.h"
83#include "private_data.h"
84#include "protos.h"
85#include "shared_data.h"
86#include "sort.h"
87#include "status.h"
88#ifdef USE_NOTMUCH
89#include "notmuch/lib.h"
90#endif
91#ifdef USE_NNTP
92#include "nntp/lib.h"
93#include "nntp/adata.h"
94#endif
95#ifdef USE_INOTIFY
96#include "monitor.h"
97#endif
98#ifdef USE_SIDEBAR
99#include "sidebar/lib.h"
100#endif
101
103static const struct Mapping IndexHelp[] = {
104 // clang-format off
105 { N_("Quit"), OP_QUIT },
106 { N_("Del"), OP_DELETE },
107 { N_("Undel"), OP_UNDELETE },
108 { N_("Save"), OP_SAVE },
109 { N_("Mail"), OP_MAIL },
110 { N_("Reply"), OP_REPLY },
111 { N_("Group"), OP_GROUP_REPLY },
112 { N_("Help"), OP_HELP },
113 { NULL, 0 },
114 // clang-format on
115};
116
117#ifdef USE_NNTP
119const struct Mapping IndexNewsHelp[] = {
120 // clang-format off
121 { N_("Quit"), OP_QUIT },
122 { N_("Del"), OP_DELETE },
123 { N_("Undel"), OP_UNDELETE },
124 { N_("Save"), OP_SAVE },
125 { N_("Post"), OP_POST },
126 { N_("Followup"), OP_FOLLOWUP },
127 { N_("Catchup"), OP_CATCHUP },
128 { N_("Help"), OP_HELP },
129 { NULL, 0 },
130 // clang-format on
131};
132#endif
133
141bool check_acl(struct Mailbox *m, AclFlags acl, const char *msg)
142{
143 if (!m)
144 return false;
145
146 if (!(m->rights & acl))
147 {
148 /* L10N: %s is one of the CHECK_ACL entries below. */
149 mutt_error(_("%s: Operation not permitted by ACL"), msg);
150 return false;
151 }
152
153 return true;
154}
155
168void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
169{
170 if (!mv || !mv->mailbox || (mv->mailbox->msg_count == 0) || !menu)
171 return;
172
173 struct Email *e_cur = mutt_get_virt_email(mv->mailbox, menu_get_index(menu));
174 if (!e_cur)
175 return;
176
177 int final;
178
179 /* Figure out what the current message would be after folding / unfolding,
180 * so that we can restore the cursor in a sane way afterwards. */
181 if (e_cur->collapsed && toggle)
182 final = mutt_uncollapse_thread(e_cur);
183 else if (mutt_thread_can_collapse(e_cur))
184 final = mutt_collapse_thread(e_cur);
185 else
186 final = e_cur->vnum;
187
188 if (final == -1)
189 return;
190
191 struct Email *base = mutt_get_virt_email(mv->mailbox, final);
192 if (!base)
193 return;
194
195 /* Iterate all threads, perform collapse/uncollapse as needed */
196 mv->collapsed = toggle ? !mv->collapsed : true;
198
199 /* Restore the cursor */
201 menu->max = mv->mailbox->vcount;
202 for (int i = 0; i < mv->mailbox->vcount; i++)
203 {
204 struct Email *e = mutt_get_virt_email(mv->mailbox, i);
205 if (!e)
206 break;
207 if (e->index == base->index)
208 {
209 menu_set_index(menu, i);
210 break;
211 }
212 }
213
215}
216
222static void uncollapse_thread(struct MailboxView *mv, int index)
223{
224 if (!mv || !mv->mailbox)
225 return;
226
227 struct Mailbox *m = mv->mailbox;
228 struct Email *e = mutt_get_virt_email(m, index);
229 if (e && e->collapsed)
230 {
232 mutt_set_vnum(m);
233 }
234}
235
244int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
245{
246 if (!mv || !mv->mailbox)
247 return -1;
248
249 struct Mailbox *m = mv->mailbox;
250
251 int index = -1;
252 for (int i = msgno + 1; i < m->vcount; i++)
253 {
254 struct Email *e = mutt_get_virt_email(m, i);
255 if (!e)
256 continue;
257 if (!e->deleted)
258 {
259 index = i;
260 break;
261 }
262 }
263
264 if (uncollapse)
266
267 return index;
268}
269
278int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
279{
280 if (!mv || !mv->mailbox)
281 return -1;
282
283 struct Mailbox *m = mv->mailbox;
284
285 int index = -1;
286 for (int i = msgno - 1; i >= 0; i--)
287 {
288 struct Email *e = mutt_get_virt_email(m, i);
289 if (!e)
290 continue;
291 if (!e->deleted)
292 {
293 index = i;
294 break;
295 }
296 }
297
298 if (uncollapse)
300
301 return index;
302}
303
313{
314 if (!mv)
315 return 0;
316
317 struct Mailbox *m = mv->mailbox;
318 if (!m || (m->msg_count == 0))
319 return 0;
320
321 int old = -1;
322 for (int i = 0; i < m->vcount; i++)
323 {
324 struct Email *e = mutt_get_virt_email(m, i);
325 if (!e)
326 continue;
327 if (!e->read && !e->deleted)
328 {
329 if (!e->old)
330 return i;
331 if (old == -1)
332 old = i;
333 }
334 }
335 if (old != -1)
336 return old;
337
338 /* If `$use_threads` is not threaded and `$sort` is reverse, the latest
339 * message is first. Otherwise, the latest message is first if exactly
340 * one of `$use_threads` and `$sort` are reverse.
341 */
342 enum SortType c_sort = cs_subset_sort(m->sub, "sort");
343 if ((c_sort & SORT_MASK) == SORT_THREADS)
344 c_sort = cs_subset_sort(m->sub, "sort_aux");
345 bool reverse = false;
346 switch (mutt_thread_style())
347 {
348 case UT_FLAT:
349 reverse = c_sort & SORT_REVERSE;
350 break;
351 case UT_THREADS:
352 reverse = c_sort & SORT_REVERSE;
353 break;
354 case UT_REVERSE:
355 reverse = !(c_sort & SORT_REVERSE);
356 break;
357 default:
358 assert(false);
359 }
360
361 if (reverse || (m->vcount == 0))
362 return 0;
363
364 return m->vcount - 1;
365}
366
372void resort_index(struct MailboxView *mv, struct Menu *menu)
373{
374 if (!mv || !mv->mailbox || !menu)
375 return;
376
377 struct Mailbox *m = mv->mailbox;
378 const int old_index = menu_get_index(menu);
379 struct Email *e_cur = mutt_get_virt_email(m, old_index);
380
381 int new_index = -1;
382 mutt_sort_headers(mv, false);
383
384 /* Restore the current message */
385 for (int i = 0; i < m->vcount; i++)
386 {
387 struct Email *e = mutt_get_virt_email(m, i);
388 if (!e)
389 continue;
390 if (e == e_cur)
391 {
392 new_index = i;
393 break;
394 }
395 }
396
397 if (mutt_using_threads() && (old_index < 0))
398 new_index = mutt_parent_message(e_cur, false);
399
400 if (old_index < 0)
401 new_index = find_first_message(mv);
402
403 menu->max = m->vcount;
404 menu_set_index(menu, new_index);
406}
407
414static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
415{
416 struct Email **save_new = NULL;
417 const bool lmt = mview_has_limit(mv);
418
419 struct Mailbox *m = mv->mailbox;
420 int num_new = MAX(0, m->msg_count - oldcount);
421
422 const bool c_uncollapse_new = cs_subset_bool(m->sub, "uncollapse_new");
423 /* save the list of new messages */
424 if ((check != MX_STATUS_REOPENED) && (oldcount > 0) &&
425 (lmt || c_uncollapse_new) && (num_new > 0))
426 {
427 save_new = mutt_mem_malloc(num_new * sizeof(struct Email *));
428 for (int i = oldcount; i < m->msg_count; i++)
429 save_new[i - oldcount] = m->emails[i];
430 }
431
432 /* Sort first to thread the new messages, because some patterns
433 * require the threading information.
434 *
435 * If the mailbox was reopened, need to rethread from scratch. */
437
438 if (lmt)
439 {
440 for (int i = 0; i < m->msg_count; i++)
441 {
442 struct Email *e = m->emails[i];
443
444 if ((e->limit_visited && e->visible) ||
446 MUTT_MATCH_FULL_ADDRESS, m, e, NULL))
447 {
448 /* vnum will get properly set by mutt_set_vnum(), which
449 * is called by mutt_sort_headers() just below. */
450 e->vnum = 1;
451 e->visible = true;
452 }
453 else
454 {
455 e->vnum = -1;
456 e->visible = false;
457 }
458
459 // mark email as visited so we don't re-apply the pattern next time
460 e->limit_visited = true;
461 }
462 /* Need a second sort to set virtual numbers and redraw the tree */
463 mutt_sort_headers(mv, false);
464 }
465
466 /* uncollapse threads with new mail */
467 if (c_uncollapse_new)
468 {
469 if (check == MX_STATUS_REOPENED)
470 {
471 mv->collapsed = false;
473 mutt_set_vnum(m);
474 }
475 else if (oldcount > 0)
476 {
477 for (int j = 0; j < num_new; j++)
478 {
479 if (save_new[j]->visible)
480 {
481 mutt_uncollapse_thread(save_new[j]);
482 }
483 }
484 mutt_set_vnum(m);
485 }
486 }
487
488 FREE(&save_new);
489}
490
496static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
497{
498 /* We are in a limited view. Check if the new message(s) satisfy
499 * the limit criteria. If they do, set their virtual msgno so that
500 * they will be visible in the limited view */
501 if (mview_has_limit(mv))
502 {
503 int padding = mx_msg_padding_size(mv->mailbox);
504 mv->mailbox->vcount = mv->vsize = 0;
505 for (int i = 0; i < mv->mailbox->msg_count; i++)
506 {
507 struct Email *e = mv->mailbox->emails[i];
508 if (!e)
509 break;
510
511 if ((e->limit_visited && e->visible) ||
513 MUTT_MATCH_FULL_ADDRESS, mv->mailbox, e, NULL))
514 {
515 assert(mv->mailbox->vcount < mv->mailbox->msg_count);
516 e->vnum = mv->mailbox->vcount;
517 mv->mailbox->v2r[mv->mailbox->vcount] = i;
518 e->visible = true;
519 mv->mailbox->vcount++;
520 struct Body *b = e->body;
521 mv->vsize += b->length + b->offset - b->hdr_offset + padding;
522 }
523 else
524 {
525 e->visible = false;
526 }
527
528 // mark email as visited so we don't re-apply the pattern next time
529 e->limit_visited = true;
530 }
531 }
532
533 /* if the mailbox was reopened, need to rethread from scratch */
535}
536
545void update_index(struct Menu *menu, struct MailboxView *mv, enum MxStatus check,
546 int oldcount, const struct IndexSharedData *shared)
547{
548 if (!menu || !mv)
549 return;
550
551 struct Mailbox *m = mv->mailbox;
552 if (mutt_using_threads())
553 update_index_threaded(mv, check, oldcount);
554 else
555 update_index_unthreaded(mv, check);
556
557 const int old_index = menu_get_index(menu);
558 int index = -1;
559 if (oldcount)
560 {
561 /* restore the current message to the message it was pointing to */
562 for (int i = 0; i < m->vcount; i++)
563 {
564 struct Email *e = mutt_get_virt_email(m, i);
565 if (!e)
566 continue;
567 if (index_shared_data_is_cur_email(shared, e))
568 {
569 index = i;
570 break;
571 }
572 }
573 }
574
575 if (index < 0)
576 {
577 index = (old_index < m->vcount) ? old_index : find_first_message(mv);
578 }
579 menu_set_index(menu, index);
580}
581
588{
589 if (nc->event_type != NT_MAILBOX)
590 return 0;
591 if (!nc->global_data)
592 return -1;
594 return 0;
595
596 struct Mailbox **ptr = nc->global_data;
597 if (!*ptr)
598 return 0;
599
600 *ptr = NULL;
601 mutt_debug(LL_DEBUG5, "mailbox done\n");
602 return 0;
603}
604
613void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount,
614 struct IndexSharedData *shared, bool read_only)
615{
616 if (!m)
617 return;
618
619 /* keepalive failure in mutt_enter_fname may kill connection. */
620 if (shared->mailbox && (buf_is_empty(&shared->mailbox->pathbuf)))
621 {
622 mview_free(&shared->mailbox_view);
623 mailbox_free(&shared->mailbox);
624 }
625
626 if (shared->mailbox)
627 {
628 char *new_last_folder = NULL;
629#ifdef USE_INOTIFY
630 int monitor_remove_rc = mutt_monitor_remove(NULL);
631#endif
632#ifdef USE_COMP_MBOX
633 if (shared->mailbox->compress_info && (shared->mailbox->realpath[0] != '\0'))
634 new_last_folder = mutt_str_dup(shared->mailbox->realpath);
635 else
636#endif
637 new_last_folder = mutt_str_dup(mailbox_path(shared->mailbox));
638 *oldcount = shared->mailbox->msg_count;
639
640 const enum MxStatus check = mx_mbox_close(shared->mailbox);
641 if (check == MX_STATUS_OK)
642 {
643 mview_free(&shared->mailbox_view);
644 if (shared->mailbox != m)
645 {
646 mailbox_free(&shared->mailbox);
647 }
648 }
649 else
650 {
651#ifdef USE_INOTIFY
652 if (monitor_remove_rc == 0)
653 mutt_monitor_add(NULL);
654#endif
655 if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED))
656 update_index(menu, shared->mailbox_view, check, *oldcount, shared);
657
658 FREE(&new_last_folder);
659 OptSearchInvalid = true;
661 return;
662 }
664 LastFolder = new_last_folder;
665 }
667
668 /* If the `folder-hook` were to call `unmailboxes`, then the Mailbox (`m`)
669 * could be deleted, leaving `m` dangling. */
670 // TODO: Refactor this function to avoid the need for an observer
672 char *dup_path = mutt_str_dup(mailbox_path(m));
673 char *dup_name = mutt_str_dup(m->name);
674
675 mutt_folder_hook(dup_path, dup_name);
676 if (m)
677 {
678 /* `m` is still valid, but we won't need the observer again before the end
679 * of the function. */
681 }
682 else
683 {
684 // Recreate the Mailbox as the folder-hook might have invoked `mailboxes`
685 // and/or `unmailboxes`.
686 m = mx_path_resolve(dup_path);
687 }
688
689 FREE(&dup_path);
690 FREE(&dup_name);
691
692 if (!m)
693 return;
694
695 const OpenMailboxFlags flags = read_only ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS;
696 if (mx_mbox_open(m, flags))
697 {
698 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
699 index_shared_data_set_mview(shared, mv);
700
701 menu->max = m->msg_count;
703#ifdef USE_INOTIFY
704 mutt_monitor_add(NULL);
705#endif
706 }
707 else
708 {
709 index_shared_data_set_mview(shared, NULL);
711 }
712
713 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
714 if (mutt_using_threads() && c_collapse_all)
715 collapse_all(shared->mailbox_view, menu, 0);
716
718 /* force the mailbox check after we have changed the folder */
719 struct EventMailbox ev_m = { shared->mailbox };
722 OptSearchInvalid = true;
723}
724
725#ifdef USE_NOTMUCH
736struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int buflen, int *oldcount,
737 struct IndexSharedData *shared, bool read_only)
738{
739 if (!nm_url_from_query(NULL, buf, buflen))
740 {
741 mutt_message(_("Failed to create query, aborting"));
742 return NULL;
743 }
744
745 struct Mailbox *m_query = mx_path_resolve(buf);
746 change_folder_mailbox(menu, m_query, oldcount, shared, read_only);
747 return m_query;
748}
749#endif
750
760void change_folder_string(struct Menu *menu, char *buf, size_t buflen, int *oldcount,
761 struct IndexSharedData *shared, bool read_only)
762{
763#ifdef USE_NNTP
764 if (OptNews)
765 {
766 OptNews = false;
768 }
769 else
770#endif
771 {
772 const char *const c_folder = cs_subset_string(shared->sub, "folder");
773 mx_path_canon(buf, buflen, c_folder, NULL);
774 }
775
776 enum MailboxType type = mx_path_probe(buf);
777 if ((type == MUTT_MAILBOX_ERROR) || (type == MUTT_UNKNOWN))
778 {
779 // Look for a Mailbox by its description, before failing
780 struct Mailbox *m = mailbox_find_name(buf);
781 if (m)
782 {
783 change_folder_mailbox(menu, m, oldcount, shared, read_only);
784 }
785 else
786 {
787 mutt_error(_("%s is not a mailbox"), buf);
788 }
789 return;
790 }
791
792 struct Mailbox *m = mx_path_resolve(buf);
793 change_folder_mailbox(menu, m, oldcount, shared, read_only);
794}
795
799void index_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
800{
801 buf[0] = '\0';
802
803 if (!menu || !menu->mdata)
804 return;
805
806 struct IndexPrivateData *priv = menu->mdata;
807 struct IndexSharedData *shared = priv->shared;
808 struct Mailbox *m = shared->mailbox;
809 if (!shared->mailbox_view)
810 menu->current = -1;
811
812 if (!m || (line < 0) || (line >= m->email_max))
813 return;
814
815 struct Email *e = mutt_get_virt_email(m, line);
816 if (!e)
817 return;
818
820 struct MuttThread *tmp = NULL;
821
822 const enum UseThreads c_threads = mutt_thread_style();
823 if ((c_threads > UT_FLAT) && e->tree && e->thread)
824 {
825 flags |= MUTT_FORMAT_TREE; /* display the thread tree */
826 if (e->display_subject)
827 {
828 flags |= MUTT_FORMAT_FORCESUBJ;
829 }
830 else
831 {
832 const bool reverse = c_threads == UT_REVERSE;
833 int edgemsgno;
834 if (reverse)
835 {
836 if (menu->top + menu->page_len > menu->max)
837 edgemsgno = m->v2r[menu->max - 1];
838 else
839 edgemsgno = m->v2r[menu->top + menu->page_len - 1];
840 }
841 else
842 {
843 edgemsgno = m->v2r[menu->top];
844 }
845
846 for (tmp = e->thread->parent; tmp; tmp = tmp->parent)
847 {
848 if (!tmp->message)
849 continue;
850
851 /* if no ancestor is visible on current screen, provisionally force
852 * subject... */
853 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
854 {
855 flags |= MUTT_FORMAT_FORCESUBJ;
856 break;
857 }
858 else if (tmp->message->vnum >= 0)
859 {
860 break;
861 }
862 }
863 if (flags & MUTT_FORMAT_FORCESUBJ)
864 {
865 for (tmp = e->thread->prev; tmp; tmp = tmp->prev)
866 {
867 if (!tmp->message)
868 continue;
869
870 /* ...but if a previous sibling is available, don't force it */
871 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
872 {
873 break;
874 }
875 else if (tmp->message->vnum >= 0)
876 {
877 flags &= ~MUTT_FORMAT_FORCESUBJ;
878 break;
879 }
880 }
881 }
882 }
883 }
884
885 const char *const c_index_format = cs_subset_string(shared->sub, "index_format");
886 int msg_in_pager = shared->mailbox_view ? shared->mailbox_view->msg_in_pager : 0;
887 mutt_make_string(buf, buflen, menu->win->state.cols, NONULL(c_index_format),
888 m, msg_in_pager, e, flags, NULL);
889}
890
894struct AttrColor *index_color(struct Menu *menu, int line)
895{
896 struct IndexPrivateData *priv = menu->mdata;
897 struct IndexSharedData *shared = priv->shared;
898 struct Mailbox *m = shared->mailbox;
899 if (!m || (line < 0))
900 return NULL;
901
902 struct Email *e = mutt_get_virt_email(m, line);
903 if (!e)
904 return NULL;
905
906 if (e->attr_color)
907 return e->attr_color;
908
910 return e->attr_color;
911}
912
926void mutt_draw_statusline(struct MuttWindow *win, int cols, const char *buf, size_t buflen)
927{
928 if (!buf || !stdscr)
929 return;
930
931 size_t i = 0;
932 size_t offset = 0;
933 bool found = false;
934 size_t chunks = 0;
935 size_t len = 0;
936
940 struct StatusSyntax
941 {
942 struct AttrColor *attr_color;
943 int first;
944 int last;
945 } *syntax = NULL;
946
949 do
950 {
951 struct RegexColor *cl = NULL;
952 found = false;
953
954 if (!buf[offset])
955 break;
956
957 /* loop through each "color status regex" */
959 {
960 regmatch_t pmatch[cl->match + 1];
961
962 if (regexec(&cl->regex, buf + offset, cl->match + 1, pmatch, 0) != 0)
963 continue; /* regex doesn't match the status bar */
964
965 int first = pmatch[cl->match].rm_so + offset;
966 int last = pmatch[cl->match].rm_eo + offset;
967
968 if (first == last)
969 continue; /* ignore an empty regex */
970
971 if (!found)
972 {
973 chunks++;
974 mutt_mem_realloc(&syntax, chunks * sizeof(struct StatusSyntax));
975 }
976
977 i = chunks - 1;
978 if (!found || (first < syntax[i].first) ||
979 ((first == syntax[i].first) && (last > syntax[i].last)))
980 {
981 struct AttrColor *ac_merge = merged_color_overlay(ac_base, &cl->attr_color);
982
983 syntax[i].attr_color = ac_merge;
984 syntax[i].first = first;
985 syntax[i].last = last;
986 }
987 found = true;
988 }
989
990 if (syntax)
991 {
992 offset = syntax[i].last;
993 }
994 } while (found);
995
996 /* Only 'len' bytes will fit into 'cols' screen columns */
997 len = mutt_wstr_trunc(buf, buflen, cols, NULL);
998
999 offset = 0;
1000
1001 if ((chunks > 0) && (syntax[0].first > 0))
1002 {
1003 /* Text before the first highlight */
1004 mutt_window_addnstr(win, buf, MIN(len, syntax[0].first));
1005 mutt_curses_set_color(ac_base);
1006 if (len <= syntax[0].first)
1007 goto dsl_finish; /* no more room */
1008
1009 offset = syntax[0].first;
1010 }
1011
1012 for (i = 0; i < chunks; i++)
1013 {
1014 /* Highlighted text */
1015 mutt_curses_set_color(syntax[i].attr_color);
1016 mutt_window_addnstr(win, buf + offset, MIN(len, syntax[i].last) - offset);
1017 if (len <= syntax[i].last)
1018 goto dsl_finish; /* no more room */
1019
1020 size_t next;
1021 if ((i + 1) == chunks)
1022 {
1023 next = len;
1024 }
1025 else
1026 {
1027 next = MIN(len, syntax[i + 1].first);
1028 }
1029
1030 mutt_curses_set_color(ac_base);
1031 offset = syntax[i].last;
1032 mutt_window_addnstr(win, buf + offset, next - offset);
1033
1034 offset = next;
1035 if (offset >= len)
1036 goto dsl_finish; /* no more room */
1037 }
1038
1039 mutt_curses_set_color(ac_base);
1040 if (offset < len)
1041 {
1042 /* Text after the last highlight */
1043 mutt_window_addnstr(win, buf + offset, len - offset);
1044 }
1045
1046 int width = mutt_strwidth(buf);
1047 if (width < cols)
1048 {
1049 /* Pad the rest of the line with whitespace */
1050 mutt_paddstr(win, cols - width, "");
1051 }
1052dsl_finish:
1053 FREE(&syntax);
1054}
1055
1062struct Mailbox *mutt_index_menu(struct MuttWindow *dlg, struct Mailbox *m_init)
1063{
1064 /* Make sure use_threads/sort/sort_aux are coherent */
1066
1067 struct IndexSharedData *shared = dlg->wdata;
1069
1070 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1071
1072 struct IndexPrivateData *priv = panel_index->wdata;
1073 priv->attach_msg = OptAttachMsg;
1074 priv->win_index = window_find_child(panel_index, WT_MENU);
1075
1076 int op = OP_NULL;
1077
1078#ifdef USE_NNTP
1079 if (shared->mailbox && (shared->mailbox->type == MUTT_NNTP))
1080 dlg->help_data = IndexNewsHelp;
1081 else
1082#endif
1083 dlg->help_data = IndexHelp;
1084 dlg->help_menu = MENU_INDEX;
1085
1086 priv->menu = priv->win_index->wdata;
1088 priv->menu->color = index_color;
1089 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1091 mutt_window_reflow(NULL);
1092
1093 if (!priv->attach_msg)
1094 {
1095 /* force the mailbox check after we enter the folder */
1097 }
1098#ifdef USE_INOTIFY
1099 mutt_monitor_add(NULL);
1100#endif
1101
1102 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
1103 if (mutt_using_threads() && c_collapse_all)
1104 {
1107 }
1108
1109 int rc = 0;
1110 do
1111 {
1112 /* Clear the tag prefix unless we just started it.
1113 * Don't clear the prefix on a timeout, but do clear on an abort */
1114 if (priv->tag_prefix && (op != OP_TAG_PREFIX) &&
1115 (op != OP_TAG_PREFIX_COND) && (op != OP_TIMEOUT))
1116 {
1117 priv->tag_prefix = false;
1118 }
1119
1120 /* check if we need to resort the index because just about
1121 * any 'op' below could do mutt_enter_command(), either here or
1122 * from any new priv->menu launched, and change $sort/$sort_aux */
1123 if (OptNeedResort && shared->mailbox && (shared->mailbox->msg_count != 0) &&
1124 (menu_get_index(priv->menu) >= 0))
1125 {
1127 }
1128
1129 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1130 priv->oldcount = shared->mailbox ? shared->mailbox->msg_count : 0;
1131
1134 {
1136 OptRedrawTree = false;
1137 }
1138
1140 {
1142
1143 shared->mailbox_view->menu = priv->menu;
1144 /* check for new mail in the mailbox. If nonzero, then something has
1145 * changed about the file (either we got new mail or the file was
1146 * modified underneath us.) */
1147 enum MxStatus check = mx_mbox_check(shared->mailbox);
1148
1149 if (check == MX_STATUS_ERROR)
1150 {
1152 {
1153 /* fatal error occurred */
1156 }
1157
1158 OptSearchInvalid = true;
1159 }
1160 else if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED) ||
1161 (check == MX_STATUS_FLAGS))
1162 {
1163 /* notify the user of new mail */
1164 if (check == MX_STATUS_REOPENED)
1165 {
1166 mutt_error(_("Mailbox was externally modified. Flags may be wrong."));
1167 }
1168 else if (check == MX_STATUS_NEW_MAIL)
1169 {
1170 for (size_t i = 0; i < shared->mailbox->msg_count; i++)
1171 {
1172 const struct Email *e = shared->mailbox->emails[i];
1173 if (e && !e->read && !e->old)
1174 {
1175 mutt_message(_("New mail in this mailbox"));
1176 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1177 if (c_beep_new)
1178 mutt_beep(true);
1179 const char *const c_new_mail_command = cs_subset_string(shared->sub, "new_mail_command");
1180 if (c_new_mail_command)
1181 {
1182 char cmd[1024] = { 0 };
1183 menu_status_line(cmd, sizeof(cmd), shared, NULL, sizeof(cmd),
1184 NONULL(c_new_mail_command));
1185 if (mutt_system(cmd) != 0)
1186 mutt_error(_("Error running \"%s\""), cmd);
1187 }
1188 break;
1189 }
1190 }
1191 }
1192 else if (check == MX_STATUS_FLAGS)
1193 {
1194 mutt_message(_("Mailbox was externally modified"));
1195 }
1196
1197 /* avoid the message being overwritten by mailbox */
1198 priv->do_mailbox_notify = false;
1199
1200 bool verbose = shared->mailbox->verbose;
1201 shared->mailbox->verbose = false;
1202 update_index(priv->menu, shared->mailbox_view, check, priv->oldcount, shared);
1203 shared->mailbox->verbose = verbose;
1204 priv->menu->max = shared->mailbox->vcount;
1206 OptSearchInvalid = true;
1207 }
1208
1210 menu_get_index(priv->menu)));
1211 }
1212
1213 if (!priv->attach_msg)
1214 {
1215 /* check for new mail in the incoming folders */
1216 priv->oldcount = priv->newcount;
1218 if (priv->do_mailbox_notify)
1219 {
1220 if (mutt_mailbox_notify(shared->mailbox))
1221 {
1222 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1223 if (c_beep_new)
1224 mutt_beep(true);
1225 const char *const c_new_mail_command = cs_subset_string(shared->sub, "new_mail_command");
1226 if (c_new_mail_command)
1227 {
1228 char cmd[1024] = { 0 };
1229 menu_status_line(cmd, sizeof(cmd), shared, priv->menu, sizeof(cmd),
1230 NONULL(c_new_mail_command));
1231 if (mutt_system(cmd) != 0)
1232 mutt_error(_("Error running \"%s\""), cmd);
1233 }
1234 }
1235 }
1236 else
1237 {
1238 priv->do_mailbox_notify = true;
1239 }
1240 }
1241
1242 window_redraw(NULL);
1243
1244 /* give visual indication that the next command is a tag- command */
1245 if (priv->tag_prefix)
1247
1248 const bool c_arrow_cursor = cs_subset_bool(shared->sub, "arrow_cursor");
1249 const bool c_braille_friendly = cs_subset_bool(shared->sub, "braille_friendly");
1250 const int index = menu_get_index(priv->menu);
1251 if (c_arrow_cursor)
1252 {
1253 mutt_window_move(priv->menu->win, 2, index - priv->menu->top);
1254 }
1255 else if (c_braille_friendly)
1256 {
1257 mutt_window_move(priv->menu->win, 0, index - priv->menu->top);
1258 }
1259 else
1260 {
1261 mutt_window_move(priv->menu->win, priv->menu->win->state.cols - 1,
1262 index - priv->menu->top);
1263 }
1264 mutt_refresh();
1265
1266 if (SigWinch)
1267 {
1268 SigWinch = false;
1271 priv->menu->top = 0; /* so we scroll the right amount */
1272 /* force a real complete redraw. clrtobot() doesn't seem to be able
1273 * to handle every case without this. */
1274 clearok(stdscr, true);
1276 continue;
1277 }
1278
1279 window_redraw(NULL);
1280 op = km_dokey(MENU_INDEX);
1281
1282 /* either user abort or timeout */
1283 if (op < OP_NULL)
1284 {
1286 if (priv->tag_prefix)
1288 continue;
1289 }
1290
1291 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
1292
1293 /* special handling for the priv->tag-prefix function */
1294 const bool c_auto_tag = cs_subset_bool(shared->sub, "auto_tag");
1295 if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
1296 {
1297 /* A second priv->tag-prefix command aborts */
1298 if (priv->tag_prefix)
1299 {
1300 priv->tag_prefix = false;
1302 continue;
1303 }
1304
1305 if (!shared->mailbox)
1306 {
1307 mutt_error(_("No mailbox is open"));
1308 continue;
1309 }
1310
1311 if (shared->mailbox->msg_tagged == 0)
1312 {
1313 if (op == OP_TAG_PREFIX)
1314 {
1315 mutt_error(_("No tagged messages"));
1316 }
1317 else if (op == OP_TAG_PREFIX_COND)
1318 {
1320 mutt_message(_("Nothing to do"));
1321 }
1322 continue;
1323 }
1324
1325 /* get the real command */
1326 priv->tag_prefix = true;
1327 continue;
1328 }
1329 else if (c_auto_tag && shared->mailbox && (shared->mailbox->msg_tagged != 0))
1330 {
1331 priv->tag_prefix = true;
1332 }
1333
1335
1336#ifdef USE_NNTP
1337 OptNews = false; /* for any case */
1338#endif
1339
1340#ifdef USE_NOTMUCH
1341 nm_db_debug_check(shared->mailbox);
1342#endif
1343
1344 rc = index_function_dispatcher(priv->win_index, op);
1345
1346 if (rc == FR_UNKNOWN)
1347 rc = menu_function_dispatcher(priv->win_index, op);
1348
1349#ifdef USE_SIDEBAR
1350 if (rc == FR_UNKNOWN)
1351 {
1352 struct MuttWindow *win_sidebar = window_find_child(dlg, WT_SIDEBAR);
1353 rc = sb_function_dispatcher(win_sidebar, op);
1354 }
1355#endif
1356 if (rc == FR_UNKNOWN)
1357 rc = global_function_dispatcher(NULL, op);
1358
1359 if (rc == FR_UNKNOWN)
1361
1362#ifdef USE_NOTMUCH
1363 nm_db_debug_check(shared->mailbox);
1364#endif
1365 } while (rc != FR_DONE);
1366
1367 mview_free(&shared->mailbox_view);
1368
1369 return shared->mailbox;
1370}
1371
1377void mutt_set_header_color(struct Mailbox *m, struct Email *e)
1378{
1379 if (!e)
1380 return;
1381
1382 struct RegexColor *color = NULL;
1383 struct PatternCache cache = { 0 };
1384
1385 struct AttrColor *ac_merge = NULL;
1387 {
1389 MUTT_MATCH_FULL_ADDRESS, m, e, &cache))
1390 {
1391 ac_merge = merged_color_overlay(ac_merge, &color->attr_color);
1392 }
1393 }
1394
1395 struct AttrColor *ac_normal = simple_color_get(MT_COLOR_NORMAL);
1396 if (ac_merge)
1397 ac_merge = merged_color_overlay(ac_normal, ac_merge);
1398 else
1399 ac_merge = ac_normal;
1400
1401 e->attr_color = ac_merge;
1402}
1403
1409{
1413
1414 struct IndexSharedData *shared = index_shared_data_new();
1415 notify_set_parent(shared->notify, dlg->notify);
1416
1417 dlg->wdata = shared;
1419
1420 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
1421
1422 struct MuttWindow *panel_index = ipanel_new(c_status_on_top, shared);
1423 struct MuttWindow *panel_pager = ppanel_new(c_status_on_top, shared);
1424
1425 mutt_window_add_child(dlg, panel_index);
1426 mutt_window_add_child(dlg, panel_pager);
1427
1428 dlg->focus = panel_index;
1429
1430 return dlg;
1431}
1432
1438void dlg_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
1439{
1440 if (!dlg || !m)
1441 return;
1442
1443 struct IndexSharedData *shared = dlg->wdata;
1444 if (!shared)
1445 return;
1446
1447 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1448 if (!panel_index)
1449 return;
1450
1451 struct IndexPrivateData *priv = panel_index->wdata;
1452 if (!priv)
1453 return;
1454
1455 change_folder_mailbox(priv->menu, m, &priv->oldcount, shared, false);
1456}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
Color and attribute parsing.
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:184
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:74
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:57
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:81
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
Convenience wrapper for the config headers.
Connection Library.
Convenience wrapper for the core headers.
size_t mutt_wstr_trunc(const char *src, size_t maxlen, size_t maxwid, size_t *width)
Work out how to truncate a widechar string.
Definition: curs_lib.c:861
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:819
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:141
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:573
void mutt_beep(bool force)
Irritate the user.
Definition: curs_lib.c:131
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:914
@ FR_DONE
Exit the Dialog.
Definition: dispatcher.h:35
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
bool check_acl(struct Mailbox *m, AclFlags acl, const char *msg)
Check the ACLs for a function.
Definition: dlg_index.c:141
struct Mailbox * mutt_index_menu(struct MuttWindow *dlg, struct Mailbox *m_init)
Display a list of emails.
Definition: dlg_index.c:1062
const struct Mapping IndexNewsHelp[]
Help Bar for the News Index dialog.
Definition: dlg_index.c:119
void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount, struct IndexSharedData *shared, bool read_only)
Change to a different Mailbox by pointer.
Definition: dlg_index.c:613
struct Mailbox * change_folder_notmuch(struct Menu *menu, char *buf, int buflen, int *oldcount, struct IndexSharedData *shared, bool read_only)
Change to a different Notmuch Mailbox by string.
Definition: dlg_index.c:736
void dlg_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
Change the current folder, cautiously.
Definition: dlg_index.c:1438
void update_index(struct Menu *menu, struct MailboxView *mv, enum MxStatus check, int oldcount, const struct IndexSharedData *shared)
Update the index.
Definition: dlg_index.c:545
void change_folder_string(struct Menu *menu, char *buf, size_t buflen, int *oldcount, struct IndexSharedData *shared, bool read_only)
Change to a different Mailbox by string.
Definition: dlg_index.c:760
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1377
void mutt_draw_statusline(struct MuttWindow *win, int cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:926
int find_first_message(struct MailboxView *mv)
Get index of first new message.
Definition: dlg_index.c:312
static const struct Mapping IndexHelp[]
Help Bar for the Index dialog.
Definition: dlg_index.c:103
static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
Update the index (if threaded)
Definition: dlg_index.c:414
void resort_index(struct MailboxView *mv, struct Menu *menu)
Resort the index.
Definition: dlg_index.c:372
int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the next undeleted email.
Definition: dlg_index.c:244
static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
Update the index (if unthreaded)
Definition: dlg_index.c:496
void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
Collapse/uncollapse all threads.
Definition: dlg_index.c:168
int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the previous undeleted email.
Definition: dlg_index.c:278
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition: dlg_index.c:1408
static void uncollapse_thread(struct MailboxView *mv, int index)
Open a collapsed thread.
Definition: dlg_index.c:222
Structs that make up an email.
bool mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:1133
Flags to control mutt_expando_format()
#define MUTT_FORMAT_FORCESUBJ
Print the subject even if unchanged.
Definition: format_flags.h:31
#define MUTT_FORMAT_INDEX
This is a main index entry.
Definition: format_flags.h:36
#define MUTT_FORMAT_TREE
Draw the thread tree.
Definition: format_flags.h:32
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:79
char * LastFolder
Previously selected mailbox.
Definition: globals.c:45
bool OptAttachMsg
(pseudo) used by attach-message
Definition: globals.c:66
bool OptSearchInvalid
(pseudo) used to invalidate the search pattern
Definition: globals.c:86
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:44
SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.c:60
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:77
bool OptRedrawTree
(pseudo) redraw the thread tree
Definition: globals.c:84
int sb_function_dispatcher(struct MuttWindow *win, int op)
Perform a Sidebar function - Implements function_dispatcher_t -.
Definition: functions.c:375
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:317
int index_function_dispatcher(struct MuttWindow *win, int op)
Perform an Index function - Implements function_dispatcher_t -.
Definition: functions.c:3017
#define mutt_error(...)
Definition: logging2.h:90
#define mutt_message(...)
Definition: logging2.h:89
#define mutt_debug(LEVEL,...)
Definition: logging2.h:87
struct AttrColor * index_color(struct Menu *menu, int line)
Calculate the colour for a line of the index - Implements Menu::color() -.
Definition: dlg_index.c:894
void index_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the index list - Implements Menu::make_entry() -.
Definition: dlg_index.c:799
static int index_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: dlg_index.c:587
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:134
Convenience wrapper for the gui headers.
void mutt_make_string(char *buf, size_t buflen, int cols, const char *s, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: hdrline.c:1489
String processing routines to generate the mail index.
void mutt_timeout_hook(void)
Execute any timeout hooks.
Definition: hook.c:892
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition: hook.c:589
Parse and execute user-defined hooks.
void index_shared_data_set_email(struct IndexSharedData *shared, struct Email *e)
Set the current Email for the Index and friends.
Definition: shared_data.c:97
bool index_shared_data_is_cur_email(const struct IndexSharedData *shared, const struct Email *e)
Check whether an email is the currently selected Email.
Definition: shared_data.c:120
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:152
void index_shared_data_set_mview(struct IndexSharedData *shared, struct MailboxView *mv)
Set the MailboxView for the Index and friends.
Definition: shared_data.c:43
Data shared between Index, Pager and Sidebar.
void index_adjust_sort_threads(const struct ConfigSubset *sub)
Adjust use_threads/sort/sort_aux.
Definition: index.c:182
struct MuttWindow * ipanel_new(bool status_on_top, struct IndexSharedData *shared)
Create the Windows for the Index panel.
Definition: ipanel.c:121
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:803
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1077
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
void mailbox_gc_run(void)
Run the garbage-collection.
Definition: mailbox.c:301
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:88
struct Mailbox * mailbox_find_name(const char *name)
Find the mailbox with a given name.
Definition: mailbox.c:177
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition: mailbox.h:169
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:209
uint16_t AclFlags
ACL Rights - These show permission to...
Definition: mailbox.h:59
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_MAILBOX_ERROR
Error occurred examining Mailbox.
Definition: mailbox.h:43
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define FREE(x)
Definition: memory.h:43
#define MIN(a, b)
Definition: memory.h:31
#define MAX(a, b)
Definition: memory.h:30
GUI present the user with a selectable list.
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:57
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:179
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:155
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:169
struct AttrColor * merged_color_overlay(struct AttrColor *base, struct AttrColor *over)
Combine two colours.
Definition: merged.c:109
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:489
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:534
Monitor files for changes.
void msgwin_set_text(enum ColorId cid, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:234
void msgwin_clear_text(void)
Clear the text in the Message Window.
Definition: msgwin.c:250
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:228
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:93
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
void mutt_curses_set_color(struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:40
void mutt_resize_screen(void)
Update NeoMutt's opinion about the window size (CURSES)
Definition: resize.c:72
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:73
NeoMutt Logging.
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:158
bool mutt_mailbox_notify(struct Mailbox *m_cur)
Notify the user if there's new mail.
Definition: mutt_mailbox.c:227
Mailbox helper functions.
void mutt_thread_collapse(struct ThreadsContext *tctx, bool collapse)
Toggle collapse.
Definition: mutt_thread.c:1783
void mutt_draw_tree(struct ThreadsContext *tctx)
Draw a tree of threaded emails.
Definition: mutt_thread.c:386
enum UseThreads mutt_thread_style(void)
Which threading style is active?
Definition: mutt_thread.c:79
off_t mutt_set_vnum(struct Mailbox *m)
Set the virtual index number of all the messages in a mailbox.
Definition: mutt_thread.c:1398
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1811
int mutt_parent_message(struct Email *e, bool find_root)
Find the parent of a message.
Definition: mutt_thread.c:1348
Create/manipulate threading in emails.
UseThreads
Which threading style is active, $use_threads.
Definition: mutt_thread.h:95
@ UT_FLAT
Unthreaded.
Definition: mutt_thread.h:97
@ UT_THREADS
Normal threading (root above subthreads)
Definition: mutt_thread.h:98
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition: mutt_thread.h:99
#define mutt_using_threads()
Definition: mutt_thread.h:112
#define mutt_uncollapse_thread(e)
Definition: mutt_thread.h:106
#define mutt_collapse_thread(e)
Definition: mutt_thread.h:105
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:605
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:341
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:440
struct MuttWindow * mutt_window_new(enum WindowType type, enum MuttWindowOrientation orient, enum MuttWindowSize size, int cols, int rows)
Create a new Window.
Definition: mutt_window.c:180
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:294
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:523
int mutt_window_addnstr(struct MuttWindow *win, const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:395
void window_invalidate_all(void)
Mark all windows as in need of repaint.
Definition: mutt_window.c:743
@ WT_DLG_INDEX
Index Dialog, index_pager_init()
Definition: mutt_window.h:86
@ WT_INDEX
A panel containing the Index Window.
Definition: mutt_window.h:97
@ WT_SIDEBAR
Side panel containing Accounts or groups of data.
Definition: mutt_window.h:101
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
@ MUTT_WIN_ORIENT_HORIZONTAL
Window uses all available horizontal space.
Definition: mutt_window.h:39
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:52
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:48
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: mview.c:407
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition: mview.c:49
bool mview_has_limit(const struct MailboxView *mv)
Is a limit active?
Definition: mview.c:428
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition: mview.c:78
View of a Mailbox.
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1570
int mx_path_canon(char *buf, size_t buflen, const char *folder, enum MailboxType *type)
Canonicalise a mailbox path - Wrapper for MxOps::path_canon()
Definition: mx.c:1394
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:307
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1348
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1698
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1143
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:618
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition: mxapi.h:64
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mxapi.h:60
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:74
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition: mxapi.h:61
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:75
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_snc(), and mbox_close()
Definition: mxapi.h:84
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:85
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:86
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mxapi.h:90
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:89
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:87
Nntp-specific Account data.
Usenet network mailbox type; talk to an NNTP server.
void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *acct)
Make fully qualified url from newsgroup name.
Definition: newsrc.c:564
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:78
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
void nm_db_debug_check(struct Mailbox *m)
Check if the database is open.
Definition: db.c:388
Notmuch virtual mailbox type.
char * nm_url_from_query(struct Mailbox *m, char *buf, size_t buflen)
Turn a query into a URL.
Definition: notmuch.c:1564
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
All user-callable functions.
#define OP_TIMEOUT
Definition: opcodes.h:32
GUI display a file/email/help in a viewport with paging.
struct MuttWindow * ppanel_new(bool status_on_top, struct IndexSharedData *shared)
Create the Windows for the Pager panel.
Definition: ppanel.c:122
Private state data for the Pager.
Match patterns to emails.
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:100
Prototypes for many functions.
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:52
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define SLIST_FIRST(head)
Definition: queue.h:229
Sidebar functions.
GUI display the mailboxes in a side panel.
GUI display the mailboxes in a side panel.
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
SortType
Methods for sorting.
Definition: sort2.h:38
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:45
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:75
void mutt_sort_headers(struct MailboxView *mv, bool init)
Sort emails by their headers.
Definition: sort.c:358
Assorted sorting methods.
void menu_status_line(char *buf, size_t buflen, struct IndexSharedData *shared, struct Menu *menu, int cols, const char *fmt)
Create the status line.
Definition: status.c:479
GUI display a user-configurable status line.
Key value store.
#define NONULL(x)
Definition: string2.h:37
A curses colour and its attributes.
Definition: attr.h:35
The body of an email.
Definition: body.h:36
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:80
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
The envelope/body of an email.
Definition: email.h:37
bool read
Email is read.
Definition: email.h:48
bool display_subject
Used for threading.
Definition: email.h:100
bool visible
Is this message part of the view?
Definition: email.h:120
bool limit_visited
Has the limit pattern been applied to this message?
Definition: email.h:121
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:119
struct Body * body
List of MIME parts.
Definition: email.h:67
char * tree
Character string to print thread tree.
Definition: email.h:124
bool old
Email is seen, but unread.
Definition: email.h:47
struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:111
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:69
int vnum
Virtual message number.
Definition: email.h:113
int msgno
Number displayed to the user.
Definition: email.h:110
bool deleted
Email is deleted.
Definition: email.h:76
int index
The absolute (unsorted) message number.
Definition: email.h:109
struct MuttThread * thread
Thread of Emails.
Definition: email.h:118
An Event that happened to a Mailbox.
Definition: mailbox.h:185
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:186
Private state data for the Index.
Definition: private_data.h:35
struct MuttWindow * win_index
Window for the Index.
Definition: private_data.h:44
int newcount
New count of Emails in the Mailbox.
Definition: private_data.h:38
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:42
bool tag_prefix
tag-prefix has been pressed
Definition: private_data.h:36
bool do_mailbox_notify
Do we need to notify the user of new mail?
Definition: private_data.h:39
bool attach_msg
Are we in "attach message" mode?
Definition: private_data.h:40
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:43
int oldcount
Old count of Emails in the Mailbox.
Definition: private_data.h:37
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
struct MailboxView * mailbox_view
Current Mailbox view.
Definition: shared_data.h:40
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
View of a Mailbox.
Definition: mview.h:39
bool collapsed
Are all threads collapsed?
Definition: mview.h:48
struct Menu * menu
Needed for pattern compilation.
Definition: mview.h:46
off_t vsize
Size (in bytes) of the messages shown.
Definition: mview.h:40
struct PatternList * limit_pattern
Compiled limit pattern.
Definition: mview.h:42
struct ThreadsContext * threads
Threads context.
Definition: mview.h:43
int msg_in_pager
Message currently shown in the pager.
Definition: mview.h:44
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:50
A mailbox.
Definition: mailbox.h:79
int vcount
The number of virtual messages.
Definition: mailbox.h:99
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:98
int msg_count
Total number of messages.
Definition: mailbox.h:88
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:117
int email_max
Size of emails array.
Definition: mailbox.h:97
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:143
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:120
int msg_tagged
How many messages are tagged?
Definition: mailbox.h:94
bool verbose
Display status messages?
Definition: mailbox.h:114
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
Mapping between user-readable string and a constant.
Definition: mapping.h:32
Definition: lib.h:70
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:77
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:97
int current
Current entry.
Definition: lib.h:71
struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:134
int top
Entry that is the top of the current page.
Definition: lib.h:81
void * mdata
Private data.
Definition: lib.h:138
int max
Number of entries in the menu.
Definition: lib.h:72
int page_len
Number of entries per screen.
Definition: lib.h:75
An Email conversation.
Definition: thread.h:34
struct MuttThread * parent
Parent of this Thread.
Definition: thread.h:44
struct MuttThread * prev
Previous sibling Thread.
Definition: thread.h:47
struct Email * message
Email this Thread refers to.
Definition: thread.h:49
const struct Mapping * help_data
Data for the Help Bar.
Definition: mutt_window.h:142
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
struct MuttWindow * focus
Focused Window.
Definition: mutt_window.h:140
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
int help_menu
Menu for key bindings, e.g. MENU_PAGER.
Definition: mutt_window.h:141
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
Data passed to a notification function.
Definition: observer.h:34
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
Cache commonly-used patterns.
Definition: lib.h:111
A regular expression and a color to highlight a line.
Definition: regex4.h:37
regex_t regex
Compiled regex.
Definition: regex4.h:40
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: regex4.h:42
struct AttrColor attr_color
Colour and attributes to apply.
Definition: regex4.h:38
int match
Substring to match, 0 for old behaviour.
Definition: regex4.h:41
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:50