Folks,
I am having problems with a 4 line LUA function. But only for a few (maybe one) user!
The argument to the function is an email address of the form xxx@yyy.zzz.com
Attached are extracts from some code in Vera Alerts:
function dump(o, levels)
local nlevels
if (levels) then
nlevels = levels - 1
end
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
local r
if (levels) then
if ((levels > 0) or (type(v) ~= "table")) then
r = dump(v, nlevels)
else
r = "*" .. type(v) .. "*"
end
else
r = dump(v, levels)
end
s = s .. '['..k..'] = ' .. r .. ','
end
return s .. '} '
else
return tostring(o)
end
end
local function FixupAddress(Rcp)
local Fixed = "<" .. Rcp .. ">"
return Fixed, '"' .. Rcp .. '" ' .. Fixed
end
--- Do not worry about the eto, or hdrt.from
--- See the results from the dump
local FixedToAddr, LongToAddr = FixupAddress(eto)
local FixedFromAddr, LongFromAddr = FixupAddress(hdrt.from)
luup.log(Dump({eto, FixedToAddr, LongToAddr, FixedFromAddr, LongFromAddr}))
Results of Dump are:
02/17/14 9:23:50.112 luup_log:52: { [1] = Alert@chelseagroup.com,[2] = ,[3] = "Alert@chelseagroup.com" ,[4] = ,[5] = "Vera@chelseagroup.com" ,} <0x2ae88000>
So you can see that eto was a string with a value of Alert@chelseagroup.com
But why are the FixedToAddr and FixedFromAddr empty strings ?
It works for me … but fails for another forum member!
For me I get:
02/15/14 7:58:07.436 luup_log:188: { [1] = Schaefer@RTS-Services.com,[2] = <Schaefer@RTS-Ser\
vices.com>,[3] = "Schaefer@RTS-Services.com" <Schaefer@RTS-Services.com>,[4] = <Vera@RTS-Services.com>,[5] = "Vera@RTS-Services.com\
" <Vera@RTS-Services.com>,} <0x2b01a000>
I added the value for eto:
local eto = "Alert@chelseagroup.com"
local FixedToAddr, LongToAddr = FixupAddress(eto)
and ran it in ZeroBrane Studio. I got:
FixedToAddr = “Alert@chelseagroup.com”
LongToAddr = “"Alert@chelseagroup.com" Alert@chelseagroup.com”
As you might expect.
Any chance that eto includes something other than the readable string?
Wait…
Change to:
luup.log(dump({eto, FixedToAddr, LongToAddr, FixedFromAddr, LongFromAddr}))
I don’t know where Dump() is but it isn’t in this code block.
I did provide the dump function.
It’s for debugging.
The actual failure in the code is consistent with the first string returned from FickupAddress as a blank string. But I can’t explain it.
But the code shown is [font=courier]dump()[/font], yet [font=courier]luup.log[/font] calls [font=courier]Dump()[/font]? (As @RexBeckett said.)
That was a typo … it was lower case dump … I actually have a wrapper to this … and wanted to simplify … The code in question is the FixupAddress function.
Note that in the bad example the first returned value is an empty string and the second one has a value of “Alert@chelseagroup.com” (Note the String has quotes in the string!, These two returned strings are email addresses that are needed for the various headers for the SMTP protocol.). I can’t even figure out how that is possible!
It’s almost like the first line’s concatenation failed. But without an error in the log.
local Fixed = "<" .. Rcp .. ">"
Seems pretty straightforward. Maybe you can put a log message in the FixupAddress function to see what’s happening after the concatenation. And maybe add another variable to see if that helps.
local function FixupAddress(Rcp)
local Fixed = "<" .. Rcp .. ">"
luup.log("Fixed = " .. Fixed)
local LongFixed = '"' .. Rcp .. '" ' .. Fixed
luup.log("LongFixed = " .. LongFixed)
return Fixed, LongFixed
end
Bruce
I can’t get it to fail in ZeroBrane so perhaps it’s something Vera is doing. Does this behave any differently?
local function FixupAddress(Rcp)
local Fixed = string.char(60) .. Rcp .. string.char(62)
return Fixed, '"' .. Rcp .. '" ' .. Fixed
end
I have to release and try … It does not fail for me.
So your hypothesis is that in some Locale the string constants are treated differently.
I can understand it failing if Rcp was null.
But than both strings should have a problem!.
My plugins are encrypted … so I know the code has not been edited/changed!
I will probably break this into two functions. It’s painful to do a release / MCV Audit/ test cycle.
I still have a few hairs left … but I believe this was a wild goose chase.
Since the outputs for my example came from a log file displayed in a browser … and I was looking for something that looked like AtSome@Email.com
I believe that some browsers see this as some type of XML tag and replace it with an empty string.
At least that’s the story I am going with
Otherwise I was thinking it was time to give up on programming.