NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
body.c File Reference

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

#include "config.h"
#include <stdbool.h>
#include <unistd.h>
#include "mutt/mutt.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. More...
 
void mutt_body_free (struct Body **ptr)
 Free a Body. More...
 
bool mutt_body_cmp_strict (const struct Body *b1, const struct Body *b2)
 Strictly compare two email Body's. More...
 

Detailed Description

Representation of the body of an email.

Authors
  • 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 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 43 of file body.c.

44 {
45  struct Body *p = mutt_mem_calloc(1, sizeof(struct Body));
46 
48  p->use_disp = true;
49  TAILQ_INIT(&p->parameter);
50  return p;
51 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
The body of an email.
Definition: body.h:34
unsigned int disposition
content-disposition
Definition: body.h:67
Content is attached.
Definition: mime.h:63
#define TAILQ_INIT(head)
Definition: queue.h:759
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:68
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ 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 57 of file body.c.

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->content = b->parts) */
90  b->email->content = 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 }
struct Body * next
next attachment in the list
Definition: body.h:53
The body of an email.
Definition: body.h:34
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:61
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
Log at debug level 1.
Definition: logging.h:56
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:69
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
+ 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 108 of file body.c.

109 {
110  if (!b1 || !b2)
111  return false;
112 
113  if ((b1->type != b2->type) || (b1->encoding != b2->encoding) ||
114  (mutt_str_strcmp(b1->subtype, b2->subtype) != 0) ||
115  (mutt_str_strcmp(b1->description, b2->description) != 0) ||
116  !mutt_param_cmp_strict(&b1->parameter, &b2->parameter) || (b1->length != b2->length))
117  {
118  return false;
119  }
120  return true;
121 }
unsigned int encoding
content-transfer-encoding
Definition: body.h:66
char * subtype
content-type subtype
Definition: body.h:37
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
char * description
content-description
Definition: body.h:40
unsigned int type
content-type primary type
Definition: body.h:65
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
Strictly compare two ParameterLists.
Definition: parameter.c:165
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function: