7 /* message header classification
9 /* #include <is_header.h>
11 /* ssize_t is_header(string)
12 /* const char *string;
14 /* ssize_t is_header_buf(string, len)
15 /* const char *string;
18 /* is_header() examines the given string and returns non-zero (true)
19 /* when it begins with a mail header name + optional space + colon.
20 /* The result is the length of the mail header name.
22 /* is_header_buf() is a more elaborate interface for use with strings
23 /* that may not be null terminated.
25 /* RFC 822 (ARPA Internet Text Messages)
29 /* The Secure Mailer license must be distributed with this software.
32 /* IBM T.J. Watson Research
34 /* Yorktown Heights, NY 10598, USA
44 #include "is_header.h"
46 /* is_header_buf - determine if this can be a header line */
48 ssize_t
is_header_buf(const char *str
, ssize_t str_len
)
50 const unsigned char *cp
;
57 #define IN_CHAR_SPACE 2
58 #define CU_CHAR_PTR(x) ((const unsigned char *) (x))
61 * XXX RFC 2822 Section 4.5, Obsolete header fields: whitespace may
62 * appear between header label and ":" (see: RFC 822, Section 3.4.2.).
64 * XXX Don't run off the end in case some non-standard iscntrl()
65 * implementation considers null a non-control character...
67 for (len
= 0, state
= INIT
, cp
= CU_CHAR_PTR(str
); /* see below */; cp
++) {
68 if (str_len
!= IS_HEADER_NULL_TERMINATED
&& str_len
-- <= 0)
72 if (c
== 0 || !ISASCII(c
) || ISCNTRL(c
))
76 if (state
== IN_CHAR
) {
84 state
= IN_CHAR_SPACE
;
85 if (state
== IN_CHAR_SPACE
)
89 return ((state
== IN_CHAR
|| state
== IN_CHAR_SPACE
) ? len
: 0);
92 /* Redundant return for future proofing. */