forked from mailru/tntlua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselist.lua
86 lines (73 loc) · 2.31 KB
/
selist.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function box.auto_increment_uniq(spaceno, uniq, ...)
local tuple = box.select(spaceno, 1, uniq)
if tuple then
local format = 'i'
if #tuple[0] == 8 then
format = 'l'
end
return box.replace(spaceno, box.unpack(format, tuple[0]), uniq, ...)
end
return box.auto_increment(spaceno, uniq, ...)
end
local function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
return t
end
local function find_second_level_domain(mask)
local splited = mysplit(mask, '@')
local email_domain_part = splited[#splited]
local domain_parts = mysplit(email_domain_part, '.')
if #domain_parts == 0 then
error('In mask ' .. mask .. ' no domain found')
end
if #domain_parts == 1 then
error('In mask ' .. mask .. ' only first level domain found')
end
return domain_parts[#domain_parts - 1] .. '.' .. domain_parts[#domain_parts]
end
function selist2_add_sender(mask, name_ru, name_en, cat)
return box.auto_increment_uniq(0, mask, name_ru, name_en, box.unpack('i', cat), find_second_level_domain(mask)):transform(5,1)
end
function get_sender_list_by_offset(offset, limit)
offset = box.unpack('i', offset)
limit = box.unpack('i', limit)
local ret = {}
local orig = {box.select_limit(0, 0, offset, limit)}
for _, tuple in pairs(orig) do
table.insert(ret, tuple:transform(5, 1))
end
return unpack(ret)
end
function get_sender_list_by_ids(...)
local ret = { }
for i, v in ipairs({...}) do
local tuples = {box.select(0, 0, box.unpack('i', v))}
for _, tuple in pairs(tuples) do
table.insert(ret, tuple:transform(5, 1))
end
end
return unpack(ret)
end
function selist2_search_by_mask(mask)
local ret = { }
local orig = {box.select(0, 1, mask)}
for _, tuple in pairs(orig) do
table.insert(ret, tuple:transform(5, 1))
end
return unpack(ret)
end
function selist2_search_by_domain(domain)
local ret = { }
local orig = {box.select(0, 2, domain)}
for _, tuple in pairs(orig) do
table.insert(ret, tuple:transform(5, 1))
end
return unpack(ret)
end