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

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

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

Go to the source code of this file.

Functions

static bool aa_contains_attach (struct AttachPtrArray *aa, struct AttachPtr *ap)
 Does a working set already include an Attachment?
 
static void aa_add_attach (struct AttachPtrArray *aa, struct AttachPtr *ap)
 Add an Attachment to a working set.
 
static void aa_add_folded (struct AttachPtrArray *aa, struct AttachCtx *actx, int rindex)
 Add an Attachment, expanding collapsed children.
 
static int aa_add_tagged (struct AttachPtrArray *aa, struct AttachCtx *actx)
 Get an array of tagged Attachments.
 
int aa_add_selection (struct AttachPtrArray *aa, struct AttachCtx *actx, struct Menu *menu, bool use_tagged, int count)
 Build a working set of Attachments for an action.
 
int ba_add_selection (struct BodyArray *ba, struct AttachCtx *actx, struct Menu *menu, bool use_tagged, int count)
 Build a working set of attachment bodies for an action.
 

Detailed Description

Build a selection of Attachments 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

◆ aa_contains_attach()

static bool aa_contains_attach ( struct AttachPtrArray * aa,
struct AttachPtr * ap )
static

Does a working set already include an Attachment?

Parameters
aaSelected attachments
apCandidate attachment
Return values
trueAttachment is selected

Definition at line 44 of file selection.c.

45{
46 if (!aa || !ap)
47 return false;
48
49 struct AttachPtr **app = NULL;
50 ARRAY_FOREACH(app, aa)
51 {
52 if (*app == ap)
53 return true;
54 }
55
56 return false;
57}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
An email to which things will be attached.
Definition attach.h:36
+ Here is the caller graph for this function:

◆ aa_add_attach()

static void aa_add_attach ( struct AttachPtrArray * aa,
struct AttachPtr * ap )
static

Add an Attachment to a working set.

Parameters
aaSelected attachments
apAttachment to add

Definition at line 64 of file selection.c.

65{
66 if (!aa_contains_attach(aa, ap))
67 ARRAY_ADD(aa, ap);
68}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
static bool aa_contains_attach(struct AttachPtrArray *aa, struct AttachPtr *ap)
Does a working set already include an Attachment?
Definition selection.c:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ aa_add_folded()

static void aa_add_folded ( struct AttachPtrArray * aa,
struct AttachCtx * actx,
int rindex )
static

Add an Attachment, expanding collapsed children.

Parameters
aaSelected attachments
actxList of Attachments
rindexReal attachment index

Definition at line 76 of file selection.c.

77{
78 if (!aa || !actx || (rindex < 0) || (rindex >= actx->idxlen))
79 return;
80
81 struct AttachPtr *ap = actx->idx[rindex];
82 aa_add_attach(aa, ap);
83
84 if (!ap->collapsed)
85 return;
86
87 const int level = ap->level;
88 for (int i = rindex + 1; (i < actx->idxlen) && (actx->idx[i]->level > level); i++)
89 {
90 aa_add_attach(aa, actx->idx[i]);
91 }
92}
static void aa_add_attach(struct AttachPtrArray *aa, struct AttachPtr *ap)
Add an Attachment to a working set.
Definition selection.c:64
struct AttachPtr ** idx
Array of attachments.
Definition attach.h:69
short idxlen
Number of attachmentes.
Definition attach.h:70
bool collapsed
Group is collapsed.
Definition attach.h:45
int level
Nesting depth of attachment.
Definition attach.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ aa_add_tagged()

static int aa_add_tagged ( struct AttachPtrArray * aa,
struct AttachCtx * actx )
static

Get an array of tagged Attachments.

Parameters
aaEmpty AttachPtrArray to populate
actxList of Attachments
Return values
numNumber of selected Attachments
-1Error

Definition at line 101 of file selection.c.

102{
103 if (!aa || !actx)
104 return -1;
105
106 for (int i = 0; i < actx->idxlen; i++)
107 {
108 if (actx->idx[i]->body->tagged)
109 aa_add_folded(aa, actx, i);
110 }
111
112 return ARRAY_SIZE(aa);
113}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
static void aa_add_folded(struct AttachPtrArray *aa, struct AttachCtx *actx, int rindex)
Add an Attachment, expanding collapsed children.
Definition selection.c:76
struct Body * body
Attachment.
Definition attach.h:37
bool tagged
This attachment is tagged.
Definition body.h:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ aa_add_selection()

int aa_add_selection ( struct AttachPtrArray * aa,
struct AttachCtx * actx,
struct Menu * menu,
bool use_tagged,
int count )

Build a working set of Attachments for an action.

Parameters
aaEmpty AttachPtrArray to populate
actxList of Attachments
menuMenu
use_taggedUse tagged attachments
countRepeat-count (0 or 1 == current selection)
Return values
numNumber of selected Attachments
-1Error

Definition at line 125 of file selection.c.

127{
128 if (!aa || !actx || !menu)
129 return -1;
130
131 if (use_tagged)
132 return aa_add_tagged(aa, actx);
133
134 const int index = menu_get_index(menu);
135 if ((index < 0) || (index >= actx->vcount))
136 return -1;
137
138 int n = (count > 1) ? count : 1;
139 if ((index + n) > actx->vcount)
140 n = actx->vcount - index;
141
142 for (int i = 0; i < n; i++)
143 {
144 const int rindex = actx->v2r[index + i];
145 if ((rindex < 0) || (rindex >= actx->idxlen))
146 return -1;
147
148 aa_add_folded(aa, actx, rindex);
149 }
150
151 return ARRAY_SIZE(aa);
152}
static int aa_add_tagged(struct AttachPtrArray *aa, struct AttachCtx *actx)
Get an array of tagged Attachments.
Definition selection.c:101
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:155
short vcount
The number of virtual attachments.
Definition attach.h:74
short * v2r
Mapping from virtual to real attachment.
Definition attach.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ba_add_selection()

int ba_add_selection ( struct BodyArray * ba,
struct AttachCtx * actx,
struct Menu * menu,
bool use_tagged,
int count )

Build a working set of attachment bodies for an action.

Parameters
baEmpty BodyArray to populate
actxList of Attachments
menuMenu
use_taggedUse tagged attachments
countRepeat-count (0 or 1 == current selection)
Return values
numNumber of selected Attachments
-1Error

Definition at line 164 of file selection.c.

166{
167 if (!ba)
168 return -1;
169
170 struct AttachPtrArray aa = ARRAY_HEAD_INITIALIZER;
171 if (aa_add_selection(&aa, actx, menu, use_tagged, count) < 0)
172 {
173 ARRAY_FREE(&aa);
174 return -1;
175 }
176
177 struct AttachPtr **app = NULL;
178 ARRAY_FOREACH(app, &aa)
179 {
180 ARRAY_ADD(ba, (*app)->body);
181 }
182
183 const int rc = ARRAY_SIZE(ba);
184 ARRAY_FREE(&aa);
185 return rc;
186}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
int aa_add_selection(struct AttachPtrArray *aa, struct AttachCtx *actx, struct Menu *menu, bool use_tagged, int count)
Build a working set of Attachments for an action.
Definition selection.c:125
+ Here is the call graph for this function:
+ Here is the caller graph for this function: