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

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

#include "config.h"
#include <limits.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 48 of file mutt_body.c.

49 {
50  if (!tgt || !src)
51  return -1;
52 
53  char tmp[PATH_MAX];
54  struct Body *b = NULL;
55 
56  bool use_disp;
57 
58  if (src->filename)
59  {
60  use_disp = true;
61  mutt_str_strfcpy(tmp, src->filename, sizeof(tmp));
62  }
63  else
64  {
65  use_disp = false;
66  tmp[0] = '\0';
67  }
68 
69  mutt_adv_mktemp(tmp, sizeof(tmp));
70  if (mutt_save_attachment(fp, src, tmp, 0, NULL) == -1)
71  return -1;
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 
81  b->filename = mutt_str_strdup(tmp);
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 Header structure currently.
99  * XXX this may change in the future
100  */
101 
102  if (b->email)
103  b->email = NULL;
104 
105  /* copy parameters */
106  struct Parameter *np, *new;
107  TAILQ_FOREACH(np, &src->parameter, entries)
108  {
109  new = mutt_param_new();
110  new->attribute = mutt_str_strdup(np->attribute);
111  new->value = mutt_str_strdup(np->value);
112  TAILQ_INSERT_HEAD(&b->parameter, new, entries);
113  }
114 
116 
117  return 0;
118 }
char * attribute
Definition: parameter.h:39
int mutt_save_attachment(FILE *fp, struct Body *m, char *path, int flags, struct Email *e)
Save an attachment.
Definition: mutt_attach.c:791
void mutt_stamp_attachment(struct Body *a)
Timestamp an Attachment.
Definition: sendlib.c:1391
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:47
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:39
bool noconv
don&#39;t do character set conversion
Definition: body.h:77
struct Body * next
next attachment in the list
Definition: body.h:57
char * form_name
Content-Disposition form-data name param.
Definition: body.h:40
The body of an email.
Definition: body.h:33
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:42
#define TAILQ_INIT(head)
Definition: queue.h:759
char * subtype
content-type subtype
Definition: body.h:36
#define PATH_MAX
Definition: mutt.h:46
char * xtype
content-type if x-unknown
Definition: body.h:35
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:58
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
char * description
content-description
Definition: body.h:39
bool mutt_is_text_part(struct Body *b)
Is this part of an email in plain text?
Definition: muttlib.c:429
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:790
char * value
Definition: parameter.h:40
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:70
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
bool unlink
flag to indicate the file named by "filename" should be unlink()ed before free()ing this structure ...
Definition: body.h:71
Attribute associated with a MIME part.
Definition: parameter.h:37
char * d_filename
filename to be used for the content-disposition header.
Definition: body.h:49
struct ParameterList parameter
parameters of the content-type
Definition: body.h:38
struct Email * email
header information for message/rfc822
Definition: body.h:59
void mutt_adv_mktemp(char *buf, size_t buflen)
Advanced mktemp(3)
Definition: muttlib.c:123

+ Here is the call graph for this function:

+ Here is the caller graph for this function: