forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutt_body.c
125 lines (109 loc) · 3.25 KB
/
mutt_body.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @file
* Representation of the body of an email
*
* @authors
* Copyright (C) 2017-2023 Richard Russon <[email protected]>
* Copyright (C) 2018-2020 Pietro Cerutti <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* 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/>.
*/
/**
* @page neo_mutt_body Representation of the body of an email
*
* Representation of the body of an email
*/
#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "email/lib.h"
#include "mutt_body.h"
#include "attach/lib.h"
#include "send/lib.h"
#include "muttlib.h"
/**
* mutt_body_copy - Create a send-mode duplicate from a receive-mode body
* @param[in] fp FILE pointer to attachments
* @param[out] b_dst New Body will be saved here
* @param[in] b_src Source Body to copy
* @retval 0 Success
* @retval -1 Failure
*/
int mutt_body_copy(FILE *fp, struct Body **b_dst, struct Body *b_src)
{
if (!b_dst || !b_src)
return -1;
struct Body *b = NULL;
bool use_disp;
struct Buffer *tmp = buf_pool_get();
if (b_src->filename)
{
use_disp = true;
buf_strcpy(tmp, b_src->filename);
}
else
{
use_disp = false;
}
mutt_adv_mktemp(tmp);
if (mutt_save_attachment(fp, b_src, buf_string(tmp), MUTT_SAVE_NO_FLAGS, NULL) == -1)
{
buf_pool_release(&tmp);
return -1;
}
*b_dst = mutt_body_new();
b = *b_dst;
memcpy(b, b_src, sizeof(struct Body));
TAILQ_INIT(&b->parameter);
b->parts = NULL;
b->next = NULL;
b->content_id = mutt_str_dup(b->content_id);
b->filename = buf_strdup(tmp);
b->use_disp = use_disp;
b->unlink = true;
if (mutt_is_text_part(b))
b->noconv = true;
b->xtype = mutt_str_dup(b->xtype);
b->subtype = mutt_str_dup(b->subtype);
b->form_name = mutt_str_dup(b->form_name);
b->d_filename = mutt_str_dup(b->d_filename);
/* mutt_adv_mktemp() will mangle the filename in tmp,
* so preserve it in d_filename */
if (!b->d_filename && use_disp)
b->d_filename = mutt_str_dup(b_src->filename);
b->description = mutt_str_dup(b->description);
b->language = mutt_str_dup(b->language);
b->charset = mutt_str_dup(b->charset);
b->content = NULL;
b->aptr = NULL;
b->mime_headers = NULL;
/* we don't seem to need the Email structure currently.
* XXX this may change in the future */
b->email = NULL;
/* copy parameters */
struct Parameter *np = NULL, *new_param = NULL;
TAILQ_FOREACH(np, &b_src->parameter, entries)
{
new_param = mutt_param_new();
new_param->attribute = mutt_str_dup(np->attribute);
new_param->value = mutt_str_dup(np->value);
TAILQ_INSERT_HEAD(&b->parameter, new_param, entries);
}
mutt_stamp_attachment(b);
buf_pool_release(&tmp);
return 0;
}