Copy header from one file to another.
109{
110 bool from = false;
111 bool this_is_from = false;
112 bool ignore = false;
113 char buf[1024] = { 0 };
114 char *nl = NULL;
116 int hdr_count;
117 int x;
118 char *this_one = NULL;
119 size_t this_one_len = 0;
120
121 if (off_start < 0)
122 return -1;
123
124 if (ftello(fp_in) != off_start)
126 return -1;
127
128 buf[0] = '\n';
129 buf[1] = '\0';
130
132 {
133
134
135 while (ftello(fp_in) < off_end)
136 {
137 nl = strchr(buf, '\n');
138
139 if (!fgets(buf, sizeof(buf), fp_in))
140 break;
141
142
143 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
144 {
145 ignore = true;
147 {
149 continue;
150 from = true;
151 }
153 {
154 continue;
155 }
156 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
157 {
158 break;
159 }
160
163 {
164 continue;
165 }
169 {
170 continue;
171 }
173 {
174 continue;
175 }
177 {
178 continue;
179 }
181 continue;
183 {
184 continue;
185 }
186
187 ignore = false;
188 }
189
190 if (!ignore && (fputs(buf, fp_out) == EOF))
191 return -1;
192 }
193 return 0;
194 }
195
196 hdr_count = 1;
197 x = 0;
198
199
200
201
203 {
206 {
208 hdr_count++;
209 }
210 }
211
213
215
216
217 while (ftello(fp_in) < off_end)
218 {
219 nl = strchr(buf, '\n');
220
221
222 if (!fgets(buf, sizeof(buf), fp_in))
223 break;
224
225
226 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
227 {
228
229 if (this_one)
230 {
232 {
236
237
238 if ((this_one_len > 2) && (this_one[this_one_len - 2] == '\r') &&
239 (this_one[this_one_len - 1] == '\n'))
240 {
241 this_one[this_one_len - 2] = '\n';
242 this_one[this_one_len - 1] = '\0';
243 }
244 }
245
247 this_one = NULL;
248 }
249
250 ignore = true;
251 this_is_from = false;
253 {
255 continue;
256 this_is_from = true;
257 from = true;
258 }
259 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
260 {
261 break;
262 }
263
264
267 {
268 continue;
269 }
271 {
272 continue;
273 }
276 {
277 continue;
278 }
281 {
282 continue;
283 }
285 {
287 {
288 continue;
289 }
293 {
294 continue;
295 }
296 }
298 {
299 continue;
300 }
302 {
303 continue;
304 }
306 continue;
308 {
309 continue;
310 }
311
312
314 {
316 x = 0;
317 int match = -1;
318 size_t match_len = 0;
319
321 {
324 {
325 if ((match == -1) || (hdr_order_len > match_len))
326 {
327 match = x;
328 match_len = hdr_order_len;
329 }
331 }
332 x++;
333 }
334 if (match != -1)
335 x = match;
336 }
337
338 ignore = false;
339 }
340
341 if (!ignore)
342 {
344 if (this_one)
345 {
347
350 this_one_len += blen;
351 }
352 else
353 {
356 }
357 }
358 }
359
360
361 if (this_one)
362 {
364 {
368 }
369
371 this_one = NULL;
372 }
373
374
375 bool error = false;
376 char **hp = NULL;
378
380 {
381 if (!error && hp && *hp)
382 {
383
384
386 {
387 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
389
391 {
392 error = true;
393 }
394 }
395 else
396 {
397 if (fputs(*hp, fp_out) == EOF)
398 {
399 error = true;
400 }
401 }
402 }
403
405 }
407
408 if (error)
409 return -1;
410 return 0;
411}
#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.
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.