diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-23 11:33:18 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-23 14:45:27 +0100 |
commit | 6832271dbc2771c7e3b2512fef2dcc054ab55c49 (patch) | |
tree | 5e7c944fabf2bcb92f8be6aa5e70d8940ba05167 /src/ragel/smtp_addr_parser.rl | |
parent | d4c86a2cd8a4f326870079d1bcf1cc2b005deec4 (diff) | |
download | rspamd-6832271dbc2771c7e3b2512fef2dcc054ab55c49.tar.gz rspamd-6832271dbc2771c7e3b2512fef2dcc054ab55c49.zip |
[Feature] Add parsers for SMTP address in ragel
Diffstat (limited to 'src/ragel/smtp_addr_parser.rl')
-rw-r--r-- | src/ragel/smtp_addr_parser.rl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/ragel/smtp_addr_parser.rl b/src/ragel/smtp_addr_parser.rl new file mode 100644 index 000000000..5d08d7d4f --- /dev/null +++ b/src/ragel/smtp_addr_parser.rl @@ -0,0 +1,77 @@ +%%{ + + machine smtp_addr_parser; + + action User_start { + addr->user = p; + addr->addr = p; + } + + action User_end { + if (addr->user) { + addr->user_len = p - addr->user; + } + } + + action Domain_start { + addr->domain = p; + } + + action Domain_end { + if (addr->domain) { + addr->domain_len = p - addr->domain; + } + } + + action Domain_addr_start { + addr->domain = p; + addr->flags |= RSPAMD_EMAIL_ADDR_IP; + } + + action Domain_addr_end { + if (addr->domain) { + addr->domain_len = p - addr->domain; + } + } + + action Quoted_addr { + addr->flags |= RSPAMD_EMAIL_ADDR_QUOTED; + } + + action Empty_addr { + addr->flags |= RSPAMD_EMAIL_ADDR_EMPTY; + addr->addr = ""; + } + + action Valid_addr { + addr->flags |= RSPAMD_EMAIL_ADDR_VALID; + } + + action Angled_addr { + addr->flags |= RSPAMD_EMAIL_ADDR_BRACED; + } + + include smtp_address "smtp_address.rl"; + + main := SMTPAddr; +}%% + +%% write data; + +static int +rspamd_smtp_addr_parse (const char *data, size_t len, struct rspamd_email_address *addr) +{ + const char *p = data, *pe = data + len, *eof; + int cs; + + g_assert (addr != NULL); + memset (addr, 0, sizeof (*addr)); + addr->raw = data; + addr->raw_len = len; + eof = pe; + + %% write init; + %% write exec; + + return cs; +} |