NeoMutt  2025-12-11-899-ga9216f
Teaching an old dog new tricks
DOXYGEN
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
43static 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
63static 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
74static 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 {
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)
100
101 if (thread == top)
102 break;
103
104 thread = thread->next;
105 }
106}
107
113static void ea_add_folded(struct EmailArray *ea, struct Email *e)
114{
115 ea_add_email(ea, e);
117}
118
128int 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}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
Convenience wrapper for the core headers.
Structs that make up an email.
static void ea_add_email(struct EmailArray *ea, struct Email *e)
Add an Email to a working set.
Definition selection.c:63
static bool ea_contains_email(struct EmailArray *ea, struct Email *e)
Does a working set already include an Email?
Definition selection.c:43
static void ea_add_folded(struct EmailArray *ea, struct Email *e)
Add an Email, expanding collapsed threads.
Definition selection.c:113
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
static void ea_add_collapsed_thread(struct EmailArray *ea, struct Email *e)
Add all emails in a collapsed thread.
Definition selection.c:74
Convenience wrapper for the library headers.
bool message_is_tagged(struct Email *e)
Is a message in the index tagged (and within limit)
Definition mview.c:361
View of a Mailbox.
The envelope/body of an email.
Definition email.h:39
bool visible
Is this message part of the view?
Definition email.h:121
bool collapsed
Is this message part of a collapsed thread?
Definition email.h:120
struct MuttThread * thread
Thread of Emails.
Definition email.h:119
View of a Mailbox.
Definition mview.h:40
struct Mailbox * mailbox
Current Mailbox.
Definition mview.h:51
A mailbox.
Definition mailbox.h:81
int msg_count
Total number of messages.
Definition mailbox.h:90
struct Email ** emails
Array of Emails.
Definition mailbox.h:98
An Email conversation.
Definition thread.h:34
struct MuttThread * parent
Parent of this Thread.
Definition thread.h:44
struct MuttThread * child
Child of this Thread.
Definition thread.h:45
struct Email * message
Email this Thread refers to.
Definition thread.h:49
struct MuttThread * next
Next sibling Thread.
Definition thread.h:46