3 * Representation of the body of an email
6 * Copyright (C) 2017 Richard Russon <rich@flatcap.org>
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 2 of the License, or (at your option) any later
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
24 * @page mutt_body Representation of the body of an email
26 * Representation of the body of an email
33 #include "mutt/mutt.h"
34 #include "email/lib.h"
35 #include "mutt_attach.h"
40 * mutt_body_copy - Create a send-mode duplicate from a receive-mode body
41 * @param[in] fp FILE pointer to attachments
42 * @param[out] tgt New Body will be saved here
43 * @param[in] src Source Body to copy
47 int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src)
52 struct Body *b = NULL;
54 struct Buffer *tmp = mutt_buffer_pool_get();
59 mutt_buffer_strcpy(tmp, src->filename);
67 if (mutt_save_attachment(fp, src, mutt_b2s(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
69 mutt_buffer_pool_release(&tmp);
73 *tgt = mutt_body_new();
76 memcpy(b, src, sizeof(struct Body));
77 TAILQ_INIT(&b->parameter);
81 b->filename = mutt_str_strdup(mutt_b2s(tmp));
82 b->use_disp = use_disp;
85 if (mutt_is_text_part(b))
88 b->xtype = mutt_str_strdup(b->xtype);
89 b->subtype = mutt_str_strdup(b->subtype);
90 b->form_name = mutt_str_strdup(b->form_name);
91 b->d_filename = mutt_str_strdup(b->d_filename);
92 /* mutt_adv_mktemp() will mangle the filename in tmp,
93 * so preserve it in d_filename */
94 if (!b->d_filename && use_disp)
95 b->d_filename = mutt_str_strdup(src->filename);
96 b->description = mutt_str_strdup(b->description);
98 /* we don't seem to need the Email structure currently.
99 * XXX this may change in the future */
104 /* copy parameters */
105 struct Parameter *np = NULL, *new_param = NULL;
106 TAILQ_FOREACH(np, &src->parameter, entries)
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);
114 mutt_stamp_attachment(b);
115 mutt_buffer_pool_release(&tmp);