@ -5,7 +5,7 @@ context("SMTP address check functions", function()
local ffi = require ( " ffi " )
local util = require ( " rspamd_util " )
local fun = require " fun "
ffi.cdef [ [
ffi.cdef [ [
struct rspamd_email_address {
const char * raw ;
const char * addr ;
@ -24,29 +24,30 @@ context("SMTP address check functions", 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 ' } } ,
{ ' <> ' , { 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 ' } } ,
-- SMTP UTF8
{ ' ñ@example.com ' , { user = ' ñ ' , domain = ' example.com ' } }
}
fun.each ( function ( case )
test ( " Parse valid smtp addr: " .. case [ 1 ] , function ( )
local st = ffi.C . rspamd_email_address_from_smtp ( case [ 1 ] , # case [ 1 ] )
@ -69,17 +70,17 @@ context("SMTP address check functions", function()
end )
end , cases_valid )
local cases_invalid = {
' a ' ,
' a"b"@example.com ' ,
' a"@example.com ' ,
' "a@example.com ' ,
' <a@example.com ' ,
' a@example.com> ' ,
' <a@.example.com> ' ,
' <a@example.com>> ' ,
' <a@example.com><> ' ,
}
local cases_invalid = {
' a ' ,
' a"b"@example.com ' ,
' a"@example.com ' ,
' "a@example.com ' ,
' <a@example.com ' ,
' a@example.com> ' ,
' <a@.example.com> ' ,
' <a@example.com>> ' ,
' <a@example.com><> ' ,
}
fun.each ( function ( case )
test ( " Parse invalid smtp addr: " .. case , function ( )
@ -95,7 +96,7 @@ context("SMTP address check functions", function()
local niter = 100000
local total = 0
for i = 1 , niter do
for i = 1 , niter do
local ncase = string.format ( case , i )
local t1 = util.get_ticks ( )
local st = ffi.C . rspamd_email_address_from_smtp ( ncase , # ncase )