Copy header from one file to another.
110{
111 bool from = false;
112 bool this_is_from = false;
113 bool ignore = false;
114 char buf[1024] = { 0 };
115 char *nl = NULL;
117 int hdr_count;
118 int x;
119 char *this_one = NULL;
120 size_t this_one_len = 0;
121
122 if (off_start < 0)
123 return -1;
124
125 if (ftello(fp_in) != off_start)
127 return -1;
128
129 buf[0] = '\n';
130 buf[1] = '\0';
131
133 {
134
135
136 while (ftello(fp_in) < off_end)
137 {
138 nl = strchr(buf, '\n');
139
140 if (!fgets(buf, sizeof(buf), fp_in))
141 break;
142
143
144 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
145 {
146 ignore = true;
148 {
150 continue;
151 from = true;
152 }
154 {
155 continue;
156 }
157 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
158 {
159 break;
160 }
161
164 {
165 continue;
166 }
170 {
171 continue;
172 }
174 {
175 continue;
176 }
178 {
179 continue;
180 }
182 continue;
184 {
185 continue;
186 }
187
188 ignore = false;
189 }
190
191 if (!ignore && (fputs(buf, fp_out) == EOF))
192 return -1;
193 }
194 return 0;
195 }
196
197 hdr_count = 1;
198 x = 0;
199
200
201
202
204 {
207 {
209 hdr_count++;
210 }
211 }
212
214
216
217
218 while (ftello(fp_in) < off_end)
219 {
220 nl = strchr(buf, '\n');
221
222
223 if (!fgets(buf, sizeof(buf), fp_in))
224 break;
225
226
227 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
228 {
229
230 if (this_one)
231 {
233 {
237
238
239 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
240 (this_one[this_one_len - 1] == '\n'))
241 {
242 this_one[this_one_len - 2] = '\n';
243 this_one[this_one_len - 1] = '\0';
244 }
245 }
246
248 this_one = NULL;
249 }
250
251 ignore = true;
252 this_is_from = false;
254 {
256 continue;
257 this_is_from = true;
258 from = true;
259 }
260 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
261 {
262 break;
263 }
264
265
268 {
269 continue;
270 }
272 {
273 continue;
274 }
277 {
278 continue;
279 }
282 {
283 continue;
284 }
286 {
288 {
289 continue;
290 }
294 {
295 continue;
296 }
297 }
299 {
300 continue;
301 }
303 {
304 continue;
305 }
307 continue;
309 {
310 continue;
311 }
312
313
315 {
317 x = 0;
318 int match = -1;
319 size_t match_len = 0;
320
322 {
325 {
326 if ((match == -1) || (hdr_order_len > match_len))
327 {
328 match = x;
329 match_len = hdr_order_len;
330 }
332 }
333 x++;
334 }
335 if (match != -1)
336 x = match;
337 }
338
339 ignore = false;
340 }
341
342 if (!ignore)
343 {
345 if (this_one)
346 {
348
351 this_one_len += blen;
352 }
353 else
354 {
357 }
358 }
359 }
360
361
362 if (this_one)
363 {
365 {
369 }
370
372 this_one = NULL;
373 }
374
375
376 bool error = false;
377 char **hp = NULL;
379
381 {
382 if (!error && hp && *hp)
383 {
384
385
387 {
388 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
390
392 {
393 error = true;
394 }
395 }
396 else
397 {
398 if (fputs(*hp, fp_out) == EOF)
399 {
400 error = true;
401 }
402 }
403 }
404
406 }
408
409 if (error)
410 return -1;
411 return 0;
412}
#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 HeaderArray *headers, size_t 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.