11.09.2015, 06:10
Here's a partially implemented example, you can extend it
First you have to install Lua on your device. Standard Lua version 5.1 or higher will work.
In smsd.conf you have to add this line in general config before [GSM1]:
Then you have to create /var/spool/sms/handler.lua file with the code below and make it executable (chmod 0755)
First you have to install Lua on your device. Standard Lua version 5.1 or higher will work.
In smsd.conf you have to add this line in general config before [GSM1]:
Code:
eventhandler = /var/spool/sms/handler.lua
Then you have to create /var/spool/sms/handler.lua file with the code below and make it executable (chmod 0755)
Code:
#!/usr/bin/lua
function parseheader(line, message)
local pos, data, header
pos = line:find(':')
if not pos then
return
end
header = line:sub(1, pos - 1)
data = line:sub(pos + 2)
if header == 'From' then
message.from = data
elseif header == 'Length' then
message.body = {}
end
end
function parse(filename)
local file, cmd, proc, body, message
-- check that file exists
file = io.open(filename)
if not file then
print('cannot open', filename)
return
end
file:close()
-- file can contain null bytes, so normal read might fail
cmd = string.format('cat %s | tr -d \\\\0', filename)
proc = io.popen(cmd)
message = {}
for line in proc:lines() do
if message.body then
if #line >= 2 then
table.insert(message.body, line)
end
else
parseheader(line, message)
end
end
proc:close()
if message.body then
message.body = table.concat(message.body)
end
print('From', message.from)
print('Body', message.body)
end
status, filename = arg[ 1 ], arg[ 2 ]
-- validate command line arguments
if type(status) == 'string' or type(filename) == 'string' then
if status == 'RECEIVED' then
parse(filename)
else
print('Wrong status', status)
end
end