NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
copy_body.c File Reference

Copy the body of an email. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "copy_body.h"
#include "attach/lib.h"
#include "send/lib.h"
#include "body.h"
#include "muttlib.h"
#include "parameter.h"
+ Include dependency graph for copy_body.c:

Go to the source code of this file.

Functions

int mutt_body_copy (FILE *fp, struct Body **b_dst, struct Body *b_src)
 Create a send-mode duplicate from a receive-mode body.
 

Detailed Description

Copy 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 copy_body.c.

Function Documentation

◆ mutt_body_copy()

int mutt_body_copy ( FILE * fp,
struct Body ** b_dst,
struct Body * b_src )

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

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

Definition at line 50 of file copy_body.c.

51{
52 if (!b_dst || !b_src)
53 return -1;
54
55 struct Body *b = NULL;
56 bool use_disp;
57 struct Buffer *tmp = buf_pool_get();
58
59 if (b_src->filename)
60 {
61 use_disp = true;
62 buf_strcpy(tmp, b_src->filename);
63 }
64 else
65 {
66 use_disp = false;
67 }
68
69 mutt_adv_mktemp(tmp);
70 if (mutt_save_attachment(fp, b_src, buf_string(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
71 {
72 buf_pool_release(&tmp);
73 return -1;
74 }
75
76 *b_dst = mutt_body_new();
77 b = *b_dst;
78
79 memcpy(b, b_src, sizeof(struct Body));
81 b->parts = NULL;
82 b->next = NULL;
83
85 b->filename = buf_strdup(tmp);
86 b->use_disp = use_disp;
87 b->unlink = true;
88
89 if (mutt_is_text_part(b))
90 b->noconv = true;
91
92 b->xtype = mutt_str_dup(b->xtype);
96 /* mutt_adv_mktemp() will mangle the filename in tmp,
97 * so preserve it in d_filename */
98 if (!b->d_filename && use_disp)
99 b->d_filename = mutt_str_dup(b_src->filename);
101
104
105 b->content = NULL;
106 b->aptr = NULL;
107 b->mime_headers = NULL;
108
109 /* we don't seem to need the Email structure currently.
110 * XXX this may change in the future */
111 b->email = NULL;
112
113 /* copy parameters */
114 struct Parameter *np = NULL, *new_param = NULL;
115 TAILQ_FOREACH(np, &b_src->parameter, entries)
116 {
117 new_param = mutt_param_new();
118 new_param->attribute = mutt_str_dup(np->attribute);
119 new_param->value = mutt_str_dup(np->value);
120 TAILQ_INSERT_HEAD(&b->parameter, new_param, entries);
121 }
122
124 buf_pool_release(&tmp);
125 return 0;
126}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
struct Body * mutt_body_new(void)
Create a new Body.
Definition body.c:44
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
int mutt_save_attachment(FILE *fp, struct Body *b, const char *path, enum SaveAttach opt, struct Email *e)
Save an attachment.
@ MUTT_SAVE_NO_FLAGS
Overwrite existing file (the default)
Definition mutt_attach.h:58
bool mutt_is_text_part(const struct Body *b)
Is this part of an email in plain text?
Definition muttlib.c:395
void mutt_adv_mktemp(struct Buffer *buf)
Create a temporary file.
Definition muttlib.c:83
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition parameter.c:40
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
#define TAILQ_INIT(head)
Definition queue.h:822
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition queue.h:853
void mutt_stamp_attachment(struct Body *b)
Timestamp an Attachment.
Definition sendlib.c:409
The body of an email.
Definition body.h:36
char * language
content-language (RFC8255)
Definition body.h:78
char * content_id
Content-Id (RFC2392)
Definition body.h:58
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
Definition body.h:56
struct Body * parts
parts of a multipart or message/rfc822
Definition body.h:73
char * xtype
content-type if x-unknown
Definition body.h:62
bool noconv
Don't do character set conversion.
Definition body.h:46
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
Definition body.h:68
struct Envelope * mime_headers
Memory hole protected headers.
Definition body.h:76
char * charset
Send mode: charset of attached file as stored on disk.
Definition body.h:79
struct ParameterList parameter
Parameters of the content-type.
Definition body.h:63
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition body.h:75
bool use_disp
Content-Disposition uses filename= ?
Definition body.h:47
struct Email * email
header information for message/rfc822
Definition body.h:74
char * description
content-description
Definition body.h:55
struct Content * content
Detailed info about the content of the attachment.
Definition body.h:70
struct Body * next
next attachment in the list
Definition body.h:72
char * subtype
content-type subtype
Definition body.h:61
char * form_name
Content-Disposition form-data name param.
Definition body.h:60
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
String manipulation buffer.
Definition buffer.h:36
Attribute associated with a MIME part.
Definition parameter.h:33
char * attribute
Parameter name.
Definition parameter.h:34
char * value
Parameter value.
Definition parameter.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function: