Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * @file |
3 | | * Representation of the body of an email |
4 | | * |
5 | | * @authors |
6 | | * Copyright (C) 2017 Richard Russon <rich@flatcap.org> |
7 | | * |
8 | | * @copyright |
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 |
12 | | * version. |
13 | | * |
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 |
17 | | * details. |
18 | | * |
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/>. |
21 | | */ |
22 | | |
23 | | /** |
24 | | * @page neo_mutt_body Representation of the body of an email |
25 | | * |
26 | | * Representation of the body of an email |
27 | | */ |
28 | | |
29 | | #include "config.h" |
30 | | #include <stdbool.h> |
31 | | #include <stdio.h> |
32 | | #include <string.h> |
33 | | #include "mutt/lib.h" |
34 | | #include "email/lib.h" |
35 | | #include "mutt_body.h" |
36 | | #include "attach/lib.h" |
37 | | #include "send/lib.h" |
38 | | #include "muttlib.h" |
39 | | |
40 | | /** |
41 | | * mutt_body_copy - Create a send-mode duplicate from a receive-mode body |
42 | | * @param[in] fp FILE pointer to attachments |
43 | | * @param[out] tgt New Body will be saved here |
44 | | * @param[in] src Source Body to copy |
45 | | * @retval 0 Success |
46 | | * @retval -1 Failure |
47 | | */ |
48 | | int mutt_body_copy(FILE *fp, struct Body **tgt, struct Body *src) |
49 | 0 | { |
50 | 0 | if (!tgt || !src) |
51 | 0 | return -1; |
52 | | |
53 | 0 | struct Body *b = NULL; |
54 | 0 | bool use_disp; |
55 | 0 | struct Buffer *tmp = buf_pool_get(); |
56 | |
|
57 | 0 | if (src->filename) |
58 | 0 | { |
59 | 0 | use_disp = true; |
60 | 0 | buf_strcpy(tmp, src->filename); |
61 | 0 | } |
62 | 0 | else |
63 | 0 | { |
64 | 0 | use_disp = false; |
65 | 0 | } |
66 | |
|
67 | 0 | mutt_adv_mktemp(tmp); |
68 | 0 | if (mutt_save_attachment(fp, src, buf_string(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1) |
69 | 0 | { |
70 | 0 | buf_pool_release(&tmp); |
71 | 0 | return -1; |
72 | 0 | } |
73 | | |
74 | 0 | *tgt = mutt_body_new(); |
75 | 0 | b = *tgt; |
76 | |
|
77 | 0 | memcpy(b, src, sizeof(struct Body)); |
78 | 0 | TAILQ_INIT(&b->parameter); |
79 | 0 | b->parts = NULL; |
80 | 0 | b->next = NULL; |
81 | |
|
82 | 0 | b->filename = buf_strdup(tmp); |
83 | 0 | b->use_disp = use_disp; |
84 | 0 | b->unlink = true; |
85 | |
|
86 | 0 | if (mutt_is_text_part(b)) |
87 | 0 | b->noconv = true; |
88 | |
|
89 | 0 | b->xtype = mutt_str_dup(b->xtype); |
90 | 0 | b->subtype = mutt_str_dup(b->subtype); |
91 | 0 | b->form_name = mutt_str_dup(b->form_name); |
92 | 0 | b->d_filename = mutt_str_dup(b->d_filename); |
93 | | /* mutt_adv_mktemp() will mangle the filename in tmp, |
94 | | * so preserve it in d_filename */ |
95 | 0 | if (!b->d_filename && use_disp) |
96 | 0 | b->d_filename = mutt_str_dup(src->filename); |
97 | 0 | b->description = mutt_str_dup(b->description); |
98 | |
|
99 | 0 | b->language = mutt_str_dup(b->language); |
100 | 0 | b->charset = mutt_str_dup(b->charset); |
101 | |
|
102 | 0 | b->content = NULL; |
103 | 0 | b->aptr = NULL; |
104 | 0 | b->mime_headers = NULL; |
105 | | |
106 | | /* we don't seem to need the Email structure currently. |
107 | | * XXX this may change in the future */ |
108 | 0 | b->email = NULL; |
109 | | |
110 | | /* copy parameters */ |
111 | 0 | struct Parameter *np = NULL, *new_param = NULL; |
112 | 0 | TAILQ_FOREACH(np, &src->parameter, entries) |
113 | 0 | { |
114 | 0 | new_param = mutt_param_new(); |
115 | 0 | new_param->attribute = mutt_str_dup(np->attribute); |
116 | 0 | new_param->value = mutt_str_dup(np->value); |
117 | 0 | TAILQ_INSERT_HEAD(&b->parameter, new_param, entries); |
118 | 0 | } |
119 | |
|
120 | 0 | mutt_stamp_attachment(b); |
121 | 0 | buf_pool_release(&tmp); |
122 | 0 | return 0; |
123 | 0 | } |