NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
Loading...
Searching...
No Matches
selection.c
Go to the documentation of this file.
1
22
28
29
#include "config.h"
30
#include <stdbool.h>
31
#include <stddef.h>
32
#include "
mutt/lib.h
"
33
#include "
email/lib.h
"
34
#include "
core/lib.h
"
35
#include "
mview.h
"
36
43
static
bool
ea_contains_email
(
struct
EmailArray *ea,
struct
Email
*e)
44
{
45
if
(!ea || !e)
46
return
false
;
47
48
struct
Email
**ep = NULL;
49
ARRAY_FOREACH
(ep, ea)
50
{
51
if
(*ep == e)
52
return
true
;
53
}
54
55
return
false
;
56
}
57
63
static
void
ea_add_email
(
struct
EmailArray *ea,
struct
Email
*e)
64
{
65
if
(!
ea_contains_email
(ea, e))
66
ARRAY_ADD
(ea, e);
67
}
68
74
static
void
ea_add_collapsed_thread
(
struct
EmailArray *ea,
struct
Email
*e)
75
{
76
if
(!e || !e->
collapsed
|| !e->
thread
)
77
return
;
78
79
struct
MuttThread
*top = e->
thread
;
80
while
(top->
parent
)
81
top = top->
parent
;
82
83
struct
MuttThread
*thread = top;
84
while
(thread)
85
{
86
struct
Email
*et =
thread
->
message
;
87
if
(et && et->
visible
)
88
ea_add_email
(ea, et);
89
90
if
(
thread
->
child
)
91
{
92
thread
=
thread
->
child
;
93
continue
;
94
}
95
96
// Leaf node: backtrack to find the next sibling,
97
// but stay within the subtree rooted at `top`
98
while
((
thread
!= top) && !
thread
->
next
)
99
thread
=
thread
->
parent
;
100
101
if
(
thread
== top)
102
break
;
103
104
thread
=
thread
->
next
;
105
}
106
}
107
113
static
void
ea_add_folded
(
struct
EmailArray *ea,
struct
Email
*e)
114
{
115
ea_add_email
(ea, e);
116
ea_add_collapsed_thread
(ea, e);
117
}
118
128
int
ea_add_tagged
(
struct
EmailArray *ea,
struct
MailboxView
*mv,
struct
Email
*e,
bool
use_tagged)
129
{
130
if
(use_tagged)
131
{
132
if
(!mv || !mv->
mailbox
|| !mv->
mailbox
->
emails
)
133
return
-1;
134
135
struct
Mailbox
*m = mv->
mailbox
;
136
for
(
int
i = 0; i < m->
msg_count
; i++)
137
{
138
e = m->
emails
[i];
139
if
(!e)
140
break
;
141
if
(!
message_is_tagged
(e))
142
continue
;
143
144
ea_add_folded
(ea, e);
145
}
146
}
147
else
148
{
149
if
(!e)
150
return
-1;
151
152
ea_add_folded
(ea, e);
153
}
154
155
return
ARRAY_SIZE
(ea);
156
}
ARRAY_ADD
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition
array.h:157
ARRAY_FOREACH
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition
array.h:223
ARRAY_SIZE
#define ARRAY_SIZE(head)
The number of elements stored.
Definition
array.h:87
lib.h
Convenience wrapper for the core headers.
lib.h
Structs that make up an email.
ea_add_email
static void ea_add_email(struct EmailArray *ea, struct Email *e)
Add an Email to a working set.
Definition
selection.c:63
ea_contains_email
static bool ea_contains_email(struct EmailArray *ea, struct Email *e)
Does a working set already include an Email?
Definition
selection.c:43
ea_add_folded
static void ea_add_folded(struct EmailArray *ea, struct Email *e)
Add an Email, expanding collapsed threads.
Definition
selection.c:113
ea_add_tagged
int ea_add_tagged(struct EmailArray *ea, struct MailboxView *mv, struct Email *e, bool use_tagged)
Get an array of the tagged Emails.
Definition
selection.c:128
ea_add_collapsed_thread
static void ea_add_collapsed_thread(struct EmailArray *ea, struct Email *e)
Add all emails in a collapsed thread.
Definition
selection.c:74
lib.h
Convenience wrapper for the library headers.
message_is_tagged
bool message_is_tagged(struct Email *e)
Is a message in the index tagged (and within limit).
Definition
mview.c:363
mview.h
View of a Mailbox.
Email
The envelope/body of an email.
Definition
email.h:39
Email::visible
bool visible
Is this message part of the view?
Definition
email.h:121
Email::collapsed
bool collapsed
Is this message part of a collapsed thread?
Definition
email.h:120
Email::thread
struct MuttThread * thread
Thread of Emails.
Definition
email.h:119
MailboxView
View of a Mailbox.
Definition
mview.h:40
MailboxView::mailbox
struct Mailbox * mailbox
Current Mailbox.
Definition
mview.h:51
Mailbox
A mailbox.
Definition
mailbox.h:81
Mailbox::msg_count
int msg_count
Total number of messages.
Definition
mailbox.h:90
Mailbox::emails
struct Email ** emails
Array of Emails.
Definition
mailbox.h:98
MuttThread
An Email conversation.
Definition
thread.h:34
MuttThread::parent
struct MuttThread * parent
Parent of this Thread.
Definition
thread.h:44
MuttThread::child
struct MuttThread * child
Child of this Thread.
Definition
thread.h:45
MuttThread::message
struct Email * message
Email this Thread refers to.
Definition
thread.h:49
MuttThread::next
struct MuttThread * next
Next sibling Thread.
Definition
thread.h:46