lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Jun 06, 2010 at 01:14:36PM -0300, Diego Nehab wrote:
> Are you experiencing performance issues with the normalization filter?
> Otherwise, why would you knowingly prefer to send messages that do not
> conform to the standards?

Not perforamance issue I am aware of. But it took me considerable time
and much headaches to figure out what was wrong. Now when I read my
first email again the problem seams really trivial and solution is
obvious: just conform to RFC. So your question is understandable.
Sorry for long reply :)

For one thing I do not know of any other MUA client on Linux that
require \r\n line endings. This is main reason why it did not come to
my mind that line ending is wrong. I do not consider it to be
unreasonable to expect the email with body as I used as example to be
sent -- that is take arbitrary string and use it as body of email
without first normalizing it. This is how all email client do that I
worked with (pine, elm, mutt, mail, kmail, ...) And we must realize
that we are talking to nonconforming SMTP servers. If I understand it
correctly SMTP servers should not recognize \n.\n sequence (instead
\r\n.\r\n) as end of DATA command -- or perhaps they are allowed to
recognize it. In both cases I think that luasocket should be able to
talk with such servers (I guess all servers are same in this).

It all boils down to this: all (many) of email client are happy to
stuff body with \n line ending AND _servers expect_ them to be stuffed
therefore luasocket should do it too.

Other thing that I found is that luasocket does not like to play
with luajit (or the other way round).
While learning about sources, filters and sinks I crafted this
stript stuff.lua:

smtp=require("socket.smtp")
ltn12 = require("ltn12")
mime = require("mime")

body_text = [[
Some dots here
...
..
.
..
...
No more dots
]]
bs = ltn12.source.string(body_text)
filter = ltn12.filter.chain(mime.normalize(), mime.stuff())
body = ltn12.source.chain(bs, filter)
f = io.open("text.stuff", "w")
ltn12.pump.all(
    body,
    ltn12.sink.file(f)
)

when run with luajit this script gives error:

$ luajit stuff.lua
luajit: /usr/share/lua/5.1/ltn12.lua:41: bad argument #1 to 'getn' (table expected, got nil)
stack traceback:
        [C]: in function 'getn'
        /usr/share/lua/5.1/ltn12.lua:41: in function 'chain'
        stuff.lua:15: in main chunk
        [C]: ?

LuaJIT ships with LUA_COMPAT_VARARG turned off by default so it does
not recognize implicit arg parameter, and luasocket uses it in some
places. Maybe those could be changed in future release of luasocket?

When script is run with plain lua the result is as expected:
line ends with \r\n

Actually at start I was running script with wine and luajit and later
plain lua crosscompiled with mingw on Debian box. So the script was
with \n line endings (both this example and example in previous post).

When run with:
$ wine lua stuff.lua
result is puzzling to me: lines ends with \r\r\n

Now I can not explain this behavior and am still looking who is guilty
party in this scenario and who need to be blamed (of course I do not
want to blame myself... hehehe... :)
I got expected results under wine only if I changed line:
f = io.open("text.stuff", "w")
to
f = io.open("text.stuff", "wb")
and this is puzzling to me because file in question is text not binary!


By the way you should change  example in docs for ltn12.sink.file form:

 ltn12.pump.all(
      ltn12.source.file(io.open("original.png")),
     ltn12.sink.file(io.open("copy.png"))
 )

to:

 ltn12.pump.all(
      ltn12.source.file(io.open("original.png")),
     ltn12.sink.file(io.open("copy.png", "w"))
 )


And I could use some more info than this:

   ltn12.sink.simplify(sink)
   Creates and returns a simple sink given a fancy sink.

What is fancy sink and what is simple sink?

Best regards
Martin