1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Routines for processing and detecting headlines.
3 *@ TODO Mostly a hackery, we need RFC compliant parsers instead.
5 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
6 * Copyright (c) 2012 - 2017 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
9 * Copyright (c) 1980, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #ifndef HAVE_AMALGAMATION
44 # if HAVE_IDNA == HAVE_IDNA_LIBIDNA
46 # include <idn-free.h>
47 # include <stringprep.h>
48 # elif HAVE_IDNA == HAVE_IDNA_IDNKIT
54 size_t tlen
; /* Length of .tdata */
55 char const *tdata
; /* Template date - see _cmatch_data[] */
58 /* Template characters for cmatch_data.tdata:
59 * 'A' An upper case char
60 * 'a' A lower case char
63 * 'O' An optional digit or space
65 * '+' Either a plus or a minus sign */
66 static struct cmatch_data
const _cmatch_data
[] = {
67 { 24, "Aaa Aaa O0 00:00:00 0000" }, /* BSD/ISO C90 ctime */
68 { 28, "Aaa Aaa O0 00:00:00 AAA 0000" }, /* BSD tmz */
69 { 21, "Aaa Aaa O0 00:00 0000" }, /* SysV ctime */
70 { 25, "Aaa Aaa O0 00:00 AAA 0000" }, /* SysV tmz */
71 /* RFC 822-alike From_ lines do not conform to RFC 4155, but seem to be used
72 * in the wild (by UW-imap) */
73 { 30, "Aaa Aaa O0 00:00:00 0000 +0000" },
74 /* RFC 822 with zone spec; 1. military, 2. UT, 3. north america time
75 * zone strings; note that 1. is strictly speaking not correct as some
76 * letters are not used, and 2. is not because only "UT" is defined */
77 #define __reuse "Aaa Aaa O0 00:00:00 0000 AAA"
78 { 28 - 2, __reuse
}, { 28 - 1, __reuse
}, { 28 - 0, __reuse
},
81 #define a_HEAD_DATE_MINLEN 21
83 /* Skip over "word" as found in From_ line */
84 static char const * _from__skipword(char const *wp
);
86 /* Match the date string against the date template (tp), return if match.
87 * See _cmatch_data[] for template character description */
88 static int _cmatch(size_t len
, char const *date
,
91 /* Check whether date is a valid 'From_' date.
92 * (Rather ctime(3) generated dates, according to RFC 4155) */
93 static int _is_date(char const *date
);
95 /* JulianDayNumber converter(s) */
96 static size_t a_head_gregorian_to_jdn(ui32_t y
, ui32_t m
, ui32_t d
);
98 static void a_head_jdn_to_gregorian(size_t jdn
,
99 ui32_t
*yp
, ui32_t
*mp
, ui32_t
*dp
);
102 /* Convert the domain part of a skinned address to IDNA.
103 * If an error occurs before Unicode information is available, revert the IDNA
104 * error to a normal CHAR one so that the error message doesn't talk Unicode */
106 static struct n_addrguts
*a_head_idna_apply(struct n_addrguts
*agp
);
109 /* Classify and check a (possibly skinned) header body according to RFC
110 * *addr-spec* rules; if it (is assumed to has been) skinned it may however be
111 * also a file or a pipe command, so check that first, then.
112 * Otherwise perform content checking and isolate the domain part (for IDNA) */
113 static bool_t
a_head_addrspec_check(struct n_addrguts
*agp
, bool_t skinned
);
115 /* Return the next header field found in the given message.
116 * Return >= 0 if something found, < 0 elsewise.
117 * "colon" is set to point to the colon in the header.
118 * Must deal with \ continuations & other such fraud */
119 static int gethfield(FILE *f
, char **linebuf
, size_t *linesize
,
120 int rem
, char **colon
);
122 static int msgidnextc(char const **cp
, int *status
);
124 /* Count the occurances of c in str */
125 static int charcount(char *str
, int c
);
127 static char const * nexttoken(char const *cp
);
129 /* TODO v15: change *customhdr* syntax and use shell tokens?! */
130 static char *a_head_customhdr__sep(char **iolist
);
133 _from__skipword(char const *wp
)
139 while ((c
= *wp
++) != '\0' && !blankchar(c
)) {
141 while ((c
= *wp
++) != '\0' && c
!= '"')
147 for (; blankchar(c
); c
= *wp
++)
151 return (c
== 0 ? NULL
: wp
- 1);
155 _cmatch(size_t len
, char const *date
, char const *tp
)
180 if (c
!= ' ' && !digitchar(c
))
188 if (c
!= '+' && c
!= '-')
200 _is_date(char const *date
)
202 struct cmatch_data
const *cmdp
;
207 if ((dl
= strlen(date
)) >= a_HEAD_DATE_MINLEN
)
208 for (cmdp
= _cmatch_data
; cmdp
->tdata
!= NULL
; ++cmdp
)
209 if (dl
== cmdp
->tlen
&& (rv
= _cmatch(dl
, date
, cmdp
->tdata
)))
216 a_head_gregorian_to_jdn(ui32_t y
, ui32_t m
, ui32_t d
){
217 /* Algorithm is taken from Communications of the ACM, Vol 6, No 8.
218 * (via third hand, plus adjustments).
219 * This algorithm is supposed to work for all dates in between 1582-10-15
220 * (0001-01-01 but that not Gregorian) and 65535-12-31 */
259 a_head_jdn_to_gregorian(size_t jdn
, ui32_t
*yp
, ui32_t
*mp
, ui32_t
*dp
){
260 /* Algorithm is taken from Communications of the ACM, Vol 6, No 8.
261 * (via third hand, plus adjustments) */
280 x
= jdn
/ 153; /* x -> month */
283 jdn
/= 5; /* jdn -> day */
291 *yp
= (ui32_t
)(y
& 0xFFFF);
292 *mp
= (ui32_t
)(x
& 0xFF);
293 *dp
= (ui32_t
)(jdn
& 0xFF);
299 # if HAVE_IDNA == HAVE_IDNA_LIBIDNA
300 static struct n_addrguts
*
301 a_head_idna_apply(struct n_addrguts
*agp
)
303 char *idna_utf8
, *idna_ascii
, *cs
;
307 sz
= agp
->ag_slen
- agp
->ag_sdom_start
;
309 idna_utf8
= ac_alloc(sz
+1);
310 memcpy(idna_utf8
, agp
->ag_skinned
+ agp
->ag_sdom_start
, sz
);
311 idna_utf8
[sz
] = '\0';
313 /* GNU Libidn settles on top of iconv(3) without any fallback, so let's just
314 * let it perform the charset conversion, if any should be necessary */
315 if (!(n_psonce
& n_PSO_UNICODE
)) {
316 char const *tcs
= ok_vlook(ttycharset
);
317 idna_ascii
= idna_utf8
;
318 idna_utf8
= stringprep_convert(idna_ascii
, "utf-8", tcs
);
319 i
= (idna_utf8
== NULL
&& n_err_no
== n_ERR_INVAL
);
322 if (idna_utf8
== NULL
) {
324 n_err(_("Cannot convert from %s to %s\n"), tcs
, "utf-8");
325 agp
->ag_n_flags
^= NAME_ADDRSPEC_ERR_IDNA
| NAME_ADDRSPEC_ERR_CHAR
;
330 if (idna_to_ascii_8z(idna_utf8
, &idna_ascii
, 0) != IDNA_SUCCESS
) {
331 agp
->ag_n_flags
^= NAME_ADDRSPEC_ERR_IDNA
| NAME_ADDRSPEC_ERR_CHAR
;
335 /* Replace the domain part of .ag_skinned with IDNA version */
336 sz
= strlen(idna_ascii
);
337 i
= agp
->ag_sdom_start
;
338 cs
= salloc(i
+ sz
+1);
339 memcpy(cs
, agp
->ag_skinned
, i
);
340 memcpy(&cs
[i
], idna_ascii
, sz
);
344 agp
->ag_skinned
= cs
;
346 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
,
347 NAME_NAME_SALLOC
| NAME_SKINNED
| NAME_IDNA
, 0);
349 idn_free(idna_ascii
);
351 if (n_psonce
& n_PSO_UNICODE
)
360 # elif HAVE_IDNA == HAVE_IDNA_IDNKIT /* IDNA==LIBIDNA */
361 static struct n_addrguts
*
362 a_head_idna_apply(struct n_addrguts
*agp
)
364 char *idna_in
, *idna_out
, *cs
;
369 sz
= agp
->ag_slen
- agp
->ag_sdom_start
;
371 idna_in
= ac_alloc(sz
+1);
372 memcpy(idna_in
, agp
->ag_skinned
+ agp
->ag_sdom_start
, sz
);
375 for (idna_out
= NULL
, sz
= HOST_NAME_MAX
+1;; sz
+= HOST_NAME_MAX
) {
376 idna_out
= ac_alloc(sz
);
378 r
= idn_encodename(IDN_ENCODE_APP
, idna_in
, idna_out
, sz
);
381 case idn_buffer_overflow
:
383 case idn_invalid_encoding
:
384 n_err(_("Cannot convert from %s to %s\n"),
385 ok_vlook(ttycharset
), "utf-8");
388 agp
->ag_n_flags
^= NAME_ADDRSPEC_ERR_IDNA
| NAME_ADDRSPEC_ERR_CHAR
;
392 if (r
== idn_success
)
397 /* Replace the domain part of .ag_skinned with IDNA version */
398 sz
= strlen(idna_out
);
399 i
= agp
->ag_sdom_start
;
400 cs
= salloc(i
+ sz
+1);
401 memcpy(cs
, agp
->ag_skinned
, i
);
402 memcpy(&cs
[i
], idna_out
, sz
);
406 agp
->ag_skinned
= cs
;
408 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
,
409 NAME_NAME_SALLOC
| NAME_SKINNED
| NAME_IDNA
, 0);
417 # endif /* IDNA==IDNKIT */
418 #endif /* HAVE_IDNA */
421 a_head_addrspec_check(struct n_addrguts
*agp
, bool_t skinned
)
425 ui8_t in_domain
, hadat
;
426 union {bool_t b
; char c
; unsigned char u
; ui32_t ui32
; si32_t si32
;} c
;
433 use_idna
= ok_blook(idna_disable
) ? 0 : 1;
435 agp
->ag_n_flags
|= NAME_ADDRSPEC_CHECKED
;
436 addr
= agp
->ag_skinned
;
438 if (agp
->ag_iaddr_aend
- agp
->ag_iaddr_start
== 0) {
439 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_EMPTY
, 0);
443 /* If the field is not a recipient, it cannot be a file or a pipe */
447 /* When changing any of the following adjust any RECIPIENTADDRSPEC;
448 * grep the latter for the complete picture */
450 agp
->ag_n_flags
|= NAME_ADDRSPEC_ISPIPE
;
453 if (addr
[0] == '/' || (addr
[0] == '.' && addr
[1] == '/') ||
454 (addr
[0] == '-' && addr
[1] == '\0'))
456 if (memchr(addr
, '@', agp
->ag_slen
) == NULL
) {
459 for (p
= addr
; (c
.c
= *p
); ++p
) {
460 if (c
.c
== '!' || c
.c
== '%')
464 agp
->ag_n_flags
|= NAME_ADDRSPEC_ISFILE
;
472 in_domain
= hadat
= 0;
474 /* TODO addrspec_check: we need a real RFC 5322 (un)?structured parser! */
475 for (p
= addr
; (c
.c
= *p
++) != '\0';) {
477 in_quote
= !in_quote
;
478 } else if (c
.u
< 040 || c
.u
>= 0177) { /* TODO no magics: !bodychar()? */
480 if (in_domain
&& use_idna
> 0) {
482 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_IDNA
,
488 } else if (in_domain
== 2) {
489 if ((c
.c
== ']' && *p
!= '\0') || c
.c
== '\\' || whitechar(c
.c
))
491 } else if (in_quote
&& in_domain
== 0) {
493 } else if (c
.c
== '\\' && *p
!= '\0') {
495 } else if (c
.c
== '@') {
497 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_ATSEQ
,
501 agp
->ag_sdom_start
= PTR2SIZE(p
- addr
);
502 agp
->ag_n_flags
|= NAME_ADDRSPEC_ISADDR
; /* TODO .. really? */
503 in_domain
= (*p
== '[') ? 2 : 1;
505 } else if (c
.c
== '(' || c
.c
== ')' || c
.c
== '<' || c
.c
== '>' ||
506 c
.c
== '[' || c
.c
== ']' || c
.c
== ':' || c
.c
== ';' ||
507 c
.c
== '\\' || c
.c
== ',')
512 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_CHAR
, c
.u
);
516 if(!(agp
->ag_n_flags
& NAME_ADDRSPEC_ISADDR
)){
517 agp
->ag_n_flags
|= NAME_ADDRSPEC_ISNAME
;
518 if(!n_alias_is_valid_name(agp
->ag_input
))
519 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_NAME
, '.');
521 /* If we seem to know that this is an address. Ensure this is correct
522 * according to RFC 5322 TODO the entire address parser should be like
523 * TODO that for one, and then we should know whether structured or
524 * TODO unstructured, and just parse correctly overall!
525 * TODO In addition, this can be optimised a lot.
526 * TODO And it is far from perfect: it should not forget whether no
527 * TODO whitespace followed some snippet, and it was written hastily */
529 struct a_token
*t_last
;
530 struct a_token
*t_next
;
536 a_T_TMASK
= (1<<4) - 1,
538 a_T_SPECIAL
= 1<<8 /* An atom actually needs to go TQUOTE */
543 } *thead
, *tcurr
, *tp
;
545 struct n_string ost
, *ostp
;
546 char const *cp
, *cp1st
, *cpmax
, *xp
;
549 /* Name and domain must be non-empty */
550 if(*addr
== '@' || &addr
[2] >= p
|| p
[-2] == '@'){
552 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_ATSEQ
, c
.u
);
558 agp
= a_head_idna_apply(agp
);
563 /* Nothing to do if there is only an address (in angle brackets) */
564 if(agp
->ag_iaddr_start
== 0){
565 if(agp
->ag_iaddr_aend
== agp
->ag_ilen
)
567 }else if(agp
->ag_iaddr_start
== 1 && *cp
== '<' &&
568 agp
->ag_iaddr_aend
== agp
->ag_ilen
- 1 &&
569 cp
[agp
->ag_iaddr_aend
] == '>')
572 /* It is not, so parse off all tokens, then resort and rejoin */
573 lofi_snap
= n_lofi_snap_create();
576 if((c
.ui32
= agp
->ag_iaddr_start
) > 0)
580 thead
= tcurr
= NULL
;
583 for(tp
= NULL
; cp
< cpmax
;){
587 tp
->t_end
= PTR2SIZE(cp
- cp1st
);
588 tp
= n_lofi_alloc(sizeof *tp
);
590 if((tp
->t_last
= tcurr
) != NULL
)
596 tp
->t_start
= PTR2SIZE(++cp
- cp1st
);
597 xp
= skip_comment(cp
);
598 tp
->t_end
= PTR2SIZE(xp
- cp1st
);
600 if(tp
->t_end
> tp
->t_start
){
604 /* No closing comment - strip trailing whitespace */
605 while(blankchar(*--xp
))
606 if(--tp
->t_end
== tp
->t_start
)
615 tp
->t_end
= PTR2SIZE(cp
- cp1st
);
616 tp
= n_lofi_alloc(sizeof *tp
);
618 if((tp
->t_last
= tcurr
) != NULL
)
623 tp
->t_f
= a_T_TQUOTE
;
624 tp
->t_start
= PTR2SIZE(++cp
- cp1st
);
625 for(xp
= cp
; xp
< cpmax
; ++xp
){
626 if((c
.c
= *xp
) == '"')
628 if(c
.c
== '\\' && xp
[1] != '\0')
631 tp
->t_end
= PTR2SIZE(xp
- cp1st
);
633 if(tp
->t_end
> tp
->t_start
){
634 /* No closing quote - strip trailing whitespace */
636 while(blankchar(*xp
--))
637 if(--tp
->t_end
== tp
->t_start
)
647 tp
->t_end
= PTR2SIZE(cp
- cp1st
);
654 tp
= n_lofi_alloc(sizeof *tp
);
656 if((tp
->t_last
= tcurr
) != NULL
)
662 tp
->t_start
= PTR2SIZE(cp
- cp1st
);
666 /* Reverse solidus transforms the following into a quoted-pair, and
667 * therefore (must occur in comment or quoted-string only) the
668 * entire atom into a quoted string */
670 tp
->t_f
|= a_T_SPECIAL
;
674 /* Is this plain RFC 5322 "atext", or "specials"? Because we don't
675 * TODO know structured/unstructured, nor anything else, we need to
676 * TODO treat "dot-atom" as being identical to "specials" */
677 else if(!alnumchar(c
.c
) &&
678 c
.c
!= '!' && c
.c
!= '#' && c
.c
!= '$' && c
.c
!= '%' &&
679 c
.c
!= '&' && c
.c
!= '\'' && c
.c
!= '*' && c
.c
!= '+' &&
680 c
.c
!= '-' && c
.c
!= '/' && c
.c
!= '=' && c
.c
!= '?' &&
681 c
.c
!= '^' && c
.c
!= '_' && c
.c
!= '`' && c
.c
!= '{' &&
682 c
.c
!= '}' && c
.c
!= '|' && c
.c
!= '}' && c
.c
!= '~')
683 tp
->t_f
|= a_T_SPECIAL
;
688 tp
->t_end
= PTR2SIZE(cp
- cp1st
);
692 tp
= n_lofi_alloc(sizeof *tp
);
694 if((tp
->t_last
= tcurr
) != NULL
)
700 tp
->t_start
= agp
->ag_iaddr_start
;
701 tp
->t_end
= agp
->ag_iaddr_aend
;
704 cp
= &agp
->ag_input
[agp
->ag_iaddr_aend
+ 1];
705 cpmax
= &agp
->ag_input
[agp
->ag_ilen
];
710 /* Nothing may follow the address, move it to the end */
711 if(!(tcurr
->t_f
& a_T_TADDR
)){
712 for(tp
= thead
; tp
!= NULL
; tp
= tp
->t_next
){
713 if(tp
->t_f
& a_T_TADDR
){
714 if(tp
->t_last
!= NULL
)
715 tp
->t_last
->t_next
= tp
->t_next
;
718 if(tp
->t_next
!= NULL
)
719 tp
->t_next
->t_last
= tp
->t_last
;
722 while(tp
->t_next
!= NULL
)
726 tcurr
->t_next
= NULL
;
732 /* Make ranges contiguous: ensure a continuous range of atoms is converted
733 * to a SPECIAL one if at least one of them requires it */
734 for(tp
= thead
; tp
!= NULL
; tp
= tp
->t_next
){
735 if(tp
->t_f
& a_T_SPECIAL
){
737 while((tp
= tp
->t_last
) != NULL
&& (tp
->t_f
& a_T_TATOM
))
738 tp
->t_f
|= a_T_SPECIAL
;
740 while((tp
= tp
->t_next
) != NULL
&& (tp
->t_f
& a_T_TATOM
))
741 tp
->t_f
|= a_T_SPECIAL
;
745 /* And yes, we want quotes to extend as much as possible */
746 for(tp
= thead
; tp
!= NULL
; tp
= tp
->t_next
){
747 if(tp
->t_f
& a_T_TQUOTE
){
749 while((tp
= tp
->t_last
) != NULL
&& (tp
->t_f
& a_T_TATOM
))
750 tp
->t_f
|= a_T_SPECIAL
;
752 while((tp
= tp
->t_next
) != NULL
&& (tp
->t_f
& a_T_TATOM
))
753 tp
->t_f
|= a_T_SPECIAL
;
758 ostp
= n_string_creat_auto(&ost
);
759 if((c
.ui32
= agp
->ag_ilen
) <= UI32_MAX
>> 1)
760 ostp
= n_string_reserve(ostp
, c
.ui32
<<= 1);
762 for(tcurr
= thead
; tcurr
!= NULL
;){
764 ostp
= n_string_push_c(ostp
, ' ');
765 if(tcurr
->t_f
& a_T_TADDR
){
766 ostp
= n_string_push_c(ostp
, '<');
767 agp
->ag_iaddr_start
= ostp
->s_len
;
768 ostp
= n_string_push_buf(ostp
, &cp1st
[tcurr
->t_start
],
769 (tcurr
->t_end
- tcurr
->t_start
));
770 agp
->ag_iaddr_aend
= ostp
->s_len
;
771 ostp
= n_string_push_c(ostp
, '>');
772 tcurr
= tcurr
->t_next
;
773 }else if(tcurr
->t_f
& a_T_TCOMM
){
774 ostp
= n_string_push_c(ostp
, '(');
775 ostp
= n_string_push_buf(ostp
, &cp1st
[tcurr
->t_start
],
776 (tcurr
->t_end
- tcurr
->t_start
));
777 while((tp
= tcurr
->t_next
) != NULL
&& (tp
->t_f
& a_T_TCOMM
)){
779 ostp
= n_string_push_c(ostp
, ' '); /* XXX may be artificial */
780 ostp
= n_string_push_buf(ostp
, &cp1st
[tcurr
->t_start
],
781 (tcurr
->t_end
- tcurr
->t_start
));
783 ostp
= n_string_push_c(ostp
, ')');
784 tcurr
= tcurr
->t_next
;
785 }else if(tcurr
->t_f
& a_T_TQUOTE
){
787 ostp
= n_string_push_c(ostp
, '"');
789 do/* while tcurr && TATOM||TQUOTE */{
790 cp
= &cp1st
[tcurr
->t_start
];
791 cpmax
= &cp1st
[tcurr
->t_end
];
796 ostp
= n_string_push_c(ostp
, ' ');
798 if((tcurr
->t_f
& (a_T_TATOM
| a_T_SPECIAL
)) == a_T_TATOM
)
799 ostp
= n_string_push_buf(ostp
, cp
, PTR2SIZE(cpmax
- cp
));
803 for(esc
= FAL0
; cp
< cpmax
;){
804 if((c
.c
= *cp
++) == '\\' && !esc
){
805 if(cp
< cpmax
&& (*cp
== '"' || *cp
== '\\'))
808 if(esc
|| c
.c
== '"'){
810 ostp
= n_string_push_c(ostp
, '\\');
812 ostp
= n_string_push_c(ostp
, c
.c
);
821 }while((tcurr
= tcurr
->t_next
) != NULL
&&
822 (tcurr
->t_f
& (a_T_TATOM
| a_T_TQUOTE
)));
823 ostp
= n_string_push_c(ostp
, '"');
824 }else if(tcurr
->t_f
& a_T_SPECIAL
)
827 /* Can we use a fast join mode? */
828 for(tp
= tcurr
; tcurr
!= NULL
; tcurr
= tcurr
->t_next
){
829 if(!(tcurr
->t_f
& a_T_TATOM
))
832 ostp
= n_string_push_c(ostp
, ' ');
833 ostp
= n_string_push_buf(ostp
, &cp1st
[tcurr
->t_start
],
834 (tcurr
->t_end
- tcurr
->t_start
));
839 n_lofi_snap_unroll(lofi_snap
);
841 agp
->ag_input
= n_string_cp(ostp
);
842 agp
->ag_ilen
= ostp
->s_len
;
843 ostp
= n_string_drop_ownership(ostp
);
847 return ((agp
->ag_n_flags
& NAME_ADDRSPEC_INVALID
) == 0);
851 gethfield(FILE *f
, char **linebuf
, size_t *linesize
, int rem
, char **colon
)
853 char *line2
= NULL
, *cp
, *cp2
;
854 size_t line2size
= 0;
858 if (*linebuf
== NULL
)
859 *linebuf
= srealloc(*linebuf
, *linesize
= 1);
866 if ((c
= readline_restart(f
, linebuf
, linesize
, 0)) <= 0) {
870 for (cp
= *linebuf
; fieldnamechar(*cp
); ++cp
)
873 while (blankchar(*cp
))
875 if (*cp
!= ':' || cp
== *linebuf
)
878 /* I guess we got a headline. Handle wraparound */
883 while (PTRCMP(--cp
, >=, *linebuf
) && blankchar(*cp
))
888 if (PTRCMP(cp
- 8, >=, *linebuf
) && cp
[-1] == '=' && cp
[-2] == '?')
890 ungetc(c
= getc(f
), f
);
893 c
= readline_restart(f
, &line2
, &line2size
, 0);
897 for (cp2
= line2
; blankchar(*cp2
); ++cp2
)
899 c
-= (int)PTR2SIZE(cp2
- line2
);
900 if (cp2
[0] == '=' && cp2
[1] == '?' && c
> 8)
902 if (PTRCMP(cp
+ c
, >=, *linebuf
+ *linesize
- 2)) {
903 size_t diff
= PTR2SIZE(cp
- *linebuf
),
904 colondiff
= PTR2SIZE(*colon
- *linebuf
);
905 *linebuf
= srealloc(*linebuf
, *linesize
+= c
+ 2);
906 cp
= &(*linebuf
)[diff
];
907 *colon
= &(*linebuf
)[colondiff
];
925 msgidnextc(char const **cp
, int *status
)
932 assert(status
!= NULL
);
950 *cp
= skip_comment(&(*cp
)[1]);
967 c
= (*status
& 02) ? lowerconv(c
) : c
;
977 charcount(char *str
, int c
)
983 for (i
= 0, cp
= str
; *cp
; ++cp
)
991 nexttoken(char const *cp
)
1010 } while (nesting
> 0 && *cp
!= '\0'); /* XXX error? */
1011 } else if (blankchar(*cp
) || *cp
== ',')
1021 a_head_customhdr__sep(char **iolist
){
1023 bool_t isesc
, anyesc
;
1026 for(base
= *iolist
; base
!= NULL
; base
= *iolist
){
1027 while((c
= *base
) != '\0' && blankspacechar(c
))
1030 for(isesc
= anyesc
= FAL0
, cp
= base
;; ++cp
){
1031 if(n_UNLIKELY((c
= *cp
) == '\0')){
1039 isesc
= (c
== '\\');
1042 anyesc
|= (c
== ',');
1046 while(cp
> base
&& blankspacechar(cp
[-1]))
1054 for(ins
= cp
= base
;; ++ins
)
1055 if((c
= *cp
) == '\\' && cp
[1] == ','){
1058 }else if((*ins
= (++cp
, c
)) == '\0')
1069 myaddrs(struct header
*hp
) /* TODO */
1072 char const *rv
, *mta
;
1075 if (hp
!= NULL
&& (np
= hp
->h_from
) != NULL
) {
1076 if ((rv
= np
->n_fullname
) != NULL
)
1078 if ((rv
= np
->n_name
) != NULL
)
1082 if((rv
= ok_vlook(from
)) != NULL
){
1083 if((np
= lextract(rv
, GEXTRA
| GFULL
)) == NULL
)
1085 n_err(_("An address given in *from* is invalid: %s\n"), rv
);
1086 else for(; np
!= NULL
; np
= np
->n_flink
)
1087 if(is_addr_invalid(np
, EACM_STRICT
| EACM_NOLOG
| EACM_NONAME
))
1092 /* When invoking *sendmail* directly, it's its task to generate an otherwise
1093 * undeterminable From: address. However, if the user sets *hostname*,
1094 * accept his desire */
1095 if (ok_vlook(hostname
) != NULL
)
1097 if (ok_vlook(smtp
) != NULL
|| /* TODO obsolete -> mta */
1098 /* TODO pretty hacky for now (this entire fun), later: url_creat()! */
1099 ((mta
= ok_vlook(mta
)) != NULL
&&
1100 (mta
= n_servbyname(mta
, NULL
)) != NULL
&& *mta
!= '\0'))
1108 char const *hn
, *ln
;
1111 hn
= n_nodename(TRU1
);
1112 ln
= ok_vlook(LOGNAME
);
1113 i
= strlen(ln
) + strlen(hn
) + 1 +1;
1114 rv
= cp
= salloc(i
);
1115 sstpcpy(sstpcpy(sstpcpy(cp
, ln
), n_at
), hn
);
1121 myorigin(struct header
*hp
) /* TODO */
1123 char const *rv
= NULL
, *ccp
;
1127 if((ccp
= myaddrs(hp
)) != NULL
&&
1128 (np
= lextract(ccp
, GEXTRA
| GFULL
)) != NULL
){
1129 if(np
->n_flink
== NULL
)
1131 else if((ccp
= ok_vlook(sender
)) != NULL
) {
1132 if((np
= lextract(ccp
, GEXTRA
| GFULL
)) == NULL
||
1133 np
->n_flink
!= NULL
||
1134 is_addr_invalid(np
, EACM_STRICT
| EACM_NOLOG
| EACM_NONAME
))
1135 n_err(_("The address given in *sender* is invalid: %s\n"), ccp
);
1145 is_head(char const *linebuf
, size_t linelen
, bool_t check_rfc4155
)
1147 char date
[n_FROM_DATEBUF
];
1151 if ((rv
= (linelen
>= 5 && !memcmp(linebuf
, "From ", 5))) && check_rfc4155
&&
1152 (extract_date_from_from_(linebuf
, linelen
, date
) <= 0 ||
1160 extract_date_from_from_(char const *line
, size_t linelen
,
1161 char datebuf
[n_FROM_DATEBUF
])
1164 char const *cp
= line
;
1170 cp
= _from__skipword(cp
);
1174 cp
= _from__skipword(cp
);
1177 if (cp
[0] == 't' && cp
[1] == 't' && cp
[2] == 'y') {
1178 cp
= _from__skipword(cp
);
1182 /* It seems there are invalid MBOX archives in the wild, compare
1183 * . http://bugs.debian.org/624111
1184 * . [Mutt] #3868: mutt should error if the imported mailbox is invalid
1185 * What they do is that they obfuscate the address to "name at host",
1186 * and even "name at host dot dom dot dom. I think we should handle that */
1187 else if(cp
[0] == 'a' && cp
[1] == 't' && cp
[2] == ' '){
1191 cp
= _from__skipword(cp
);
1194 if(cp
[0] == 'd' && cp
[1] == 'o' && cp
[2] == 't' && cp
[3] == ' '){
1200 linelen
-= PTR2SIZE(cp
- line
);
1201 if (linelen
< a_HEAD_DATE_MINLEN
)
1203 if (cp
[linelen
- 1] == '\n') {
1205 /* (Rather IMAP/POP3 only) */
1206 if (cp
[linelen
- 1] == '\r')
1208 if (linelen
< a_HEAD_DATE_MINLEN
)
1211 if (linelen
>= n_FROM_DATEBUF
)
1215 memcpy(datebuf
, cp
, linelen
);
1216 datebuf
[linelen
] = '\0';
1220 cp
= _("<Unknown date>");
1221 linelen
= strlen(cp
);
1222 if (linelen
>= n_FROM_DATEBUF
)
1223 linelen
= n_FROM_DATEBUF
;
1229 extract_header(FILE *fp
, struct header
*hp
, si8_t
*checkaddr_err
)
1231 /* See the prototype declaration for the hairy relationship of
1232 * n_poption&n_PO_t_FLAG and/or n_psonce&n_PSO_t_FLAG in here */
1233 struct n_header_field
**hftail
;
1234 struct header nh
, *hq
= &nh
;
1235 char *linebuf
= NULL
/* TODO line pool */, *colon
;
1236 size_t linesize
= 0, seenfields
= 0;
1238 char const *val
, *cp
;
1241 memset(hq
, 0, sizeof *hq
);
1242 if ((n_psonce
& n_PSO_t_FLAG
) && (n_poption
& n_PO_t_FLAG
)) {
1243 hq
->h_to
= hp
->h_to
;
1244 hq
->h_cc
= hp
->h_cc
;
1245 hq
->h_bcc
= hp
->h_bcc
;
1247 hftail
= &hq
->h_user_headers
;
1249 for (lc
= 0; readline_restart(fp
, &linebuf
, &linesize
, 0) > 0; ++lc
)
1252 /* TODO yippieia, cat(check(lextract)) :-) */
1254 while ((lc
= gethfield(fp
, &linebuf
, &linesize
, lc
, &colon
)) >= 0) {
1257 /* We explicitly allow EAF_NAME for some addressees since aliases are not
1258 * yet expanded when we parse these! */
1259 if ((val
= thisfield(linebuf
, "to")) != NULL
) {
1261 hq
->h_to
= cat(hq
->h_to
, checkaddrs(lextract(val
, GTO
| GFULL
),
1262 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1263 } else if ((val
= thisfield(linebuf
, "cc")) != NULL
) {
1265 hq
->h_cc
= cat(hq
->h_cc
, checkaddrs(lextract(val
, GCC
| GFULL
),
1266 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1267 } else if ((val
= thisfield(linebuf
, "bcc")) != NULL
) {
1269 hq
->h_bcc
= cat(hq
->h_bcc
, checkaddrs(lextract(val
, GBCC
| GFULL
),
1270 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1271 } else if ((val
= thisfield(linebuf
, "from")) != NULL
) {
1272 if (!(n_psonce
& n_PSO_t_FLAG
) || (n_poption
& n_PO_t_FLAG
)) {
1274 hq
->h_from
= cat(hq
->h_from
,
1275 checkaddrs(lextract(val
, GEXTRA
| GFULL
| GFULLEXTRA
),
1276 EACM_STRICT
, NULL
));
1278 } else if ((val
= thisfield(linebuf
, "reply-to")) != NULL
) {
1280 hq
->h_replyto
= cat(hq
->h_replyto
,
1281 checkaddrs(lextract(val
, GEXTRA
| GFULL
), EACM_STRICT
, NULL
));
1282 } else if ((val
= thisfield(linebuf
, "sender")) != NULL
) {
1283 if (!(n_psonce
& n_PSO_t_FLAG
) || (n_poption
& n_PO_t_FLAG
)) {
1285 hq
->h_sender
= cat(hq
->h_sender
, /* TODO cat? check! */
1286 checkaddrs(lextract(val
, GEXTRA
| GFULL
| GFULLEXTRA
),
1287 EACM_STRICT
, NULL
));
1290 } else if ((val
= thisfield(linebuf
, "subject")) != NULL
||
1291 (val
= thisfield(linebuf
, "subj")) != NULL
) {
1293 for (cp
= val
; blankchar(*cp
); ++cp
)
1295 hq
->h_subject
= (hq
->h_subject
!= NULL
)
1296 ? save2str(hq
->h_subject
, cp
) : savestr(cp
);
1298 /* The remaining are mostly hacked in and thus TODO -- at least in
1299 * TODO respect to their content checking */
1300 else if((val
= thisfield(linebuf
, "message-id")) != NULL
){
1301 if(n_psonce
& n_PSO_t_FLAG
){
1302 np
= checkaddrs(lextract(val
, GREF
),
1303 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1305 if (np
== NULL
|| np
->n_flink
!= NULL
)
1308 hq
->h_message_id
= np
;
1311 }else if((val
= thisfield(linebuf
, "in-reply-to")) != NULL
){
1312 if(n_psonce
& n_PSO_t_FLAG
){
1313 np
= checkaddrs(lextract(val
, GREF
),
1314 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1317 hq
->h_in_reply_to
= np
;
1320 }else if((val
= thisfield(linebuf
, "references")) != NULL
){
1321 if(n_psonce
& n_PSO_t_FLAG
){
1323 /* TODO Limit number of references TODO better on parser side */
1324 hq
->h_ref
= cat(hq
->h_ref
, checkaddrs(extract(val
, GREF
),
1325 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1330 /* and that is very hairy */
1331 else if((val
= thisfield(linebuf
, "mail-followup-to")) != NULL
){
1332 if(n_psonce
& n_PSO_t_FLAG
){
1334 hq
->h_mft
= cat(hq
->h_mft
, checkaddrs(lextract(val
, GEXTRA
| GFULL
),
1335 /*EACM_STRICT | TODO '/' valid!! | EACM_NOLOG | */EACM_NONAME
,
1340 /* A free-form user header; gethfield() did some verification already.. */
1342 struct n_header_field
*hfp
;
1346 for(nstart
= cp
= linebuf
;; ++cp
)
1347 if(!fieldnamechar(*cp
))
1349 nl
= (ui32_t
)PTR2SIZE(cp
- nstart
);
1351 while(blankchar(*cp
))
1355 n_err(_("Ignoring header field: %s\n"), linebuf
);
1358 while(blankchar(*cp
))
1360 bl
= (ui32_t
)strlen(cp
) +1;
1363 *hftail
= hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
1365 hftail
= &hfp
->hf_next
;
1366 hfp
->hf_next
= NULL
;
1368 hfp
->hf_bl
= bl
- 1;
1369 memcpy(hfp
->hf_dat
, nstart
, nl
);
1370 hfp
->hf_dat
[nl
++] = '\0';
1371 memcpy(hfp
->hf_dat
+ nl
, cp
, bl
);
1375 /* In case the blank line after the header has been edited out. Otherwise,
1376 * fetch the header separator */
1377 if (linebuf
!= NULL
) {
1378 if (linebuf
[0] != '\0') {
1379 for (cp
= linebuf
; *(++cp
) != '\0';)
1381 fseek(fp
, (long)-PTR2SIZE(1 + cp
- linebuf
), SEEK_CUR
);
1383 if ((c
= getc(fp
)) != '\n' && c
!= EOF
)
1388 if (seenfields
> 0 && (checkaddr_err
== NULL
|| *checkaddr_err
== 0)) {
1389 hp
->h_to
= hq
->h_to
;
1390 hp
->h_cc
= hq
->h_cc
;
1391 hp
->h_bcc
= hq
->h_bcc
;
1392 hp
->h_from
= hq
->h_from
;
1393 hp
->h_replyto
= hq
->h_replyto
;
1394 hp
->h_sender
= hq
->h_sender
;
1395 if (hq
->h_subject
!= NULL
|| !(n_psonce
& n_PSO_t_FLAG
) ||
1396 !(n_poption
& n_PO_t_FLAG
))
1397 hp
->h_subject
= hq
->h_subject
;
1398 hp
->h_user_headers
= hq
->h_user_headers
;
1400 if (n_psonce
& n_PSO_t_FLAG
) {
1401 hp
->h_ref
= hq
->h_ref
;
1402 hp
->h_message_id
= hq
->h_message_id
;
1403 hp
->h_in_reply_to
= hq
->h_in_reply_to
;
1404 hp
->h_mft
= hq
->h_mft
;
1406 /* And perform additional validity checks so that we don't bail later
1407 * on TODO this is good and the place where this should occur,
1408 * TODO unfortunately a lot of other places do again and blabla */
1409 if (hp
->h_from
== NULL
)
1410 hp
->h_from
= n_poption_arg_r
;
1411 else if (hp
->h_from
->n_flink
!= NULL
&& hp
->h_sender
== NULL
)
1412 hp
->h_sender
= lextract(ok_vlook(sender
),
1413 GEXTRA
| GFULL
| GFULLEXTRA
);
1416 n_err(_("Restoring deleted header lines\n"));
1418 if (linebuf
!= NULL
)
1424 hfield_mult(char const *field
, struct message
*mp
, int mult
)
1429 size_t linesize
= 0; /* TODO line pool */
1430 char *linebuf
= NULL
, *colon
;
1434 /* There are (spam) messages which have header bytes which are many KB when
1435 * joined, so resize a single heap storage until we are done if we shall
1436 * collect a field that may have multiple bodies; only otherwise use the
1437 * string dope directly */
1438 memset(&hfs
, 0, sizeof hfs
);
1440 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
1442 if ((lc
= mp
->m_lines
- 1) < 0)
1445 if ((mp
->m_flag
& MNOFROM
) == 0 &&
1446 readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1449 if ((lc
= gethfield(ibuf
, &linebuf
, &linesize
, lc
, &colon
)) < 0)
1451 if ((hfield
= thisfield(linebuf
, field
)) != NULL
&& *hfield
!= '\0') {
1453 n_str_add_buf(&hfs
, hfield
, strlen(hfield
));
1455 hfs
.s
= savestr(hfield
);
1462 if (linebuf
!= NULL
)
1464 if (mult
&& hfs
.s
!= NULL
) {
1465 colon
= savestrbuf(hfs
.s
, hfs
.l
);
1474 thisfield(char const *linebuf
, char const *field
)
1476 char const *rv
= NULL
;
1479 while (lowerconv(*linebuf
) == lowerconv(*field
)) {
1486 while (blankchar(*linebuf
))
1488 if (*linebuf
++ != ':')
1491 while (blankchar(*linebuf
)) /* TODO header parser.. strip trailing WS?!? */
1500 nameof(struct message
*mp
, int reptype
)
1505 cp
= skin(name1(mp
, reptype
));
1506 if (reptype
!= 0 || charcount(cp
, '!') < 2)
1508 cp2
= strrchr(cp
, '!');
1510 while (cp2
> cp
&& *cp2
!= '!')
1520 skip_comment(char const *cp
)
1525 for (nesting
= 1; nesting
> 0 && *cp
; ++cp
) {
1544 routeaddr(char const *name
)
1546 char const *np
, *rp
= NULL
;
1549 for (np
= name
; *np
; np
++) {
1552 np
= skip_comment(np
+ 1) - 1;
1558 if (*np
== '\\' && np
[1])
1575 FL
enum expand_addr_flags
1576 expandaddr_to_eaf(void)
1579 char const *eafd_name
;
1580 bool_t eafd_is_target
;
1584 {"restrict", FAL0
, EAF_TARGET_MASK
, EAF_RESTRICT
| EAF_RESTRICT_TARGETS
},
1585 {"fail", FAL0
, EAF_NONE
, EAF_FAIL
},
1586 {"failinvaddr", FAL0
, EAF_NONE
, EAF_FAILINVADDR
| EAF_ADDR
},
1587 {"all", TRU1
, EAF_NONE
, EAF_TARGET_MASK
},
1588 {"file", TRU1
, EAF_NONE
, EAF_FILE
},
1589 {"pipe", TRU1
, EAF_NONE
, EAF_PIPE
},
1590 {"name", TRU1
, EAF_NONE
, EAF_NAME
},
1591 {"addr", TRU1
, EAF_NONE
, EAF_ADDR
}
1595 enum expand_addr_flags rv
;
1599 if ((cp
= ok_vlook(expandaddr
)) == NULL
)
1600 rv
= EAF_RESTRICT_TARGETS
;
1601 else if (*cp
== '\0')
1602 rv
= EAF_TARGET_MASK
;
1604 rv
= EAF_TARGET_MASK
;
1606 for (buf
= savestr(cp
); (cp
= n_strsep(&buf
, ',', TRU1
)) != NULL
;) {
1609 if ((minus
= (*cp
== '-')) || *cp
== '+')
1611 for (eafp
= eafa
;; ++eafp
) {
1612 if (eafp
== eafa
+ n_NELEM(eafa
)) {
1613 if (n_poption
& n_PO_D_V
)
1614 n_err(_("Unknown *expandaddr* value: %s\n"), cp
);
1616 } else if (!asccasecmp(cp
, eafp
->eafd_name
)) {
1618 rv
&= ~eafp
->eafd_andoff
;
1619 rv
|= eafp
->eafd_or
;
1621 if (eafp
->eafd_is_target
)
1622 rv
&= ~eafp
->eafd_or
;
1623 else if (n_poption
& n_PO_D_V
)
1624 n_err(_("minus - prefix invalid for *expandaddr* value: "
1628 } else if (!asccasecmp(cp
, "noalias")) { /* TODO v15 OBSOLETE */
1629 n_OBSOLETE(_("*expandaddr*: noalias is henceforth -name"));
1636 if((rv
& EAF_RESTRICT
) && ((n_psonce
& n_PSO_INTERACTIVE
) ||
1637 (n_poption
& n_PO_TILDE_FLAG
)))
1638 rv
|= EAF_TARGET_MASK
;
1639 else if(n_poption
& n_PO_D_V
){
1640 if(!(rv
& EAF_TARGET_MASK
))
1641 n_err(_("*expandaddr* doesn't allow any addressees\n"));
1642 else if((rv
& EAF_FAIL
) && (rv
& EAF_TARGET_MASK
) == EAF_TARGET_MASK
)
1643 n_err(_("*expandaddr* with fail, but no restrictions to apply\n"));
1651 is_addr_invalid(struct name
*np
, enum expand_addr_check_mode eacm
)
1653 char cbuf
[sizeof "'\\U12340'"];
1657 enum expand_addr_flags eaf
;
1660 eaf
= expandaddr_to_eaf();
1663 if ((rv
= ((f
& NAME_ADDRSPEC_INVALID
) != 0))) {
1664 if (eaf
& EAF_FAILINVADDR
)
1667 if ((eacm
& EACM_NOLOG
) || (f
& NAME_ADDRSPEC_ERR_EMPTY
)) {
1671 char const *fmt
= "'\\x%02X'";
1672 bool_t ok8bit
= TRU1
;
1674 if (f
& NAME_ADDRSPEC_ERR_IDNA
) {
1675 cs
= _("Invalid domain name: %s, character %s\n");
1678 } else if (f
& NAME_ADDRSPEC_ERR_ATSEQ
)
1679 cs
= _("%s contains invalid %s sequence\n");
1680 else if (f
& NAME_ADDRSPEC_ERR_NAME
) {
1681 cs
= _("%s is an invalid alias name\n");
1683 cs
= _("%s contains invalid byte %s\n");
1685 c
= NAME_ADDRSPEC_ERR_GETWC(f
);
1686 snprintf(cbuf
, sizeof cbuf
,
1687 (ok8bit
&& c
>= 040 && c
<= 0177 ? "'%c'" : fmt
), c
);
1693 /* *expandaddr* stuff */
1694 if (!(rv
= ((eacm
& EACM_MODE_MASK
) != EACM_NONE
)))
1697 if ((eacm
& EACM_STRICT
) && (f
& NAME_ADDRSPEC_ISFILEORPIPE
)) {
1700 cs
= _("%s%s: file or pipe addressees not allowed here\n");
1701 if (eacm
& EACM_NOLOG
)
1707 eaf
|= (eacm
& EAF_TARGET_MASK
);
1708 if (eacm
& EACM_NONAME
)
1711 if (eaf
== EAF_NONE
) {
1718 if (!(eaf
& EAF_FILE
) && (f
& NAME_ADDRSPEC_ISFILE
)) {
1719 cs
= _("%s%s: *expandaddr* doesn't allow file target\n");
1720 if (eacm
& EACM_NOLOG
)
1722 } else if (!(eaf
& EAF_PIPE
) && (f
& NAME_ADDRSPEC_ISPIPE
)) {
1723 cs
= _("%s%s: *expandaddr* doesn't allow command pipe target\n");
1724 if (eacm
& EACM_NOLOG
)
1726 } else if (!(eaf
& EAF_NAME
) && (f
& NAME_ADDRSPEC_ISNAME
)) {
1727 cs
= _("%s%s: *expandaddr* doesn't allow user name target\n");
1728 if (eacm
& EACM_NOLOG
)
1730 } else if (!(eaf
& EAF_ADDR
) && (f
& NAME_ADDRSPEC_ISADDR
)) {
1731 cs
= _("%s%s: *expandaddr* doesn't allow mail address target\n");
1732 if (eacm
& EACM_NOLOG
)
1742 n_err(cs
, n_shexp_quote_cp(np
->n_name
, TRU1
), cbuf
);
1749 skin(char const *name
)
1751 struct n_addrguts ag
;
1756 name
= n_addrspec_with_guts(&ag
,name
, TRU1
, FAL0
);
1758 if(!(ag
.ag_n_flags
& NAME_NAME_SALLOC
))
1759 rv
= savestrbuf(rv
, ag
.ag_slen
);
1766 /* TODO addrspec_with_guts: RFC 5322
1767 * TODO addrspec_with_guts: trim whitespace ETC. ETC. ETC.!!! */
1769 n_addrspec_with_guts(struct n_addrguts
*agp
, char const *name
, bool_t doskin
,
1770 bool_t issingle_hack
){
1772 char *cp2
, *bufend
, *nbuf
, c
;
1782 memset(agp
, 0, sizeof *agp
);
1784 if((agp
->ag_input
= name
) == NULL
|| (agp
->ag_ilen
= strlen(name
)) == 0){
1785 agp
->ag_skinned
= n_UNCONST(n_empty
); /* ok: NAME_SALLOC is not set */
1787 agp
->ag_n_flags
|= NAME_ADDRSPEC_CHECKED
;
1788 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_EMPTY
, 0);
1791 /*agp->ag_iaddr_start = 0;*/
1792 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1793 agp
->ag_skinned
= n_UNCONST(name
); /* (NAME_SALLOC not set) */
1794 agp
->ag_slen
= agp
->ag_ilen
;
1795 agp
->ag_n_flags
= NAME_SKINNED
;
1800 nbuf
= n_lofi_alloc(agp
->ag_ilen
+1);
1801 /*agp->ag_iaddr_start = 0;*/
1802 cp2
= bufend
= nbuf
;
1804 /* TODO This is complete crap and should use a token parser */
1805 for(cp
= name
++; (c
= *cp
++) != '\0';){
1808 cp
= skip_comment(cp
);
1812 /* Start of a "quoted-string". Copy it in its entirety */
1813 /* XXX RFC: quotes are "semantically invisible"
1814 * XXX But it was explicitly added (Changelog.Heirloom,
1815 * XXX [9.23] released 11/15/00, "Do not remove quotes
1816 * XXX when skinning names"? No more info.. */
1818 while ((c
= *cp
) != '\0') { /* TODO improve */
1826 else if ((c
= *cp
) != '\0') {
1835 if((flags
& (a_GOTADDR
| a_GOTSPACE
)) == a_GOTADDR
){
1836 flags
|= a_GOTSPACE
;
1837 agp
->ag_iaddr_aend
= PTR2SIZE(cp
- name
);
1839 if (cp
[0] == 'a' && cp
[1] == 't' && blankchar(cp
[2]))
1840 cp
+= 3, *cp2
++ = '@';
1841 else if (cp
[0] == '@' && blankchar(cp
[1]))
1842 cp
+= 2, *cp2
++ = '@';
1847 agp
->ag_iaddr_start
= PTR2SIZE(cp
- (name
- 1));
1849 flags
&= ~(a_GOTSPACE
| a_LASTSP
);
1850 flags
|= a_GOTLT
| a_GOTADDR
;
1853 if(flags
& a_GOTLT
){
1854 /* (_addrspec_check() verifies these later!) */
1855 flags
&= ~(a_GOTLT
| a_LASTSP
);
1856 agp
->ag_iaddr_aend
= PTR2SIZE(cp
- name
);
1858 /* Skip over the entire remaining field */
1859 while((c
= *cp
) != '\0' && c
!= ','){
1862 cp
= skip_comment(cp
);
1864 while ((c
= *cp
) != '\0') {
1868 if (c
== '\\' && *cp
!= '\0')
1876 if(flags
& a_LASTSP
){
1878 if(flags
& a_GOTADDR
)
1882 /* This character is forbidden here, but it may nonetheless be
1883 * present: ensure we turn this into something valid! (E.g., if the
1884 * next character would be a "..) */
1885 if(c
== '\\' && *cp
!= '\0')
1887 if(c
== ',' && !issingle_hack
){
1888 if(!(flags
& a_GOTLT
)){
1890 for(; blankchar(*cp
); ++cp
)
1895 }else if(!(flags
& a_GOTADDR
)){
1897 agp
->ag_iaddr_start
= PTR2SIZE(cp
- name
);
1902 agp
->ag_slen
= PTR2SIZE(cp2
- nbuf
);
1903 if (agp
->ag_iaddr_aend
== 0)
1904 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1906 else if (agp
->ag_iaddr_aend
< agp
->ag_iaddr_start
) {
1907 cp2
= n_autorec_alloc(agp
->ag_ilen
+ 1 +1);
1908 memcpy(cp2
, agp
->ag_input
, agp
->ag_ilen
);
1909 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1910 cp2
[agp
->ag_ilen
++] = '>';
1911 cp2
[agp
->ag_ilen
] = '\0';
1913 agp
->ag_skinned
= savestrbuf(nbuf
, agp
->ag_slen
);
1915 agp
->ag_n_flags
= NAME_NAME_SALLOC
| NAME_SKINNED
;
1917 if(a_head_addrspec_check(agp
, doskin
) <= FAL0
)
1920 name
= agp
->ag_input
;
1927 realname(char const *name
)
1929 char const *cp
, *cq
, *cstart
= NULL
, *cend
= NULL
;
1932 int quoted
, good
, nogood
;
1935 if ((cp
= n_UNCONST(name
)) == NULL
)
1937 for (; *cp
!= '\0'; ++cp
) {
1940 if (cstart
!= NULL
) {
1941 /* More than one comment in address, doesn't make sense to display
1942 * it without context. Return the entire field */
1943 cp
= mime_fromaddr(name
);
1947 cp
= skip_comment(cp
);
1950 cend
= cstart
= NULL
;
1956 if (*cp
== '\\' && cp
[1])
1967 /* More than one address. Just use the first one */
1973 if (cstart
== NULL
) {
1975 /* If name contains only a route-addr, the surrounding angle brackets
1976 * don't serve any useful purpose when displaying, so remove */
1977 cp
= prstr(skin(name
));
1979 cp
= mime_fromaddr(name
);
1983 /* Strip quotes. Note that quotes that appear within a MIME encoded word are
1984 * not stripped. The idea is to strip only syntactical relevant things (but
1985 * this is not necessarily the most sensible way in practice) */
1986 rp
= rname
= ac_alloc(PTR2SIZE(cend
- cstart
+1));
1988 for (cp
= cstart
; cp
< cend
; ++cp
) {
1989 if (*cp
== '(' && !quoted
) {
1990 cq
= skip_comment(++cp
);
1991 if (PTRCMP(--cq
, >, cend
))
1994 if (*cp
== '\\' && PTRCMP(cp
+ 1, <, cq
))
1998 } else if (*cp
== '\\' && PTRCMP(cp
+ 1, <, cend
))
2000 else if (*cp
== '"') {
2009 mime_fromhdr(&in
, &out
, TD_ISPR
| TD_ICONV
);
2011 rname
= savestr(out
.s
);
2014 while (blankchar(*rname
))
2016 for (rp
= rname
; *rp
!= '\0'; ++rp
)
2018 while (PTRCMP(--rp
, >=, rname
) && blankchar(*rp
))
2021 cp
= mime_fromaddr(name
);
2025 /* mime_fromhdr() has converted all nonprintable characters to question
2026 * marks now. These and blanks are considered uninteresting; if the
2027 * displayed part of the real name contains more than 25% of them, it is
2028 * probably better to display the plain email address instead */
2031 for (rp
= rname
; *rp
!= '\0' && PTRCMP(rp
, <, rname
+ 20); ++rp
)
2032 if (*rp
== '?' || blankchar(*rp
))
2036 cp
= (good
* 3 < nogood
) ? prstr(skin(name
)) : rname
;
2039 return n_UNCONST(cp
);
2043 name1(struct message
*mp
, int reptype
)
2045 char *namebuf
, *cp
, *cp2
, *linebuf
= NULL
/* TODO line pool */;
2046 size_t namesize
, linesize
= 0;
2051 if ((cp
= hfield1("from", mp
)) != NULL
&& *cp
!= '\0')
2053 if (reptype
== 0 && (cp
= hfield1("sender", mp
)) != NULL
&& *cp
!= '\0')
2056 namebuf
= smalloc(namesize
= 1);
2058 if (mp
->m_flag
& MNOFROM
)
2060 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
2062 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2066 if (namesize
<= linesize
)
2067 namebuf
= srealloc(namebuf
, namesize
= linesize
+1);
2068 for (cp
= linebuf
; *cp
!= '\0' && *cp
!= ' '; ++cp
)
2070 for (; blankchar(*cp
); ++cp
)
2072 for (cp2
= namebuf
+ strlen(namebuf
);
2073 *cp
&& !blankchar(*cp
) && PTRCMP(cp2
, <, namebuf
+ namesize
-1);)
2077 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2079 if ((cp
= strchr(linebuf
, 'F')) == NULL
)
2081 if (strncmp(cp
, "From", 4))
2083 if (namesize
<= linesize
)
2084 namebuf
= srealloc(namebuf
, namesize
= linesize
+ 1);
2086 while ((cp
= strchr(cp
, 'r')) != NULL
) {
2087 if (!strncmp(cp
, "remote", 6)) {
2088 if ((cp
= strchr(cp
, 'f')) == NULL
)
2090 if (strncmp(cp
, "from", 4) != 0)
2092 if ((cp
= strchr(cp
, ' ')) == NULL
)
2096 strncpy(namebuf
, cp
, namesize
);
2099 cp2
= strrchr(namebuf
, '!') + 1;
2100 strncpy(cp2
, cp
, PTR2SIZE(namebuf
+ namesize
- cp2
));
2102 namebuf
[namesize
- 2] = '!';
2103 namebuf
[namesize
- 1] = '\0';
2109 if (*namebuf
!= '\0' || ((cp
= hfield1("return-path", mp
))) == NULL
||
2111 cp
= savestr(namebuf
);
2113 if (linebuf
!= NULL
)
2122 subject_re_trim(char const *s
){
2126 }const *pp
, ignored
[] = { /* Update *reply-strings* manual upon change! */
2128 {3, "aw:"}, {5, "antw:"}, /* de */
2129 {3, "wg:"}, /* Seen too often in the wild */
2134 char *re_st
, *re_st_x
;
2144 if((re_st_x
= ok_vlook(reply_strings
)) != NULL
&&
2145 (re_l
= strlen(re_st_x
)) > 0){
2146 re_st
= n_lofi_alloc(++re_l
* 2);
2147 memcpy(re_st
, re_st_x
, re_l
);
2152 while(spacechar(*s
))
2155 for(pp
= ignored
; pp
->len
> 0; ++pp
)
2156 if(is_asccaseprefix(pp
->dat
, s
)){
2165 memcpy(re_st_x
= &re_st
[re_l
], re_st
, re_l
);
2166 while((cp
= n_strsep(&re_st_x
, ',', TRU1
)) != NULL
)
2167 if(is_asccaseprefix(cp
, s
)){
2179 return any
? s
: orig_s
;
2183 msgidcmp(char const *s1
, char const *s2
)
2185 int q1
= 0, q2
= 0, c1
, c2
;
2194 c1
= msgidnextc(&s1
, &q1
);
2195 c2
= msgidnextc(&s2
, &q2
);
2204 fakefrom(struct message
*mp
)
2209 if (((name
= skin(hfield1("return-path", mp
))) == NULL
|| *name
== '\0' ) &&
2210 ((name
= skin(hfield1("from", mp
))) == NULL
|| *name
== '\0'))
2211 /* XXX MAILER-DAEMON is what an old MBOX manual page says.
2212 * RFC 4155 however requires a RFC 5322 (2822) conforming
2213 * "addr-spec", but we simply can't provide that */
2214 name
= "MAILER-DAEMON";
2226 for (cq
= cp
; *cq
!= '\0' && *cq
!= '\n'; ++cq
)
2234 #ifdef HAVE_IMAP_SEARCH
2236 unixtime(char const *fromline
)
2238 char const *fp
, *xp
;
2240 si32_t i
, year
, month
, day
, hour
, minute
, second
, tzdiff
;
2244 for (fp
= fromline
; *fp
!= '\0' && *fp
!= '\n'; ++fp
)
2247 if (PTR2SIZE(fp
- fromline
) < 7)
2252 if (!strncmp(fp
+ 4, n_month_names
[i
], 3))
2254 if (n_month_names
[++i
][0] == '\0')
2260 n_idec_si32_cp(&day
, &fp
[8], 10, &xp
);
2261 if (*xp
!= ' ' || xp
!= fp
+ 10)
2263 n_idec_si32_cp(&hour
, &fp
[11], 10, &xp
);
2264 if (*xp
!= ':' || xp
!= fp
+ 13)
2266 n_idec_si32_cp(&minute
, &fp
[14], 10, &xp
);
2267 if (*xp
!= ':' || xp
!= fp
+ 16)
2269 n_idec_si32_cp(&second
, &fp
[17], 10, &xp
);
2270 if (*xp
!= ' ' || xp
!= fp
+ 19)
2272 n_idec_si32_cp(&year
, &fp
[20], 10, &xp
);
2275 if ((t
= combinetime(year
, month
, day
, hour
, minute
, second
)) == (time_t)-1)
2277 tzdiff
= t
- mktime(gmtime(&t
));
2278 tmptr
= localtime(&t
);
2279 if (tmptr
->tm_isdst
> 0)
2289 #endif /* HAVE_IMAP_SEARCH */
2292 rfctime(char const *date
) /* TODO n_idec_ return tests */
2296 si32_t i
, year
, month
, day
, hour
, minute
, second
;
2301 if ((cp
= nexttoken(cp
)) == NULL
)
2303 if (alphachar(cp
[0]) && alphachar(cp
[1]) && alphachar(cp
[2]) &&
2305 if ((cp
= nexttoken(&cp
[4])) == NULL
)
2308 n_idec_si32_cp(&day
, cp
, 10, &x
);
2309 if ((cp
= nexttoken(x
)) == NULL
)
2312 if (!strncmp(cp
, n_month_names
[i
], 3))
2314 if (n_month_names
[++i
][0] == '\0')
2318 if ((cp
= nexttoken(&cp
[3])) == NULL
)
2321 * Where a two or three digit year occurs in a date, the year is to be
2322 * interpreted as follows: If a two digit year is encountered whose
2323 * value is between 00 and 49, the year is interpreted by adding 2000,
2324 * ending up with a value between 2000 and 2049. If a two digit year
2325 * is encountered with a value between 50 and 99, or any three digit
2326 * year is encountered, the year is interpreted by adding 1900 */
2327 n_idec_si32_cp(&year
, cp
, 10, &x
);
2328 i
= (int)PTR2SIZE(x
- cp
);
2329 if (i
== 2 && year
>= 0 && year
<= 49)
2331 else if (i
== 3 || (i
== 2 && year
>= 50 && year
<= 99))
2333 if ((cp
= nexttoken(x
)) == NULL
)
2335 n_idec_si32_cp(&hour
, cp
, 10, &x
);
2339 n_idec_si32_cp(&minute
, cp
, 10, &x
);
2342 n_idec_si32_cp(&second
, cp
, 10, &x
);
2346 if ((t
= combinetime(year
, month
, day
, hour
, minute
, second
)) == (time_t)-1)
2348 if ((cp
= nexttoken(x
)) != NULL
) {
2360 if (digitchar(cp
[0]) && digitchar(cp
[1]) && digitchar(cp
[2]) &&
2367 n_idec_si32_cp(&i
, buf
, 10, NULL
);
2368 tadj
= (si64_t
)i
* 3600; /* XXX */
2371 n_idec_si32_cp(&i
, buf
, 10, NULL
);
2372 tadj
+= (si64_t
)i
* 60; /* XXX */
2377 /* TODO WE DO NOT YET PARSE (OBSOLETE) ZONE NAMES
2378 * TODO once again, Christos Zoulas and NetBSD Mail have done
2379 * TODO a really good job already, but using strptime(3), which
2380 * TODO is not portable. Nonetheless, WE must improve, not
2381 * TODO at last because we simply ignore obsolete timezones!!
2382 * TODO See RFC 5322, 4.3! */
2393 combinetime(int year
, int month
, int day
, int hour
, int minute
, int second
){
2394 size_t const jdn_epoch
= 2440588;
2395 bool_t
const y2038p
= (sizeof(time_t) == 4);
2401 if(UICMP(32, second
, >/*XXX leap=*/, n_DATE_SECSMIN
) ||
2402 UICMP(32, minute
, >=, n_DATE_MINSHOUR
) ||
2403 UICMP(32, hour
, >=, n_DATE_HOURSDAY
) ||
2404 day
< 1 || day
> 31 ||
2405 month
< 1 || month
> 12 ||
2409 if(year
>= 1970 + ((y2038p
? SI32_MAX
: SI64_MAX
) /
2410 (n_DATE_SECSDAY
* n_DATE_DAYSYEAR
))){
2411 /* Be a coward regarding Y2038, many people (mostly myself, that is) do
2412 * test by stepping second-wise around the flip. Don't care otherwise */
2415 if(year
> 2038 || month
> 1 || day
> 19 ||
2416 hour
> 3 || minute
> 14 || second
> 7)
2421 t
+= minute
* n_DATE_SECSMIN
;
2422 t
+= hour
* n_DATE_SECSHOUR
;
2424 jdn
= a_head_gregorian_to_jdn(year
, month
, day
);
2426 t
+= (time_t)jdn
* n_DATE_SECSDAY
;
2436 substdate(struct message
*m
)
2441 /* Determine the date to print in faked 'From ' lines. This is traditionally
2442 * the date the message was written to the mail file. Try to determine this
2443 * using RFC message header fields, or fall back to current time */
2444 if ((cp
= hfield1("received", m
)) != NULL
) {
2445 while ((cp
= nexttoken(cp
)) != NULL
&& *cp
!= ';') {
2448 while (alnumchar(*cp
));
2451 m
->m_time
= rfctime(cp
);
2453 if (m
->m_time
== 0 || m
->m_time
> time_current
.tc_time
) {
2454 if ((cp
= hfield1("date", m
)) != NULL
)
2455 m
->m_time
= rfctime(cp
);
2457 if (m
->m_time
== 0 || m
->m_time
> time_current
.tc_time
)
2458 m
->m_time
= time_current
.tc_time
;
2463 setup_from_and_sender(struct header
*hp
)
2469 /* If -t parsed or composed From: then take it. With -t we otherwise
2470 * want -r to be honoured in favour of *from* in order to have
2471 * a behaviour that is compatible with what users would expect from e.g.
2473 if ((np
= hp
->h_from
) != NULL
||
2474 ((n_psonce
& n_PSO_t_FLAG
) && (np
= n_poption_arg_r
) != NULL
)) {
2476 } else if ((addr
= myaddrs(hp
)) != NULL
)
2477 np
= lextract(addr
, GEXTRA
| GFULL
| GFULLEXTRA
);
2480 if ((np
= hp
->h_sender
) != NULL
) {
2482 } else if ((addr
= ok_vlook(sender
)) != NULL
)
2483 np
= lextract(addr
, GEXTRA
| GFULL
| GFULLEXTRA
);
2489 FL
struct name
const *
2490 check_from_and_sender(struct name
const *fromfield
,
2491 struct name
const *senderfield
)
2493 struct name
const *rv
= NULL
;
2496 if (senderfield
!= NULL
) {
2497 if (senderfield
->n_flink
!= NULL
) {
2498 n_err(_("The Sender: field may contain only one address\n"));
2504 if (fromfield
!= NULL
) {
2505 if (fromfield
->n_flink
!= NULL
&& senderfield
== NULL
) {
2506 n_err(_("A Sender: is required when there are multiple "
2507 "addresses in From:\n"));
2515 rv
= (struct name
*)0x1;
2523 getsender(struct message
*mp
)
2529 if ((cp
= hfield1("from", mp
)) == NULL
||
2530 (np
= lextract(cp
, GEXTRA
| GSKIN
)) == NULL
)
2533 cp
= (np
->n_flink
!= NULL
) ? skin(hfield1("sender", mp
)) : np
->n_name
;
2540 grab_headers(enum n_go_input_flags gif
, struct header
*hp
, enum gfield gflags
,
2543 /* TODO grab_headers: again, check counts etc. against RFC;
2544 * TODO (now assumes check_from_and_sender() is called afterwards ++ */
2550 comma
= (ok_blook(bsdcompat
) || ok_blook(bsdmsgs
)) ? 0 : GCOMMA
;
2553 hp
->h_to
= grab_names(gif
, "To: ", hp
->h_to
, comma
, GTO
| GFULL
);
2554 if (subjfirst
&& (gflags
& GSUBJECT
))
2555 hp
->h_subject
= n_go_input_cp(gif
, "Subject: ", hp
->h_subject
);
2557 hp
->h_cc
= grab_names(gif
, "Cc: ", hp
->h_cc
, comma
, GCC
| GFULL
);
2559 hp
->h_bcc
= grab_names(gif
, "Bcc: ", hp
->h_bcc
, comma
, GBCC
| GFULL
);
2561 if (gflags
& GEXTRA
) {
2562 if (hp
->h_from
== NULL
)
2563 hp
->h_from
= lextract(myaddrs(hp
), GEXTRA
| GFULL
| GFULLEXTRA
);
2564 hp
->h_from
= grab_names(gif
, "From: ", hp
->h_from
, comma
,
2565 GEXTRA
| GFULL
| GFULLEXTRA
);
2566 if (hp
->h_replyto
== NULL
)
2567 hp
->h_replyto
= lextract(ok_vlook(replyto
), GEXTRA
| GFULL
);
2568 hp
->h_replyto
= grab_names(gif
, "Reply-To: ", hp
->h_replyto
, comma
,
2570 if (hp
->h_sender
== NULL
)
2571 hp
->h_sender
= extract(ok_vlook(sender
), GEXTRA
| GFULL
);
2572 hp
->h_sender
= grab_names(gif
, "Sender: ", hp
->h_sender
, comma
,
2576 if (!subjfirst
&& (gflags
& GSUBJECT
))
2577 hp
->h_subject
= n_go_input_cp(gif
, "Subject: ", hp
->h_subject
);
2584 header_match(struct message
*mp
, struct search_expr
const *sep
)
2589 size_t linesize
= 0; /* TODO line pool */
2590 char *linebuf
= NULL
, *colon
;
2594 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
2596 if ((lc
= mp
->m_lines
- 1) < 0)
2599 if ((mp
->m_flag
& MNOFROM
) == 0 &&
2600 readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2603 if (gethfield(ibuf
, &linebuf
, &linesize
, lc
, &colon
) <= 0)
2605 if (blankchar(*++colon
))
2607 in
.l
= strlen(in
.s
= colon
);
2608 mime_fromhdr(&in
, &out
, TD_ICONV
);
2610 if (sep
->ss_sexpr
== NULL
)
2611 rv
= (regexec(&sep
->ss_regex
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
2614 rv
= substr(out
.s
, sep
->ss_sexpr
);
2621 if (linebuf
!= NULL
)
2627 FL
struct n_header_field
*
2628 n_customhdr_query(void){
2630 struct n_header_field
*rv
, **tail
, *hfp
;
2635 if((vp
= ok_vlook(customhdr
)) != NULL
){
2641 while((vp
= a_head_customhdr__sep(&buf
)) != NULL
){
2643 char const *nstart
, *cp
;
2645 for(nstart
= cp
= vp
;; ++cp
){
2646 if(fieldnamechar(*cp
))
2650 n_err(_("Invalid nameless *customhdr* entry\n"));
2653 }else if(*cp
!= ':' && !blankchar(*cp
)){
2655 n_err(_("Invalid *customhdr* entry: %s\n"), vp
);
2660 nl
= (ui32_t
)PTR2SIZE(cp
- nstart
);
2662 while(blankchar(*cp
))
2666 while(blankchar(*cp
))
2668 bl
= (ui32_t
)strlen(cp
) +1;
2671 hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
) +
2673 tail
= &hfp
->hf_next
;
2674 hfp
->hf_next
= NULL
;
2676 hfp
->hf_bl
= bl
- 1;
2677 memcpy(hfp
->hf_dat
, nstart
, nl
);
2678 hfp
->hf_dat
[nl
++] = '\0';
2679 memcpy(hfp
->hf_dat
+ nl
, cp
, bl
);