NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "key/lib.h"
69#include "menu/lib.h"
70#include "nntp/lib.h"
71#include "pager/lib.h"
72#include "pattern/lib.h"
73#include "sidebar/lib.h"
74#include "format_flags.h"
75#include "functions.h"
76#include "globals.h"
77#include "hdrline.h"
78#include "hook.h"
79#include "mutt_logging.h"
80#include "mutt_mailbox.h"
81#include "mutt_thread.h"
82#include "mview.h"
83#include "mx.h"
84#include "nntp/adata.h"
85#include "private_data.h"
86#include "protos.h"
87#include "shared_data.h"
88#include "sort.h"
89#include "status.h"
90#ifdef USE_NOTMUCH
91#include "notmuch/lib.h"
92#endif
93#ifdef USE_INOTIFY
94#include "monitor.h"
95#endif
96
98static const struct Mapping IndexHelp[] = {
99 // clang-format off
100 { N_("Quit"), OP_QUIT },
101 { N_("Del"), OP_DELETE },
102 { N_("Undel"), OP_UNDELETE },
103 { N_("Save"), OP_SAVE },
104 { N_("Mail"), OP_MAIL },
105 { N_("Reply"), OP_REPLY },
106 { N_("Group"), OP_GROUP_REPLY },
107 { N_("Help"), OP_HELP },
108 { NULL, 0 },
109 // clang-format on
110};
111
113const struct Mapping IndexNewsHelp[] = {
114 // clang-format off
115 { N_("Quit"), OP_QUIT },
116 { N_("Del"), OP_DELETE },
117 { N_("Undel"), OP_UNDELETE },
118 { N_("Save"), OP_SAVE },
119 { N_("Post"), OP_POST },
120 { N_("Followup"), OP_FOLLOWUP },
121 { N_("Catchup"), OP_CATCHUP },
122 { N_("Help"), OP_HELP },
123 { NULL, 0 },
124 // clang-format on
125};
126
134bool check_acl(struct Mailbox *m, AclFlags acl, const char *msg)
135{
136 if (!m)
137 return false;
138
139 if (!(m->rights & acl))
140 {
141 /* L10N: %s is one of the CHECK_ACL entries below. */
142 mutt_error(_("%s: Operation not permitted by ACL"), msg);
143 return false;
144 }
145
146 return true;
147}
148
161void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
162{
163 if (!mv || !mv->mailbox || (mv->mailbox->msg_count == 0) || !menu)
164 return;
165
166 struct Email *e_cur = mutt_get_virt_email(mv->mailbox, menu_get_index(menu));
167 if (!e_cur)
168 return;
169
170 int final;
171
172 /* Figure out what the current message would be after folding / unfolding,
173 * so that we can restore the cursor in a sane way afterwards. */
174 if (e_cur->collapsed && toggle)
175 final = mutt_uncollapse_thread(e_cur);
176 else if (mutt_thread_can_collapse(e_cur))
177 final = mutt_collapse_thread(e_cur);
178 else
179 final = e_cur->vnum;
180
181 if (final == -1)
182 return;
183
184 struct Email *base = mutt_get_virt_email(mv->mailbox, final);
185 if (!base)
186 return;
187
188 /* Iterate all threads, perform collapse/uncollapse as needed */
189 mv->collapsed = toggle ? !mv->collapsed : true;
191
192 /* Restore the cursor */
194 menu->max = mv->mailbox->vcount;
195 for (int i = 0; i < mv->mailbox->vcount; i++)
196 {
197 struct Email *e = mutt_get_virt_email(mv->mailbox, i);
198 if (!e)
199 break;
200 if (e->index == base->index)
201 {
202 menu_set_index(menu, i);
203 break;
204 }
205 }
206
208}
209
215static void uncollapse_thread(struct MailboxView *mv, int index)
216{
217 if (!mv || !mv->mailbox)
218 return;
219
220 struct Mailbox *m = mv->mailbox;
221 struct Email *e = mutt_get_virt_email(m, index);
222 if (e && e->collapsed)
223 {
225 mutt_set_vnum(m);
226 }
227}
228
237int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
238{
239 if (!mv || !mv->mailbox)
240 return -1;
241
242 struct Mailbox *m = mv->mailbox;
243
244 int index = -1;
245 for (int i = msgno + 1; i < m->vcount; i++)
246 {
247 struct Email *e = mutt_get_virt_email(m, i);
248 if (!e)
249 continue;
250 if (!e->deleted)
251 {
252 index = i;
253 break;
254 }
255 }
256
257 if (uncollapse)
259
260 return index;
261}
262
271int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
272{
273 if (!mv || !mv->mailbox)
274 return -1;
275
276 struct Mailbox *m = mv->mailbox;
277
278 int index = -1;
279 for (int i = msgno - 1; i >= 0; i--)
280 {
281 struct Email *e = mutt_get_virt_email(m, i);
282 if (!e)
283 continue;
284 if (!e->deleted)
285 {
286 index = i;
287 break;
288 }
289 }
290
291 if (uncollapse)
293
294 return index;
295}
296
306{
307 if (!mv)
308 return 0;
309
310 struct Mailbox *m = mv->mailbox;
311 if (!m || (m->msg_count == 0))
312 return 0;
313
314 int old = -1;
315 for (int i = 0; i < m->vcount; i++)
316 {
317 struct Email *e = mutt_get_virt_email(m, i);
318 if (!e)
319 continue;
320 if (!e->read && !e->deleted)
321 {
322 if (!e->old)
323 return i;
324 if (old == -1)
325 old = i;
326 }
327 }
328 if (old != -1)
329 return old;
330
331 /* If `$use_threads` is not threaded and `$sort` is reverse, the latest
332 * message is first. Otherwise, the latest message is first if exactly
333 * one of `$use_threads` and `$sort` are reverse.
334 */
335 enum SortType c_sort = cs_subset_sort(m->sub, "sort");
336 if ((c_sort & SORT_MASK) == SORT_THREADS)
337 c_sort = cs_subset_sort(m->sub, "sort_aux");
338 bool reverse = false;
339 switch (mutt_thread_style())
340 {
341 case UT_FLAT:
342 reverse = c_sort & SORT_REVERSE;
343 break;
344 case UT_THREADS:
345 reverse = c_sort & SORT_REVERSE;
346 break;
347 case UT_REVERSE:
348 reverse = !(c_sort & SORT_REVERSE);
349 break;
350 default:
351 assert(false);
352 }
353
354 if (reverse || (m->vcount == 0))
355 return 0;
356
357 return m->vcount - 1;
358}
359
365void resort_index(struct MailboxView *mv, struct Menu *menu)
366{
367 if (!mv || !mv->mailbox || !menu)
368 return;
369
370 struct Mailbox *m = mv->mailbox;
371 const int old_index = menu_get_index(menu);
372 struct Email *e_cur = mutt_get_virt_email(m, old_index);
373
374 int new_index = -1;
375 mutt_sort_headers(mv, false);
376
377 /* Restore the current message */
378 for (int i = 0; i < m->vcount; i++)
379 {
380 struct Email *e = mutt_get_virt_email(m, i);
381 if (!e)
382 continue;
383 if (e == e_cur)
384 {
385 new_index = i;
386 break;
387 }
388 }
389
390 if (mutt_using_threads() && (old_index < 0))
391 new_index = mutt_parent_message(e_cur, false);
392
393 if (old_index < 0)
394 new_index = find_first_message(mv);
395
396 menu->max = m->vcount;
397 menu_set_index(menu, new_index);
399}
400
407static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
408{
409 struct Email **save_new = NULL;
410 const bool lmt = mview_has_limit(mv);
411
412 struct Mailbox *m = mv->mailbox;
413 int num_new = MAX(0, m->msg_count - oldcount);
414
415 const bool c_uncollapse_new = cs_subset_bool(m->sub, "uncollapse_new");
416 /* save the list of new messages */
417 if ((check != MX_STATUS_REOPENED) && (oldcount > 0) &&
418 (lmt || c_uncollapse_new) && (num_new > 0))
419 {
420 save_new = mutt_mem_malloc(num_new * sizeof(struct Email *));
421 for (int i = oldcount; i < m->msg_count; i++)
422 save_new[i - oldcount] = m->emails[i];
423 }
424
425 /* Sort first to thread the new messages, because some patterns
426 * require the threading information.
427 *
428 * If the mailbox was reopened, need to rethread from scratch. */
430
431 if (lmt)
432 {
433 for (int i = 0; i < m->msg_count; i++)
434 {
435 struct Email *e = m->emails[i];
436
437 if ((e->limit_visited && e->visible) ||
439 MUTT_MATCH_FULL_ADDRESS, m, e, NULL))
440 {
441 /* vnum will get properly set by mutt_set_vnum(), which
442 * is called by mutt_sort_headers() just below. */
443 e->vnum = 1;
444 e->visible = true;
445 }
446 else
447 {
448 e->vnum = -1;
449 e->visible = false;
450 }
451
452 // mark email as visited so we don't re-apply the pattern next time
453 e->limit_visited = true;
454 }
455 /* Need a second sort to set virtual numbers and redraw the tree */
456 mutt_sort_headers(mv, false);
457 }
458
459 /* uncollapse threads with new mail */
460 if (c_uncollapse_new)
461 {
462 if (check == MX_STATUS_REOPENED)
463 {
464 mv->collapsed = false;
466 mutt_set_vnum(m);
467 }
468 else if (oldcount > 0)
469 {
470 for (int j = 0; j < num_new; j++)
471 {
472 if (save_new[j]->visible)
473 {
474 mutt_uncollapse_thread(save_new[j]);
475 }
476 }
477 mutt_set_vnum(m);
478 }
479 }
480
481 FREE(&save_new);
482}
483
489static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
490{
491 /* We are in a limited view. Check if the new message(s) satisfy
492 * the limit criteria. If they do, set their virtual msgno so that
493 * they will be visible in the limited view */
494 if (mview_has_limit(mv))
495 {
496 int padding = mx_msg_padding_size(mv->mailbox);
497 mv->mailbox->vcount = mv->vsize = 0;
498 for (int i = 0; i < mv->mailbox->msg_count; i++)
499 {
500 struct Email *e = mv->mailbox->emails[i];
501 if (!e)
502 break;
503
504 if ((e->limit_visited && e->visible) ||
506 MUTT_MATCH_FULL_ADDRESS, mv->mailbox, e, NULL))
507 {
508 assert(mv->mailbox->vcount < mv->mailbox->msg_count);
509 e->vnum = mv->mailbox->vcount;
510 mv->mailbox->v2r[mv->mailbox->vcount] = i;
511 e->visible = true;
512 mv->mailbox->vcount++;
513 struct Body *b = e->body;
514 mv->vsize += b->length + b->offset - b->hdr_offset + padding;
515 }
516 else
517 {
518 e->visible = false;
519 }
520
521 // mark email as visited so we don't re-apply the pattern next time
522 e->limit_visited = true;
523 }
524 }
525
526 /* if the mailbox was reopened, need to rethread from scratch */
528}
529
538void update_index(struct Menu *menu, struct MailboxView *mv, enum MxStatus check,
539 int oldcount, const struct IndexSharedData *shared)
540{
541 if (!menu || !mv)
542 return;
543
544 struct Mailbox *m = mv->mailbox;
545 if (mutt_using_threads())
546 update_index_threaded(mv, check, oldcount);
547 else
548 update_index_unthreaded(mv, check);
549
550 menu->max = m->vcount;
551 const int old_index = menu_get_index(menu);
552 int index = -1;
553 if (oldcount)
554 {
555 /* restore the current message to the message it was pointing to */
556 for (int i = 0; i < m->vcount; i++)
557 {
558 struct Email *e = mutt_get_virt_email(m, i);
559 if (!e)
560 continue;
561 if (index_shared_data_is_cur_email(shared, e))
562 {
563 index = i;
564 break;
565 }
566 }
567 }
568
569 if (index < 0)
570 {
571 index = (old_index < m->vcount) ? old_index : find_first_message(mv);
572 }
573 menu_set_index(menu, index);
574}
575
582{
583 if (nc->event_type != NT_MAILBOX)
584 return 0;
585 if (!nc->global_data)
586 return -1;
588 return 0;
589
590 struct Mailbox **ptr = nc->global_data;
591 if (!*ptr)
592 return 0;
593
594 *ptr = NULL;
595 mutt_debug(LL_DEBUG5, "mailbox done\n");
596 return 0;
597}
598
607void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount,
608 struct IndexSharedData *shared, bool read_only)
609{
610 if (!m)
611 return;
612
613 /* keepalive failure in mutt_enter_fname may kill connection. */
614 if (shared->mailbox && (buf_is_empty(&shared->mailbox->pathbuf)))
615 {
616 mview_free(&shared->mailbox_view);
617 mailbox_free(&shared->mailbox);
618 }
619
620 if (shared->mailbox)
621 {
622 char *new_last_folder = NULL;
623#ifdef USE_INOTIFY
624 int monitor_remove_rc = mutt_monitor_remove(NULL);
625#endif
626 if (shared->mailbox->compress_info && (shared->mailbox->realpath[0] != '\0'))
627 new_last_folder = mutt_str_dup(shared->mailbox->realpath);
628 else
629 new_last_folder = mutt_str_dup(mailbox_path(shared->mailbox));
630 *oldcount = shared->mailbox->msg_count;
631
632 const enum MxStatus check = mx_mbox_close(shared->mailbox);
633 if (check == MX_STATUS_OK)
634 {
635 mview_free(&shared->mailbox_view);
636 if (shared->mailbox != m)
637 {
638 mailbox_free(&shared->mailbox);
639 }
640 }
641 else
642 {
643#ifdef USE_INOTIFY
644 if (monitor_remove_rc == 0)
645 mutt_monitor_add(NULL);
646#endif
647 if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED))
648 update_index(menu, shared->mailbox_view, check, *oldcount, shared);
649
650 FREE(&new_last_folder);
653 return;
654 }
656 LastFolder = new_last_folder;
657 }
659
660 /* If the `folder-hook` were to call `unmailboxes`, then the Mailbox (`m`)
661 * could be deleted, leaving `m` dangling. */
662 // TODO: Refactor this function to avoid the need for an observer
664 char *dup_path = mutt_str_dup(mailbox_path(m));
665 char *dup_name = mutt_str_dup(m->name);
666
667 mutt_folder_hook(dup_path, dup_name);
668 if (m)
669 {
670 /* `m` is still valid, but we won't need the observer again before the end
671 * of the function. */
673 }
674 else
675 {
676 // Recreate the Mailbox as the folder-hook might have invoked `mailboxes`
677 // and/or `unmailboxes`.
678 m = mx_path_resolve(dup_path);
679 }
680
681 FREE(&dup_path);
682 FREE(&dup_name);
683
684 if (!m)
685 return;
686
687 const OpenMailboxFlags flags = read_only ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS;
688 if (mx_mbox_open(m, flags))
689 {
690 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
691 index_shared_data_set_mview(shared, mv);
692
693 menu->max = m->msg_count;
695#ifdef USE_INOTIFY
696 mutt_monitor_add(NULL);
697#endif
698 }
699 else
700 {
701 index_shared_data_set_mview(shared, NULL);
703 }
704
705 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
706 if (mutt_using_threads() && c_collapse_all)
707 collapse_all(shared->mailbox_view, menu, 0);
708
710 /* force the mailbox check after we have changed the folder */
711 struct EventMailbox ev_m = { shared->mailbox };
715}
716
717#ifdef USE_NOTMUCH
728struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int buflen, int *oldcount,
729 struct IndexSharedData *shared, bool read_only)
730{
731 if (!nm_url_from_query(NULL, buf, buflen))
732 {
733 mutt_message(_("Failed to create query, aborting"));
734 return NULL;
735 }
736
737 struct Mailbox *m_query = mx_path_resolve(buf);
738 change_folder_mailbox(menu, m_query, oldcount, shared, read_only);
739 return m_query;
740}
741#endif
742
751void change_folder_string(struct Menu *menu, struct Buffer *buf, int *oldcount,
752 struct IndexSharedData *shared, bool read_only)
753{
754 if (OptNews)
755 {
756 OptNews = false;
758 }
759 else
760 {
761 const char *const c_folder = cs_subset_string(shared->sub, "folder");
762 mx_path_canon(buf, c_folder, NULL);
763 }
764
766 if ((type == MUTT_MAILBOX_ERROR) || (type == MUTT_UNKNOWN))
767 {
768 // Look for a Mailbox by its description, before failing
769 struct Mailbox *m = mailbox_find_name(buf_string(buf));
770 if (m)
771 {
772 change_folder_mailbox(menu, m, oldcount, shared, read_only);
773 }
774 else
775 {
776 mutt_error(_("%s is not a mailbox"), buf_string(buf));
777 }
778 return;
779 }
780
781 struct Mailbox *m = mx_path_resolve(buf_string(buf));
782 change_folder_mailbox(menu, m, oldcount, shared, read_only);
783}
784
790void index_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
791{
792 buf[0] = '\0';
793
794 if (!menu || !menu->mdata)
795 return;
796
797 struct IndexPrivateData *priv = menu->mdata;
798 struct IndexSharedData *shared = priv->shared;
799 struct Mailbox *m = shared->mailbox;
800 if (!shared->mailbox_view)
801 menu->current = -1;
802
803 if (!m || (line < 0) || (line >= m->email_max))
804 return;
805
806 struct Email *e = mutt_get_virt_email(m, line);
807 if (!e)
808 return;
809
811 struct MuttThread *tmp = NULL;
812
813 const enum UseThreads c_threads = mutt_thread_style();
814 if ((c_threads > UT_FLAT) && e->tree && e->thread)
815 {
816 flags |= MUTT_FORMAT_TREE; /* display the thread tree */
817 if (e->display_subject)
818 {
819 flags |= MUTT_FORMAT_FORCESUBJ;
820 }
821 else
822 {
823 const bool reverse = c_threads == UT_REVERSE;
824 int edgemsgno;
825 if (reverse)
826 {
827 if (menu->top + menu->page_len > menu->max)
828 edgemsgno = m->v2r[menu->max - 1];
829 else
830 edgemsgno = m->v2r[menu->top + menu->page_len - 1];
831 }
832 else
833 {
834 edgemsgno = m->v2r[menu->top];
835 }
836
837 for (tmp = e->thread->parent; tmp; tmp = tmp->parent)
838 {
839 if (!tmp->message)
840 continue;
841
842 /* if no ancestor is visible on current screen, provisionally force
843 * subject... */
844 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
845 {
846 flags |= MUTT_FORMAT_FORCESUBJ;
847 break;
848 }
849 else if (tmp->message->vnum >= 0)
850 {
851 break;
852 }
853 }
854 if (flags & MUTT_FORMAT_FORCESUBJ)
855 {
856 for (tmp = e->thread->prev; tmp; tmp = tmp->prev)
857 {
858 if (!tmp->message)
859 continue;
860
861 /* ...but if a previous sibling is available, don't force it */
862 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
863 {
864 break;
865 }
866 else if (tmp->message->vnum >= 0)
867 {
868 flags &= ~MUTT_FORMAT_FORCESUBJ;
869 break;
870 }
871 }
872 }
873 }
874 }
875
876 const char *const c_index_format = cs_subset_string(shared->sub, "index_format");
877 int msg_in_pager = shared->mailbox_view ? shared->mailbox_view->msg_in_pager : 0;
878 mutt_make_string(buf, buflen, menu->win->state.cols, NONULL(c_index_format),
879 m, msg_in_pager, e, flags, NULL);
880}
881
885const struct AttrColor *index_color(struct Menu *menu, int line)
886{
887 struct IndexPrivateData *priv = menu->mdata;
888 struct IndexSharedData *shared = priv->shared;
889 struct Mailbox *m = shared->mailbox;
890 if (!m || (line < 0))
891 return NULL;
892
893 struct Email *e = mutt_get_virt_email(m, line);
894 if (!e)
895 return NULL;
896
897 if (e->attr_color)
898 return e->attr_color;
899
901 return e->attr_color;
902}
903
917void mutt_draw_statusline(struct MuttWindow *win, int cols, const char *buf, size_t buflen)
918{
919 if (!buf || !stdscr)
920 return;
921
922 size_t i = 0;
923 size_t offset = 0;
924 bool found = false;
925 size_t chunks = 0;
926 size_t len = 0;
927
931 struct StatusSyntax
932 {
933 const struct AttrColor *attr_color;
934 int first;
935 int last;
936 } *syntax = NULL;
937
940 do
941 {
942 struct RegexColor *cl = NULL;
943 found = false;
944
945 if (!buf[offset])
946 break;
947
948 /* loop through each "color status regex" */
950 {
951 regmatch_t pmatch[cl->match + 1];
952
953 if (regexec(&cl->regex, buf + offset, cl->match + 1, pmatch, 0) != 0)
954 continue; /* regex doesn't match the status bar */
955
956 int first = pmatch[cl->match].rm_so + offset;
957 int last = pmatch[cl->match].rm_eo + offset;
958
959 if (first == last)
960 continue; /* ignore an empty regex */
961
962 if (!found)
963 {
964 chunks++;
965 mutt_mem_realloc(&syntax, chunks * sizeof(struct StatusSyntax));
966 }
967
968 i = chunks - 1;
969 if (!found || (first < syntax[i].first) ||
970 ((first == syntax[i].first) && (last > syntax[i].last)))
971 {
972 const struct AttrColor *ac_merge = merged_color_overlay(ac_base, &cl->attr_color);
973
974 syntax[i].attr_color = ac_merge;
975 syntax[i].first = first;
976 syntax[i].last = last;
977 }
978 found = true;
979 }
980
981 if (syntax)
982 {
983 offset = syntax[i].last;
984 }
985 } while (found);
986
987 /* Only 'len' bytes will fit into 'cols' screen columns */
988 len = mutt_wstr_trunc(buf, buflen, cols, NULL);
989
990 offset = 0;
991
992 if ((chunks > 0) && (syntax[0].first > 0))
993 {
994 /* Text before the first highlight */
995 mutt_window_addnstr(win, buf, MIN(len, syntax[0].first));
996 mutt_curses_set_color(ac_base);
997 if (len <= syntax[0].first)
998 goto dsl_finish; /* no more room */
999
1000 offset = syntax[0].first;
1001 }
1002
1003 for (i = 0; i < chunks; i++)
1004 {
1005 /* Highlighted text */
1006 mutt_curses_set_color(syntax[i].attr_color);
1007 mutt_window_addnstr(win, buf + offset, MIN(len, syntax[i].last) - offset);
1008 if (len <= syntax[i].last)
1009 goto dsl_finish; /* no more room */
1010
1011 size_t next;
1012 if ((i + 1) == chunks)
1013 {
1014 next = len;
1015 }
1016 else
1017 {
1018 next = MIN(len, syntax[i + 1].first);
1019 }
1020
1021 mutt_curses_set_color(ac_base);
1022 offset = syntax[i].last;
1023 mutt_window_addnstr(win, buf + offset, next - offset);
1024
1025 offset = next;
1026 if (offset >= len)
1027 goto dsl_finish; /* no more room */
1028 }
1029
1030 mutt_curses_set_color(ac_base);
1031 if (offset < len)
1032 {
1033 /* Text after the last highlight */
1034 mutt_window_addnstr(win, buf + offset, len - offset);
1035 }
1036
1037 int width = mutt_strwidth(buf);
1038 if (width < cols)
1039 {
1040 /* Pad the rest of the line with whitespace */
1041 mutt_paddstr(win, cols - width, "");
1042 }
1043dsl_finish:
1044 FREE(&syntax);
1045}
1046
1057struct Mailbox *dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
1058{
1059 /* Make sure use_threads/sort/sort_aux are coherent */
1061
1062 struct IndexSharedData *shared = dlg->wdata;
1064
1065 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1066
1067 struct IndexPrivateData *priv = panel_index->wdata;
1068 priv->win_index = window_find_child(panel_index, WT_MENU);
1069
1070 int op = OP_NULL;
1071
1072 if (shared->mailbox && (shared->mailbox->type == MUTT_NNTP))
1073 dlg->help_data = IndexNewsHelp;
1074 else
1075 dlg->help_data = IndexHelp;
1076 dlg->help_menu = MENU_INDEX;
1077
1078 priv->menu = priv->win_index->wdata;
1080 priv->menu->color = index_color;
1081 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1083
1084 struct MuttWindow *old_focus = window_set_focus(priv->menu->win);
1085 mutt_window_reflow(NULL);
1086
1087 if (!shared->attach_msg)
1088 {
1089 /* force the mailbox check after we enter the folder */
1091 }
1092#ifdef USE_INOTIFY
1093 mutt_monitor_add(NULL);
1094#endif
1095
1096 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
1097 if (mutt_using_threads() && c_collapse_all)
1098 {
1099 collapse_all(shared->mailbox_view, priv->menu, 0);
1101 }
1102
1103 int rc = 0;
1104 do
1105 {
1106 /* Clear the tag prefix unless we just started it.
1107 * Don't clear the prefix on a timeout, but do clear on an abort */
1108 if (priv->tag_prefix && (op != OP_TAG_PREFIX) &&
1109 (op != OP_TAG_PREFIX_COND) && (op != OP_TIMEOUT))
1110 {
1111 priv->tag_prefix = false;
1112 }
1113
1114 /* check if we need to resort the index because just about
1115 * any 'op' below could do mutt_enter_command(), either here or
1116 * from any new priv->menu launched, and change $sort/$sort_aux */
1117 if (OptNeedResort && shared->mailbox && (shared->mailbox->msg_count != 0) &&
1118 (menu_get_index(priv->menu) >= 0))
1119 {
1120 resort_index(shared->mailbox_view, priv->menu);
1121 }
1122
1123 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1124 priv->oldcount = shared->mailbox ? shared->mailbox->msg_count : 0;
1125
1126 if (shared->mailbox && shared->mailbox_view)
1127 {
1129
1130 shared->mailbox_view->menu = priv->menu;
1131 /* check for new mail in the mailbox. If nonzero, then something has
1132 * changed about the file (either we got new mail or the file was
1133 * modified underneath us.) */
1134 enum MxStatus check = mx_mbox_check(shared->mailbox);
1135
1136 if (check == MX_STATUS_ERROR)
1137 {
1138 if (buf_is_empty(&shared->mailbox->pathbuf))
1139 {
1140 /* fatal error occurred */
1141 mview_free(&shared->mailbox_view);
1143 }
1144
1146 }
1147 else if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED) ||
1148 (check == MX_STATUS_FLAGS))
1149 {
1150 /* notify the user of new mail */
1151 if (check == MX_STATUS_REOPENED)
1152 {
1153 mutt_error(_("Mailbox was externally modified. Flags may be wrong."));
1154 }
1155 else if (check == MX_STATUS_NEW_MAIL)
1156 {
1157 for (size_t i = 0; i < shared->mailbox->msg_count; i++)
1158 {
1159 const struct Email *e = shared->mailbox->emails[i];
1160 if (e && !e->read && !e->old)
1161 {
1162 mutt_message(_("New mail in this mailbox"));
1163 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1164 if (c_beep_new)
1165 mutt_beep(true);
1166 const char *const c_new_mail_command = cs_subset_string(shared->sub, "new_mail_command");
1167 if (c_new_mail_command)
1168 {
1169 char cmd[1024] = { 0 };
1170 menu_status_line(cmd, sizeof(cmd), shared, NULL, sizeof(cmd),
1171 NONULL(c_new_mail_command));
1172 if (mutt_system(cmd) != 0)
1173 mutt_error(_("Error running \"%s\""), cmd);
1174 }
1175 break;
1176 }
1177 }
1178 }
1179 else if (check == MX_STATUS_FLAGS)
1180 {
1181 mutt_message(_("Mailbox was externally modified"));
1182 }
1183
1184 /* avoid the message being overwritten by mailbox */
1185 priv->do_mailbox_notify = false;
1186
1187 bool verbose = shared->mailbox->verbose;
1188 shared->mailbox->verbose = false;
1189 update_index(priv->menu, shared->mailbox_view, check, priv->oldcount, shared);
1190 shared->mailbox->verbose = verbose;
1191 priv->menu->max = shared->mailbox->vcount;
1194 }
1195
1197 menu_get_index(priv->menu)));
1198 }
1199
1200 if (!shared->attach_msg)
1201 {
1202 /* check for new mail in the incoming folders */
1204 if (priv->do_mailbox_notify)
1205 {
1206 if (mutt_mailbox_notify(shared->mailbox))
1207 {
1208 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1209 if (c_beep_new)
1210 mutt_beep(true);
1211 const char *const c_new_mail_command = cs_subset_string(shared->sub, "new_mail_command");
1212 if (c_new_mail_command)
1213 {
1214 char cmd[1024] = { 0 };
1215 menu_status_line(cmd, sizeof(cmd), shared, priv->menu, sizeof(cmd),
1216 NONULL(c_new_mail_command));
1217 if (mutt_system(cmd) != 0)
1218 mutt_error(_("Error running \"%s\""), cmd);
1219 }
1220 }
1221 }
1222 else
1223 {
1224 priv->do_mailbox_notify = true;
1225 }
1226 }
1227
1228 window_redraw(NULL);
1229
1230 /* give visual indication that the next command is a tag- command */
1231 if (priv->tag_prefix)
1232 {
1233 msgwin_set_text(NULL, "tag-", MT_COLOR_NORMAL);
1234 }
1235
1236 const bool c_arrow_cursor = cs_subset_bool(shared->sub, "arrow_cursor");
1237 const bool c_braille_friendly = cs_subset_bool(shared->sub, "braille_friendly");
1238 const int index = menu_get_index(priv->menu);
1239 if (c_arrow_cursor)
1240 {
1241 const char *const c_arrow_string = cs_subset_string(shared->sub, "arrow_string");
1242 const int arrow_width = mutt_strwidth(c_arrow_string);
1243 mutt_window_move(priv->menu->win, arrow_width, index - priv->menu->top);
1244 }
1245 else if (c_braille_friendly)
1246 {
1247 mutt_window_move(priv->menu->win, 0, index - priv->menu->top);
1248 }
1249 else
1250 {
1251 mutt_window_move(priv->menu->win, priv->menu->win->state.cols - 1,
1252 index - priv->menu->top);
1253 }
1254 mutt_refresh();
1255
1256 window_redraw(NULL);
1258
1259 if (op == OP_REPAINT)
1260 {
1261 priv->menu->top = 0; /* so we scroll the right amount */
1262 /* force a real complete redraw. clrtobot() doesn't seem to be able
1263 * to handle every case without this. */
1264 msgwin_clear_text(NULL);
1265 mutt_refresh();
1266 continue;
1267 }
1268
1269 /* either user abort or timeout */
1270 if (op < OP_NULL)
1271 {
1272 if (priv->tag_prefix)
1273 msgwin_clear_text(NULL);
1274 continue;
1275 }
1276
1277 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
1278
1279 /* special handling for the priv->tag-prefix function */
1280 const bool c_auto_tag = cs_subset_bool(shared->sub, "auto_tag");
1281 if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
1282 {
1283 /* A second priv->tag-prefix command aborts */
1284 if (priv->tag_prefix)
1285 {
1286 priv->tag_prefix = false;
1287 msgwin_clear_text(NULL);
1288 continue;
1289 }
1290
1291 if (!shared->mailbox)
1292 {
1293 mutt_error(_("No mailbox is open"));
1294 continue;
1295 }
1296
1297 if (shared->mailbox->msg_tagged == 0)
1298 {
1299 if (op == OP_TAG_PREFIX)
1300 {
1301 mutt_error(_("No tagged messages"));
1302 }
1303 else if (op == OP_TAG_PREFIX_COND)
1304 {
1306 mutt_message(_("Nothing to do"));
1307 }
1308 continue;
1309 }
1310
1311 /* get the real command */
1312 priv->tag_prefix = true;
1313 continue;
1314 }
1315 else if (c_auto_tag && shared->mailbox && (shared->mailbox->msg_tagged != 0))
1316 {
1317 priv->tag_prefix = true;
1318 }
1319
1321
1322 OptNews = false; /* for any case */
1323
1324#ifdef USE_NOTMUCH
1325 nm_db_debug_check(shared->mailbox);
1326#endif
1327
1328 rc = index_function_dispatcher(priv->win_index, op);
1329
1330 if (rc == FR_UNKNOWN)
1331 rc = menu_function_dispatcher(priv->win_index, op);
1332
1333 if (rc == FR_UNKNOWN)
1334 {
1335 struct MuttWindow *win_sidebar = window_find_child(dlg, WT_SIDEBAR);
1336 rc = sb_function_dispatcher(win_sidebar, op);
1337 }
1338 if (rc == FR_UNKNOWN)
1339 rc = global_function_dispatcher(NULL, op);
1340
1341 if (rc == FR_UNKNOWN)
1343
1344#ifdef USE_NOTMUCH
1345 nm_db_debug_check(shared->mailbox);
1346#endif
1347 } while (rc != FR_DONE);
1348
1349 mview_free(&shared->mailbox_view);
1350 window_set_focus(old_focus);
1351
1352 return shared->mailbox;
1353}
1354
1360void mutt_set_header_color(struct Mailbox *m, struct Email *e)
1361{
1362 if (!e)
1363 return;
1364
1365 struct RegexColor *color = NULL;
1366 struct PatternCache cache = { 0 };
1367
1368 const struct AttrColor *ac_merge = NULL;
1370 {
1372 MUTT_MATCH_FULL_ADDRESS, m, e, &cache))
1373 {
1374 ac_merge = merged_color_overlay(ac_merge, &color->attr_color);
1375 }
1376 }
1377
1378 struct AttrColor *ac_normal = simple_color_get(MT_COLOR_NORMAL);
1379 if (ac_merge)
1380 ac_merge = merged_color_overlay(ac_normal, ac_merge);
1381 else
1382 ac_merge = ac_normal;
1383
1384 e->attr_color = ac_merge;
1385}
1386
1392{
1396
1397 struct IndexSharedData *shared = index_shared_data_new();
1398 notify_set_parent(shared->notify, dlg->notify);
1399
1400 dlg->wdata = shared;
1402
1403 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
1404
1405 struct MuttWindow *panel_index = ipanel_new(c_status_on_top, shared);
1406 struct MuttWindow *panel_pager = ppanel_new(c_status_on_top, shared);
1407
1408 mutt_window_add_child(dlg, panel_index);
1409 mutt_window_add_child(dlg, panel_pager);
1410
1411 return dlg;
1412}
1413
1419void index_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
1420{
1421 if (!dlg || !m)
1422 return;
1423
1424 struct IndexSharedData *shared = dlg->wdata;
1425 if (!shared)
1426 return;
1427
1428 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1429 if (!panel_index)
1430 return;
1431
1432 struct IndexPrivateData *priv = panel_index->wdata;
1433 if (!priv)
1434 return;
1435
1436 change_folder_mailbox(priv->menu, m, &priv->oldcount, shared, false);
1437}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
Color and attribute parsing.
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:183
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:88
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:74
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:58
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:82
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:777
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
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:394
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:352
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:75
void mutt_beep(bool force)
Irritate the user.
Definition: curs_lib.c:65
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:454
@ 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:134
const struct Mapping IndexNewsHelp[]
Help Bar for the News Index dialog.
Definition: dlg_index.c:113
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:607
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:728
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:538
void mutt_set_header_color(struct Mailbox *m, struct Email *e)
Select a colour for a message.
Definition: dlg_index.c:1360
void mutt_draw_statusline(struct MuttWindow *win, int cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:917
void index_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
Change the current folder, cautiously.
Definition: dlg_index.c:1419
int find_first_message(struct MailboxView *mv)
Get index of first new message.
Definition: dlg_index.c:305
static const struct Mapping IndexHelp[]
Help Bar for the Index dialog.
Definition: dlg_index.c:98
static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
Update the index (if threaded)
Definition: dlg_index.c:407
void resort_index(struct MailboxView *mv, struct Menu *menu)
Resort the index.
Definition: dlg_index.c:365
int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the next undeleted email.
Definition: dlg_index.c:237
static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
Update the index (if unthreaded)
Definition: dlg_index.c:489
void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
Collapse/uncollapse all threads.
Definition: dlg_index.c:161
void change_folder_string(struct Menu *menu, struct Buffer *buf, int *oldcount, struct IndexSharedData *shared, bool read_only)
Change to a different Mailbox by string.
Definition: dlg_index.c:751
int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the previous undeleted email.
Definition: dlg_index.c:271
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition: dlg_index.c:1391
static void uncollapse_thread(struct MailboxView *mv, int index)
Open a collapsed thread.
Definition: dlg_index.c:215
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:1127
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
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:475
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: get.c:165
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:305
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:75
char * LastFolder
Previously selected mailbox.
Definition: globals.c:45
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:44
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:74
int sb_function_dispatcher(struct MuttWindow *win, int op)
Perform a Sidebar function - Implements function_dispatcher_t -.
Definition: functions.c:374
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:169
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:3254
struct Mailbox * dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
Display a list of emails -.
Definition: dlg_index.c:1057
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
const 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:885
void index_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format an Email for the Menu - Implements Menu::make_entry() -.
Definition: dlg_index.c:790
static int index_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: dlg_index.c:581
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:277
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:1422
String processing routines to generate the mail index.
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition: hook.c:597
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:234
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:263
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:306
void index_shared_data_set_mview(struct IndexSharedData *shared, struct MailboxView *mv)
Set the MailboxView for the Index and friends.
Definition: shared_data.c:159
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
Manage keymappings.
#define GETCH_NO_FLAGS
No flags are set.
Definition: lib.h:52
@ 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:305
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:90
struct Mailbox * mailbox_find_name(const char *name)
Find the mailbox with a given name.
Definition: mailbox.c:180
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition: mailbox.h:170
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
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:45
#define MIN(a, b)
Definition: memory.h:32
#define MAX(a, b)
Definition: memory.h:31
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:180
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:156
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition: merged.c:107
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:480
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:524
Monitor files for changes.
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition: msgwin.c:516
void msgwin_set_text(struct MuttWindow *win, const char *text, enum ColorId color)
Set the text for the Message Window.
Definition: msgwin.c:484
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:230
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:191
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
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(const struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:40
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:166
bool mutt_mailbox_notify(struct Mailbox *m_cur)
Notify the user if there's new mail.
Definition: mutt_mailbox.c:232
Mailbox helper functions.
void mutt_thread_collapse(struct ThreadsContext *tctx, bool collapse)
Toggle collapse.
Definition: mutt_thread.c:1786
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:1401
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1814
int mutt_parent_message(struct Email *e, bool find_root)
Find the parent of a message.
Definition: mutt_thread.c:1351
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:634
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:344
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:446
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:182
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:297
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:684
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:533
int mutt_window_addnstr(struct MuttWindow *win, const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:401
@ WT_DLG_INDEX
Index Dialog, dlg_index()
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:417
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:438
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition: mview.c:90
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:1521
int mx_path_canon(struct Buffer *path, const char *folder, enum MailboxType *type)
Canonicalise a mailbox path - Wrapper for MxOps::path_canon()
Definition: mx.c:1372
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:284
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1326
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1652
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1099
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:593
API for mailboxes.
#define MUTT_READONLY
Open in read-only mode.
Definition: mxapi.h:43
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mxapi.h:39
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:53
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition: mxapi.h:40
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:54
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_snc(), and mbox_close()
Definition: mxapi.h:63
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:64
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:65
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mxapi.h:69
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:68
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:66
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:77
@ 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:1565
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:48
#define OP_TIMEOUT
1 second with no events
Definition: opcodes.h:34
#define OP_REPAINT
Repaint is needed.
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:121
Private state data for the Pager.
Match patterns to emails.
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:106
Prototypes for many functions.
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50
#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:348
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:477
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:66
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
String manipulation buffer.
Definition: buffer.h:34
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
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:102
bool visible
Is this message part of the view?
Definition: email.h:122
bool limit_visited
Has the limit pattern been applied to this message?
Definition: email.h:123
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:121
struct Body * body
List of MIME parts.
Definition: email.h:67
char * tree
Character string to print thread tree.
Definition: email.h:126
bool old
Email is seen, but unread.
Definition: email.h:47
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:69
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:113
int vnum
Virtual message number.
Definition: email.h:115
int msgno
Number displayed to the user.
Definition: email.h:112
bool deleted
Email is deleted.
Definition: email.h:76
int index
The absolute (unsorted) message number.
Definition: email.h:111
struct MuttThread * thread
Thread of Emails.
Definition: email.h:120
An Event that happened to a Mailbox.
Definition: mailbox.h:186
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:187
Private state data for the Index.
Definition: private_data.h:35
struct MuttWindow * win_index
Window for the Index.
Definition: private_data.h:42
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:40
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:38
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:41
int oldcount
Old count of mails 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
bool attach_msg
Are we in "attach message" mode?
Definition: shared_data.h:46
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 SearchState * search_state
State of the current search.
Definition: shared_data.h:45
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:118
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:144
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:116
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:96
int current
Current entry.
Definition: lib.h:71
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:133
int top
Entry that is the top of the current page.
Definition: lib.h:81
void * mdata
Private data.
Definition: lib.h:137
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
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:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
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:117
A regular expression and a color to highlight a line.
Definition: regex4.h:36
regex_t regex
Compiled regex.
Definition: regex4.h:39
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: regex4.h:41
struct AttrColor attr_color
Colour and attributes to apply.
Definition: regex4.h:37
int match
Substring to match, 0 for old behaviour.
Definition: regex4.h:40
struct PatternList * pattern
compiled search pattern
Definition: search_state.h:36
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:51