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 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
141 {
142 ignore = true;
144 {
146 continue;
147 from = true;
148 }
150 continue;
151 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
152 break;
153
156 {
157 continue;
158 }
162 {
163 continue;
164 }
166 {
167 continue;
168 }
170 {
171 continue;
172 }
174 continue;
176 {
177 continue;
178 }
179
180 ignore = false;
181 }
182
183 if (!ignore && (fputs(buf, fp_out) == EOF))
184 return -1;
185 }
186 return 0;
187 }
188
189 hdr_count = 1;
190 x = 0;
191
192
193
194
196 {
199 {
201 hdr_count++;
202 }
203 }
204
206
208
209
210 while (ftello(fp_in) < off_end)
211 {
212 nl = strchr(buf, '\n');
213
214
215 if (!fgets(buf, sizeof(buf), fp_in))
216 break;
217
218
219 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
220 {
221
222 if (this_one)
223 {
225 {
229
230
231 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
232 (this_one[this_one_len - 1] == '\n'))
233 {
234 this_one[this_one_len - 2] = '\n';
235 this_one[this_one_len - 1] = '\0';
236 }
237 }
238
240 this_one = NULL;
241 }
242
243 ignore = true;
244 this_is_from = false;
246 {
248 continue;
249 this_is_from = true;
250 from = true;
251 }
252 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
253 break;
254
255
258 {
259 continue;
260 }
262 {
263 continue;
264 }
267 {
268 continue;
269 }
272 {
273 continue;
274 }
276 {
278 {
279 continue;
280 }
284 {
285 continue;
286 }
287 }
289 {
290 continue;
291 }
293 {
294 continue;
295 }
297 continue;
299 {
300 continue;
301 }
302
303
305 {
307 x = 0;
308 int match = -1;
309 size_t match_len = 0;
310
312 {
313 x++;
316 {
317 if ((match == -1) || (hdr_order_len > match_len))
318 {
319 match = x;
320 match_len = hdr_order_len;
321 }
323 }
324 }
325 if (match != -1)
326 x = match;
327 }
328
329 ignore = false;
330 }
331
332 if (!ignore)
333 {
335 if (this_one)
336 {
338
340 strcat(this_one + this_one_len, buf);
341 this_one_len += blen;
342 }
343 else
344 {
347 }
348 }
349 }
350
351
352 if (this_one)
353 {
355 {
359 }
360
362 this_one = NULL;
363 }
364
365
366 bool error = false;
367 char **hp = NULL;
369 {
370 if (!error && hp && *hp)
371 {
372
373
375 {
376 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
379
381 {
382 error = true;
383 }
384 }
385 else
386 {
387 if (fputs(*hp, fp_out) == EOF)
388 {
389 error = true;
390 }
391 }
392 }
393
395 }
397
398 if (error)
399 return -1;
400 return 0;
401}
#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 Headers *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:
#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.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
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.
struct ListHead HeaderOrderList
List of header fields in the order they should be displayed.
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
static size_t plen
Length of cached packet.
#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.