NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

GUI manage the main index (list of emails) More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "functions.h"
#include "shared_data.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NT_INDEX_NO_FLAGS   0
 No flags are set.
 
#define NT_INDEX_ADD   (1 << 0)
 New Index Shared Data has been created.
 
#define NT_INDEX_DELETE   (1 << 1)
 Index Shared Data is about to be freed.
 
#define NT_INDEX_SUBSET   (1 << 2)
 Config Subset has changed.
 
#define NT_INDEX_ACCOUNT   (1 << 3)
 Account has changed.
 
#define NT_INDEX_MVIEW   (1 << 4)
 MailboxView has changed.
 
#define NT_INDEX_MAILBOX   (1 << 5)
 Mailbox has changed.
 
#define NT_INDEX_EMAIL   (1 << 6)
 Email has changed.
 
#define CHECK_NO_FLAGS   0
 No flags are set.
 
#define CHECK_IN_MAILBOX   (1 << 0)
 Is there a mailbox open?
 
#define CHECK_MSGCOUNT   (1 << 1)
 Are there any messages?
 
#define CHECK_VISIBLE   (1 << 2)
 Is the selected message visible in the index?
 
#define CHECK_READONLY   (1 << 3)
 Is the mailbox readonly?
 
#define CHECK_ATTACH   (1 << 4)
 Is the user in message-attach mode?
 

Typedefs

typedef uint8_t NotifyIndex
 Flags, e.g. NT_INDEX_ACCOUNT.
 
typedef uint8_t CheckFlags
 Flags, e.g. CHECK_IN_MAILBOX.
 

Functions

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.
 
struct Mailboxchange_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.
 
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.
 
bool check_acl (struct Mailbox *m, AclFlags acl, const char *msg)
 Check the ACLs for a function.
 
void collapse_all (struct MailboxView *mv, struct Menu *menu, int toggle)
 Collapse/uncollapse all threads.
 
struct Mailboxdlg_index (struct MuttWindow *dlg, struct Mailbox *m)
 Display a list of emails -.
 
int find_first_message (struct MailboxView *mv)
 Get index of first new message.
 
int find_next_undeleted (struct MailboxView *mv, int msgno, bool uncollapse)
 Find the next undeleted email.
 
int find_previous_undeleted (struct MailboxView *mv, int msgno, bool uncollapse)
 Find the previous undeleted email.
 
struct Mailboxget_current_mailbox (void)
 Get the current Mailbox.
 
struct MailboxViewget_current_mailbox_view (void)
 Get the current Mailbox view.
 
struct Menuget_current_menu (void)
 Get the current Menu.
 
void index_change_folder (struct MuttWindow *dlg, struct Mailbox *m)
 Change the current folder, cautiously.
 
const struct AttrColorindex_color (struct Menu *menu, int line)
 Calculate the colour for a line of the index - Implements Menu::color() -.
 
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() -.
 
struct MuttWindowindex_pager_init (void)
 Allocate the Windows for the Index/Pager.
 
int mutt_dlgindex_observer (struct NotifyCallback *nc)
 
void mutt_draw_statusline (struct MuttWindow *win, int max_cols, const char *buf, size_t buflen)
 Draw a highlighted status bar.
 
void mutt_set_header_color (struct Mailbox *m, struct Email *e)
 Select a colour for a message.
 
void resort_index (struct MailboxView *mv, struct Menu *menu)
 Resort the index.
 
void update_index (struct Menu *menu, struct MailboxView *mv, enum MxStatus check, int oldcount, const struct IndexSharedData *shared)
 Update the index.
 

Variables

const struct Mapping IndexNewsHelp []
 Help Bar for the News Index dialog.
 

Detailed Description

GUI manage the main index (list of emails)

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ NT_INDEX_NO_FLAGS

#define NT_INDEX_NO_FLAGS   0

No flags are set.

Definition at line 58 of file lib.h.

◆ NT_INDEX_ADD

#define NT_INDEX_ADD   (1 << 0)

New Index Shared Data has been created.

Definition at line 59 of file lib.h.

◆ NT_INDEX_DELETE

#define NT_INDEX_DELETE   (1 << 1)

Index Shared Data is about to be freed.

Definition at line 60 of file lib.h.

◆ NT_INDEX_SUBSET

#define NT_INDEX_SUBSET   (1 << 2)

Config Subset has changed.

Definition at line 61 of file lib.h.

◆ NT_INDEX_ACCOUNT

#define NT_INDEX_ACCOUNT   (1 << 3)

Account has changed.

Definition at line 62 of file lib.h.

◆ NT_INDEX_MVIEW

#define NT_INDEX_MVIEW   (1 << 4)

MailboxView has changed.

Definition at line 63 of file lib.h.

◆ NT_INDEX_MAILBOX

#define NT_INDEX_MAILBOX   (1 << 5)

Mailbox has changed.

Definition at line 64 of file lib.h.

◆ NT_INDEX_EMAIL

#define NT_INDEX_EMAIL   (1 << 6)

Email has changed.

Definition at line 65 of file lib.h.

◆ CHECK_NO_FLAGS

#define CHECK_NO_FLAGS   0

No flags are set.

Definition at line 68 of file lib.h.

◆ CHECK_IN_MAILBOX

#define CHECK_IN_MAILBOX   (1 << 0)

Is there a mailbox open?

Definition at line 69 of file lib.h.

◆ CHECK_MSGCOUNT

#define CHECK_MSGCOUNT   (1 << 1)

Are there any messages?

Definition at line 70 of file lib.h.

◆ CHECK_VISIBLE

#define CHECK_VISIBLE   (1 << 2)

Is the selected message visible in the index?

Definition at line 71 of file lib.h.

◆ CHECK_READONLY

#define CHECK_READONLY   (1 << 3)

Is the mailbox readonly?

Definition at line 72 of file lib.h.

◆ CHECK_ATTACH

#define CHECK_ATTACH   (1 << 4)

Is the user in message-attach mode?

Definition at line 73 of file lib.h.

Typedef Documentation

◆ NotifyIndex

typedef uint8_t NotifyIndex

Flags, e.g. NT_INDEX_ACCOUNT.

Definition at line 57 of file lib.h.

◆ CheckFlags

typedef uint8_t CheckFlags

Flags, e.g. CHECK_IN_MAILBOX.

Definition at line 67 of file lib.h.

Function Documentation

◆ change_folder_mailbox()

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.

Parameters
menuCurrent Menu
mMailbox
oldcountHow many items are currently in the index
sharedShared Index data
read_onlyOpen Mailbox in read-only mode

Definition at line 613 of file dlg_index.c.

615{
616 if (!m)
617 return;
618
619 /* keepalive failure in mutt_enter_fname may kill connection. */
620 if (shared->mailbox && (buf_is_empty(&shared->mailbox->pathbuf)))
621 {
622 mview_free(&shared->mailbox_view);
623 mailbox_free(&shared->mailbox);
624 }
625
626 if (shared->mailbox)
627 {
628 char *new_last_folder = NULL;
629#ifdef USE_INOTIFY
630 int monitor_remove_rc = mutt_monitor_remove(NULL);
631#endif
632 if (shared->mailbox->compress_info && (shared->mailbox->realpath[0] != '\0'))
633 new_last_folder = mutt_str_dup(shared->mailbox->realpath);
634 else
635 new_last_folder = mutt_str_dup(mailbox_path(shared->mailbox));
636 *oldcount = shared->mailbox->msg_count;
637
638 const enum MxStatus check = mx_mbox_close(shared->mailbox);
639 if (check == MX_STATUS_OK)
640 {
641 mview_free(&shared->mailbox_view);
642 if (shared->mailbox != m)
643 {
644 mailbox_free(&shared->mailbox);
645 }
646 }
647 else
648 {
649#ifdef USE_INOTIFY
650 if (monitor_remove_rc == 0)
651 mutt_monitor_add(NULL);
652#endif
653 if ((check == MX_STATUS_NEW_MAIL) || (check == MX_STATUS_REOPENED))
654 update_index(menu, shared->mailbox_view, check, *oldcount, shared);
655
656 FREE(&new_last_folder);
659 return;
660 }
662 LastFolder = new_last_folder;
663 }
665
666 /* If the `folder-hook` were to call `unmailboxes`, then the Mailbox (`m`)
667 * could be deleted, leaving `m` dangling. */
668 // TODO: Refactor this function to avoid the need for an observer
670 char *dup_path = mutt_str_dup(mailbox_path(m));
671 char *dup_name = mutt_str_dup(m->name);
672
673 mutt_folder_hook(dup_path, dup_name);
674 if (m)
675 {
676 /* `m` is still valid, but we won't need the observer again before the end
677 * of the function. */
679 }
680 else
681 {
682 // Recreate the Mailbox as the folder-hook might have invoked `mailboxes`
683 // and/or `unmailboxes`.
684 m = mx_path_resolve(dup_path);
685 }
686
687 FREE(&dup_path);
688 FREE(&dup_name);
689
690 if (!m)
691 return;
692
693 const OpenMailboxFlags flags = read_only ? MUTT_READONLY : MUTT_OPEN_NO_FLAGS;
694 if (mx_mbox_open(m, flags))
695 {
696 struct MailboxView *mv = mview_new(m, NeoMutt->notify);
697 index_shared_data_set_mview(shared, mv);
698
699 menu->max = m->msg_count;
701#ifdef USE_INOTIFY
702 mutt_monitor_add(NULL);
703#endif
704 }
705 else
706 {
707 index_shared_data_set_mview(shared, NULL);
709 }
710
711 const bool c_collapse_all = cs_subset_bool(shared->sub, "collapse_all");
712 if (mutt_using_threads() && c_collapse_all)
713 collapse_all(shared->mailbox_view, menu, 0);
714
716 /* force the mailbox check after we have changed the folder */
717 struct EventMailbox ev_m = { shared->mailbox };
721}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:290
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:777
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:90
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
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:544
int find_first_message(struct MailboxView *mv)
Get index of first new message.
Definition: dlg_index.c:311
void collapse_all(struct MailboxView *mv, struct Menu *menu, int toggle)
Collapse/uncollapse all threads.
Definition: dlg_index.c:167
char * LastFolder
Previously selected mailbox.
Definition: globals.c:44
char * CurrentFolder
Currently selected mailbox.
Definition: globals.c:43
static int index_mailbox_observer(struct NotifyCallback *nc)
Notification that a Mailbox has changed - Implements observer_t -.
Definition: dlg_index.c:587
void mutt_folder_hook(const char *path, const char *desc)
Perform a folder hook.
Definition: hook.c:623
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
#define FREE(x)
Definition: memory.h:45
#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
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:483
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:527
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
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:329
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:168
#define mutt_using_threads()
Definition: mutt_thread.h:114
void mview_free(struct MailboxView **ptr)
Free a MailboxView.
Definition: mview.c:50
struct MailboxView * mview_new(struct Mailbox *m, struct Notify *parent)
Create a new MailboxView.
Definition: mview.c:91
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:286
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1634
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
Definition: mx.c:596
#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_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_sync(), and mbox_close()
Definition: mxapi.h:63
@ MX_STATUS_OK
No changes.
Definition: mxapi.h:65
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mxapi.h:68
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mxapi.h:66
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
An Event that happened to a Mailbox.
Definition: mailbox.h:199
struct Mailbox * mailbox
The Mailbox this Event relates to.
Definition: mailbox.h:200
struct Mailbox * mailbox
Current Mailbox.
Definition: shared_data.h:41
struct ConfigSubset * sub
Config set to use.
Definition: shared_data.h:38
struct MailboxView * mailbox_view
Current Mailbox view.
Definition: shared_data.h:40
struct SearchState * search_state
State of the current search.
Definition: shared_data.h:45
View of a Mailbox.
Definition: mview.h:40
struct Menu * menu
Needed for pattern compilation.
Definition: mview.h:47
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
int msg_count
Total number of messages.
Definition: mailbox.h:88
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 max
Number of entries in the menu.
Definition: lib.h:81
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
struct PatternList * pattern
compiled search pattern
Definition: search_state.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ change_folder_notmuch()

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.

Parameters
menuCurrent Menu
bufFolder to change to
buflenLength of buffer
oldcountHow many items are currently in the index
sharedShared Index data
read_onlyOpen Mailbox in read-only mode
Return values
ptrMailbox

Definition at line 734 of file dlg_index.c.

736{
737 if (!nm_url_from_query(NULL, buf, buflen))
738 {
739 mutt_message(_("Failed to create query, aborting"));
740 return NULL;
741 }
742
743 struct Mailbox *m_query = mx_path_resolve(buf);
744 change_folder_mailbox(menu, m_query, oldcount, shared, read_only);
745 if (!shared->mailbox_view)
746 mailbox_free(&m_query);
747 return m_query;
748}
void change_folder_mailbox(struct Menu *menu, struct Mailbox *m, int *oldcount, struct IndexSharedData *shared, bool read_only)
Change to a different Mailbox by pointer.
Definition: dlg_index.c:613
#define mutt_message(...)
Definition: logging2.h:91
#define _(a)
Definition: message.h:28
char * nm_url_from_query(struct Mailbox *m, char *buf, size_t buflen)
Turn a query into a URL.
Definition: notmuch.c:1579
A mailbox.
Definition: mailbox.h:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ change_folder_string()

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.

Parameters
menuCurrent Menu
bufFolder to change to
oldcountHow many items are currently in the index
sharedShared Index data
read_onlyOpen Mailbox in read-only mode

Definition at line 759 of file dlg_index.c.

761{
762 if (OptNews)
763 {
764 OptNews = false;
766 }
767 else
768 {
769 const char *const c_folder = cs_subset_string(shared->sub, "folder");
770 mx_path_canon(buf, c_folder, NULL);
771 }
772
773 enum MailboxType type = mx_path_probe(buf_string(buf));
774 if ((type == MUTT_MAILBOX_ERROR) || (type == MUTT_UNKNOWN))
775 {
776 // Look for a Mailbox by its description, before failing
777 struct Mailbox *m = mailbox_find_name(buf_string(buf));
778 if (m)
779 {
780 change_folder_mailbox(menu, m, oldcount, shared, read_only);
781 }
782 else
783 {
784 mutt_error(_("%s is not a mailbox"), buf_string(buf));
785 }
786 return;
787 }
788
789 struct Mailbox *m = mx_path_resolve(buf_string(buf));
790 change_folder_mailbox(menu, m, oldcount, shared, read_only);
791}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
struct Mailbox * mailbox_find_name(const char *name)
Find the mailbox with a given name.
Definition: mailbox.c:188
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_MAILBOX_ERROR
Error occurred examining Mailbox.
Definition: mailbox.h:43
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:70
#define mutt_error(...)
Definition: logging2.h:92
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:1365
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1319
void nntp_expand_path(char *buf, size_t buflen, struct ConnAccount *acct)
Make fully qualified url from newsgroup name.
Definition: newsrc.c:567
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
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
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_acl()

