Copy header from one file to another.
106{
107 bool from = false;
108 bool this_is_from = false;
109 bool ignore = false;
110 char buf[1024] = { 0 };
111 char *nl = NULL;
113 int hdr_count;
114 int x;
115 char *this_one = NULL;
116 size_t this_one_len = 0;
117
118 if (off_start < 0)
119 return -1;
120
121 if (ftello(fp_in) != off_start)
123 return -1;
124
125 buf[0] = '\n';
126 buf[1] = '\0';
127
129 {
130
131
132 while (ftello(fp_in) < off_end)
133 {
134 nl = strchr(buf, '\n');
135
136 if (!fgets(buf, sizeof(buf), fp_in))
137 break;
138
139
140 const size_t line_len = strlen(buf);
141 if ((line_len > 2) && (buf[line_len - 2] == '\r') && (buf[line_len - 1] == '\n'))
142 {
143 buf[line_len - 2] = '\n';
144 buf[line_len - 1] = '\0';
145 }
146
147
148 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
149 {
150 ignore = true;
152 {
154 continue;
155 from = true;
156 }
158 {
159 continue;
160 }
161 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
162 {
163 break;
164 }
165
168 {
169 continue;
170 }
174 {
175 continue;
176 }
178 {
179 continue;
180 }
182 {
183 continue;
184 }
186 continue;
188 {
189 continue;
190 }
191
192 ignore = false;
193 }
194
195 if (!ignore && (fputs(buf, fp_out) == EOF))
196 return -1;
197 }
198 return 0;
199 }
200
201 hdr_count = 1;
202 x = 0;
203
204
205
206
208 {
211 {
213 hdr_count++;
214 }
215 }
216
218
220
221
222 while (ftello(fp_in) < off_end)
223 {
224 nl = strchr(buf, '\n');
225
226
227 if (!fgets(buf, sizeof(buf), fp_in))
228 break;
229
230
231 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
232 {
233
234 if (this_one)
235 {
237 {
241 }
242
244 this_one = NULL;
245 }
246
247 ignore = true;
248 this_is_from = false;
250 {
252 continue;
253 this_is_from = true;
254 from = true;
255 }
256 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
257 {
258 break;
259 }
260
261
264 {
265 continue;
266 }
268 {
269 continue;
270 }
273 {
274 continue;
275 }
278 {
279 continue;
280 }
282 {
284 {
285 continue;
286 }
290 {
291 continue;
292 }
293 }
295 {
296 continue;
297 }
299 {
300 continue;
301 }
303 continue;
305 {
306 continue;
307 }
308
309
311 {
313 x = 0;
314 int match = -1;
315 size_t match_len = 0;
316
318 {
321 {
322 if ((match == -1) || (hdr_order_len > match_len))
323 {
324 match = x;
325 match_len = hdr_order_len;
326 }
328 }
329 x++;
330 }
331 if (match != -1)
332 x = match;
333 }
334
335 ignore = false;
336 }
337
338 if (!ignore)
339 {
341 if (this_one)
342 {
344
347 this_one_len += blen;
348 }
349 else
350 {
353 }
354 }
355 }
356
357
358 if (this_one)
359 {
361 {
365 }
366
368 this_one = NULL;
369 }
370
371
372 bool error = false;
373 const char **hp = NULL;
375
377 {
378 if (!error && hp && *hp)
379 {
380
381
383 {
384 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
386
388 {
389 error = true;
390 }
391 }
392 else
393 {
394 if (fputs(*hp, fp_out) == EOF)
395 {
396 error = true;
397 }
398 }
399 }
400
402 }
404
405 if (error)
406 return -1;
407 return 0;
408}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_FREE(head)
Release all memory.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
static int address_header_decode(char **h)
Parse an email's headers.
static void add_one_header(struct StringArray *headers, int pos, char *value)
Add a header to a Headers array.
#define CH_DECODE
Do RFC2047 header decoding.
#define CH_XMIT
Transmitting this message? (Ignore Lines: and Content-Length:)
#define CH_PREFIX
Quote header using $indent_string string?
#define CH_UPDATE
Update the status and x-status fields?
#define CH_NOSTATUS
Suppress the status and x-status fields.
#define CH_FROM
Retain the "From " message separator?
#define CH_WEED_DELIVERED
Weed eventual Delivered-To headers.
#define CH_UPDATE_LABEL
Update X-Label: from email->env->x_label?
#define CH_WEED
Weed the headers?
#define CH_REORDER
Re-order output of headers (specified by 'hdr_order')
#define CH_MIME
Ignore MIME fields.
#define CH_UPDATE_REFS
Update References:
#define CH_NOQFROM
Ignore ">From " line.
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
#define CH_UPDATE_IRT
Update In-Reply-To:
#define CH_FORCE_FROM
Give CH_FROM precedence over CH_WEED?
#define CH_UPDATE_SUBJECT
Update Subject: protected header update.
#define CH_NOLEN
Don't write Content-Length: and Lines:
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
#define mutt_debug(LEVEL,...)
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
#define MUTT_MEM_REALLOC(pptr, n, type)
char * mutt_strn_copy(char *dest, const char *src, size_t len, size_t dsize)
Copy a sub-string into a buffer.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
#define STAILQ_FOREACH(var, head, field)
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.