Copy header from one file to another.
108{
109 bool from = false;
110 bool this_is_from = false;
111 bool ignore = false;
112 char buf[1024] = { 0 };
113 char *nl = NULL;
115 int hdr_count;
116 int x;
117 char *this_one = NULL;
118 size_t this_one_len = 0;
119
120 if (off_start < 0)
121 return -1;
122
123 if (ftello(fp_in) != off_start)
125 return -1;
126
127 buf[0] = '\n';
128 buf[1] = '\0';
129
131 {
132
133
134 while (ftello(fp_in) < off_end)
135 {
136 nl = strchr(buf, '\n');
137
138 if (!fgets(buf, sizeof(buf), fp_in))
139 break;
140
141
142 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
143 {
144 ignore = true;
146 {
148 continue;
149 from = true;
150 }
152 {
153 continue;
154 }
155 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
156 {
157 break;
158 }
159
162 {
163 continue;
164 }
168 {
169 continue;
170 }
172 {
173 continue;
174 }
176 {
177 continue;
178 }
180 continue;
182 {
183 continue;
184 }
185
186 ignore = false;
187 }
188
189 if (!ignore && (fputs(buf, fp_out) == EOF))
190 return -1;
191 }
192 return 0;
193 }
194
195 hdr_count = 1;
196 x = 0;
197
198
199
200
202 {
205 {
207 hdr_count++;
208 }
209 }
210
212
214
215
216 while (ftello(fp_in) < off_end)
217 {
218 nl = strchr(buf, '\n');
219
220
221 if (!fgets(buf, sizeof(buf), fp_in))
222 break;
223
224
225 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
226 {
227
228 if (this_one)
229 {
231 {
235
236
237 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
238 (this_one[this_one_len - 1] == '\n'))
239 {
240 this_one[this_one_len - 2] = '\n';
241 this_one[this_one_len - 1] = '\0';
242 }
243 }
244
246 this_one = NULL;
247 }
248
249 ignore = true;
250 this_is_from = false;
252 {
254 continue;
255 this_is_from = true;
256 from = true;
257 }
258 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
259 {
260 break;
261 }
262
263
266 {
267 continue;
268 }
270 {
271 continue;
272 }
275 {
276 continue;
277 }
280 {
281 continue;
282 }
284 {
286 {
287 continue;
288 }
292 {
293 continue;
294 }
295 }
297 {
298 continue;
299 }
301 {
302 continue;
303 }
305 continue;
307 {
308 continue;
309 }
310
311
313 {
315 x = 0;
316 int match = -1;
317 size_t match_len = 0;
318
320 {
323 {
324 if ((match == -1) || (hdr_order_len > match_len))
325 {
326 match = x;
327 match_len = hdr_order_len;
328 }
330 }
331 x++;
332 }
333 if (match != -1)
334 x = match;
335 }
336
337 ignore = false;
338 }
339
340 if (!ignore)
341 {
343 if (this_one)
344 {
346
349 this_one_len += blen;
350 }
351 else
352 {
355 }
356 }
357 }
358
359
360 if (this_one)
361 {
363 {
367 }
368
370 this_one = NULL;
371 }
372
373
374 bool error = false;
375 char **hp = NULL;
377
379 {
380 if (!error && hp && *hp)
381 {
382
383
385 {
386 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
388
390 {
391 error = true;
392 }
393 }
394 else
395 {
396 if (fputs(*hp, fp_out) == EOF)
397 {
398 error = true;
399 }
400 }
401 }
402
404 }
406
407 if (error)
408 return -1;
409 return 0;
410}
#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.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
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.