rfc822-parser.c revision 2de709376eddc50ec5fa470358bb57cf0a87bb1f
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen/* Copyright (C) 2005 Timo Sirainen */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen atext = ALPHA / DIGIT / ; Any character except controls,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen "!" / "#" / ; SP, and specials.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen "$" / "%" / ; Used for atoms
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen token := 1*<any (US-ASCII) CHAR except SPACE, CTLs,
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen or tspecials>
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen tspecials := "(" / ")" / "<" / ">" / "@" /
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen "," / ";" / ":" / "\" / <">
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen "/" / "[" / "]" / "?" / "="
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen So token is same as dot-atom, except stops also at '/', '?' and '='.
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen/* atext chars are marked with 1, alpha and digits with 2,
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen atext-but-mime-tspecials with 4 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0-15 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 16-31 */
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 4, /* 32-47 */
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 4, 0, 4, /* 48-63 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 64-79 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, /* 80-95 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 96-111 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, /* 112-127 */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen (atext_chars[(int)(unsigned char)(c)] != 0)
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen ((atext_chars[(int)(unsigned char)(c)] & 3) != 0)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenvoid rfc822_parser_init(struct rfc822_parser_context *ctx,
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_skip_comment(struct rfc822_parser_context *ctx)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen const unsigned char *start;
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if (--level == 0) {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen /* missing ')' */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_skip_lwsp(struct rfc822_parser_context *ctx)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if (*ctx->data == ' ' || *ctx->data == '\t' ||
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_parse_atom(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen const unsigned char *start;
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen atom = [CFWS] 1*atext [CFWS]
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen ; Any character except controls, SP, and specials.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_parse_dot_atom(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen const unsigned char *start;
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen dot-atom = [CFWS] dot-atom-text [CFWS]
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen dot-atom-text = 1*atext *("." 1*atext)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen ; Any character except controls, SP, and specials.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen For RFC-822 compatibility allow LWSP around '.'
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainenint rfc822_parse_mime_token(struct rfc822_parser_context *ctx, string_t *str)
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen const unsigned char *start;
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen if (IS_ATEXT_NON_TSPECIAL(*ctx->data) || *ctx->data == '.')
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_parse_quoted_string(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen const unsigned char *start;
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen /* missing '"' */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_parse_phrase(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if (!IS_ATEXT(*ctx->data) && *ctx->data != '"')
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenrfc822_parse_domain_literal(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen const unsigned char *start;
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen dcontent = dtext / quoted-pair
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen dtext = NO-WS-CTL / ; Non white space controls
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen %d33-90 / ; The rest of the US-ASCII
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen %d94-126 ; characters not including "[",
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen ; "]", or "\"
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen for (start = ctx->data; ctx->data != ctx->end; ctx->data++) {
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen /* missing ']' */
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenint rfc822_parse_domain(struct rfc822_parser_context *ctx, string_t *str)
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen domain = dot-atom / domain-literal / obs-domain
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen obs-domain = atom *("." atom)