bool check_acl ( struct Mailbox m,
AclFlags  acl,
const char *  msg 
)

Check the ACLs for a function.

Parameters
mMailbox
aclACL, see AclFlags
msgError message for failure
Return values
trueThe function is permitted

Definition at line 140 of file dlg_index.c.

141{
142 if (!m)
143 return false;
144
145 if (!(m->rights & acl))
146 {
147 /* L10N: %s is one of the CHECK_ACL entries below. */
148 mutt_error(_("%s: Operation not permitted by ACL"), msg);
149 return false;
150 }
151
152 return true;
153}
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:119
+ Here is the caller graph for this function:

◆ collapse_all()

void collapse_all ( struct MailboxView mv,
struct Menu menu,
int  toggle 
)

Collapse/uncollapse all threads.

Parameters
mvMailbox View
menucurrent menu
toggletoggle collapsed state

This function is called by the OP_MAIN_COLLAPSE_ALL command and on folder enter if the $collapse_all option is set. In the first case, the toggle parameter is 1 to actually toggle collapsed/uncollapsed state on all threads. In the second case, the toggle parameter is 0, actually turning this function into a one-way collapse.

Definition at line 167 of file dlg_index.c.

168{
169 if (!mv || !mv->mailbox || (mv->mailbox->msg_count == 0) || !menu)
170 return;
171
172 struct Email *e_cur = mutt_get_virt_email(mv->mailbox, menu_get_index(menu));
173 if (!e_cur)
174 return;
175
176 int final;
177
178 /* Figure out what the current message would be after folding / unfolding,
179 * so that we can restore the cursor in a sane way afterwards. */
180 if (e_cur->collapsed && toggle)
181 final = mutt_uncollapse_thread(e_cur);
182 else if (mutt_thread_can_collapse(e_cur))
183 final = mutt_collapse_thread(e_cur);
184 else
185 final = e_cur->vnum;
186
187 if (final == -1)
188 return;
189
190 struct Email *base = mutt_get_virt_email(mv->mailbox, final);
191 if (!base)
192 return;
193
194 /* Iterate all threads, perform collapse/uncollapse as needed */
195 mv->collapsed = toggle ? !mv->collapsed : true;
197
198 /* Restore the cursor */
200 menu->max = mv->mailbox->vcount;
201 for (int i = 0; i < mv->mailbox->vcount; i++)
202 {
203 struct Email *e = mutt_get_virt_email(mv->mailbox, i);
204 if (!e)
205 break;
206 if (e->index == base->index)
207 {
208 menu_set_index(menu, i);
209 break;
210 }
211 }
212
214}
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
void mutt_thread_collapse(struct ThreadsContext *tctx, bool collapse)
Toggle collapse.
Definition: mutt_thread.c:1790
off_t mutt_set_vnum(struct Mailbox *m)
Set the virtual index number of all the messages in a mailbox.
Definition: mutt_thread.c:1405
bool mutt_thread_can_collapse(struct Email *e)
Check whether a thread can be collapsed.
Definition: mutt_thread.c:1818
#define mutt_uncollapse_thread(e)
Definition: mutt_thread.h:108
#define mutt_collapse_thread(e)
Definition: mutt_thread.h:107
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: mview.c:418
The envelope/body of an email.
Definition: email.h:39
bool collapsed
Is this message part of a collapsed thread?
Definition: email.h:123
int vnum
Virtual message number.
Definition: email.h:117
int index
The absolute (unsorted) message number.
Definition: email.h:113
bool collapsed
Are all threads collapsed?
Definition: mview.h:49
struct ThreadsContext * threads
Threads context.
Definition: mview.h:44
struct Mailbox * mailbox
Current Mailbox.
Definition: mview.h:51
int vcount
The number of virtual messages.
Definition: mailbox.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_first_message()

int find_first_message ( struct MailboxView mv)

Get index of first new message.

Parameters
mvMailbox view
Return values
numIndex of first new message

Return the index of the first new message, or failing that, the first unread message.

Definition at line 311 of file dlg_index.c.

