Add filters

This commit is contained in:
Athozus 2023-04-05 18:58:34 +02:00
parent 618b338295
commit 1a1989a01d
No known key found for this signature in database
GPG key ID: B50895022E8484BF
6 changed files with 58 additions and 15 deletions

View file

@ -98,6 +98,22 @@ function mail.sort_messages(unsorted_messages, sortfield, sortdirection)
return sorted_messages
end
function mail.filter_messages(unfiltered_messages, filter)
if not filter or filter == "" then
return unfiltered_messages
end
local filtered_messages = {}
for _, msg in ipairs(unfiltered_messages) do
if string.find(msg.from, filter) or string.find(msg.to, filter) or string.find(msg.subject, filter) then
table.insert(filtered_messages, msg)
end
end
return filtered_messages
end
-- marks a mail read by its id
function mail.mark_read(playername, msg_id)
local entry = mail.get_storage_entry(playername)