Copy header from one file to another.
114{
115 bool from = false;
116 bool this_is_from = false;
117 bool ignore = false;
118 char buf[1024] = { 0 };
119 char *nl = NULL;
121 int hdr_count;
122 int x;
123 char *this_one = NULL;
124 size_t this_one_len = 0;
125
126 if (off_start < 0)
127 return -1;
128
129 if (ftello(fp_in) != off_start)
131 return -1;
132
133 buf[0] = '\n';
134 buf[1] = '\0';
135
137 {
138
139
140 while (ftello(fp_in) < off_end)
141 {
142 nl = strchr(buf, '\n');
143
144 if (!fgets(buf, sizeof(buf), fp_in))
145 break;
146
147
148 const size_t line_len = strlen(buf);
149 if ((line_len > 2) && (buf[line_len - 2] == '\r') && (buf[line_len - 1] == '\n'))
150 {
151 buf[line_len - 2] = '\n';
152 buf[line_len - 1] = '\0';
153 }
154
155
156 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
157 {
158 ignore = true;
160 {
162 continue;
163 from = true;
164 }
166 {
167 continue;
168 }
169 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
170 {
171 break;
172 }
173
176 {
177 continue;
178 }
182 {
183 continue;
184 }
186 {
187 continue;
188 }
190 {
191 continue;
192 }
194 continue;
196 {
197 continue;
198 }
199
200 ignore = false;
201 }
202
203 if (!ignore && (fputs(buf, fp_out) == EOF))
204 return -1;
205 }
206 return 0;
207 }
208
209 hdr_count = 1;
210 x = 0;
211
214
215
216
217
219 {
222 {
224 hdr_count++;
225 }
226 }
227
229
231
232
233 while (ftello(fp_in) < off_end)
234 {
235 nl = strchr(buf, '\n');
236
237
238 if (!fgets(buf, sizeof(buf), fp_in))
239 break;
240
241
242 if (nl && (buf[0] != ' ') && (buf[0] != '\t'))
243 {
244
245 if (this_one)
246 {
248 {
252 }
253
255 this_one = NULL;
256 }
257
258 ignore = true;
259 this_is_from = false;
261 {
263 continue;
264 this_is_from = true;
265 from = true;
266 }
267 else if ((buf[0] == '\n') || ((buf[0] == '\r') && (buf[1] == '\n')))
268 {
269 break;
270 }
271
272
275 {
276 continue;
277 }
279 {
280 continue;
281 }
284 {
285 continue;
286 }
289 {
290 continue;
291 }
293 {
295 {
296 continue;
297 }
301 {
302 continue;
303 }
304 }
306 {
307 continue;
308 }
310 {
311 continue;
312 }
314 continue;
316 {
317 continue;
318 }
319
320
322 {
324 x = 0;
325 int match = -1;
326 size_t match_len = 0;
327
329 {
332 {
333 if ((match == -1) || (hdr_order_len > match_len))
334 {
335 match = x;
336 match_len = hdr_order_len;
337 }
339 }
340 x++;
341 }
342 if (match != -1)
343 x = match;
344 }
345
346 ignore = false;
347 }
348
349 if (!ignore)
350 {
352 if (this_one)
353 {
355
358 this_one_len += blen;
359 }
360 else
361 {
364 }
365 }
366 }
367
368
369 if (this_one)
370 {
372 {
376 }
377
379 this_one = NULL;
380 }
381
382
383 bool error = false;
384 const char **hp = NULL;
386
388 {
389 if (!error && hp && *hp)
390 {
391
392
394 {
395 const char *pre = (chflags &
CH_PREFIX) ? prefix : NULL;
397
399 {
400 error = true;
401 }
402 }
403 else
404 {
405 if (fputs(*hp, fp_out) == EOF)
406 {
407 error = true;
408 }
409 }
410 }
411
413 }
415
416 if (error)
417 return -1;
418 return 0;
419}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_RESERVE(head, n)
Reserve memory for 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 'header-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.
#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)
@ MODULE_ID_EMAIL
ModuleEmail, Email code
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.
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
#define STAILQ_FOREACH(var, head, field)
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Email private Module data.
struct ListHead header_order
List of header fields in the order they should be displayed.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.