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
= n_servbyname(ok_vlook(mta
), NULL
)) != NULL
&& *mta
!= '\0'))
1107 char const *hn
, *ln
;
1110 hn
= n_nodename(TRU1
);
1111 ln
= ok_vlook(LOGNAME
);
1112 i
= strlen(ln
) + strlen(hn
) + 1 +1;
1113 rv
= cp
= salloc(i
);
1114 sstpcpy(sstpcpy(sstpcpy(cp
, ln
), n_at
), hn
);
1120 myorigin(struct header
*hp
) /* TODO */
1122 char const *rv
= NULL
, *ccp
;
1126 if((ccp
= myaddrs(hp
)) != NULL
&&
1127 (np
= lextract(ccp
, GEXTRA
| GFULL
)) != NULL
){
1128 if(np
->n_flink
== NULL
)
1130 else if((ccp
= ok_vlook(sender
)) != NULL
) {
1131 if((np
= lextract(ccp
, GEXTRA
| GFULL
)) == NULL
||
1132 np
->n_flink
!= NULL
||
1133 is_addr_invalid(np
, EACM_STRICT
| EACM_NOLOG
| EACM_NONAME
))
1134 n_err(_("The address given in *sender* is invalid: %s\n"), ccp
);
1144 is_head(char const *linebuf
, size_t linelen
, bool_t check_rfc4155
)
1146 char date
[n_FROM_DATEBUF
];
1150 if ((rv
= (linelen
>= 5 && !memcmp(linebuf
, "From ", 5))) && check_rfc4155
&&
1151 (extract_date_from_from_(linebuf
, linelen
, date
) <= 0 ||
1159 extract_date_from_from_(char const *line
, size_t linelen
,
1160 char datebuf
[n_FROM_DATEBUF
])
1163 char const *cp
= line
;
1169 cp
= _from__skipword(cp
);
1173 cp
= _from__skipword(cp
);
1176 if((cp
[0] == 't' || cp
[0] == 'T') && (cp
[1] == 't' || cp
[1] == 'T') &&
1177 (cp
[2] == 'y' || 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.
1187 * The [Aa][Tt] is also RFC 733, so be tolerant */
1188 else if((cp
[0] == 'a' || cp
[0] == 'A') && (cp
[1] == 't' || cp
[1] == 'T') &&
1193 cp
= _from__skipword(cp
);
1196 if((cp
[0] == 'd' || cp
[0] == 'D') && (cp
[1] == 'o' || cp
[1] == 'O') &&
1197 (cp
[2] == 't' || cp
[2] == 'T') && cp
[3] == ' '){
1203 linelen
-= PTR2SIZE(cp
- line
);
1204 if (linelen
< a_HEAD_DATE_MINLEN
)
1206 if (cp
[linelen
- 1] == '\n') {
1208 /* (Rather IMAP/POP3 only) */
1209 if (cp
[linelen
- 1] == '\r')
1211 if (linelen
< a_HEAD_DATE_MINLEN
)
1214 if (linelen
>= n_FROM_DATEBUF
)
1218 memcpy(datebuf
, cp
, linelen
);
1219 datebuf
[linelen
] = '\0';
1223 cp
= _("<Unknown date>");
1224 linelen
= strlen(cp
);
1225 if (linelen
>= n_FROM_DATEBUF
)
1226 linelen
= n_FROM_DATEBUF
;
1232 extract_header(FILE *fp
, struct header
*hp
, si8_t
*checkaddr_err
)
1234 /* See the prototype declaration for the hairy relationship of
1235 * n_poption&n_PO_t_FLAG and/or n_psonce&n_PSO_t_FLAG in here */
1236 struct n_header_field
**hftail
;
1237 struct header nh
, *hq
= &nh
;
1238 char *linebuf
= NULL
/* TODO line pool */, *colon
;
1239 size_t linesize
= 0, seenfields
= 0;
1241 char const *val
, *cp
;
1244 memset(hq
, 0, sizeof *hq
);
1245 if ((n_psonce
& n_PSO_t_FLAG
) && (n_poption
& n_PO_t_FLAG
)) {
1246 hq
->h_to
= hp
->h_to
;
1247 hq
->h_cc
= hp
->h_cc
;
1248 hq
->h_bcc
= hp
->h_bcc
;
1250 hftail
= &hq
->h_user_headers
;
1252 for (lc
= 0; readline_restart(fp
, &linebuf
, &linesize
, 0) > 0; ++lc
)
1255 /* TODO yippieia, cat(check(lextract)) :-) */
1257 while ((lc
= gethfield(fp
, &linebuf
, &linesize
, lc
, &colon
)) >= 0) {
1260 /* We explicitly allow EAF_NAME for some addressees since aliases are not
1261 * yet expanded when we parse these! */
1262 if ((val
= thisfield(linebuf
, "to")) != NULL
) {
1264 hq
->h_to
= cat(hq
->h_to
, checkaddrs(lextract(val
, GTO
| GFULL
),
1265 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1266 } else if ((val
= thisfield(linebuf
, "cc")) != NULL
) {
1268 hq
->h_cc
= cat(hq
->h_cc
, checkaddrs(lextract(val
, GCC
| GFULL
),
1269 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1270 } else if ((val
= thisfield(linebuf
, "bcc")) != NULL
) {
1272 hq
->h_bcc
= cat(hq
->h_bcc
, checkaddrs(lextract(val
, GBCC
| GFULL
),
1273 EACM_NORMAL
| EAF_NAME
| EAF_MAYKEEP
, checkaddr_err
));
1274 } else if ((val
= thisfield(linebuf
, "from")) != NULL
) {
1275 if (!(n_psonce
& n_PSO_t_FLAG
) || (n_poption
& n_PO_t_FLAG
)) {
1277 hq
->h_from
= cat(hq
->h_from
,
1278 checkaddrs(lextract(val
, GEXTRA
| GFULL
| GFULLEXTRA
),
1279 EACM_STRICT
, NULL
));
1281 } else if ((val
= thisfield(linebuf
, "reply-to")) != NULL
) {
1283 hq
->h_replyto
= cat(hq
->h_replyto
,
1284 checkaddrs(lextract(val
, GEXTRA
| GFULL
), EACM_STRICT
, NULL
));
1285 } else if ((val
= thisfield(linebuf
, "sender")) != NULL
) {
1286 if (!(n_psonce
& n_PSO_t_FLAG
) || (n_poption
& n_PO_t_FLAG
)) {
1288 hq
->h_sender
= cat(hq
->h_sender
, /* TODO cat? check! */
1289 checkaddrs(lextract(val
, GEXTRA
| GFULL
| GFULLEXTRA
),
1290 EACM_STRICT
, NULL
));
1293 } else if ((val
= thisfield(linebuf
, "subject")) != NULL
||
1294 (val
= thisfield(linebuf
, "subj")) != NULL
) {
1296 for (cp
= val
; blankchar(*cp
); ++cp
)
1298 hq
->h_subject
= (hq
->h_subject
!= NULL
)
1299 ? save2str(hq
->h_subject
, cp
) : savestr(cp
);
1301 /* The remaining are mostly hacked in and thus TODO -- at least in
1302 * TODO respect to their content checking */
1303 else if((val
= thisfield(linebuf
, "message-id")) != NULL
){
1304 if(n_psonce
& n_PSO_t_FLAG
){
1305 np
= checkaddrs(lextract(val
, GREF
),
1306 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1308 if (np
== NULL
|| np
->n_flink
!= NULL
)
1311 hq
->h_message_id
= np
;
1314 }else if((val
= thisfield(linebuf
, "in-reply-to")) != NULL
){
1315 if(n_psonce
& n_PSO_t_FLAG
){
1316 np
= checkaddrs(lextract(val
, GREF
),
1317 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1320 hq
->h_in_reply_to
= np
;
1323 }else if((val
= thisfield(linebuf
, "references")) != NULL
){
1324 if(n_psonce
& n_PSO_t_FLAG
){
1326 /* TODO Limit number of references TODO better on parser side */
1327 hq
->h_ref
= cat(hq
->h_ref
, checkaddrs(extract(val
, GREF
),
1328 /*EACM_STRICT | TODO '/' valid!! */ EACM_NOLOG
| EACM_NONAME
,
1333 /* and that is very hairy */
1334 else if((val
= thisfield(linebuf
, "mail-followup-to")) != NULL
){
1335 if(n_psonce
& n_PSO_t_FLAG
){
1337 hq
->h_mft
= cat(hq
->h_mft
, checkaddrs(lextract(val
, GEXTRA
| GFULL
),
1338 /*EACM_STRICT | TODO '/' valid!! | EACM_NOLOG | */EACM_NONAME
,
1343 /* A free-form user header; gethfield() did some verification already.. */
1345 struct n_header_field
*hfp
;
1349 for(nstart
= cp
= linebuf
;; ++cp
)
1350 if(!fieldnamechar(*cp
))
1352 nl
= (ui32_t
)PTR2SIZE(cp
- nstart
);
1354 while(blankchar(*cp
))
1358 n_err(_("Ignoring header field: %s\n"), linebuf
);
1361 while(blankchar(*cp
))
1363 bl
= (ui32_t
)strlen(cp
) +1;
1366 *hftail
= hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
1368 hftail
= &hfp
->hf_next
;
1369 hfp
->hf_next
= NULL
;
1371 hfp
->hf_bl
= bl
- 1;
1372 memcpy(hfp
->hf_dat
, nstart
, nl
);
1373 hfp
->hf_dat
[nl
++] = '\0';
1374 memcpy(hfp
->hf_dat
+ nl
, cp
, bl
);
1378 /* In case the blank line after the header has been edited out. Otherwise,
1379 * fetch the header separator */
1380 if (linebuf
!= NULL
) {
1381 if (linebuf
[0] != '\0') {
1382 for (cp
= linebuf
; *(++cp
) != '\0';)
1384 fseek(fp
, (long)-PTR2SIZE(1 + cp
- linebuf
), SEEK_CUR
);
1386 if ((c
= getc(fp
)) != '\n' && c
!= EOF
)
1391 if (seenfields
> 0 && (checkaddr_err
== NULL
|| *checkaddr_err
== 0)) {
1392 hp
->h_to
= hq
->h_to
;
1393 hp
->h_cc
= hq
->h_cc
;
1394 hp
->h_bcc
= hq
->h_bcc
;
1395 hp
->h_from
= hq
->h_from
;
1396 hp
->h_replyto
= hq
->h_replyto
;
1397 hp
->h_sender
= hq
->h_sender
;
1398 if (hq
->h_subject
!= NULL
|| !(n_psonce
& n_PSO_t_FLAG
) ||
1399 !(n_poption
& n_PO_t_FLAG
))
1400 hp
->h_subject
= hq
->h_subject
;
1401 hp
->h_user_headers
= hq
->h_user_headers
;
1403 if (n_psonce
& n_PSO_t_FLAG
) {
1404 hp
->h_ref
= hq
->h_ref
;
1405 hp
->h_message_id
= hq
->h_message_id
;
1406 hp
->h_in_reply_to
= hq
->h_in_reply_to
;
1407 hp
->h_mft
= hq
->h_mft
;
1409 /* And perform additional validity checks so that we don't bail later
1410 * on TODO this is good and the place where this should occur,
1411 * TODO unfortunately a lot of other places do again and blabla */
1412 if (hp
->h_from
== NULL
)
1413 hp
->h_from
= n_poption_arg_r
;
1414 else if (hp
->h_from
->n_flink
!= NULL
&& hp
->h_sender
== NULL
)
1415 hp
->h_sender
= lextract(ok_vlook(sender
),
1416 GEXTRA
| GFULL
| GFULLEXTRA
);
1419 n_err(_("Restoring deleted header lines\n"));
1421 if (linebuf
!= NULL
)
1427 hfield_mult(char const *field
, struct message
*mp
, int mult
)
1432 size_t linesize
= 0; /* TODO line pool */
1433 char *linebuf
= NULL
, *colon
;
1437 /* There are (spam) messages which have header bytes which are many KB when
1438 * joined, so resize a single heap storage until we are done if we shall
1439 * collect a field that may have multiple bodies; only otherwise use the
1440 * string dope directly */
1441 memset(&hfs
, 0, sizeof hfs
);
1443 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
1445 if ((lc
= mp
->m_lines
- 1) < 0)
1448 if ((mp
->m_flag
& MNOFROM
) == 0 &&
1449 readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
1452 if ((lc
= gethfield(ibuf
, &linebuf
, &linesize
, lc
, &colon
)) < 0)
1454 if ((hfield
= thisfield(linebuf
, field
)) != NULL
&& *hfield
!= '\0') {
1456 n_str_add_buf(&hfs
, hfield
, strlen(hfield
));
1458 hfs
.s
= savestr(hfield
);
1465 if (linebuf
!= NULL
)
1467 if (mult
&& hfs
.s
!= NULL
) {
1468 colon
= savestrbuf(hfs
.s
, hfs
.l
);
1477 thisfield(char const *linebuf
, char const *field
)
1479 char const *rv
= NULL
;
1482 while (lowerconv(*linebuf
) == lowerconv(*field
)) {
1489 while (blankchar(*linebuf
))
1491 if (*linebuf
++ != ':')
1494 while (blankchar(*linebuf
)) /* TODO header parser.. strip trailing WS?!? */
1503 nameof(struct message
*mp
, int reptype
)
1508 cp
= skin(name1(mp
, reptype
));
1509 if (reptype
!= 0 || charcount(cp
, '!') < 2)
1511 cp2
= strrchr(cp
, '!');
1513 while (cp2
> cp
&& *cp2
!= '!')
1523 skip_comment(char const *cp
)
1528 for (nesting
= 1; nesting
> 0 && *cp
; ++cp
) {
1547 routeaddr(char const *name
)
1549 char const *np
, *rp
= NULL
;
1552 for (np
= name
; *np
; np
++) {
1555 np
= skip_comment(np
+ 1) - 1;
1561 if (*np
== '\\' && np
[1])
1578 FL
enum expand_addr_flags
1579 expandaddr_to_eaf(void)
1582 char const *eafd_name
;
1583 bool_t eafd_is_target
;
1587 {"restrict", FAL0
, EAF_TARGET_MASK
, EAF_RESTRICT
| EAF_RESTRICT_TARGETS
},
1588 {"fail", FAL0
, EAF_NONE
, EAF_FAIL
},
1589 {"failinvaddr", FAL0
, EAF_NONE
, EAF_FAILINVADDR
| EAF_ADDR
},
1590 {"all", TRU1
, EAF_NONE
, EAF_TARGET_MASK
},
1591 {"file", TRU1
, EAF_NONE
, EAF_FILE
},
1592 {"pipe", TRU1
, EAF_NONE
, EAF_PIPE
},
1593 {"name", TRU1
, EAF_NONE
, EAF_NAME
},
1594 {"addr", TRU1
, EAF_NONE
, EAF_ADDR
}
1598 enum expand_addr_flags rv
;
1602 if ((cp
= ok_vlook(expandaddr
)) == NULL
)
1603 rv
= EAF_RESTRICT_TARGETS
;
1604 else if (*cp
== '\0')
1605 rv
= EAF_TARGET_MASK
;
1607 rv
= EAF_TARGET_MASK
;
1609 for (buf
= savestr(cp
); (cp
= n_strsep(&buf
, ',', TRU1
)) != NULL
;) {
1612 if ((minus
= (*cp
== '-')) || *cp
== '+')
1614 for (eafp
= eafa
;; ++eafp
) {
1615 if (eafp
== eafa
+ n_NELEM(eafa
)) {
1616 if (n_poption
& n_PO_D_V
)
1617 n_err(_("Unknown *expandaddr* value: %s\n"), cp
);
1619 } else if (!asccasecmp(cp
, eafp
->eafd_name
)) {
1621 rv
&= ~eafp
->eafd_andoff
;
1622 rv
|= eafp
->eafd_or
;
1624 if (eafp
->eafd_is_target
)
1625 rv
&= ~eafp
->eafd_or
;
1626 else if (n_poption
& n_PO_D_V
)
1627 n_err(_("minus - prefix invalid for *expandaddr* value: "
1631 } else if (!asccasecmp(cp
, "noalias")) { /* TODO v15 OBSOLETE */
1632 n_OBSOLETE(_("*expandaddr*: noalias is henceforth -name"));
1639 if((rv
& EAF_RESTRICT
) && ((n_psonce
& n_PSO_INTERACTIVE
) ||
1640 (n_poption
& n_PO_TILDE_FLAG
)))
1641 rv
|= EAF_TARGET_MASK
;
1642 else if(n_poption
& n_PO_D_V
){
1643 if(!(rv
& EAF_TARGET_MASK
))
1644 n_err(_("*expandaddr* doesn't allow any addressees\n"));
1645 else if((rv
& EAF_FAIL
) && (rv
& EAF_TARGET_MASK
) == EAF_TARGET_MASK
)
1646 n_err(_("*expandaddr* with fail, but no restrictions to apply\n"));
1654 is_addr_invalid(struct name
*np
, enum expand_addr_check_mode eacm
)
1656 char cbuf
[sizeof "'\\U12340'"];
1660 enum expand_addr_flags eaf
;
1663 eaf
= expandaddr_to_eaf();
1666 if ((rv
= ((f
& NAME_ADDRSPEC_INVALID
) != 0))) {
1667 if (eaf
& EAF_FAILINVADDR
)
1670 if ((eacm
& EACM_NOLOG
) || (f
& NAME_ADDRSPEC_ERR_EMPTY
)) {
1674 char const *fmt
= "'\\x%02X'";
1675 bool_t ok8bit
= TRU1
;
1677 if (f
& NAME_ADDRSPEC_ERR_IDNA
) {
1678 cs
= _("Invalid domain name: %s, character %s\n");
1681 } else if (f
& NAME_ADDRSPEC_ERR_ATSEQ
)
1682 cs
= _("%s contains invalid %s sequence\n");
1683 else if (f
& NAME_ADDRSPEC_ERR_NAME
) {
1684 cs
= _("%s is an invalid alias name\n");
1686 cs
= _("%s contains invalid byte %s\n");
1688 c
= NAME_ADDRSPEC_ERR_GETWC(f
);
1689 snprintf(cbuf
, sizeof cbuf
,
1690 (ok8bit
&& c
>= 040 && c
<= 0177 ? "'%c'" : fmt
), c
);
1696 /* *expandaddr* stuff */
1697 if (!(rv
= ((eacm
& EACM_MODE_MASK
) != EACM_NONE
)))
1700 if ((eacm
& EACM_STRICT
) && (f
& NAME_ADDRSPEC_ISFILEORPIPE
)) {
1703 cs
= _("%s%s: file or pipe addressees not allowed here\n");
1704 if (eacm
& EACM_NOLOG
)
1710 eaf
|= (eacm
& EAF_TARGET_MASK
);
1711 if (eacm
& EACM_NONAME
)
1714 if (eaf
== EAF_NONE
) {
1721 if (!(eaf
& EAF_FILE
) && (f
& NAME_ADDRSPEC_ISFILE
)) {
1722 cs
= _("%s%s: *expandaddr* doesn't allow file target\n");
1723 if (eacm
& EACM_NOLOG
)
1725 } else if (!(eaf
& EAF_PIPE
) && (f
& NAME_ADDRSPEC_ISPIPE
)) {
1726 cs
= _("%s%s: *expandaddr* doesn't allow command pipe target\n");
1727 if (eacm
& EACM_NOLOG
)
1729 } else if (!(eaf
& EAF_NAME
) && (f
& NAME_ADDRSPEC_ISNAME
)) {
1730 cs
= _("%s%s: *expandaddr* doesn't allow user name target\n");
1731 if (eacm
& EACM_NOLOG
)
1733 } else if (!(eaf
& EAF_ADDR
) && (f
& NAME_ADDRSPEC_ISADDR
)) {
1734 cs
= _("%s%s: *expandaddr* doesn't allow mail address target\n");
1735 if (eacm
& EACM_NOLOG
)
1745 n_err(cs
, n_shexp_quote_cp(np
->n_name
, TRU1
), cbuf
);
1752 skin(char const *name
)
1754 struct n_addrguts ag
;
1759 name
= n_addrspec_with_guts(&ag
,name
, TRU1
, FAL0
);
1761 if(!(ag
.ag_n_flags
& NAME_NAME_SALLOC
))
1762 rv
= savestrbuf(rv
, ag
.ag_slen
);
1769 /* TODO addrspec_with_guts: RFC 5322
1770 * TODO addrspec_with_guts: trim whitespace ETC. ETC. ETC.!!! */
1772 n_addrspec_with_guts(struct n_addrguts
*agp
, char const *name
, bool_t doskin
,
1773 bool_t issingle_hack
){
1775 char *cp2
, *bufend
, *nbuf
, c
;
1785 memset(agp
, 0, sizeof *agp
);
1787 if((agp
->ag_input
= name
) == NULL
|| (agp
->ag_ilen
= strlen(name
)) == 0){
1788 agp
->ag_skinned
= n_UNCONST(n_empty
); /* ok: NAME_SALLOC is not set */
1790 agp
->ag_n_flags
|= NAME_ADDRSPEC_CHECKED
;
1791 NAME_ADDRSPEC_ERR_SET(agp
->ag_n_flags
, NAME_ADDRSPEC_ERR_EMPTY
, 0);
1794 /*agp->ag_iaddr_start = 0;*/
1795 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1796 agp
->ag_skinned
= n_UNCONST(name
); /* (NAME_SALLOC not set) */
1797 agp
->ag_slen
= agp
->ag_ilen
;
1798 agp
->ag_n_flags
= NAME_SKINNED
;
1803 nbuf
= n_lofi_alloc(agp
->ag_ilen
+1);
1804 /*agp->ag_iaddr_start = 0;*/
1805 cp2
= bufend
= nbuf
;
1807 /* TODO This is complete crap and should use a token parser */
1808 for(cp
= name
++; (c
= *cp
++) != '\0';){
1811 cp
= skip_comment(cp
);
1815 /* Start of a "quoted-string". Copy it in its entirety */
1816 /* XXX RFC: quotes are "semantically invisible"
1817 * XXX But it was explicitly added (Changelog.Heirloom,
1818 * XXX [9.23] released 11/15/00, "Do not remove quotes
1819 * XXX when skinning names"? No more info.. */
1821 while ((c
= *cp
) != '\0') { /* TODO improve */
1829 else if ((c
= *cp
) != '\0') {
1838 if((flags
& (a_GOTADDR
| a_GOTSPACE
)) == a_GOTADDR
){
1839 flags
|= a_GOTSPACE
;
1840 agp
->ag_iaddr_aend
= PTR2SIZE(cp
- name
);
1842 if (cp
[0] == 'a' && cp
[1] == 't' && blankchar(cp
[2]))
1843 cp
+= 3, *cp2
++ = '@';
1844 else if (cp
[0] == '@' && blankchar(cp
[1]))
1845 cp
+= 2, *cp2
++ = '@';
1850 agp
->ag_iaddr_start
= PTR2SIZE(cp
- (name
- 1));
1852 flags
&= ~(a_GOTSPACE
| a_LASTSP
);
1853 flags
|= a_GOTLT
| a_GOTADDR
;
1856 if(flags
& a_GOTLT
){
1857 /* (_addrspec_check() verifies these later!) */
1858 flags
&= ~(a_GOTLT
| a_LASTSP
);
1859 agp
->ag_iaddr_aend
= PTR2SIZE(cp
- name
);
1861 /* Skip over the entire remaining field */
1862 while((c
= *cp
) != '\0' && c
!= ','){
1865 cp
= skip_comment(cp
);
1867 while ((c
= *cp
) != '\0') {
1871 if (c
== '\\' && *cp
!= '\0')
1879 if(flags
& a_LASTSP
){
1881 if(flags
& a_GOTADDR
)
1885 /* This character is forbidden here, but it may nonetheless be
1886 * present: ensure we turn this into something valid! (E.g., if the
1887 * next character would be a "..) */
1888 if(c
== '\\' && *cp
!= '\0')
1890 if(c
== ',' && !issingle_hack
){
1891 if(!(flags
& a_GOTLT
)){
1893 for(; blankchar(*cp
); ++cp
)
1898 }else if(!(flags
& a_GOTADDR
)){
1900 agp
->ag_iaddr_start
= PTR2SIZE(cp
- name
);
1905 agp
->ag_slen
= PTR2SIZE(cp2
- nbuf
);
1906 if (agp
->ag_iaddr_aend
== 0)
1907 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1909 else if (agp
->ag_iaddr_aend
< agp
->ag_iaddr_start
) {
1910 cp2
= n_autorec_alloc(agp
->ag_ilen
+ 1 +1);
1911 memcpy(cp2
, agp
->ag_input
, agp
->ag_ilen
);
1912 agp
->ag_iaddr_aend
= agp
->ag_ilen
;
1913 cp2
[agp
->ag_ilen
++] = '>';
1914 cp2
[agp
->ag_ilen
] = '\0';
1916 agp
->ag_skinned
= savestrbuf(nbuf
, agp
->ag_slen
);
1918 agp
->ag_n_flags
= NAME_NAME_SALLOC
| NAME_SKINNED
;
1920 if(a_head_addrspec_check(agp
, doskin
) <= FAL0
)
1923 name
= agp
->ag_input
;
1930 realname(char const *name
)
1932 char const *cp
, *cq
, *cstart
= NULL
, *cend
= NULL
;
1935 int quoted
, good
, nogood
;
1938 if ((cp
= n_UNCONST(name
)) == NULL
)
1940 for (; *cp
!= '\0'; ++cp
) {
1943 if (cstart
!= NULL
) {
1944 /* More than one comment in address, doesn't make sense to display
1945 * it without context. Return the entire field */
1946 cp
= mime_fromaddr(name
);
1950 cp
= skip_comment(cp
);
1953 cend
= cstart
= NULL
;
1959 if (*cp
== '\\' && cp
[1])
1970 /* More than one address. Just use the first one */
1976 if (cstart
== NULL
) {
1978 /* If name contains only a route-addr, the surrounding angle brackets
1979 * don't serve any useful purpose when displaying, so remove */
1980 cp
= prstr(skin(name
));
1982 cp
= mime_fromaddr(name
);
1986 /* Strip quotes. Note that quotes that appear within a MIME encoded word are
1987 * not stripped. The idea is to strip only syntactical relevant things (but
1988 * this is not necessarily the most sensible way in practice) */
1989 rp
= rname
= ac_alloc(PTR2SIZE(cend
- cstart
+1));
1991 for (cp
= cstart
; cp
< cend
; ++cp
) {
1992 if (*cp
== '(' && !quoted
) {
1993 cq
= skip_comment(++cp
);
1994 if (PTRCMP(--cq
, >, cend
))
1997 if (*cp
== '\\' && PTRCMP(cp
+ 1, <, cq
))
2001 } else if (*cp
== '\\' && PTRCMP(cp
+ 1, <, cend
))
2003 else if (*cp
== '"') {
2012 mime_fromhdr(&in
, &out
, TD_ISPR
| TD_ICONV
);
2014 rname
= savestr(out
.s
);
2017 while (blankchar(*rname
))
2019 for (rp
= rname
; *rp
!= '\0'; ++rp
)
2021 while (PTRCMP(--rp
, >=, rname
) && blankchar(*rp
))
2024 cp
= mime_fromaddr(name
);
2028 /* mime_fromhdr() has converted all nonprintable characters to question
2029 * marks now. These and blanks are considered uninteresting; if the
2030 * displayed part of the real name contains more than 25% of them, it is
2031 * probably better to display the plain email address instead */
2034 for (rp
= rname
; *rp
!= '\0' && PTRCMP(rp
, <, rname
+ 20); ++rp
)
2035 if (*rp
== '?' || blankchar(*rp
))
2039 cp
= (good
* 3 < nogood
) ? prstr(skin(name
)) : rname
;
2042 return n_UNCONST(cp
);
2046 name1(struct message
*mp
, int reptype
)
2048 char *namebuf
, *cp
, *cp2
, *linebuf
= NULL
/* TODO line pool */;
2049 size_t namesize
, linesize
= 0;
2054 if ((cp
= hfield1("from", mp
)) != NULL
&& *cp
!= '\0')
2056 if (reptype
== 0 && (cp
= hfield1("sender", mp
)) != NULL
&& *cp
!= '\0')
2059 namebuf
= smalloc(namesize
= 1);
2061 if (mp
->m_flag
& MNOFROM
)
2063 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
2065 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2069 if (namesize
<= linesize
)
2070 namebuf
= srealloc(namebuf
, namesize
= linesize
+1);
2071 for (cp
= linebuf
; *cp
!= '\0' && *cp
!= ' '; ++cp
)
2073 for (; blankchar(*cp
); ++cp
)
2075 for (cp2
= namebuf
+ strlen(namebuf
);
2076 *cp
&& !blankchar(*cp
) && PTRCMP(cp2
, <, namebuf
+ namesize
-1);)
2080 if (readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2082 if ((cp
= strchr(linebuf
, 'F')) == NULL
)
2084 if (strncmp(cp
, "From", 4))
2086 if (namesize
<= linesize
)
2087 namebuf
= srealloc(namebuf
, namesize
= linesize
+ 1);
2089 while ((cp
= strchr(cp
, 'r')) != NULL
) {
2090 if (!strncmp(cp
, "remote", 6)) {
2091 if ((cp
= strchr(cp
, 'f')) == NULL
)
2093 if (strncmp(cp
, "from", 4) != 0)
2095 if ((cp
= strchr(cp
, ' ')) == NULL
)
2099 strncpy(namebuf
, cp
, namesize
);
2102 cp2
= strrchr(namebuf
, '!') + 1;
2103 strncpy(cp2
, cp
, PTR2SIZE(namebuf
+ namesize
- cp2
));
2105 namebuf
[namesize
- 2] = '!';
2106 namebuf
[namesize
- 1] = '\0';
2112 if (*namebuf
!= '\0' || ((cp
= hfield1("return-path", mp
))) == NULL
||
2114 cp
= savestr(namebuf
);
2116 if (linebuf
!= NULL
)
2125 subject_re_trim(char const *s
){
2129 }const *pp
, ignored
[] = { /* Update *reply-strings* manual upon change! */
2131 {3, "aw:"}, {5, "antw:"}, /* de */
2132 {3, "wg:"}, /* Seen too often in the wild */
2137 char *re_st
, *re_st_x
;
2147 if((re_st_x
= ok_vlook(reply_strings
)) != NULL
&&
2148 (re_l
= strlen(re_st_x
)) > 0){
2149 re_st
= n_lofi_alloc(++re_l
* 2);
2150 memcpy(re_st
, re_st_x
, re_l
);
2155 while(spacechar(*s
))
2158 for(pp
= ignored
; pp
->len
> 0; ++pp
)
2159 if(is_asccaseprefix(pp
->dat
, s
)){
2168 memcpy(re_st_x
= &re_st
[re_l
], re_st
, re_l
);
2169 while((cp
= n_strsep(&re_st_x
, ',', TRU1
)) != NULL
)
2170 if(is_asccaseprefix(cp
, s
)){
2182 return any
? s
: orig_s
;
2186 msgidcmp(char const *s1
, char const *s2
)
2188 int q1
= 0, q2
= 0, c1
, c2
;
2197 c1
= msgidnextc(&s1
, &q1
);
2198 c2
= msgidnextc(&s2
, &q2
);
2207 fakefrom(struct message
*mp
)
2212 if (((name
= skin(hfield1("return-path", mp
))) == NULL
|| *name
== '\0' ) &&
2213 ((name
= skin(hfield1("from", mp
))) == NULL
|| *name
== '\0'))
2214 /* XXX MAILER-DAEMON is what an old MBOX manual page says.
2215 * RFC 4155 however requires a RFC 5322 (2822) conforming
2216 * "addr-spec", but we simply can't provide that */
2217 name
= "MAILER-DAEMON";
2229 for (cq
= cp
; *cq
!= '\0' && *cq
!= '\n'; ++cq
)
2237 #if defined HAVE_IMAP_SEARCH || defined HAVE_IMAP
2239 unixtime(char const *fromline
)
2241 char const *fp
, *xp
;
2243 si32_t i
, year
, month
, day
, hour
, minute
, second
, tzdiff
;
2247 for (fp
= fromline
; *fp
!= '\0' && *fp
!= '\n'; ++fp
)
2250 if (PTR2SIZE(fp
- fromline
) < 7)
2255 if (!strncmp(fp
+ 4, n_month_names
[i
], 3))
2257 if (n_month_names
[++i
][0] == '\0')
2263 n_idec_si32_cp(&day
, &fp
[8], 10, &xp
);
2264 if (*xp
!= ' ' || xp
!= fp
+ 10)
2266 n_idec_si32_cp(&hour
, &fp
[11], 10, &xp
);
2267 if (*xp
!= ':' || xp
!= fp
+ 13)
2269 n_idec_si32_cp(&minute
, &fp
[14], 10, &xp
);
2270 if (*xp
!= ':' || xp
!= fp
+ 16)
2272 n_idec_si32_cp(&second
, &fp
[17], 10, &xp
);
2273 if (*xp
!= ' ' || xp
!= fp
+ 19)
2275 n_idec_si32_cp(&year
, &fp
[20], 10, &xp
);
2278 if ((t
= combinetime(year
, month
, day
, hour
, minute
, second
)) == (time_t)-1)
2280 tzdiff
= t
- mktime(gmtime(&t
));
2281 tmptr
= localtime(&t
);
2282 if (tmptr
->tm_isdst
> 0)
2292 #endif /* HAVE_IMAP_SEARCH || HAVE_IMAP */
2295 rfctime(char const *date
) /* TODO n_idec_ return tests */
2299 si32_t i
, year
, month
, day
, hour
, minute
, second
;
2304 if ((cp
= nexttoken(cp
)) == NULL
)
2306 if (alphachar(cp
[0]) && alphachar(cp
[1]) && alphachar(cp
[2]) &&
2308 if ((cp
= nexttoken(&cp
[4])) == NULL
)
2311 n_idec_si32_cp(&day
, cp
, 10, &x
);
2312 if ((cp
= nexttoken(x
)) == NULL
)
2315 if (!strncmp(cp
, n_month_names
[i
], 3))
2317 if (n_month_names
[++i
][0] == '\0')
2321 if ((cp
= nexttoken(&cp
[3])) == NULL
)
2324 * Where a two or three digit year occurs in a date, the year is to be
2325 * interpreted as follows: If a two digit year is encountered whose
2326 * value is between 00 and 49, the year is interpreted by adding 2000,
2327 * ending up with a value between 2000 and 2049. If a two digit year
2328 * is encountered with a value between 50 and 99, or any three digit
2329 * year is encountered, the year is interpreted by adding 1900 */
2330 n_idec_si32_cp(&year
, cp
, 10, &x
);
2331 i
= (int)PTR2SIZE(x
- cp
);
2332 if (i
== 2 && year
>= 0 && year
<= 49)
2334 else if (i
== 3 || (i
== 2 && year
>= 50 && year
<= 99))
2336 if ((cp
= nexttoken(x
)) == NULL
)
2338 n_idec_si32_cp(&hour
, cp
, 10, &x
);
2342 n_idec_si32_cp(&minute
, cp
, 10, &x
);
2345 n_idec_si32_cp(&second
, cp
, 10, &x
);
2349 if ((t
= combinetime(year
, month
, day
, hour
, minute
, second
)) == (time_t)-1)
2351 if ((cp
= nexttoken(x
)) != NULL
) {
2363 if (digitchar(cp
[0]) && digitchar(cp
[1]) && digitchar(cp
[2]) &&
2370 n_idec_si32_cp(&i
, buf
, 10, NULL
);
2371 tadj
= (si64_t
)i
* 3600; /* XXX */
2374 n_idec_si32_cp(&i
, buf
, 10, NULL
);
2375 tadj
+= (si64_t
)i
* 60; /* XXX */
2380 /* TODO WE DO NOT YET PARSE (OBSOLETE) ZONE NAMES
2381 * TODO once again, Christos Zoulas and NetBSD Mail have done
2382 * TODO a really good job already, but using strptime(3), which
2383 * TODO is not portable. Nonetheless, WE must improve, not
2384 * TODO at last because we simply ignore obsolete timezones!!
2385 * TODO See RFC 5322, 4.3! */
2396 combinetime(int year
, int month
, int day
, int hour
, int minute
, int second
){
2397 size_t const jdn_epoch
= 2440588;
2398 bool_t
const y2038p
= (sizeof(time_t) == 4);
2404 if(UICMP(32, second
, >/*XXX leap=*/, n_DATE_SECSMIN
) ||
2405 UICMP(32, minute
, >=, n_DATE_MINSHOUR
) ||
2406 UICMP(32, hour
, >=, n_DATE_HOURSDAY
) ||
2407 day
< 1 || day
> 31 ||
2408 month
< 1 || month
> 12 ||
2412 if(year
>= 1970 + ((y2038p
? SI32_MAX
: SI64_MAX
) /
2413 (n_DATE_SECSDAY
* n_DATE_DAYSYEAR
))){
2414 /* Be a coward regarding Y2038, many people (mostly myself, that is) do
2415 * test by stepping second-wise around the flip. Don't care otherwise */
2418 if(year
> 2038 || month
> 1 || day
> 19 ||
2419 hour
> 3 || minute
> 14 || second
> 7)
2424 t
+= minute
* n_DATE_SECSMIN
;
2425 t
+= hour
* n_DATE_SECSHOUR
;
2427 jdn
= a_head_gregorian_to_jdn(year
, month
, day
);
2429 t
+= (time_t)jdn
* n_DATE_SECSDAY
;
2439 substdate(struct message
*m
)
2444 /* Determine the date to print in faked 'From ' lines. This is traditionally
2445 * the date the message was written to the mail file. Try to determine this
2446 * using RFC message header fields, or fall back to current time */
2448 if ((cp
= hfield1("received", m
)) != NULL
) {
2449 while ((cp
= nexttoken(cp
)) != NULL
&& *cp
!= ';') {
2452 while (alnumchar(*cp
));
2455 m
->m_time
= rfctime(cp
);
2457 if (m
->m_time
== 0 || m
->m_time
> time_current
.tc_time
) {
2458 if ((cp
= hfield1("date", m
)) != NULL
)
2459 m
->m_time
= rfctime(cp
);
2461 if (m
->m_time
== 0 || m
->m_time
> time_current
.tc_time
)
2462 m
->m_time
= time_current
.tc_time
;
2467 setup_from_and_sender(struct header
*hp
)
2473 /* If -t parsed or composed From: then take it. With -t we otherwise
2474 * want -r to be honoured in favour of *from* in order to have
2475 * a behaviour that is compatible with what users would expect from e.g.
2477 if ((np
= hp
->h_from
) != NULL
||
2478 ((n_psonce
& n_PSO_t_FLAG
) && (np
= n_poption_arg_r
) != NULL
)) {
2480 } else if ((addr
= myaddrs(hp
)) != NULL
)
2481 np
= lextract(addr
, GEXTRA
| GFULL
| GFULLEXTRA
);
2484 if ((np
= hp
->h_sender
) != NULL
) {
2486 } else if ((addr
= ok_vlook(sender
)) != NULL
)
2487 np
= lextract(addr
, GEXTRA
| GFULL
| GFULLEXTRA
);
2493 FL
struct name
const *
2494 check_from_and_sender(struct name
const *fromfield
,
2495 struct name
const *senderfield
)
2497 struct name
const *rv
= NULL
;
2500 if (senderfield
!= NULL
) {
2501 if (senderfield
->n_flink
!= NULL
) {
2502 n_err(_("The Sender: field may contain only one address\n"));
2508 if (fromfield
!= NULL
) {
2509 if (fromfield
->n_flink
!= NULL
&& senderfield
== NULL
) {
2510 n_err(_("A Sender: is required when there are multiple "
2511 "addresses in From:\n"));
2519 rv
= (struct name
*)0x1;
2527 getsender(struct message
*mp
)
2533 if ((cp
= hfield1("from", mp
)) == NULL
||
2534 (np
= lextract(cp
, GEXTRA
| GSKIN
)) == NULL
)
2537 cp
= (np
->n_flink
!= NULL
) ? skin(hfield1("sender", mp
)) : np
->n_name
;
2544 grab_headers(enum n_go_input_flags gif
, struct header
*hp
, enum gfield gflags
,
2547 /* TODO grab_headers: again, check counts etc. against RFC;
2548 * TODO (now assumes check_from_and_sender() is called afterwards ++ */
2554 comma
= (ok_blook(bsdcompat
) || ok_blook(bsdmsgs
)) ? 0 : GCOMMA
;
2557 hp
->h_to
= grab_names(gif
, "To: ", hp
->h_to
, comma
, GTO
| GFULL
);
2558 if (subjfirst
&& (gflags
& GSUBJECT
))
2559 hp
->h_subject
= n_go_input_cp(gif
, "Subject: ", hp
->h_subject
);
2561 hp
->h_cc
= grab_names(gif
, "Cc: ", hp
->h_cc
, comma
, GCC
| GFULL
);
2563 hp
->h_bcc
= grab_names(gif
, "Bcc: ", hp
->h_bcc
, comma
, GBCC
| GFULL
);
2565 if (gflags
& GEXTRA
) {
2566 if (hp
->h_from
== NULL
)
2567 hp
->h_from
= lextract(myaddrs(hp
), GEXTRA
| GFULL
| GFULLEXTRA
);
2568 hp
->h_from
= grab_names(gif
, "From: ", hp
->h_from
, comma
,
2569 GEXTRA
| GFULL
| GFULLEXTRA
);
2570 if (hp
->h_replyto
== NULL
)
2571 hp
->h_replyto
= lextract(ok_vlook(replyto
), GEXTRA
| GFULL
);
2572 hp
->h_replyto
= grab_names(gif
, "Reply-To: ", hp
->h_replyto
, comma
,
2574 if (hp
->h_sender
== NULL
)
2575 hp
->h_sender
= extract(ok_vlook(sender
), GEXTRA
| GFULL
);
2576 hp
->h_sender
= grab_names(gif
, "Sender: ", hp
->h_sender
, comma
,
2580 if (!subjfirst
&& (gflags
& GSUBJECT
))
2581 hp
->h_subject
= n_go_input_cp(gif
, "Subject: ", hp
->h_subject
);
2588 header_match(struct message
*mp
, struct search_expr
const *sep
)
2593 size_t linesize
= 0; /* TODO line pool */
2594 char *linebuf
= NULL
, *colon
;
2598 if ((ibuf
= setinput(&mb
, mp
, NEED_HEADER
)) == NULL
)
2600 if ((lc
= mp
->m_lines
- 1) < 0)
2603 if ((mp
->m_flag
& MNOFROM
) == 0 &&
2604 readline_restart(ibuf
, &linebuf
, &linesize
, 0) < 0)
2607 if (gethfield(ibuf
, &linebuf
, &linesize
, lc
, &colon
) <= 0)
2609 if (blankchar(*++colon
))
2611 in
.l
= strlen(in
.s
= colon
);
2612 mime_fromhdr(&in
, &out
, TD_ICONV
);
2614 if (sep
->ss_sexpr
== NULL
)
2615 rv
= (regexec(&sep
->ss_regex
, out
.s
, 0,NULL
, 0) != REG_NOMATCH
);
2618 rv
= substr(out
.s
, sep
->ss_sexpr
);
2625 if (linebuf
!= NULL
)
2631 FL
struct n_header_field
*
2632 n_customhdr_query(void){
2634 struct n_header_field
*rv
, **tail
, *hfp
;
2639 if((vp
= ok_vlook(customhdr
)) != NULL
){
2645 while((vp
= a_head_customhdr__sep(&buf
)) != NULL
){
2647 char const *nstart
, *cp
;
2649 for(nstart
= cp
= vp
;; ++cp
){
2650 if(fieldnamechar(*cp
))
2654 n_err(_("Invalid nameless *customhdr* entry\n"));
2657 }else if(*cp
!= ':' && !blankchar(*cp
)){
2659 n_err(_("Invalid *customhdr* entry: %s\n"), vp
);
2664 nl
= (ui32_t
)PTR2SIZE(cp
- nstart
);
2666 while(blankchar(*cp
))
2670 while(blankchar(*cp
))
2672 bl
= (ui32_t
)strlen(cp
) +1;
2675 hfp
= salloc(n_VSTRUCT_SIZEOF(struct n_header_field
, hf_dat
) +
2677 tail
= &hfp
->hf_next
;
2678 hfp
->hf_next
= NULL
;
2680 hfp
->hf_bl
= bl
- 1;
2681 memcpy(hfp
->hf_dat
, nstart
, nl
);
2682 hfp
->hf_dat
[nl
++] = '\0';
2683 memcpy(hfp
->hf_dat
+ nl
, cp
, bl
);