Coverage Report

Created: 2026-01-10 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-mail/rfc822-parser.h
Line
Count
Source
1
#ifndef RFC822_PARSER_H
2
#define RFC822_PARSER_H
3
4
#include "unichar.h"
5
6
/* This can be used as a common NUL replacement character */
7
53.8k
#define RFC822_NUL_REPLACEMENT_STR UNICODE_REPLACEMENT_CHAR_UTF8
8
9
struct rfc822_parser_context {
10
  const unsigned char *data, *end;
11
  string_t *last_comment;
12
13
  /* Replace NUL characters with this string */
14
  const char *nul_replacement_str;
15
};
16
17
#define IS_ATEXT(c) \
18
0
  (rfc822_atext_chars[(int)(unsigned char)(c)] != 0)
19
#define IS_ATEXT_NON_TSPECIAL(c) \
20
57.5M
  ((rfc822_atext_chars[(int)(unsigned char)(c)] & 3) != 0)
21
extern unsigned char rfc822_atext_chars[256];
22
23
/* Parse given data using RFC 822 token parser. */
24
void rfc822_parser_init(struct rfc822_parser_context *ctx,
25
      const unsigned char *data, size_t size,
26
      string_t *last_comment) ATTR_NULL(4);
27
static inline void rfc822_parser_deinit(struct rfc822_parser_context *ctx)
28
86.9k
{
29
  /* make sure the parsing didn't trigger a bug that caused reading
30
     past the end pointer. */
31
86.9k
  i_assert(ctx->data <= ctx->end);
32
  /* make sure the parser is no longer accessed */
33
86.9k
  ctx->data = ctx->end = NULL;
34
86.9k
}
message-decoder.c:rfc822_parser_deinit
Line
Count
Source
28
49.1k
{
29
  /* make sure the parsing didn't trigger a bug that caused reading
30
     past the end pointer. */
31
49.1k
  i_assert(ctx->data <= ctx->end);
32
  /* make sure the parser is no longer accessed */
33
49.1k
  ctx->data = ctx->end = NULL;
34
49.1k
}
message-parser.c:rfc822_parser_deinit
Line
Count
Source
28
37.7k
{
29
  /* make sure the parsing didn't trigger a bug that caused reading
30
     past the end pointer. */
31
37.7k
  i_assert(ctx->data <= ctx->end);
32
  /* make sure the parser is no longer accessed */
33
37.7k
  ctx->data = ctx->end = NULL;
34
37.7k
}
Unexecuted instantiation: rfc2231-parser.c:rfc822_parser_deinit
Unexecuted instantiation: rfc822-parser.c:rfc822_parser_deinit
35
36
/* The functions below return 1 = more data available, 0 = no more data
37
   available (but a value might have been returned now), -1 = invalid input.
38
39
   LWSP is automatically skipped after value, but not before it. So typically
40
   you begin with skipping LWSP and then start using the parse functions. */
41
42
/* Parse comment. Assumes parser's data points to '(' */
43
int rfc822_skip_comment(struct rfc822_parser_context *ctx);
44
/* Skip LWSP if there is any */
45
int ATTR_NOWARN_UNUSED_RESULT
46
rfc822_skip_lwsp(struct rfc822_parser_context *ctx);
47
/* Stop at next non-atext char */
48
int rfc822_parse_atom(struct rfc822_parser_context *ctx, string_t *str);
49
/* Like parse_atom() but don't stop at '.' */
50
int rfc822_parse_dot_atom(struct rfc822_parser_context *ctx, string_t *str);
51
/* Like parse_dot_atom() but stops for '/', '?' and '='.
52
   Also it doesn't allow LWSP around '.' chars. */
53
int rfc822_parse_mime_token(struct rfc822_parser_context *ctx, string_t *str);
54
/* "quoted string" */
55
int rfc822_parse_quoted_string(struct rfc822_parser_context *ctx,
56
             string_t *str);
57
/* atom or quoted-string */
58
int rfc822_parse_phrase(struct rfc822_parser_context *ctx, string_t *str);
59
/* dot-atom / domain-literal */
60
int rfc822_parse_domain(struct rfc822_parser_context *ctx, string_t *str);
61
62
/* Parse Content-Type header's type/subtype. */
63
int rfc822_parse_content_type(struct rfc822_parser_context *ctx, string_t *str);
64
/* For Content-Type style parameter parsing. Expect ";" key "=" value.
65
   value is unescaped if needed. The returned key is allocated from data
66
   stack. The value string is truncated for each call. Returns 1 = key/value
67
   set, 0 = no more data, -1 = invalid input. */
68
int rfc822_parse_content_param(struct rfc822_parser_context *ctx,
69
             const char **key_r, string_t *value);
70
71
/* Decode a punycode-encoded domain name and return the UTF8
72
   form in result. Returns 0 on success and -1 on failure. */
73
void rfc822_decode_punycode(const char *input, size_t len, string_t *result);
74
75
#endif