Hey akbooer
I’ve been running openLuup for a looong time now and it’s that stable that I’ve not had to touch it for over a year (I use it mostly to integrate with my Visonic alarm).
I finally updated yesterday to take advantage of some of the newer features … in particular the smtp camera motion sensor triggers.
My cameras are attached to an NVR which sends the motion event emails from a single IP address to a single destination email address, but with different subjects to specify which channel triggered the event.
So, I very badly hacked smtp.lua and the I_openLuupCamera1.xml to allow registering of a handler for “subject fuzzy matching”.
For now I just used the “mac” attribute on the camera device to hold the partial subject (for example “NVR alarm:NVR1 channel:3”) and made I_openLuupCamera1.xml register the handler with that as the destination with:
--local ip = luup.attr_get ("ip", devNo)
--ip = (ip or ''): match "%d+%.%d+%.%d+%.%d+"
--if ip then
--smtp.register_handler (openLuupCamera, ip) -- receive mail from camera IP
--end
local mac = luup.attr_get ("mac", devNo) or -1
if mac ~= -1 && and mac ~= nil and mac ~= '' then
smtp.register_handler (openLuupCamera, mac)
end
Then I added a bodge to smtp.lua for “subject matching”:
[code]-- subject receipients
for i, destination in pairs (destinations) do
local message = state.data: decode () – decode MIME message
local headers = message.header
local newHeaders = {["content-type"] = "text/plain"} -- vanilla message
for a,b in pairs (headers) do
if type(a) == "string" and not a: match "^content" then
newHeaders[a] = b
end
end
newHeaders.subject = newHeaders.subject or "---no subject---"
if newHeaders.subject:sub(1, #destination.email) == destination.email then
deliver (destinations[destination.email])
end
end[/code]
It seems to work OK, maybe worth adding as an option to openLuup officially as I am sure it would be useful to others … but of course coded in a much better fashion than my mashed together attempt!