NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_index.c
Go to the documentation of this file.
1
60#include "config.h"
61#include <stdbool.h>
62#include <stdio.h>
63#include <string.h>
64#include "private.h"
65#include "mutt/lib.h"
66#include "config/lib.h"
67#include "email/lib.h"
68#include "core/lib.h"
69#include "conn/lib.h"
70#include "gui/lib.h"
71#include "lib.h"
72#include "color/lib.h"
73#include "expando/lib.h"
74#include "key/lib.h"
75#include "menu/lib.h"
76#include "nntp/lib.h"
77#include "pager/lib.h"
78#include "pattern/lib.h"
79#include "sidebar/lib.h"
80#include "expando_index.h"
81#include "functions.h"
82#include "globals.h"
83#include "hook.h"
84#include "mutt_logging.h"
85#include "mutt_mailbox.h"
86#include "mutt_thread.h"
87#include "mview.h"
88#include "mx.h"
89#include "nntp/adata.h"
90#include "private_data.h"
91#include "protos.h"
92#include "shared_data.h"
93#include "status.h"
94#ifdef USE_NOTMUCH
95#include "notmuch/lib.h"
96#endif
97#ifdef USE_INOTIFY
98#include "monitor.h"
99#endif
100
102static const struct Mapping IndexHelp[] = {
103 // clang-format off
104 { N_("Quit"), OP_QUIT },
105 { N_("Del"), OP_DELETE },
106 { N_("Undel"), OP_UNDELETE },
107 { N_("Save"), OP_SAVE },
108 { N_("Mail"), OP_MAIL },
109 { N_("Reply"), OP_REPLY },
110 { N_("Group"), OP_GROUP_REPLY },
111 { N_("Help"), OP_HELP },
112 { NULL, 0 },
113 // clang-format on
114};
115
117const struct Mapping IndexNewsHelp[] = {
118 // clang-format off
119 { N_("Quit"), OP_QUIT },
120 { N_("Del"), OP_DELETE },
121 { N_("Undel"), OP_UNDELETE },
122 { N_("Save"), OP_SAVE },
123 { N_("Post"), OP_POST },
124 { N_("Followup"), OP_FOLLOWUP },
125 { N_("Catchup"), OP_CATCHUP },
126 { N_("Help"), OP_HELP },
127 { NULL, 0 },
128 // clang-format on
129};
130
138bool check_acl(struct Mailbox *m, AclFlags acl, const char *msg)
139{
140 if (!m)
141 return false;
142
143 if (!(m->rights & acl))
144 {
145 /* L10N: %s is one of the CHECK_ACL entries below. */
146 mutt_error(_("%s: Operation not permitted by ACL"), msg);
147 return false;
148 }
149
150 return true;
151}
152
165void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
166{
167 if (!mv || !mv->mailbox || (mv->mailbox->msg_count == 0) || !menu)
168 return;
169
170 struct Email *e_cur = mutt_get_virt_email(mv->mailbox, menu_get_index(menu));
171 if (!e_cur)
172 return;
173
174 int final;
175
176 /* Figure out what the current message would be after folding / unfolding,
177 * so that we can restore the cursor in a sane way afterwards. */
178 if (e_cur->collapsed && toggle)
179 final = mutt_uncollapse_thread(e_cur);
180 else if (mutt_thread_can_collapse(e_cur))
181 final = mutt_collapse_thread(e_cur);
182 else
183 final = e_cur->vnum;
184
185 if (final == -1)
186 return;
187
188 struct Email *base = mutt_get_virt_email(mv->mailbox, final);
189 if (!base)
190 return;
191
192 /* Iterate all threads, perform collapse/uncollapse as needed */
193 mv->collapsed = toggle ? !mv->collapsed : true;
195
196 /* Restore the cursor */
198 menu->max = mv->mailbox->vcount;
199 for (int i = 0; i < mv->mailbox->vcount; i++)
200 {
201 struct Email *e = mutt_get_virt_email(mv->mailbox, i);
202 if (!e)
203 break;
204 if (e->index == base->index)
205 {
206 menu_set_index(menu, i);
207 break;
208 }
209 }
210
212}
213
219static void uncollapse_thread(struct MailboxView *mv, int index)
220{
221 if (!mv || !mv->mailbox)
222 return;
223
224 struct Mailbox *m = mv->mailbox;
225 struct Email *e = mutt_get_virt_email(m, index);
226 if (e && e->collapsed)
227 {
229 mutt_set_vnum(m);
230 }
231}
232
241int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
242{
243 if (!mv || !mv->mailbox)
244 return -1;
245
246 struct Mailbox *m = mv->mailbox;
247
248 int index = -1;
249 for (int i = msgno + 1; i < m->vcount; i++)
250 {
251 struct Email *e = mutt_get_virt_email(m, i);
252 if (!e)
253 continue;
254 if (!e->deleted)
255 {
256 index = i;
257 break;
258 }
259 }
260
261 if (uncollapse)
263
264 return index;
265}
266
275int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
276{
277 if (!mv || !mv->mailbox)
278 return -1;
279
280 struct Mailbox *m = mv->mailbox;
281
282 int index = -1;
283 for (int i = msgno - 1; i >= 0; i--)
284 {
285 struct Email *e = mutt_get_virt_email(m, i);
286 if (!e)
287 continue;
288 if (!e->deleted)
289 {
290 index = i;
291 break;
292 }
293 }
294
295 if (uncollapse)
297
298 return index;
299}
300
310{
311 if (!mv)
312 return 0;
313
314 struct Mailbox *m = mv->mailbox;
315 if (!m || (m->msg_count == 0))
316 return 0;
317
318 int old = -1;
319 for (int i = 0; i < m->vcount; i++)
320 {
321 struct Email *e = mutt_get_virt_email(m, i);
322 if (!e)
323 continue;
324 if (!e->read && !e->deleted)
325 {
326 if (!e->old)
327 return i;
328 if (old == -1)
329 old = i;
330 }
331 }
332 if (old != -1)
333 return old;
334
335 /* If `$use_threads` is not threaded and `$sort` is reverse, the latest
336 * message is first. Otherwise, the latest message is first if exactly
337 * one of `$use_threads` and `$sort` are reverse.
338 */
339 enum EmailSortType c_sort = cs_subset_sort(m->sub, "sort");
340 if ((c_sort & SORT_MASK) == EMAIL_SORT_THREADS)
341 c_sort = cs_subset_sort(m->sub, "sort_aux");
342 bool reverse = false;
343 switch (mutt_thread_style())
344 {
345 case UT_FLAT:
346 reverse = c_sort & SORT_REVERSE;
347 break;
348 case UT_THREADS:
349 reverse = c_sort & SORT_REVERSE;
350 break;
351 case UT_REVERSE:
352 reverse = !(c_sort & SORT_REVERSE);
353 break;
354 default:
355 ASSERT(false);
356 }
357
358 if (reverse || (m->vcount == 0))
359 return 0;
360
361 return m->vcount - 1;
362}
363
369void resort_index(struct MailboxView *mv, struct Menu *menu)
370{
371 if (!mv || !mv->mailbox || !menu)
372 return;
373
374 struct Mailbox *m = mv->mailbox;
375 const int old_index = menu_get_index(menu);
376 struct Email *e_cur = mutt_get_virt_email(m, old_index);
377
378 int new_index = -1;
379 mutt_sort_headers(mv, false);
380
381 /* Restore the current message */
382 for (int i = 0; i < m->vcount; i++)
383 {
384 struct Email *e = mutt_get_virt_email(m, i);
385 if (!e)
386 continue;
387 if (e == e_cur)
388 {
389 new_index = i;
390 break;
391 }
392 }
393
394 if (mutt_using_threads() && (old_index < 0))
395 new_index = mutt_parent_message(e_cur, false);
396
397 if (old_index < 0)
398 new_index = find_first_message(mv);
399
400 menu->max = m->vcount;
401 menu_set_index(menu, new_index);
403}
404
411static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
412{
413 struct Email **save_new = NULL;
414 const bool lmt = mview_has_limit(mv);
415
416 struct Mailbox *m = mv->mailbox;
417 int num_new = MAX(0, m->msg_count - oldcount);
418
419 const bool c_uncollapse_new = cs_subset_bool(m->sub, "uncollapse_new");
420 /* save the list of new messages */
421 if ((check != MX_STATUS_REOPENED) && (oldcount > 0) &&
422 (lmt || c_uncollapse_new) && (num_new > 0))
423 {
424 save_new = MUTT_MEM_MALLOC(num_new, struct Email *);
425 for (int i = oldcount; i < m->msg_count; i++)
426 save_new[i - oldcount] = m->emails[i];
427 }
428
429 /* Sort first to thread the new messages, because some patterns
430 * require the threading information.
431 *
432 * If the mailbox was reopened, need to rethread from scratch. */
434
435 if (lmt)
436 {
437 for (int i = 0; i < m->msg_count; i++)
438 {
439 struct Email *e = m->emails[i];
440
441 if ((e->limit_visited && e->visible) ||
443 MUTT_MATCH_FULL_ADDRESS, m, e, NULL))
444 {
445 /* vnum will get properly set by mutt_set_vnum(), which
446 * is called by mutt_sort_headers() just below. */
447 e->vnum = 1;
448 e->visible = true;
449 }
450 else
451 {
452 e->vnum = -1;
453 e->visible = false;
454 }
455
456 // mark email as visited so we don't re-apply the pattern next time
457 e->limit_visited = true;
458 }
459 /* Need a second sort to set virtual numbers and redraw the tree */
460 mutt_sort_headers(mv, false);
461 }
462
463 /* uncollapse threads with new mail */
464 if (c_uncollapse_new)
465 {
466 if (check == MX_STATUS_REOPENED)
467 {
468 mv->collapsed = false;
470 mutt_set_vnum(m);
471 }
472 else if (oldcount > 0)
473 {
474 for (int j = 0; j < num_new; j++)
475 {
476 if (save_new[j]->visible)
477 {
478 mutt_uncollapse_thread(save_new[j]);
479 }
480 }
481 mutt_set_vnum(m);
482 }
483 }
484
485 FREE(&save_new);
486}
487
493static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
494{
495 /* We are in a limited view. Check if the new message(s) satisfy
496 * the limit criteria. If they do, set their virtual msgno so that
497 * they will be visible in the limited view */
498 if (mview_has_limit(mv))
499 {
500 int padding = mx_msg_padding_size(mv->mailbox);
501 mv->mailbox->vcount = mv->vsize = 0;
502 for (int i = 0; i < mv->mailbox->msg_count; i++)
503 {
504 struct Email *e = mv->mailbox->emails[i];
505 if (!e)
506 break;
507
508 if ((e->limit_visited && e->visible) ||
510 MUTT_MATCH_FULL_ADDRESS, mv->mailbox, e, NULL))
511 {
513 e->vnum = mv->mailbox->vcount;
514 mv->mailbox->v2r[mv->mailbox->vcount] = i;
515 e->visible = true;
516 mv->mailbox->vcount++;
517 struct Body *b = e->body;
518 mv->vsize += b->length + b->offset - b->hdr_offset + padding;
519 }
520 else
521 {
522 e->visible = false;
523 }
524
525 // mark email as visited so we don't re-apply the pattern next time
526 e->limit_visited = true;
527 }
528 }
529
530 /* if the mailbox was reopened, need to rethread from scratch */
532}
533
542void update_index(struct Menu *menu, struct MailboxView *mv, enum MxStatus check,
543 int oldcount, const struct IndexSharedData *shared)
544{
545 if (!menu || !mv)
546 return;
547
548 struct Mailbox *m = mv->mailbox;
549 if (mutt_using_threads())
550 update_index_threaded(mv, check, oldcount);
551 else
552 update_index_unthreaded(mv, check);
553
554 menu->max = m->vcount;
555 const int old_index = menu_get_index(menu);
556 int index = -1;
557 if (oldcount)
558 {
559 /* restore the current message to the message it was pointing to */
560 for (int i = 0; i < m->vcount; i++)
561 {
562 struct Email *e = mutt_get_virt_email(m, i);
563 if (!e)
564 continue;
565 if (index_shared_data_is_cur_email(shared, e))
566 {
567 index = i;
568 break;
569 }
570 }
571 }
572
573 if (index < 0)
574 {
575 index = (old_index < m->vcount) ? old_index : find_first_message(mv);
576 }
577 menu_set_index(menu, index);
578}
579
586{
587 if (nc->event_type != NT_MAILBOX)
588 return 0;
589 if (!nc->global_data)
590 return -1;
592 return 0;
593
594 struct Mailbox **ptr = nc->global_data;
595 if (!*ptr)
596 return 0;
597
598 *ptr = NULL;
599 mutt_debug(LL_DEBUG5, "mailbox done\n");
600 return 0;
601}
602
611void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount,
612 struct IndexSharedData *shared, bool read_only)
613{
614 if (!m)
615 return;
616
617 /* keepalive failure in mutt_enter_fname may kill connection. */
618 if (shared->mailbox && (buf_is_empty(&shared->mailbox->pathbuf)))
619 {
620 mview_free(&shared->mailbox_view);
621 mailbox_free(&shared->mailbox);
622 }
623
624 if (shared->mailbox)
625 {
626 char *new_last_folder = NULL;
627#ifdef USE_INOTIFY
628 int monitor_remove_rc = mutt_monitor_remove(NULL);
629#endif
630 if (shared->mailbox->compress_info && (shared->mailbox->realpath[0] != '\0'))
631 new_last_folder = mutt_str_dup(shared->mailbox->realpath);
632 else
633 new_last_folder = mutt_str_dup(mailbox_path(shared->mailbox));
634 *oldcount = shared->mailbox->msg_count;
635
636 const enum MxStatus check = mx_mbox_close(shared->mailbox);
637 if (check == MX_STATUS_OK)
638 {
639 mview_free(&shared->mailbox_view);
640 if (shared->mailbox != m)
641 {
642 mailbox_free(&shared->mailbox);
643 }
644 }
645 else
646 {
647#ifdef USE_INOTIFY
648 if (monitor_remove_rc == 0)
649 mutt_monitor_add(NULL);
650#endif
651 if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED))
652 update_index(menu, shared->mailbox_view, check, *oldcount, shared);
653
654 FREE(&new_last_folder);
657 return;
658 }
660 LastFolder = new_last_folder;
661 }
663
664 /* If the `folder-hook` were to call `unmailboxes`, then the Mailbox (`m`)
665 * could be deleted, leaving `m` dangling. */
666 // TODO: Refactor this function to avoid the need for an observer
668 char *dup_path = mutt_str_dup(mailbox_path(m));
669 char *dup_name = mutt_str_dup(m->name);
670
671 mutt_folder_hook(dup_path, dup_name);
672 if (m)
673 {
674 /* `m` is still valid, but we won't need the observer again before the end
675 * of the function. */
677 }
678 else
679 {
680 // Recreate the Mailbox as the folder-hook might have invoked `mailboxes`
681 // and/or `unmailboxes`.
682 m = mx_path_resolve(dup_path);
683 }
684
685 FREE(&dup_path);
686 FREE(&dup_name);
687
688 if (!m)
689 return;
690
691 const OpenMailboxFlags flags = read_only ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS;
692 if (mx_mbox_open(m, flags))
693 {
694 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
695 index_shared_data_set_mview(shared, mv);
696
697 menu->max = m->msg_count;
699#ifdef USE_INOTIFY
700 mutt_monitor_add(NULL);
701#endif
702 }
703 else
704 {
705 index_shared_data_set_mview(shared, NULL);
707 }
708
709 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
710 if (mutt_using_threads() && c_collapse_all)
711 collapse_all(shared->mailbox_view, menu, 0);
712
714 /* force the mailbox check after we have changed the folder */
715 struct EventMailbox ev_m = { shared->mailbox };
719}
720
721#ifdef USE_NOTMUCH
732struct Mailbox *change_folder_notmuch(struct Menu *menu, char *buf, int buflen, int *oldcount,
733 struct IndexSharedData *shared, bool read_only)
734{
735 if (!nm_url_from_query(NULL, buf, buflen))
736 {
737 mutt_message(_("Failed to create query, aborting"));
738 return NULL;
739 }
740
741 struct Mailbox *m_query = mx_path_resolve(buf);
742 change_folder_mailbox(menu, m_query, oldcount, shared, read_only);
743 if (!shared->mailbox_view)
744 mailbox_free(&m_query);
745 return m_query;
746}
747#endif
748
757void change_folder_string(struct Menu *menu, struct Buffer *buf, int *oldcount,
758 struct IndexSharedData *shared, bool read_only)
759{
760 if (OptNews)
761 {
762 OptNews = false;
764 }
765 else
766 {
767 const char *const c_folder = cs_subset_string(shared->sub, "folder");
768 mx_path_canon(buf, c_folder, NULL);
769 }
770
772 if ((type == MUTT_MAILBOX_ERROR) || (type == MUTT_UNKNOWN))
773 {
774 // Look for a Mailbox by its description, before failing
775 struct Mailbox *m = mailbox_find_name(buf_string(buf));
776 if (m)
777 {
778 change_folder_mailbox(menu, m, oldcount, shared, read_only);
779 }
780 else
781 {
782 mutt_error(_("%s is not a mailbox"), buf_string(buf));
783 }
784 return;
785 }
786
787 struct Mailbox *m = mx_path_resolve(buf_string(buf));
788 change_folder_mailbox(menu, m, oldcount, shared, read_only);
789}
790
803int mutt_make_string(struct Buffer *buf, size_t max_cols,
804 const struct Expando *exp, struct Mailbox *m, int inpgr,
805 struct Email *e, MuttFormatFlags flags, const char *progress)
806{
807 if (!exp)
808 return 0;
809
810 struct EmailFormatInfo efi = { 0 };
811
812 efi.email = e;
813 efi.mailbox = m;
814 efi.msg_in_pager = inpgr;
815 efi.pager_progress = progress;
816
817 return expando_filter(exp, IndexRenderCallbacks, &efi, flags, max_cols,
818 NeoMutt->env, buf);
819}
820
826int index_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
827{
828 if (!menu || !menu->mdata)
829 return 0;
830
831 struct IndexPrivateData *priv = menu->mdata;
832 struct IndexSharedData *shared = priv->shared;
833 struct Mailbox *m = shared->mailbox;
834 if (!shared->mailbox_view)
835 menu->current = -1;
836
837 if (!m || (line < 0) || (line >= m->email_max))
838 return 0;
839
840 struct Email *e = mutt_get_virt_email(m, line);
841 if (!e)
842 return 0;
843
845 struct MuttThread *tmp = NULL;
846
847 const enum UseThreads c_threads = mutt_thread_style();
848 if ((c_threads > UT_FLAT) && e->tree && e->thread)
849 {
850 flags |= MUTT_FORMAT_TREE; /* display the thread tree */
851 if (e->display_subject)
852 {
853 flags |= MUTT_FORMAT_FORCESUBJ;
854 }
855 else
856 {
857 const bool reverse = c_threads == UT_REVERSE;
858 int edgemsgno;
859 if (reverse)
860 {
861 if (menu->top + menu->page_len > menu->max)
862 edgemsgno = m->v2r[menu->max - 1];
863 else
864 edgemsgno = m->v2r[menu->top + menu->page_len - 1];
865 }
866 else
867 {
868 edgemsgno = m->v2r[menu->top];
869 }
870
871 for (tmp = e->thread->parent; tmp; tmp = tmp->parent)
872 {
873 if (!tmp->message)
874 continue;
875
876 /* if no ancestor is visible on current screen, provisionally force
877 * subject... */
878 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
879 {
880 flags |= MUTT_FORMAT_FORCESUBJ;
881 break;
882 }
883 else if (tmp->message->vnum >= 0)
884 {
885 break;
886 }
887 }
888 if (flags & MUTT_FORMAT_FORCESUBJ)
889 {
890 for (tmp = e->thread->prev; tmp; tmp = tmp->prev)
891 {
892 if (!tmp->message)
893 continue;
894
895 /* ...but if a previous sibling is available, don't force it */
896 if (reverse ? (tmp->message->msgno > edgemsgno) : (tmp->message->msgno < edgemsgno))
897 {
898 break;
899 }
900 else if (tmp->message->vnum >= 0)
901 {
902 flags &= ~MUTT_FORMAT_FORCESUBJ;
903 break;
904 }
905 }
906 }
907 }
908 }
909
910 const struct Expando *c_index_format = cs_subset_expando(shared->sub, "index_format");
911 int msg_in_pager = shared->mailbox_view ? shared->mailbox_view->msg_in_pager : 0;
912
913 const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
914 if (c_arrow_cursor)
915 {
916 const char *const c_arrow_string = cs_subset_string(menu->sub, "arrow_string");
917 if (max_cols > 0)
918 max_cols -= (mutt_strwidth(c_arrow_string) + 1);
919 }
920
921 return mutt_make_string(buf, max_cols, c_index_format, m, msg_in_pager, e, flags, NULL);
922}
923
927const struct AttrColor *index_color(struct Menu *menu, int line)
928{
929 struct IndexPrivateData *priv = menu->mdata;
930 struct IndexSharedData *shared = priv->shared;
931 struct Mailbox *m = shared->mailbox;
932 if (!m || (line < 0))
933 return NULL;
934
935 struct Email *e = mutt_get_virt_email(m, line);
936 if (!e)
937 return NULL;
938
939 if (e->attr_color)
940 return e->attr_color;
941
942 email_set_color(m, e);
943 return e->attr_color;
944}
945
959void mutt_draw_statusline(struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
960{
961 if (!buf || !stdscr)
962 return;
963
964 size_t i = 0;
965 size_t offset = 0;
966 bool found = false;
967 size_t chunks = 0;
968 size_t len = 0;
969
973 struct StatusSyntax
974 {
975 const struct AttrColor *attr_color;
976 int first;
977 int last;
978 } *syntax = NULL;
979
982 do
983 {
984 struct RegexColor *cl = NULL;
985 found = false;
986
987 if (!buf[offset])
988 break;
989
990 /* loop through each "color status regex" */
992 {
993 regmatch_t pmatch[cl->match + 1];
994 memset(pmatch, 0, (cl->match + 1) * sizeof(regmatch_t));
995
996 if (regexec(&cl->regex, buf + offset, cl->match + 1, pmatch, 0) != 0)
997 continue; /* regex doesn't match the status bar */
998
999 int first = pmatch[cl->match].rm_so + offset;
1000 int last = pmatch[cl->match].rm_eo + offset;
1001
1002 if (first == last)
1003 continue; /* ignore an empty regex */
1004
1005 if (!found)
1006 {
1007 chunks++;
1008 MUTT_MEM_REALLOC(&syntax, chunks, struct StatusSyntax);
1009 }
1010
1011 i = chunks - 1;
1012 if (!found || (first < syntax[i].first) ||
1013 ((first == syntax[i].first) && (last > syntax[i].last)))
1014 {
1015 const struct AttrColor *ac_merge = merged_color_overlay(ac_base, &cl->attr_color);
1016
1017 syntax[i].attr_color = ac_merge;
1018 syntax[i].first = first;
1019 syntax[i].last = last;
1020 }
1021 found = true;
1022 }
1023
1024 if (syntax)
1025 {
1026 offset = syntax[i].last;
1027 }
1028 } while (found);
1029
1030 /* Only 'len' bytes will fit into 'max_cols' screen columns */
1031 len = mutt_wstr_trunc(buf, buflen, max_cols, NULL);
1032
1033 offset = 0;
1034
1035 if ((chunks > 0) && (syntax[0].first > 0))
1036 {
1037 /* Text before the first highlight */
1038 mutt_window_addnstr(win, buf, MIN(len, syntax[0].first));
1039 mutt_curses_set_color(ac_base);
1040 if (len <= syntax[0].first)
1041 goto dsl_finish; /* no more room */
1042
1043 offset = syntax[0].first;
1044 }
1045
1046 for (i = 0; i < chunks; i++)
1047 {
1048 /* Highlighted text */
1049 mutt_curses_set_color(syntax[i].attr_color);
1050 mutt_window_addnstr(win, buf + offset, MIN(len, syntax[i].last) - offset);
1051 if (len <= syntax[i].last)
1052 goto dsl_finish; /* no more room */
1053
1054 size_t next;
1055 if ((i + 1) == chunks)
1056 {
1057 next = len;
1058 }
1059 else
1060 {
1061 next = MIN(len, syntax[i + 1].first);
1062 }
1063
1064 mutt_curses_set_color(ac_base);
1065 offset = syntax[i].last;
1066 mutt_window_addnstr(win, buf + offset, next - offset);
1067
1068 offset = next;
1069 if (offset >= len)
1070 goto dsl_finish; /* no more room */
1071 }
1072
1073 mutt_curses_set_color(ac_base);
1074 if (offset < len)
1075 {
1076 /* Text after the last highlight */
1077 mutt_window_addnstr(win, buf + offset, len - offset);
1078 }
1079
1080 int width = mutt_strwidth(buf);
1081 if (width < max_cols)
1082 {
1083 /* Pad the rest of the line with whitespace */
1084 mutt_paddstr(win, max_cols - width, "");
1085 }
1086dsl_finish:
1087 FREE(&syntax);
1088}
1089
1100struct Mailbox *dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
1101{
1102 /* Make sure use_threads/sort/sort_aux are coherent */
1104
1105 struct IndexSharedData *shared = dlg->wdata;
1107
1108 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1109
1110 struct IndexPrivateData *priv = panel_index->wdata;
1111 priv->win_index = window_find_child(panel_index, WT_MENU);
1112
1113 int op = OP_NULL;
1114
1115 if (shared->mailbox && (shared->mailbox->type == MUTT_NNTP))
1116 dlg->help_data = IndexNewsHelp;
1117 else
1118 dlg->help_data = IndexHelp;
1119 dlg->help_menu = MENU_INDEX;
1120
1121 priv->menu = priv->win_index->wdata;
1123 priv->menu->color = index_color;
1124 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1126
1127 struct MuttWindow *old_focus = window_set_focus(priv->menu->win);
1128 mutt_window_reflow(NULL);
1129
1130 if (!shared->attach_msg)
1131 {
1132 /* force the mailbox check after we enter the folder */
1134 }
1135#ifdef USE_INOTIFY
1136 mutt_monitor_add(NULL);
1137#endif
1138
1139 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
1140 if (mutt_using_threads() && c_collapse_all)
1141 {
1142 collapse_all(shared->mailbox_view, priv->menu, 0);
1144 }
1145
1146 int rc = 0;
1147 do
1148 {
1149 /* Clear the tag prefix unless we just started it.
1150 * Don't clear the prefix on a timeout, but do clear on an abort */
1151 if (priv->tag_prefix && (op != OP_TAG_PREFIX) &&
1152 (op != OP_TAG_PREFIX_COND) && (op != OP_TIMEOUT))
1153 {
1154 priv->tag_prefix = false;
1155 }
1156
1157 /* check if we need to resort the index because just about
1158 * any 'op' below could do mutt_enter_command(), either here or
1159 * from any new priv->menu launched, and change $sort/$sort_aux */
1160 if (OptNeedResort && shared->mailbox && (shared->mailbox->msg_count != 0) &&
1161 (menu_get_index(priv->menu) >= 0))
1162 {
1163 resort_index(shared->mailbox_view, priv->menu);
1164 }
1165
1166 priv->menu->max = shared->mailbox ? shared->mailbox->vcount : 0;
1167 priv->oldcount = shared->mailbox ? shared->mailbox->msg_count : 0;
1168
1169 if (shared->mailbox && shared->mailbox_view)
1170 {
1172
1173 shared->mailbox_view->menu = priv->menu;
1174 /* check for new mail in the mailbox. If nonzero, then something has
1175 * changed about the file (either we got new mail or the file was
1176 * modified underneath us.) */
1177 enum MxStatus check = mx_mbox_check(shared->mailbox);
1178
1179 if (check == MX_STATUS_ERROR)
1180 {
1181 if (buf_is_empty(&shared->mailbox->pathbuf))
1182 {
1183 /* fatal error occurred */
1184 mview_free(&shared->mailbox_view);
1186 }
1187
1189 }
1190 else if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED) ||
1191 (check == MX_STATUS_FLAGS))
1192 {
1193 /* notify the user of new mail */
1194 if (check == MX_STATUS_REOPENED)
1195 {
1196 mutt_error(_("Mailbox was externally modified. Flags may be wrong."));
1197 }
1198 else if (check == MX_STATUS_NEW_MAIL)
1199 {
1200 for (size_t i = 0; i < shared->mailbox->msg_count; i++)
1201 {
1202 const struct Email *e = shared->mailbox->emails[i];
1203 if (e && !e->read && !e->old)
1204 {
1205 mutt_message(_("New mail in this mailbox"));
1206 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1207 if (c_beep_new)
1208 mutt_beep(true);
1209 const struct Expando *c_new_mail_command =
1210 cs_subset_expando(shared->sub, "new_mail_command");
1211 if (c_new_mail_command)
1212 {
1213 struct Buffer *cmd = buf_pool_get();
1214 menu_status_line(cmd, shared, NULL, -1, c_new_mail_command);
1215 if (mutt_system(buf_string(cmd)) != 0)
1216 mutt_error(_("Error running \"%s\""), buf_string(cmd));
1217 buf_pool_release(&cmd);
1218 }
1219 break;
1220 }
1221 }
1222 }
1223 else if (check == MX_STATUS_FLAGS)
1224 {
1225 mutt_message(_("Mailbox was externally modified"));
1226 }
1227
1228 /* avoid the message being overwritten by mailbox */
1229 priv->do_mailbox_notify = false;
1230
1231 bool verbose = shared->mailbox->verbose;
1232 shared->mailbox->verbose = false;
1233 update_index(priv->menu, shared->mailbox_view, check, priv->oldcount, shared);
1234 shared->mailbox->verbose = verbose;
1235 priv->menu->max = shared->mailbox->vcount;
1238 }
1239
1241 menu_get_index(priv->menu)));
1242 }
1243
1244 if (!shared->attach_msg)
1245 {
1246 /* check for new mail in the incoming folders */
1248 if (priv->do_mailbox_notify)
1249 {
1250 if (mutt_mailbox_notify(shared->mailbox))
1251 {
1252 const bool c_beep_new = cs_subset_bool(shared->sub, "beep_new");
1253 if (c_beep_new)
1254 mutt_beep(true);
1255 const struct Expando *c_new_mail_command = cs_subset_expando(shared->sub, "new_mail_command");
1256 if (c_new_mail_command)
1257 {
1258 struct Buffer *cmd = buf_pool_get();
1259 menu_status_line(cmd, shared, priv->menu, -1, c_new_mail_command);
1260 if (mutt_system(buf_string(cmd)) != 0)
1261 mutt_error(_("Error running \"%s\""), buf_string(cmd));
1262 buf_pool_release(&cmd);
1263 }
1264 }
1265 }
1266 else
1267 {
1268 priv->do_mailbox_notify = true;
1269 }
1270 }
1271
1272 window_redraw(NULL);
1273
1274 /* give visual indication that the next command is a tag- command */
1275 if (priv->tag_prefix)
1276 {
1277 msgwin_set_text(NULL, "tag-", MT_COLOR_NORMAL);
1278 }
1279
1280 const bool c_arrow_cursor = cs_subset_bool(shared->sub, "arrow_cursor");
1281 const bool c_braille_friendly = cs_subset_bool(shared->sub, "braille_friendly");
1282 const int index = menu_get_index(priv->menu);
1283 if (c_arrow_cursor)
1284 {
1285 const char *const c_arrow_string = cs_subset_string(shared->sub, "arrow_string");
1286 const int arrow_width = mutt_strwidth(c_arrow_string);
1287 mutt_window_move(priv->menu->win, index - priv->menu->top, arrow_width);
1288 }
1289 else if (c_braille_friendly)
1290 {
1291 mutt_window_move(priv->menu->win, index - priv->menu->top, 0);
1292 }
1293 else
1294 {
1295 mutt_window_move(priv->menu->win, index - priv->menu->top,
1296 priv->menu->win->state.cols - 1);
1297 }
1298 mutt_refresh();
1299
1300 window_redraw(NULL);
1302
1303 if (op == OP_REPAINT)
1304 {
1305 /* force a real complete redraw. clrtobot() doesn't seem to be able
1306 * to handle every case without this. */
1307 msgwin_clear_text(NULL);
1308 mutt_refresh();
1309 continue;
1310 }
1311
1312 /* either user abort or timeout */
1313 if (op < OP_NULL)
1314 {
1315 if (priv->tag_prefix)
1316 msgwin_clear_text(NULL);
1317 continue;
1318 }
1319
1320 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
1321
1322 /* special handling for the priv->tag-prefix function */
1323 const bool c_auto_tag = cs_subset_bool(shared->sub, "auto_tag");
1324 if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
1325 {
1326 /* A second priv->tag-prefix command aborts */
1327 if (priv->tag_prefix)
1328 {
1329 priv->tag_prefix = false;
1330 msgwin_clear_text(NULL);
1331 continue;
1332 }
1333
1334 if (!shared->mailbox)
1335 {
1336 mutt_error(_("No mailbox is open"));
1337 continue;
1338 }
1339
1340 if (shared->mailbox->msg_tagged == 0)
1341 {
1342 if (op == OP_TAG_PREFIX)
1343 {
1344 mutt_error(_("No tagged messages"));
1345 }
1346 else if (op == OP_TAG_PREFIX_COND)
1347 {
1349 mutt_message(_("Nothing to do"));
1350 }
1351 continue;
1352 }
1353
1354 /* get the real command */
1355 priv->tag_prefix = true;
1356 continue;
1357 }
1358 else if (c_auto_tag && shared->mailbox && (shared->mailbox->msg_tagged != 0))
1359 {
1360 priv->tag_prefix = true;
1361 }
1362
1364
1365 OptNews = false; /* for any case */
1366
1367#ifdef USE_NOTMUCH
1368 nm_db_debug_check(shared->mailbox);
1369#endif
1370
1371 rc = index_function_dispatcher(priv->win_index, op);
1372
1373 if (rc == FR_UNKNOWN)
1374 rc = menu_function_dispatcher(priv->win_index, op);
1375
1376 if (rc == FR_UNKNOWN)
1377 {
1378 struct MuttWindow *win_sidebar = window_find_child(dlg, WT_SIDEBAR);
1379 rc = sb_function_dispatcher(win_sidebar, op);
1380 }
1381 if (rc == FR_UNKNOWN)
1382 rc = global_function_dispatcher(NULL, op);
1383
1384 if (rc == FR_UNKNOWN)
1386
1387#ifdef USE_NOTMUCH
1388 nm_db_debug_check(shared->mailbox);
1389#endif
1390 } while (rc != FR_DONE);
1391
1392 mview_free(&shared->mailbox_view);
1393 window_set_focus(old_focus);
1394
1395 return shared->mailbox;
1396}
1397
1406void email_set_color(struct Mailbox *m, struct Email *e)
1407{
1408 if (!e)
1409 return;
1410
1411 struct RegexColor *color = NULL;
1412 struct PatternCache cache = { 0 };
1413
1414 const struct AttrColor *ac_merge = NULL;
1416 {
1418 MUTT_MATCH_FULL_ADDRESS, m, e, &cache))
1419 {
1420 ac_merge = merged_color_overlay(ac_merge, &color->attr_color);
1421 }
1422 }
1423
1424 struct AttrColor *ac_normal = simple_color_get(MT_COLOR_NORMAL);
1425 if (ac_merge)
1426 ac_merge = merged_color_overlay(ac_normal, ac_merge);
1427 else
1428 ac_merge = ac_normal;
1429
1430 e->attr_color = ac_merge;
1431}
1432
1438{
1442
1443 struct IndexSharedData *shared = index_shared_data_new();
1444 notify_set_parent(shared->notify, dlg->notify);
1445
1446 dlg->wdata = shared;
1448
1449 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
1450
1451 struct MuttWindow *panel_index = ipanel_new(c_status_on_top, shared);
1452 struct MuttWindow *panel_pager = ppanel_new(c_status_on_top, shared);
1453
1454 mutt_window_add_child(dlg, panel_index);
1455 mutt_window_add_child(dlg, panel_pager);
1456
1457 return dlg;
1458}
1459
1465void index_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
1466{
1467 if (!dlg || !m)
1468 return;
1469
1470 struct IndexSharedData *shared = dlg->wdata;
1471 if (!shared)
1472 return;
1473
1474 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1475 if (!panel_index)
1476 return;
1477
1478 struct IndexPrivateData *priv = panel_index->wdata;
1479 if (!priv)
1480 return;
1481
1482 change_folder_mailbox(priv->menu, m, &priv->oldcount, shared, false);
1483}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
Color and attribute parsing.
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a Colour ID.
Definition: regex.c:190
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:95
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:80
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:55
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:88
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:291
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
const struct Expando * cs_subset_expando(const struct ConfigSubset *sub, const char *name)
Get an Expando config item by name.
Definition: config_type.c:361
Convenience wrapper for the config headers.
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:38
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort.h:39
Connection Library.
Convenience wrapper for the core headers.
void mailbox_gc_run(void)
Run the garbage-collection.
Definition: mailbox.c:312
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:89
struct Mailbox * mailbox_find_name(const char *name)
Find the mailbox with a given name.
Definition: mailbox.c:187
@ NT_MAILBOX_DELETE
Mailbox is about to be deleted.
Definition: mailbox.h:183
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
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
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:385
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:343
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:79
void mutt_beep(bool force)
Irritate the user.
Definition: curs_lib.c:69
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:445
@ 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:138
const struct Mapping IndexNewsHelp[]
Help Bar for the News Index dialog.
Definition: dlg_index.c:117
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:611
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:732
void mutt_draw_statusline(struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
Draw a highlighted status bar.
Definition: dlg_index.c:959
void email_set_color(struct Mailbox *m, struct Email *e)
Select an Index colour for an Email.
Definition: dlg_index.c:1406
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:542
void index_change_folder(struct MuttWindow *dlg, struct Mailbox *m)
Change the current folder, cautiously.
Definition: dlg_index.c:1465
int find_first_message(struct MailboxView *mv)
Get index of first new message.
Definition: dlg_index.c:309
static const struct Mapping IndexHelp[]
Help Bar for the Index dialog.
Definition: dlg_index.c:102
static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
Update the index (if threaded)
Definition: dlg_index.c:411
void resort_index(struct MailboxView *mv, struct Menu *menu)
Resort the index.
Definition: dlg_index.c:369
int find_next_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the next undeleted email.
Definition: dlg_index.c:241
static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
Update the index (if unthreaded)
Definition: dlg_index.c:493
void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
Collapse/uncollapse all threads.
Definition: dlg_index.c:165
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:757
int mutt_make_string(struct Buffer *buf, size_t max_cols, const struct Expando *exp, struct Mailbox *m, int inpgr, struct Email *e, MuttFormatFlags flags, const char *progress)
Create formatted strings using mailbox expandos.
Definition: dlg_index.c:803
int find_previous_undeleted(struct MailboxView *mv, int msgno, bool uncollapse)
Find the previous undeleted email.
Definition: dlg_index.c:275
struct MuttWindow * index_pager_init(void)
Allocate the Windows for the Index/Pager.
Definition: dlg_index.c:1437
static void uncollapse_thread(struct MailboxView *mv, int index)
Open a collapsed thread.
Definition: dlg_index.c:219
Structs that make up an email.
void mutt_sort_headers(struct MailboxView *mv, bool init)
Sort emails by their headers.
Definition: sort.c:355
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:63
EmailSortType
Methods for sorting Emails.
Definition: sort.h:53
@ EMAIL_SORT_THREADS
Sort by email threads.
Definition: sort.h:62
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:1148
int expando_filter(const struct Expando *exp, const struct ExpandoRenderCallback *erc, void *data, MuttFormatFlags flags, int max_cols, char **env_list, struct Buffer *buf)
Render an Expando and run the result through a filter.
Definition: filter.c:139
Parse Expando string.
const struct ExpandoRenderCallback IndexRenderCallbacks[]
Callbacks for Index Expandos.
String processing routines to generate the mail index.
int km_dokey(enum MenuType mtype, GetChFlags flags)
Determine what a keypress should do.
Definition: get.c:537
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: get.c:166
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: get.c:294
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:64
char * LastFolder
Previously selected mailbox.
Definition: globals.c:40
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:39
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:185
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:318
int index_function_dispatcher(struct MuttWindow *win, int op)
Perform an Index function - Implements function_dispatcher_t -.
Definition: functions.c:3259
struct Mailbox * dlg_index(struct MuttWindow *dlg, struct Mailbox *m_init)
Display a list of emails -.
Definition: dlg_index.c:1100
#define mutt_error(...)
Definition: logging2.h:93
#define mutt_message(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:90
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:927
int index_make_entry(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Format an Email for the Menu - Implements Menu::make_entry() -.
Definition: dlg_index.c:826
static int index_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: dlg_index.c:585
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:278
Convenience wrapper for the gui headers.
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition: hook.c:632
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:235
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:264
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:307
void index_shared_data_set_mview(struct IndexSharedData *shared, struct MailboxView *mv)
Set the MailboxView for the Index and friends.
Definition: shared_data.c:160
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:184
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:48
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:44
#define FREE(x)
Definition: memory.h:55
#define MIN(a, b)
Definition: memory.h:32
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition: memory.h:43
#define MUTT_MEM_MALLOC(n, type)
Definition: memory.h:41
#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:59
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
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:484
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:528
Monitor files for changes.
void msgwin_clear_text(struct MuttWindow *win)
Clear the text in the Message Window.
Definition: msgwin.c:519
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:254
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:281
void mutt_curses_set_color(const struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:38
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:169
bool mutt_mailbox_notify(struct Mailbox *m_cur)
Notify the user if there's new mail.
Definition: mutt_mailbox.c:235
Mailbox helper functions.
void mutt_thread_collapse(struct ThreadsContext *tctx, bool collapse)
Toggle collapse.
Definition: mutt_thread.c:1789
enum UseThreads mutt_thread_style(void)
Which threading style is active?
Definition: mutt_thread.c:81
off_t mutt_set_vnum(struct Mailbox *m)
Set the virtual index number of all the messages in a mailbox.
Definition: mutt_thread.c:1404
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1817
int mutt_parent_message(struct Email *e, bool find_root)
Find the parent of a message.
Definition: mutt_thread.c:1354
Create/manipulate threading in emails.
UseThreads
Which threading style is active, $use_threads.
Definition: mutt_thread.h:96
@ UT_FLAT
Unthreaded.
Definition: mutt_thread.h:98
@ UT_THREADS
Normal threading (root above subthreads)
Definition: mutt_thread.h:99
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition: mutt_thread.h:100
#define mutt_using_threads()
Definition: mutt_thread.h:113
#define mutt_uncollapse_thread(e)
Definition: mutt_thread.h:107
#define mutt_collapse_thread(e)
Definition: mutt_thread.h:106
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:599
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:309
void mutt_window_add_child(struct MuttWindow *parent, struct MuttWindow *child)
Add a child to Window.
Definition: mutt_window.c:411
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
struct MuttWindow * window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:649
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:300
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:498
int mutt_window_addnstr(struct MuttWindow *win, const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:366
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:87
@ 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:40
#define MUTT_WIN_SIZE_UNLIMITED
Use as much space as possible.
Definition: mutt_window.h:53
@ MUTT_WIN_SIZE_MAXIMISE
Window wants as much space as possible.
Definition: mutt_window.h:49
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:1510
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:288
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:1641
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1110
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:598
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:50
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition: mxapi.h:40
#define MUTT_MAILBOX_CHECK_POSTPONED
Make sure the number of postponed messages is updated.
Definition: mxapi.h:51
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_sync(), and mbox_close()
Definition: mxapi.h:60
@ MX_STATUS_ERROR
An error occurred.
Definition: mxapi.h:61
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:62
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mxapi.h:66
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:65
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:63
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:556
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:397
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:1599
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:36
#define OP_REPAINT
Repaint is needed.
Definition: opcodes.h:34
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:133
Private state data for the Pager.
Match patterns to emails.
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:106
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
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:390
#define SLIST_FIRST(head)
Definition: queue.h:227
#define MUTT_FORMAT_FORCESUBJ
Print the subject even if unchanged.
Definition: render.h:34
#define MUTT_FORMAT_INDEX
This is a main index entry.
Definition: render.h:38
#define MUTT_FORMAT_TREE
Draw the thread tree.
Definition: render.h:35
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: render.h:37
uint8_t MuttFormatFlags
Flags for expando_render(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: render.h:32
Sidebar functions.
GUI display the mailboxes in a side panel.
GUI display the mailboxes in a side panel.
#define ASSERT(COND)
Definition: signal2.h:60
void menu_status_line(struct Buffer *buf, struct IndexSharedData *shared, struct Menu *menu, int max_cols, const struct Expando *exp)
Create the status line.
Definition: status.c:51
GUI display a user-configurable status line.
Key value store.
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:81
String manipulation buffer.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:39
char * data
Pointer to data.
Definition: buffer.h:37
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
Data passed to index_format_str()
Definition: private.h:37
struct Email * email
Current Email.
Definition: private.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition: private.h:38
int msg_in_pager
Index of Email displayed in the Pager.
Definition: private.h:39
const char * pager_progress
String representing Pager position through Email.
Definition: private.h:41
The envelope/body of an email.
Definition: email.h:39
bool read
Email is read.
Definition: email.h:50
bool display_subject
Used for threading.
Definition: email.h:101
bool visible
Is this message part of the view?
Definition: email.h:121
bool limit_visited
Has the limit pattern been applied to this message?
Definition: email.h:122
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:120
struct Body * body
List of MIME parts.
Definition: email.h:69
char * tree
Character string to print thread tree.
Definition: email.h:125
bool old
Email is seen, but unread.
Definition: email.h:49
LOFF_T offset
Where in the stream does this message begin?
Definition: email.h:71
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:112
int vnum
Virtual message number.
Definition: email.h:114
int msgno
Number displayed to the user.
Definition: email.h:111
bool deleted
Email is deleted.
Definition: email.h:78
int index
The absolute (unsorted) message number.
Definition: email.h:110
struct MuttThread * thread
Thread of Emails.
Definition: email.h:119
An Event that happened to a Mailbox.
Definition: mailbox.h:199
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:200
Parsed Expando trees.
Definition: expando.h:41
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:40
bool collapsed
Are all threads collapsed?
Definition: mview.h:49
struct Menu * menu
Needed for pattern compilation.
Definition: mview.h:47
off_t vsize
Size (in bytes) of the messages shown.
Definition: mview.h:41
struct PatternList * limit_pattern
Compiled limit pattern.
Definition: mview.h:43
struct ThreadsContext * threads
Threads context.
Definition: mview.h:44
int msg_in_pager
Message currently shown in the pager.
Definition: mview.h:45
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
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:119
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:145
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
void * compress_info
Compressed mbox module private data.
Definition: mailbox.h:121
int msg_tagged
How many messages are tagged?
Definition: mailbox.h:94
bool verbose
Display status messages?
Definition: mailbox.h:117
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
Mapping between user-readable string and a constant.
Definition: mapping.h:33
Definition: lib.h:79
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:86
int current
Current entry.
Definition: lib.h:80
const struct AttrColor *(* color)(struct Menu *menu, int line)
Definition: lib.h:143
int top
Entry that is the top of the current page.
Definition: lib.h:90
int(* make_entry)(struct Menu *menu, int line, int max_cols, struct Buffer *buf)
Definition: lib.h:106
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:87
void * mdata
Private data.
Definition: lib.h:147
int max
Number of entries in the menu.
Definition: lib.h:81
int page_len
Number of entries per screen.
Definition: lib.h:84
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:43
char ** env
Private copy of the environment variables.
Definition: neomutt.h:55
struct Notify * notify
Notifications handler.
Definition: neomutt.h:44
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:47
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:37
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
@ MENU_INDEX
Index panel (list of emails)
Definition: type.h:47