NeoMutt  2024-03-23-142-g2b2e76
Teaching an old dog new tricks
No Matches
Go to the documentation of this file.
30#include "config.h"
31#include <stdbool.h>
32#include <stdio.h>
33#include <string.h>
34#include "mutt/lib.h"
35#include "email/lib.h"
36#include "mutt_body.h"
37#include "attach/lib.h"
38#include "send/lib.h"
39#include "muttlib.h"
49int mutt_body_copy(FILE *fp, struct Body **b_dst, struct Body *b_src)
51 if (!b_dst || !b_src)
52 return -1;
54 struct Body *b = NULL;
55 bool use_disp;
56 struct Buffer *tmp = buf_pool_get();
58 if (b_src->filename)
59 {
60 use_disp = true;
61 buf_strcpy(tmp, b_src->filename);
62 }
63 else
64 {
65 use_disp = false;
66 }
68 mutt_adv_mktemp(tmp);
69 if (mutt_save_attachment(fp, b_src, buf_string(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
70 {
71 buf_pool_release(&tmp);
72 return -1;
73 }
75 *b_dst = mutt_body_new();
76 b = *b_dst;
78 memcpy(b, b_src, sizeof(struct Body));
80 b->parts = NULL;
81 b->next = NULL;
83 b->filename = buf_strdup(tmp);
84 b->use_disp = use_disp;
85 b->unlink = true;
87 if (mutt_is_text_part(b))
88 b->noconv = true;
90 b->xtype = mutt_str_dup(b->xtype);
94 /* mutt_adv_mktemp() will mangle the filename in tmp,
95 * so preserve it in d_filename */
96 if (!b->d_filename && use_disp)
97 b->d_filename = mutt_str_dup(b_src->filename);
103 b->content = NULL;
104 b->aptr = NULL;
105 b->mime_headers = NULL;
107 /* we don't seem to need the Email structure currently.
108 * XXX this may change in the future */
109 b->email = NULL;
111 /* copy parameters */
112 struct Parameter *np = NULL, *new_param = NULL;
113 TAILQ_FOREACH(np, &b_src->parameter, entries)
114 {
115 new_param = mutt_param_new();
116 new_param->attribute = mutt_str_dup(np->attribute);
117 new_param->value = mutt_str_dup(np->value);
118 TAILQ_INSERT_HEAD(&b->parameter, new_param, entries);
119 }
122 buf_pool_release(&tmp);
123 return 0;
GUI display the mailboxes in a side panel.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
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
Structs that make up an email.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
int mutt_save_attachment(FILE *fp, struct Body *b, const char *path, enum SaveAttach opt, struct Email *e)
Save an attachment.
Definition: mutt_attach.c:905
No flags set.
Definition: mutt_attach.h:58
int mutt_body_copy(FILE *fp, struct Body **b_dst, struct Body *b_src)
Create a send-mode duplicate from a receive-mode body.
Definition: mutt_body.c:49
Representation of the body of an email.
bool mutt_is_text_part(const struct Body *b)
Is this part of an email in plain text?
Definition: muttlib.c:442
void mutt_adv_mktemp(struct Buffer *buf)
Create a temporary file.
Definition: muttlib.c:84
Some miscellaneous functions.
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:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_INIT(head)
Definition: queue.h:765
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
Convenience wrapper for the send headers.
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:77
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:72
char * xtype
content-type if x-unknown
Definition: body.h:61
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:67
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
char * charset
Send mode: charset of attached file as stored on disk.
Definition: body.h:78
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:74
bool use_disp
Content-Disposition uses filename= ?
Definition: body.h:47
struct Email * email
header information for message/rfc822
Definition: body.h:73
char * description
Definition: body.h:55
struct Content * content
Detailed info about the content of the attachment.
Definition: body.h:69
struct Body * next
next attachment in the list
Definition: body.h:71
char * subtype
content-type subtype
Definition: body.h:60
char * form_name
Content-Disposition form-data name param.
Definition: body.h:59
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:58
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