unsigned raw_len;
unsigned addr_len;
- unsigned user_len;
unsigned domain_len;
- unsigned name_len;
- int flags;
+ uint16_t user_len;
+ unsigned char flags;
};
struct rspamd_email_address * rspamd_email_address_from_smtp (const char *str, unsigned len);
void rspamd_email_address_free (struct rspamd_email_address *addr);
]]
- test("Parse addrs", function()
- local cases_valid = {
- {'<>', {addr = ''}},
- {'<a@example.com>', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'<a-b@example.com>', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}},
- {'<a-b@ex-ample.com>', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}},
- {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru',
- {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370',
- domain = 'example.220-volt.ru',
- addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}},
- {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}},
- {'a@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
- {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
- {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
- {'"<>"@example.com', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
- {'<"<>"@example.com>', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
- {'"\\""@example.com', {user = '"', domain = 'example.com', addr = '"@example.com'}},
- {'"\\"abc"@example.com', {user = '"abc', domain = 'example.com', addr = '"abc@example.com'}},
- {'<@domain1,@domain2,@domain3:abc@example.com>',
- {user = 'abc', domain = 'example.com', addr = 'abc@example.com'}},
+ local cases_valid = {
+ {'<>', {addr = ''}},
+ {'<a@example.com>', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
+ {'<a-b@example.com>', {user = 'a-b', domain = 'example.com', addr = 'a-b@example.com'}},
+ {'<a-b@ex-ample.com>', {user = 'a-b', domain = 'ex-ample.com', addr = 'a-b@ex-ample.com'}},
+ {'1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru',
+ {user = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370',
+ domain = 'example.220-volt.ru',
+ addr = '1367=dec2a6ce-81bd-4fa9-ad02-ec5956466c04=9=1655370@example.220-volt.ru'}},
+ {'notification+kjdm---m7wwd@facebookmail.com', {user = 'notification+kjdm---m7wwd'}},
+ {'a@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
+ {'a+b@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
+ {'"a"@example.com', {user = 'a', domain = 'example.com', addr = 'a@example.com'}},
+ {'"a+b"@example.com', {user = 'a+b', domain = 'example.com', addr = 'a+b@example.com'}},
+ {'"<>"@example.com', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
+ {'<"<>"@example.com>', {user = '<>', domain = 'example.com', addr = '<>@example.com'}},
+ {'"\\""@example.com', {user = '"', domain = 'example.com', addr = '"@example.com'}},
+ {'"\\"abc"@example.com', {user = '"abc', domain = 'example.com', addr = '"abc@example.com'}},
+ {'<@domain1,@domain2,@domain3:abc@example.com>',
+ {user = 'abc', domain = 'example.com', addr = 'abc@example.com'}},
+
+ }
- }
- each(function(case)
+ each(function(case)
+ test("Parse valid smtp addr: " .. case[1], function()
local st = ffi.C.rspamd_email_address_from_smtp(case[1], #case[1])
assert_not_nil(st, "should be able to parse " .. case[1])
end
end, case[2])
ffi.C.rspamd_email_address_free(st)
- end, cases_valid)
+ end)
+ end, cases_valid)
local cases_invalid = {
'a',
'<a@example.com',
'a@example.com>',
'<a@.example.com>',
- '<a@example.com.>',
'<a@example.com>>',
'<a@example.com><>',
}
- each(function(case)
+ each(function(case)
+ test("Parse invalid smtp addr: " .. case, function()
local st = ffi.C.rspamd_email_address_from_smtp(case, #case)
assert_nil(st, "should not be able to parse " .. case)
- end, cases_invalid)
- end)
+ end)
+ end, cases_invalid)
+
test("Speed test", function()
local case = '<@domain1,@domain2,@domain3:abc%d@example.com>'
local niter = 100000