diff options
Diffstat (limited to 'vmail-model.lua')
-rw-r--r-- | vmail-model.lua | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/vmail-model.lua b/vmail-model.lua index d129fdf..37b0c2d 100644 --- a/vmail-model.lua +++ b/vmail-model.lua @@ -456,27 +456,35 @@ mymodule.list_messages = function(username) return cfe({ type="structure", value=retval, label="Messages", errtxt=errtxt }) end -mymodule.get_message = function(message, username) - local retval = cfe({ type="raw", label="error", option="audio/x-wav" }) +mymodule.get_download_message = function(self, clientdata) + local result = {} + result.message = cfe({ label="Message" }) + result.username = cfe({ label="User Name" }) + return cfe({ type="group", value=result, label="Download Message" }) +end + +mymodule.download_message = function(self, downloadrequest) + local file = cfe({ type="raw", label="error", option="audio/x-wav" }) local res, err = pcall(function() local connected = vmaildb.databaseconnect() local sql = "SELECT username, file_path FROM voicemail_msgs" - sql = sql .. generatewhereclause(username, message) + sql = sql .. generatewhereclause(downloadrequest.value.username.value, downloadrequest.value.message.value) local tmp = vmaildb.getselectresponse(sql) if connected then databasedisconnect() end if #tmp == 0 then - retval.errtxt = "Invalid message" + downloadrequest.errtxt = "Invalid message" else - retval.label = posix.basename(tmp[1].file_path) - retval.value = fs.read_file(tmp[1].file_path) + file.label = posix.basename(tmp[1].file_path) + file.value = fs.read_file(tmp[1].file_path) -- Mark the message as read - voicemail_read(tmp[1].username, config.domain, message) + voicemail_read(tmp[1].username, config.domain, downloadrequest.value.message.value) end + downloadrequest.value.file = file end) if not res and err then - retval.errtxt = err + downloadrequest.errtxt = err end - return retval + return downloadrequest end mymodule.get_delete_message = function(self, clientdata) |