NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <stddef.h>
32#include "mutt/lib.h"
33#include "email/lib.h"
34
42int attach_body_count(struct Body *body, bool recurse)
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}
61
71bool attach_body_parent(struct Body *start, struct Body *start_parent,
72 struct Body *body, struct Body **body_parent)
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}
107
116struct Body *attach_body_ancestor(struct Body *start, struct Body *body, const char *subtype)
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}
133
142bool attach_body_previous(struct Body *start, struct Body *body, struct Body **previous)
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_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
int attach_body_count(struct Body *body, bool recurse)
Count bodies.
Definition: lib.c:42
struct Body * attach_body_ancestor(struct Body *start, struct Body *body, const char *subtype)
Find the ancestor of a body with specified subtype.
Definition: lib.c:116
bool attach_body_previous(struct Body *start, struct Body *body, struct Body **previous)
Find the previous body of a body.
Definition: lib.c:142
Structs that make up an email.
Convenience wrapper for the library headers.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:73
struct Body * next
next attachment in the list
Definition: body.h:72
char * subtype
content-type subtype
Definition: body.h:61