312{
313 if (!mv)
314 return 0;
315
316 struct Mailbox *m = mv->mailbox;
317 if (!m || (m->msg_count == 0))
318 return 0;
319
320 int old = -1;
321 for (int i = 0; i < m->vcount; i++)
322 {
323 struct Email *e = mutt_get_virt_email(m, i);
324 if (!e)
325 continue;
326 if (!e->read && !e->deleted)
327 {
328 if (!e->old)
329 return i;
330 if (old == -1)
331 old = i;
332 }
333 }
334 if (old != -1)
335 return old;
336
337 /* If `$use_threads` is not threaded and `$sort` is reverse, the latest
338 * message is first. Otherwise, the latest message is first if exactly
339 * one of `$use_threads` and `$sort` are reverse.
340 */
341 enum SortType c_sort = cs_subset_sort(m->sub, "sort");
342 if ((c_sort & SORT_MASK) == SORT_THREADS)
343 c_sort = cs_subset_sort(m->sub, "sort_aux");
344 bool reverse = false;
345 switch (mutt_thread_style())
346 {
347 case UT_FLAT:
348 reverse = c_sort & SORT_REVERSE;
349 break;
350 case UT_THREADS:
351 reverse = c_sort & SORT_REVERSE;
352 break;
353 case UT_REVERSE:
354 reverse = !(c_sort & SORT_REVERSE);
355 break;
356 default:
357 assert(false);
358 }
359
360 if (reverse || (m->vcount == 0))
361 return 0;
362
363 return m->vcount - 1;
364}
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
enum UseThreads mutt_thread_style(void)
Which threading style is active?
Definition: mutt_thread.c:83
@ UT_FLAT
Unthreaded.
Definition: mutt_thread.h:99
@ UT_THREADS
Normal threading (root above subthreads)
Definition: mutt_thread.h:100
@ UT_REVERSE
Reverse threading (subthreads above root)
Definition: mutt_thread.h:101
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_THREADS
Sort by email threads.
Definition: sort2.h:41
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:71
bool read
Email is read.
Definition: email.h:50
bool old
Email is seen, but unread.
Definition: email.h:49
bool deleted
Email is deleted.
Definition: email.h:78
struct ConfigSubset * sub
Inherited config items.
Definition: mailbox.h:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_next_undeleted()

int find_next_undeleted ( struct MailboxView mv,
int  msgno,
bool  uncollapse 
)

Find the next undeleted email.

Parameters
mvMailbox view
msgnoMessage number to start at
uncollapseOpen collapsed threads
Return values
>=0Message number of next undeleted email
-1No more undeleted messages

Definition at line 243 of file dlg_index.c.

244{
245 if (!mv || !mv->mailbox)
246 return -1;
247
248 struct Mailbox *m = mv->mailbox;
249
250 int index = -1;
251 for (int i = msgno + 1; i < m->vcount; i++)
252 {
253 struct Email *e = mutt_get_virt_email(m, i);
254 if (!e)
255 continue;
256 if (!e->deleted)
257 {
258 index = i;
259 break;
260 }
261 }
262
263 if (uncollapse)
265
266 return index;
267}
static void uncollapse_thread(struct MailboxView *mv, int index)
Open a collapsed thread.
Definition: dlg_index.c:221
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_previous_undeleted()

int find_previous_undeleted ( struct MailboxView mv,
int  msgno,
bool  uncollapse 
)

Find the previous undeleted email.

Parameters
mvMailbox View
msgnoMessage number to start at
uncollapseOpen collapsed threads
Return values
>=0Message number of next undeleted email
-1No more undeleted messages

Definition at line 277 of file dlg_index.c.

278{
279 if (!mv || !mv->mailbox)
280 return -1;
281
282 struct Mailbox *m = mv->mailbox;
283
284 int index = -1;
285 for (int i = msgno - 1; i >= 0; i--)
286 {
287 struct Email *e = mutt_get_virt_email(m, i);
288 if (!e)
289 continue;
290 if (!e->deleted)
291 {
292 index = i;
293 break;
294 }
295 }
296
297 if (uncollapse)
299
300 return index;
301}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_mailbox()

struct Mailbox * get_current_mailbox ( void  )

Get the current Mailbox.

Return values
ptrCurrent Mailbox

Search for the last (most recent) dialog that has an Index. Then return the Mailbox from its shared data.

Definition at line 715 of file index.c.

716{
718 if (mv)
719 return mv->mailbox;
720
721 return NULL;
722}
struct MailboxView * get_current_mailbox_view(void)
Get the current Mailbox view.
Definition: index.c:683
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_mailbox_view()

struct MailboxView * get_current_mailbox_view ( void  )

Get the current Mailbox view.

Return values
ptrCurrent Mailbox view

Search for the last (most recent) dialog that has an Index. Then return the Mailbox from its shared data.

Definition at line 683 of file index.c.

684{
685 if (!AllDialogsWindow)
686 return NULL;
687
688 struct MuttWindow *np = NULL;
689 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
690 {
691 struct MuttWindow *win = window_find_child(np, WT_DLG_INDEX);
692 if (win)
693 {
694 struct IndexSharedData *shared = win->wdata;
695 return shared->mailbox_view;
696 }
697
699 if (win)
700 {
701 return postponed_get_mailbox_view(win);
702 }
703 }
704
705 return NULL;
706}
struct MuttWindow * AllDialogsWindow
Parent of all Dialogs.
Definition: dialog.c:80
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
@ WT_DLG_INDEX
Index Dialog, dlg_index()
Definition: mutt_window.h:86
@ WT_DLG_POSTPONED
Postponed Dialog, dlg_postponed()
Definition: mutt_window.h:89
struct MailboxView * postponed_get_mailbox_view(struct MuttWindow *dlg)
Extract the Mailbox from the Postponed Dialog.
Definition: functions.c:213
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:745
Data shared between Index, Pager and Sidebar.
Definition: shared_data.h:37
void * wdata
Private data.
Definition: mutt_window.h:145
struct MuttWindowList children
Children Windows.
Definition: mutt_window.h:136
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_menu()

struct Menu * get_current_menu ( void  )

Get the current Menu.

Return values
ptrCurrent Menu

Search for the last (most recent) dialog that has an Index. Then return the Menu from its private data.

Definition at line 731 of file index.c.

732{
733 if (!AllDialogsWindow)
734 return NULL;
735
736 struct MuttWindow *np = NULL;
737 TAILQ_FOREACH_REVERSE(np, &AllDialogsWindow->children, MuttWindowList, entries)
738 {
739 struct MuttWindow *dlg = window_find_child(np, WT_DLG_INDEX);
740 if (dlg)
741 {
742 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
743 struct IndexPrivateData *priv = panel_index->wdata;
744 return priv->menu;
745 }
746 }
747
748 return NULL;
749}
@ WT_INDEX
A panel containing the Index Window.
Definition: mutt_window.h:97
Private state data for the Index.
Definition: private_data.h:35
struct Menu * menu
Menu controlling the index.
Definition: private_data.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_change_folder()

void index_change_folder ( struct MuttWindow dlg,
struct Mailbox m 
)

Change the current folder, cautiously.

Parameters
dlgDialog holding the Index
mMailbox to change to

Definition at line 1433 of file dlg_index.c.

1434{
1435 if (!dlg || !m)
1436 return;
1437
1438 struct IndexSharedData *shared = dlg->wdata;
1439 if (!shared)
1440 return;
1441
1442 struct MuttWindow *panel_index = window_find_child(dlg, WT_INDEX);
1443 if (!panel_index)
1444 return;
1445
1446 struct IndexPrivateData *priv = panel_index->wdata;
1447 if (!priv)
1448 return;
1449
1450 change_folder_mailbox(priv->menu, m, &priv->oldcount, shared, false);
1451}
struct IndexSharedData * shared
Shared Index data.
Definition: private_data.h:40
int oldcount
Old count of mails in the mailbox.
Definition: private_data.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ index_pager_init()

struct MuttWindow * index_pager_init ( void  )

Allocate the Windows for the Index/Pager.

Return values
ptrDialog containing nested Windows

Definition at line 1405 of file dlg_index.c.

1406{
1410
1411 struct IndexSharedData *shared = index_shared_data_new();
1412 notify_set_parent(shared->notify, dlg->notify);
1413
1414 dlg->wdata = shared;
1416
1417 const bool c_status_on_top = cs_subset_bool(NeoMutt->sub, "status_on_top");
1418
1419 struct MuttWindow *panel_index = ipanel_new(c_status_on_top, shared);
1420 struct MuttWindow *panel_pager = ppanel_new(c_status_on_top, shared);
1421
1422 mutt_window_add_child(dlg, panel_index);
1423 mutt_window_add_child(dlg, panel_pager);
1424
1425 return dlg;
1426}
void index_shared_data_free(struct MuttWindow *win, void **ptr)
Free Shared Index Data - Implements MuttWindow::wdata_free() -.
Definition: shared_data.c:278
struct IndexSharedData * index_shared_data_new(void)
Create new Index Data.
Definition: shared_data.c:307
struct MuttWindow * ipanel_new(bool status_on_top, struct IndexSharedData *shared)
Create the Windows for the Index panel.
Definition: ipanel.c:121
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:95
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
@ 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 MuttWindow * ppanel_new(bool status_on_top, struct IndexSharedData *shared)
Create the Windows for the Pager panel.
Definition: ppanel.c:121
struct Notify * notify
Notifications: NotifyIndex, IndexSharedData.
Definition: shared_data.h:44
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
void(* wdata_free)(struct MuttWindow *win, void **ptr)
Definition: mutt_window.h:159
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_dlgindex_observer()

int mutt_dlgindex_observer ( struct NotifyCallback nc)

◆ mutt_draw_statusline()

void mutt_draw_statusline ( struct MuttWindow win,
int  max_cols,
const char *  buf,
size_t  buflen 
)

Draw a highlighted status bar.

Parameters
winWindow
max_colsMaximum number of screen columns
bufMessage to be displayed
buflenLength of the buffer

Users configure the highlighting of the status bar, e.g. color status red default "[0-9][0-9]:[0-9][0-9]"

Where regexes overlap, the one nearest the start will be used. If two regexes start at the same place, the longer match will be used.

Colours of the status bar

< First character of that colour

< Last character of that colour

Definition at line 930 of file dlg_index.c.

931{
932 if (!buf || !stdscr)
933 return;
934
935 size_t i = 0;
936 size_t offset = 0;
937 bool found = false;
938 size_t chunks = 0;
939 size_t len = 0;
940
944 struct StatusSyntax
945 {
946 const struct AttrColor *attr_color;
947 int first;
948 int last;
949 } *syntax = NULL;
950
953 do
954 {
955 struct RegexColor *cl = NULL;
956 found = false;
957
958 if (!buf[offset])
959 break;
960
961 /* loop through each "color status regex" */
963 {
964 regmatch_t pmatch[cl->match + 1];
965 memset(pmatch, 0, (cl->match + 1) * sizeof(regmatch_t));
966
967 if (regexec(&cl->regex, buf + offset, cl->match + 1, pmatch, 0) != 0)
968 continue; /* regex doesn't match the status bar */
969
970 int first = pmatch[cl->match].rm_so + offset;
971 int last = pmatch[cl->match].rm_eo + offset;
972
973 if (first == last)
974 continue; /* ignore an empty regex */
975
976 if (!found)
977 {
978 chunks++;
979 mutt_mem_realloc(&syntax, chunks * sizeof(struct StatusSyntax));
980 }
981
982 i = chunks - 1;
983 if (!found || (first < syntax[i].first) ||
984 ((first == syntax[i].first) && (last > syntax[i].last)))
985 {
986 const struct AttrColor *ac_merge = merged_color_overlay(ac_base, &cl->attr_color);
987
988 syntax[i].attr_color = ac_merge;
989 syntax[i].first = first;
990 syntax[i].last = last;
991 }
992 found = true;
993 }
994
995 if (syntax)
996 {
997 offset = syntax[i].last;
998 }
999 } while (found);
1000
1001 /* Only 'len' bytes will fit into 'max_cols' screen columns */
1002 len = mutt_wstr_trunc(buf, buflen, max_cols, NULL);
1003
1004 offset = 0;
1005
1006 if ((chunks > 0) && (syntax[0].first > 0))
1007 {
1008 /* Text before the first highlight */
1009 mutt_window_addnstr(win, buf, MIN(len, syntax[0].first));
1010 mutt_curses_set_color(ac_base);
1011 if (len <= syntax[0].first)
1012 goto dsl_finish; /* no more room */
1013
1014 offset = syntax[0].first;
1015 }
1016
1017 for (i = 0; i < chunks; i++)
1018 {
1019 /* Highlighted text */
1020 mutt_curses_set_color(syntax[i].attr_color);
1021 mutt_window_addnstr(win, buf + offset, MIN(len, syntax[i].last) - offset);
1022 if (len <= syntax[i].last)
1023 goto dsl_finish; /* no more room */
1024
1025 size_t next;
1026 if ((i + 1) == chunks)
1027 {
1028 next = len;
1029 }
1030 else
1031 {
1032 next = MIN(len, syntax[i + 1].first);
1033 }
1034
1035 mutt_curses_set_color(ac_base);
1036 offset = syntax[i].last;
1037 mutt_window_addnstr(win, buf + offset, next - offset);
1038
1039 offset = next;
1040 if (offset >= len)
1041 goto dsl_finish; /* no more room */
1042 }
1043
1044 mutt_curses_set_color(ac_base);
1045 if (offset < len)
1046 {
1047 /* Text after the last highlight */
1048 mutt_window_addnstr(win, buf + offset, len - offset);
1049 }
1050
1051 int width = mutt_strwidth(buf);
1052 if (width < max_cols)
1053 {
1054 /* Pad the rest of the line with whitespace */
1055 mutt_paddstr(win, max_cols - width, "");
1056 }
1057dsl_finish:
1058 FREE(&syntax);
1059}
struct RegexColorList * regex_colors_get_list(enum ColorId cid)
Return the RegexColorList for a colour id.
Definition: regex.c:184
struct AttrColor * simple_color_get(enum ColorId cid)
Get the colour of an object by its ID.
Definition: simple.c:88
@ MT_COLOR_STATUS
Status bar (takes a pattern)
Definition: color.h:75
@ MT_COLOR_NORMAL
Plain text.
Definition: color.h:59
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:383
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:341
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
Definition: curs_lib.c:443
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define MIN(a, b)
Definition: memory.h:32
const struct AttrColor * merged_color_overlay(const struct AttrColor *base, const struct AttrColor *over)
Combine two colours.
Definition: merged.c:107
void mutt_curses_set_color(const struct AttrColor *ac)
Set the colour and attributes for text.
Definition: mutt_curses.c:38
int mutt_window_addnstr(struct MuttWindow *win, const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:401
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A curses colour and its attributes.
Definition: attr.h:66
A regular expression and a color to highlight a line.
Definition: regex4.h:36
regex_t regex
Compiled regex.
Definition: regex4.h:39
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_set_header_color()

void mutt_set_header_color ( struct Mailbox m,
struct Email e 
)

Select a colour for a message.

Parameters
mMailbox
eCurrent Email

Definition at line 1374 of file dlg_index.c.

1375{
1376 if (!e)
1377 return;
1378
1379 struct RegexColor *color = NULL;
1380 struct PatternCache cache = { 0 };
1381
1382 const struct AttrColor *ac_merge = NULL;
1384 {
1386 MUTT_MATCH_FULL_ADDRESS, m, e, &cache))
1387 {
1388 ac_merge = merged_color_overlay(ac_merge, &color->attr_color);
1389 }
1390 }
1391
1392 struct AttrColor *ac_normal = simple_color_get(MT_COLOR_NORMAL);
1393 if (ac_merge)
1394 ac_merge = merged_color_overlay(ac_normal, ac_merge);
1395 else
1396 ac_merge = ac_normal;
1397
1398 e->attr_color = ac_merge;
1399}
@ MT_COLOR_INDEX
Index: default colour.
Definition: color.h:83
bool mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:1133
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:106
#define SLIST_FIRST(head)
Definition: queue.h:229
const struct AttrColor * attr_color
Color-pair to use when displaying in the index.
Definition: email.h:115
Cache commonly-used patterns.
Definition: lib.h:117
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: regex4.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resort_index()

void resort_index ( struct MailboxView mv,
struct Menu menu 
)

Resort the index.

Parameters
mvMailbox View
menuCurrent Menu

Definition at line 371 of file dlg_index.c.

372{
373 if (!mv || !mv->mailbox || !menu)
374 return;
375
376 struct Mailbox *m = mv->mailbox;
377 const int old_index = menu_get_index(menu);
378 struct Email *e_cur = mutt_get_virt_email(m, old_index);
379
380 int new_index = -1;
381 mutt_sort_headers(mv, false);
382
383 /* Restore the current message */
384 for (int i = 0; i < m->vcount; i++)
385 {
386 struct Email *e = mutt_get_virt_email(m, i);
387 if (!e)
388 continue;
389 if (e == e_cur)
390 {
391 new_index = i;
392 break;
393 }
394 }
395
396 if (mutt_using_threads() && (old_index < 0))
397 new_index = mutt_parent_message(e_cur, false);
398
399 if (old_index < 0)
400 new_index = find_first_message(mv);
401
402 menu->max = m->vcount;
403 menu_set_index(menu, new_index);
405}
int mutt_parent_message(struct Email *e, bool find_root)
Find the parent of a message.
Definition: mutt_thread.c:1355
void mutt_sort_headers(struct MailboxView *mv, bool init)
Sort emails by their headers.
Definition: sort.c:350
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_index()

void update_index ( struct Menu menu,
struct MailboxView mv,
enum MxStatus  check,
int  oldcount,
const struct IndexSharedData shared 
)

Update the index.

Parameters
menuCurrent Menu
mvMailbox
checkFlags, e.g. MX_STATUS_REOPENED
oldcountHow many items are currently in the index
sharedShared Index data

Definition at line 544 of file dlg_index.c.

546{
547 if (!menu || !mv)
548 return;
549
550 struct Mailbox *m = mv->mailbox;
551 if (mutt_using_threads())
552 update_index_threaded(mv, check, oldcount);
553 else
554 update_index_unthreaded(mv, check);
555
556 menu->max = m->vcount;
557 const int old_index = menu_get_index(menu);
558 int index = -1;
559 if (oldcount)
560 {
561 /* restore the current message to the message it was pointing to */
562 for (int i = 0; i < m->vcount; i++)
563 {
564 struct Email *e = mutt_get_virt_email(m, i);
565 if (!e)
566 continue;
567 if (index_shared_data_is_cur_email(shared, e))
568 {
569 index = i;
570 break;
571 }
572 }
573 }
574
575 if (index < 0)
576 {
577 index = (old_index < m->vcount) ? old_index : find_first_message(mv);
578 }
579 menu_set_index(menu, index);
580}
static void update_index_threaded(struct MailboxView *mv, enum MxStatus check, int oldcount)
Update the index (if threaded)
Definition: dlg_index.c:413
static void update_index_unthreaded(struct MailboxView *mv, enum MxStatus check)
Update the index (if unthreaded)
Definition: dlg_index.c:495
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ IndexNewsHelp

const struct Mapping IndexNewsHelp[]
extern

Help Bar for the News Index dialog.

Definition at line 119 of file dlg_index.c.