Skip to content

Commit

Permalink
lib-smtp: Fix UTF-8 local-parts
Browse files Browse the repository at this point in the history
  • Loading branch information
arnt authored and sirainen committed Oct 28, 2024
1 parent 1ccd5b5 commit d88bac2
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/lib-smtp/smtp-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@
(1<<9) => %x22
(1<<6) => %x2b
(1<<7) => %x3d
RFC 6532 says:
VCHAR =/ UTF8-non-ascii
ctext =/ UTF8-non-ascii
atext =/ UTF8-non-ascii
qtext =/ UTF8-non-ascii
text =/ UTF8-non-ascii
; note that this upgrades the body to UTF-8
dtext =/ UTF8-non-ascii
At a byte level, this means that %x80-fd include 1<<1 (atext),
(1<<1)|(1<<2)|(1<<3)|(1<<4) (qtext).
*/

/* xtext */
Expand Down Expand Up @@ -95,6 +114,24 @@ const uint16_t smtp_char_lookup[256] = {
0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, // 70
0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x100, // 78

#ifdef EXPERIMENTAL_MAIL_UTF8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // 80
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // 88
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // 90
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // 98
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // a0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // a8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // b0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // b8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // c0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // c8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // d0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // d8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // e0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // e8
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, // f0
0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x01e, 0x000, 0x000, // f8
#else
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // 80
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // 88
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // 90
Expand All @@ -111,6 +148,7 @@ const uint16_t smtp_char_lookup[256] = {
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // e8
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // f0
0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, // f8
#endif
};

/*
Expand Down Expand Up @@ -202,6 +240,9 @@ int smtp_parser_parse_domain(struct smtp_parser *parser,
/* Ldh-str (nope) */
while (parser->cur < parser->end) {
if (!i_isalnum(*parser->cur) && *parser->cur != '-' &&
#ifdef EXPERIMENTAL_MAIL_UTF8
(*parser->cur < 0x80 || *parser->cur >= 0xfe) &&
#endif
*parser->cur != '_')
break;

Expand Down

0 comments on commit d88bac2

Please sign in to comment.