Coverage Report

Created: 2026-06-15 06:36

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