From 42db40b7a72a65226393a99d118c39fa78cfb570 Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Mon, 5 Jun 2023 10:25:34 +0200 Subject: [PATCH] partial fox for #97 (#98) * partial fox for #97 * Fix #97 --------- Co-authored-by: BuckarooBanzay Co-authored-by: Athozus --- storage.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/storage.lua b/storage.lua index 576064a..a3b14b5 100644 --- a/storage.lua +++ b/storage.lua @@ -114,24 +114,30 @@ function mail.delete_mail(playername, msg_ids) if type(msg_ids) ~= "table" then -- if this is not a table msg_ids = { msg_ids } end - for i = #entry.inbox, 1, -1 do - for _, deleted_msg in ipairs(msg_ids) do - if entry.inbox[i].id == deleted_msg then - table.remove(entry.inbox, i) + if #entry.inbox > 0 then + for i = #entry.inbox, 1, -1 do + for _, deleted_msg in ipairs(msg_ids) do + if entry.inbox[i].id == deleted_msg then + table.remove(entry.inbox, i) + end end end end - for i = #entry.outbox, 1, -1 do - for _, deleted_msg in ipairs(msg_ids) do - if entry.outbox[i].id == deleted_msg then - table.remove(entry.outbox, i) + if #entry.outbox > 0 then + for i = #entry.outbox, 1, -1 do + for _, deleted_msg in ipairs(msg_ids) do + if entry.outbox[i].id == deleted_msg then + table.remove(entry.outbox, i) + end end end end - for i = #entry.drafts, 1, -1 do - for _, deleted_msg in ipairs(msg_ids) do - if entry.drafts[i].id == deleted_msg then - table.remove(entry.drafts, i) + if #entry.drafts > 0 then + for i = #entry.drafts, 1, -1 do + for _, deleted_msg in ipairs(msg_ids) do + if entry.drafts[i].id == deleted_msg then + table.remove(entry.drafts, i) + end end end end