NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
multipart.c File Reference

Manipulate multipart Emails. More...

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

Go to the source code of this file.

Macros

#define BOUNDARY_MAX_DEPTH   50
 Maximum MIME nesting depth for boundary checking.
 

Functions

static int get_toplevel_encoding (struct Body *b)
 Find the most restrictive encoding type.
 
static bool check_boundary (const char *boundary, struct Body *b, int depth)
 Check for duplicate boundary.
 
void mutt_generate_boundary (struct ParameterList *pl)
 Create a unique boundary id for a MIME part.
 
struct Bodymutt_make_multipart (struct Body *b)
 Create a multipart email.
 
struct Bodymutt_remove_multipart (struct Body *b)
 Extract the multipart body if it exists.
 

Detailed Description

Manipulate multipart Emails.

Authors
  • Pietro Cerutti
  • 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 multipart.c.

Macro Definition Documentation

◆ BOUNDARY_MAX_DEPTH

#define BOUNDARY_MAX_DEPTH   50

Maximum MIME nesting depth for boundary checking.

Definition at line 59 of file multipart.c.

Function Documentation

◆ get_toplevel_encoding()

static int get_toplevel_encoding ( struct Body * b)
static

Find the most restrictive encoding type.

Parameters
bBody to examine
Return values
numEncoding type, e.g. ENC_7BIT

Definition at line 43 of file multipart.c.

44{
45 int e = ENC_7BIT;
46
47 for (; b; b = b->next)
48 {
49 if (b->encoding == ENC_BINARY)
50 return ENC_BINARY;
51 if (b->encoding == ENC_8BIT)
52 e = ENC_8BIT;
53 }
54
55 return e;
56}
@ ENC_7BIT
7-bit text
Definition mime.h:49
@ ENC_BINARY
Binary.
Definition mime.h:53
@ ENC_8BIT
8-bit text
Definition mime.h:50
struct Body * next
next attachment in the list
Definition body.h:72
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition body.h:41
+ Here is the caller graph for this function:

◆ check_boundary()

static bool check_boundary ( const char * boundary,
struct Body * b,
int depth )
static

Check for duplicate boundary.

Parameters
boundaryBoundary to look for
bBody parts to check
depthCurrent recursion depth
Return values
trueDuplicate found

Definition at line 68 of file multipart.c.

69{
70 if (depth >= BOUNDARY_MAX_DEPTH)
71 return false;
72
73 char *p = NULL;
74
75 if (b->parts && check_boundary(boundary, b->parts, depth + 1))
76 return true;
77
78 if (b->next && check_boundary(boundary, b->next, depth))
79 return true;
80
81 p = mutt_param_get(&b->parameter, "boundary");
82 if (p && mutt_str_equal(p, boundary))
83 {
84 return true;
85 }
86 return false;
87}
#define BOUNDARY_MAX_DEPTH
Maximum MIME nesting depth for boundary checking.
Definition multipart.c:59
static bool check_boundary(const char *boundary, struct Body *b, int depth)
Check for duplicate boundary.
Definition multipart.c:68
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition parameter.c:85
struct Body * parts
parts of a multipart or message/rfc822
Definition body.h:73
struct ParameterList parameter
Parameters of the content-type.
Definition body.h:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_generate_boundary()

void mutt_generate_boundary ( struct ParameterList * pl)

Create a unique boundary id for a MIME part.

Parameters
plMIME part

Definition at line 93 of file multipart.c.

94{
95 char rs[MUTT_RANDTAG_LEN + 1];
96
97 mutt_rand_base32(rs, sizeof(rs) - 1);
98 rs[MUTT_RANDTAG_LEN] = 0;
99 mutt_param_set(pl, "boundary", rs);
100}
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition parameter.c:111
void mutt_rand_base32(char *buf, size_t buflen)
Fill a buffer with a base32-encoded random string.
Definition random.c:106
#define MUTT_RANDTAG_LEN
Length of random tag for message boundaries.
Definition sendlib.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_make_multipart()

struct Body * mutt_make_multipart ( struct Body * b)

Create a multipart email.

Parameters
bBody of email to start
Return values
ptrNewly allocated Body

Definition at line 107 of file multipart.c.

108{
109 struct Body *b_new = mutt_body_new();
110 b_new->type = TYPE_MULTIPART;
111 b_new->subtype = mutt_str_dup("mixed");
113 do
114 {
116 if (check_boundary(mutt_param_get(&b_new->parameter, "boundary"), b, 0))
117 mutt_param_delete(&b_new->parameter, "boundary");
118 } while (!mutt_param_get(&b_new->parameter, "boundary"));
119 b_new->use_disp = false;
120 b_new->disposition = DISP_INLINE;
121 b_new->parts = b;
122
123 return b_new;
124}
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition mime.h:37
@ DISP_INLINE
Content is inline.
Definition mime.h:62
static int get_toplevel_encoding(struct Body *b)
Find the most restrictive encoding type.
Definition multipart.c:43
void mutt_generate_boundary(struct ParameterList *pl)
Create a unique boundary id for a MIME part.
Definition multipart.c:93
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition parameter.c:143
The body of an email.
Definition body.h:36
bool use_disp
Content-Disposition uses filename= ?
Definition body.h:47
unsigned int disposition
content-disposition, ContentDisposition
Definition body.h:42
char * subtype
content-type subtype
Definition body.h:61
unsigned int type
content-type primary type, ContentType
Definition body.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_remove_multipart()

struct Body * mutt_remove_multipart ( struct Body * b)

Extract the multipart body if it exists.

Parameters
bBody to alter
Return values
ptrThe parts of the Body
Note
The original Body is freed

Definition at line 133 of file multipart.c.

134{
135 struct Body *t = NULL;
136
137 if (b->parts)
138 {
139 t = b;
140 b = b->parts;
141 t->parts = NULL;
142 mutt_body_free(&t);
143 }
144 return b;
145}
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition body.c:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function: