NeoMutt  2024-12-12-14-g7b49f7
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
body.c File Reference

Representation of the body of an email. More...

#include "config.h"
#include <stdbool.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "body.h"
#include "email.h"
#include "envelope.h"
#include "mime.h"
#include "parameter.h"
+ Include dependency graph for body.c:

Go to the source code of this file.

Functions

struct Bodymutt_body_new (void)
 Create a new Body.
 
void mutt_body_free (struct Body **ptr)
 Free a Body.
 
bool mutt_body_cmp_strict (const struct Body *b1, const struct Body *b2)
 Strictly compare two email Body's.
 
char * mutt_body_get_charset (struct Body *b, char *buf, size_t buflen)
 Get a body's character set.
 

Detailed Description

Representation of the body of an email.

Authors
  • Richard Russon
  • Pietro Cerutti

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

Function Documentation

◆ mutt_body_new()

struct Body * mutt_body_new ( void  )

Create a new Body.

Return values
ptrNewly allocated Body

Definition at line 44 of file body.c.

45{
46 struct Body *p = MUTT_MEM_CALLOC(1, struct Body);
47
49 p->use_disp = true;
51 return p;
52}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
@ DISP_ATTACH
Content is attached.
Definition: mime.h:63
#define TAILQ_INIT(head)
Definition: queue.h:783
The body of an email.
Definition: body.h:36
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:63
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:47
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:42
+ Here is the caller graph for this function:

◆ mutt_body_free()

void mutt_body_free ( struct Body **  ptr)

Free a Body.

Parameters
[out]ptrBody to free

Definition at line 58 of file body.c.

59{
60 if (!ptr || !*ptr)
61 return;
62
63 struct Body *a = *ptr, *b = NULL;
64
65 while (a)
66 {
67 b = a;
68 a = a->next;
69
70 mutt_param_free(&b->parameter);
71 if (b->filename)
72 {
73 if (b->unlink)
74 unlink(b->filename);
75 mutt_debug(LL_DEBUG1, "%sunlinking %s\n", b->unlink ? "" : "not ", b->filename);
76 }
77
78 FREE(&b->content_id);
79 FREE(&b->filename);
80 FREE(&b->d_filename);
81 FREE(&b->charset);
82 FREE(&b->content);
83 FREE(&b->xtype);
84 FREE(&b->subtype);
85 FREE(&b->language);
86 FREE(&b->description);
87 FREE(&b->form_name);
88
89 if (b->email)
90 {
91 /* Don't free twice (b->email->body = b->parts) */
92 b->email->body = NULL;
93 email_free(&b->email);
94 }
95
96 mutt_env_free(&b->mime_headers);
97 mutt_body_free(&b->parts);
98 FREE(&b);
99 }
100
101 *ptr = NULL;
102}
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:46
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define FREE(x)
Definition: memory.h:55
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:62
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:68
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:

◆ mutt_body_cmp_strict()

bool mutt_body_cmp_strict ( const struct Body b1,
const struct Body b2 
)

Strictly compare two email Body's.

Parameters
b1First Body
b2Second Body
Return values
trueBody's are strictly identical

Definition at line 110 of file body.c.

111{
112 if (!b1 || !b2)
113 return false;
114
115 if ((b1->type != b2->type) || (b1->encoding != b2->encoding) ||
116 !mutt_str_equal(b1->subtype, b2->subtype) ||
118 !mutt_param_cmp_strict(&b1->parameter, &b2->parameter) || (b1->length != b2->length))
119 {
120 return false;
121 }
122 return true;
123}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
Strictly compare two ParameterLists.
Definition: parameter.c:166
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
char * description
content-description
Definition: body.h:55
char * subtype
content-type subtype
Definition: body.h:61
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:41
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_body_get_charset()

char * mutt_body_get_charset ( struct Body b,
char *  buf,
size_t  buflen 
)

Get a body's character set.

Parameters
bBody to examine
bufBuffer for the result
buflenLength of the buffer
Return values
ptrBuffer containing character set
NULLOn error, or if not a text type

Definition at line 133 of file body.c.

134{
135 char *p = NULL;
136
137 if (b && (b->type != TYPE_TEXT))
138 return NULL;
139
140 if (b)
141 p = mutt_param_get(&b->parameter, "charset");
142
143 if (p)
144 mutt_ch_canonical_charset(buf, buflen, p);
145 else
146 mutt_str_copy(buf, "us-ascii", buflen);
147
148 return buf;
149}
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name)
Canonicalise the charset of a string.
Definition: charset.c:374
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:581
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function: