NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.c File Reference

Attachment helper functions. More...

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

Go to the source code of this file.

Functions

int attach_body_count (struct Body *body, bool recurse)
 Count bodies.
 
bool attach_body_parent (struct Body *start, struct Body *start_parent, struct Body *body, struct Body **body_parent)
 Find the parent of a body.
 
struct Bodyattach_body_ancestor (struct Body *start, struct Body *body, const char *subtype)
 Find the ancestor of a body with specified subtype.
 
bool attach_body_previous (struct Body *start, struct Body *body, struct Body **previous)
 Find the previous body of a body.
 

Detailed Description

Attachment helper functions.

Authors
  • David Purton

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

Function Documentation

◆ attach_body_count()

int attach_body_count ( struct Body body,
bool  recurse 
)

Count bodies.

Parameters
bodyBody to start counting from
recurseWhether to recurse into groups or not
Return values
numNumber of bodies
-1Failure

Definition at line 42 of file lib.c.

43{
44 if (!body)
45 return -1;
46
47 int bodies = 0;
48
49 for (struct Body *b = body; b; b = b->next)
50 {
51 bodies++;
52 if (recurse)
53 {
54 if (b->parts)
55 bodies += attach_body_count(b->parts, true);
56 }
57 }
58
59 return bodies;
60}
int attach_body_count(struct Body *body, bool recurse)
Count bodies.
Definition: lib.c:42
The body of an email.
Definition: body.h:36
struct Body * next
next attachment in the list
Definition: body.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_body_parent()

bool attach_body_parent ( struct Body start,
struct Body start_parent,
struct Body body,
struct Body **  body_parent 
)

Find the parent of a body.

Parameters
[in]startBody to start search from
[in]start_parentParent of start Body pointer (or NULL if none)
[in]bodyBody to find parent of
[out]body_parentBody Parent if found
Return values
trueParent body found
falseParent body not found

Definition at line 71 of file lib.c.

73{
74 if (!start || !body)
75 return false;
76
77 struct Body *b = start;
78
79 if (b->parts)
80 {
81 if (b->parts == body)
82 {
83 *body_parent = b;
84 return true;
85 }
86 }
87 while (b)
88 {
89 if (b == body)
90 {
91 *body_parent = start_parent;
92 if (start_parent)
93 return true;
94 else
95 return false;
96 }
97 if (b->parts)
98 {
99 if (attach_body_parent(b->parts, b, body, body_parent))
100 return true;
101 }
102 b = b->next;
103 }
104
105 return false;
106}
bool attach_body_parent(struct Body *start, struct Body *start_parent, struct Body *body, struct Body **body_parent)
Find the parent of a body.
Definition: lib.c:71
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_body_ancestor()

struct Body * attach_body_ancestor ( struct Body start,
struct Body body,
const char *  subtype 
)

Find the ancestor of a body with specified subtype.

Parameters
[in]startBody to start search from
[in]bodyBody to find ancestor of
[in]subtypeMime subtype of ancestor to find
Return values
ptrBody ancestor if found
NULLIf ancestor body not found

Definition at line 116 of file lib.c.

117{
118 if (!start || !body)
119 return NULL;
120
121 struct Body *b = body;
122 struct Body *b_parent = NULL;
123
124 while (attach_body_parent(start, NULL, b, &b_parent))
125 {
126 if (mutt_str_equal(subtype, b_parent->subtype))
127 return b_parent;
128 b = b_parent;
129 }
130
131 return NULL;
132}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
char * subtype
content-type subtype
Definition: body.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_body_previous()

bool attach_body_previous ( struct Body start,
struct Body body,
struct Body **  previous 
)

Find the previous body of a body.

Parameters
[in]startBody to start search from
[in]bodyBody to find previous body of
[out]previousPrevious Body if found
Return values
truePrevious body found
falsePrevious body not found

Definition at line 142 of file lib.c.

143{
144 if (!start || !body)
145 return false;
146
147 struct Body *b = start;
148
149 while (b)
150 {
151 if (b->next == body)
152 {
153 *previous = b;
154 return true;
155 }
156 if (b->parts)
157 {
158 if (attach_body_previous(b->parts, body, previous))
159 return true;
160 }
161 b = b->next;
162 }
163
164 return false;
165}
bool attach_body_previous(struct Body *start, struct Body *body, struct Body **previous)
Find the previous body of a body.
Definition: lib.c:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function: