NeoMutt  2018-07-16 +2388-bcedc8
Teaching an old dog new tricks
DOXYGEN
mutt_body.c File Reference

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

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/mutt.h"
#include "email/lib.h"
#include "mutt_attach.h"
#include "muttlib.h"
#include "sendlib.h"
+ Include dependency graph for mutt_body.c:

Go to the source code of this file.

Functions

int mutt_body_copy (FILE *fp, struct Body **tgt, struct Body *src)
 Create a send-mode duplicate from a receive-mode body. 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 mutt_body.c.

Function Documentation

int mutt_body_copy ( FILE *  fp,
struct Body **  tgt,
struct Body src 
)

Create a send-mode duplicate from a receive-mode body.

Parameters
[in]fpFILE pointer to attachments
[out]tgtNew Body will be saved here
[in]srcSource Body to copy
Return values
0Success
-1Failure

Definition at line 47 of file mutt_body.c.

48 {
49  if (!tgt || !src)
50  return -1;
51 
52  struct Body *b = NULL;
53  bool use_disp;
54  struct Buffer *tmp = mutt_buffer_pool_get();
55 
56  if (src->filename)
57  {
58  use_disp = true;
59  mutt_buffer_strcpy(tmp, src->filename);
60  }
61  else
62  {
63  use_disp = false;
64  }
65 
66  mutt_adv_mktemp(tmp);
67  if (mutt_save_attachment(fp, src, mutt_b2s(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
68  {
70  return -1;
71  }
72 
73  *tgt = mutt_body_new();
74  b = *tgt;
75 
76  memcpy(b, src, sizeof(struct Body));
77  TAILQ_INIT(&b->parameter);
78  b->parts = NULL;
79  b->next = NULL;
80 
82  b->use_disp = use_disp;
83  b->unlink = true;
84 
85  if (mutt_is_text_part(b))
86  b->noconv = true;
87 
88  b->xtype = mutt_str_strdup(b->xtype);
92  /* mutt_adv_mktemp() will mangle the filename in tmp,
93  * so preserve it in d_filename */
94  if (!b->d_filename && use_disp)
97 
98  /* we don't seem to need the Email structure currently.
99  * XXX this may change in the future */
100 
101  if (b->email)
102  b->email = NULL;
103 
104  /* copy parameters */
105  struct Parameter *np = NULL, *new_param = NULL;
106  TAILQ_FOREACH(np, &src->parameter, entries)
107  {
108  new_param = mutt_param_new();
109  new_param->attribute = mutt_str_strdup(np->attribute);
110  new_param->value = mutt_str_strdup(np->value);
111  TAILQ_INSERT_HEAD(&b->parameter, new_param, entries);
112  }
113 
116  return 0;
117 }
char * attribute
Parameter name.
Definition: parameter.h:34
void mutt_stamp_attachment(struct Body *a)
Timestamp an Attachment.
Definition: sendlib.c:1418
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:39
No flags set.
Definition: mutt_attach.h:54
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
bool noconv
Don&#39;t do character set conversion.
Definition: body.h:73
String manipulation buffer.
Definition: buffer.h:33
struct Body * next
next attachment in the list
Definition: body.h:53
int mutt_save_attachment(FILE *fp, struct Body *m, const char *path, enum SaveAttach opt, struct Email *e)
Save an attachment.
Definition: mutt_attach.c:791
char * form_name
Content-Disposition form-data name param.
Definition: body.h:41
The body of an email.
Definition: body.h:34
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:43
#define TAILQ_INIT(head)
Definition: queue.h:759
char * subtype
content-type subtype
Definition: body.h:37
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:314
char * xtype
content-type if x-unknown
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
char * description
content-description
Definition: body.h:40
bool mutt_is_text_part(struct Body *b)
Is this part of an email in plain text?
Definition: muttlib.c:433
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:790
char * value
Parameter value.
Definition: parameter.h:35
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:68
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition: body.h:69
Attribute associated with a MIME part.
Definition: parameter.h:32
void mutt_adv_mktemp(struct Buffer *buf)
Create a temporary file.
Definition: muttlib.c:90
char * d_filename
filename to be used for the content-disposition header.
Definition: body.h:47
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
struct Email * email
header information for message/rfc822
Definition: body.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function: