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 {
151 continue;
152 }
153 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
154 {
155 break;
156 }
157
160 {
161 continue;
162 }
166 {
167 continue;
168 }
170 {
171 continue;
172 }
174 {
175 continue;
176 }
178 continue;
180 {
181 continue;
182 }
183
184 ignore = false;
185 }
186
187 if (!ignore && (fputs(buf, fp_out) == EOF))
188 return -1;
189 }
190 return 0;
191 }
192
193 hdr_count = 1;
194 x = 0;
195
196
197
198
200 {
203 {
205 hdr_count++;
206 }
207 }
208
210
212
213
214 while (ftello(fp_in) < off_end)
215 {
216 nl = strchr(buf, '\n');
217
218
219 if (!fgets(buf, sizeof(buf), fp_in))
220 break;
221
222
223 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
224 {
225
226 if (this_one)
227 {
229 {
233
234
235 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
236 (this_one[this_one_len - 1] == '\n'))
237 {
238 this_one[this_one_len - 2] = '\n';
239 this_one[this_one_len - 1] = '\0';
240 }
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.
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
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_str_dup(const char *str)
Copy a string, safely.
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.
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
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.