summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vmail-model.lua27
1 files changed, 22 insertions, 5 deletions
diff --git a/vmail-model.lua b/vmail-model.lua
index d9fd31c..4b1b885 100644
--- a/vmail-model.lua
+++ b/vmail-model.lua
@@ -12,7 +12,6 @@ socket = require("socket")
-- Set variables
local configfile = "/etc/freeswitchvmail.conf"
-local recording_path = "/var/lib/freeswitch/voicemail/"
local db_path = "/var/lib/freeswitch/db/"
local configcontent = fs.read_file(configfile) or ""
local config = format.parse_ini_file(configcontent, "") or {}
@@ -372,12 +371,32 @@ local delete_user = function(username)
if #users == 0 then
return false, "User does not exist"
else
+ local recording_path
+
-- Delete all of the user's voicemails
local messages = mymodule.list_messages(username)
- if #messages.value then
+ if #messages.value > 0 then
+ recording_path = posix.dirname(messages.value[1].file_path)
+ local uuids = {}
for i,m in ipairs(messages.value) do
- delete_message(m.uuid)
+ uuids[#uuids+1] = m.uuid
end
+ delete_message(uuids)
+ end
+ -- Remove the greetings
+ if not recording_path then
+ local sql = "SELECT * FROM voicemail_prefs"..generatewhereclause(username)
+ local prefs = vmaildb.getselectresponse(sql)
+ if prefs and prefs[1] then
+ if prefs[1].greeting_path then
+ recording_path = posix.dirname(prefs[1].greeting_path)
+ elseif prefs[1].name_path then
+ recording_path = posix.dirname(prefs[1].name_path)
+ end
+ end
+ end
+ if recording_path then
+ fs.remove_directory(recording_path)
end
-- Remove the user parameters
local sql = "DELETE FROM voicemail_values " .. generatewhereclause(nil, nil, nil, users[1].uid)
@@ -389,8 +408,6 @@ local delete_user = function(username)
sql = "DELETE FROM voicemail_users " .. generatewhereclause(nil, nil, nil, users[1].uid)
vmaildb.runsqlcommand(sql)
result = "Voicemail User Deleted"
- -- Remove the greetings
- fs.remove_directory(recording_path..(users[1].domain or config.domain).."/"..username)
end
return true
end