NeoMutt  2025-12-11-899-ga9216f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
selection.c File Reference

Build a selection of Emails for an action. More...

#include "config.h"
#include <stdbool.h>
#include <stddef.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mview.h"
+ Include dependency graph for selection.c:

Go to the source code of this file.

Functions

static bool ea_contains_email (struct EmailArray *ea, struct Email *e)
 Does a working set already include an Email?
 
static void ea_add_email (struct EmailArray *ea, struct Email *e)
 Add an Email to a working set.
 
static void ea_add_collapsed_thread (struct EmailArray *ea, struct Email *e)
 Add all emails in a collapsed thread.
 
static void ea_add_folded (struct EmailArray *ea, struct Email *e)
 Add an Email, expanding collapsed threads.
 
int ea_add_tagged (struct EmailArray *ea, struct MailboxView *mv, struct Email *e, bool use_tagged)
 Get an array of the tagged Emails.
 

Detailed Description

Build a selection of Emails for an action.

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 selection.c.

Function Documentation

◆ ea_contains_email()

static bool ea_contains_email ( struct EmailArray * ea,
struct Email * e )
static

Does a working set already include an Email?

Parameters
eaSelected emails
eCandidate email
Return values
trueEmail is selected

Definition at line 43 of file selection.c.

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}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
The envelope/body of an email.
Definition email.h:39
+ Here is the caller graph for this function:

◆ ea_add_email()

static void ea_add_email ( struct EmailArray * ea,
struct Email * e )
static

Add an Email to a working set.

Parameters
eaSelected emails
eEmail to add

Definition at line 63 of file selection.c.

64{
65 if (!ea_contains_email(ea, e))
66 ARRAY_ADD(ea, e);
67}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
static bool ea_contains_email(struct EmailArray *ea, struct Email *e)
Does a working set already include an Email?
Definition selection.c:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ea_add_collapsed_thread()

static void ea_add_collapsed_thread ( struct EmailArray * ea,
struct Email * e )
static

Add all emails in a collapsed thread.

Parameters
eaSelected emails
eCollapsed email

Definition at line 74 of file selection.c.

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}
static void ea_add_email(struct EmailArray *ea, struct Email *e)
Add an Email to a working set.
Definition selection.c:63
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
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ea_add_folded()

static void ea_add_folded ( struct EmailArray * ea,
struct Email * e )
static

Add an Email, expanding collapsed threads.

Parameters
eaSelected emails
eEmail to add

Definition at line 113 of file selection.c.

114{
115 ea_add_email(ea, e);
117}
static void ea_add_collapsed_thread(struct EmailArray *ea, struct Email *e)
Add all emails in a collapsed thread.
Definition selection.c:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Parameters
eaEmpty EmailArray to populate
mvCurrent Mailbox
eCurrent Email
use_taggedUse tagged Emails
Return values
numNumber of selected emails
-1Error

Definition at line 128 of file selection.c.

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_SIZE(head)
The number of elements stored.
Definition array.h:87
static void ea_add_folded(struct EmailArray *ea, struct Email *e)
Add an Email, expanding collapsed threads.
Definition selection.c:113
bool message_is_tagged(struct Email *e)
Is a message in the index tagged (and within limit)
Definition mview.c:361
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function: