NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
body.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <unistd.h>
32#include "mutt/lib.h"
33#include "body.h"
34#include "email.h"
35#include "envelope.h"
36#include "mime.h"
37#include "parameter.h"
38
43struct Body *mutt_body_new(void)
44{
45 struct Body *p = mutt_mem_calloc(1, sizeof(struct Body));
46
48 p->use_disp = true;
50 return p;
51}
52
57void mutt_body_free(struct Body **ptr)
58{
59 if (!ptr)
60 return;
61
62 struct Body *a = *ptr, *b = NULL;
63
64 while (a)
65 {
66 b = a;
67 a = a->next;
68
69 mutt_param_free(&b->parameter);
70 if (b->filename)
71 {
72 if (b->unlink)
73 unlink(b->filename);
74 mutt_debug(LL_DEBUG1, "%sunlinking %s\n", b->unlink ? "" : "not ", b->filename);
75 }
76
77 FREE(&b->filename);
78 FREE(&b->d_filename);
79 FREE(&b->charset);
80 FREE(&b->content);
81 FREE(&b->xtype);
82 FREE(&b->subtype);
83 FREE(&b->language);
84 FREE(&b->description);
85 FREE(&b->form_name);
86
87 if (b->email)
88 {
89 /* Don't free twice (b->email->body = b->parts) */
90 b->email->body = NULL;
91 email_free(&b->email);
92 }
93
94 mutt_env_free(&b->mime_headers);
95 mutt_body_free(&b->parts);
96 FREE(&b);
97 }
98
99 *ptr = NULL;
100}
101
108bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2)
109{
110 if (!b1 || !b2)
111 return false;
112
113 if ((b1->type != b2->type) || (b1->encoding != b2->encoding) ||
114 !mutt_str_equal(b1->subtype, b2->subtype) ||
116 !mutt_param_cmp_strict(&b1->parameter, &b2->parameter) || (b1->length != b2->length))
117 {
118 return false;
119 }
120 return true;
121}
122
131char *mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
132{
133 char *p = NULL;
134
135 if (b && (b->type != TYPE_TEXT))
136 return NULL;
137
138 if (b)
139 p = mutt_param_get(&b->parameter, "charset");
140
141 if (p)
142 mutt_ch_canonical_charset(buf, buflen, p);
143 else
144 mutt_str_copy(buf, "us-ascii", buflen);
145
146 return buf;
147}
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:43
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
Definition: body.c:131
bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2)
Strictly compare two email Body's.
Definition: body.c:108
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:44
Representation of an email.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
Representation of an email header (envelope)
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:43
Constants and macros for managing MIME encoding.
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
@ DISP_ATTACH
Content is attached.
Definition: mime.h:63
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:351
Convenience wrapper for the library headers.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:652
bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
Strictly compare two ParameterLists.
Definition: parameter.c:165
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:61
Store attributes associated with a MIME part.
#define TAILQ_INIT(head)
Definition: queue.h:765
Convenience wrapper for the send headers.
The body of an email.
Definition: body.h:36
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:67
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:47
char * description
content-description
Definition: body.h:55
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:42
struct Body * next
next attachment in the list
Definition: body.h:71
char * subtype
content-type subtype
Definition: body.h:60
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:41
unsigned int type
content-type primary type, ContentType
Definition: body.h:40