try this code you have to queue them all up first. Then when you process the code it fires the first delete event. The event will keep triggering mailOpen.ProcessDelQueue() until it runs out of entries in the table.
Lua Code:
function mailOpen.QueueDelete(mailId,forceDelete)
table.insert(delQueue,{['mailId']=mailId,['forceDelete']=forceDelete})
end
function mailOpen.ProcessDelQueue()
if delQueue[1].mailId ~= nil then
--d(delQueue[1].mailId)
DeleteMail(delQueue[1].mailId,delQueue[1].forceDelete)
table.remove(delQueue,1)
end
end
function mailOpen.Test()
for k, v in pairs(mailOpen.mailInfo) do
if v.unread then RequestReadMail(v.mailId) end
mailOpen.QueueDelete(v.mailId,false)
end
mailOpen.ProcessDelQueue()
end
--EVENT_MAIL_REMOVED
function mailOpen.MailRemoved(eventCode, mailId)
mailOpen.ProcessDelQueue()
d('mail deleted')
end