fix http, updated ftp & smtp with similar create method call

This commit is contained in:
Thijs Schreijer 2015-03-13 18:02:18 +01:00
parent 01a2ee90a8
commit 9016e91238
3 changed files with 16 additions and 10 deletions

View file

@ -113,9 +113,10 @@ function metat.__index:send(mailt)
self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step)
end
function _M.open(server, port, create)
local tp = socket.try(tp.connect(server or _M.SERVER, port or _M.PORT,
_M.TIMEOUT, create))
function _M.open(mailt)
local c = function() return mailt:create() end -- wrap to do a method call
local tp = socket.try(tp.connect(mailt.server or _M.SERVER, mailt.port or _M.PORT,
_M.TIMEOUT, c))
local s = base.setmetatable({tp = tp}, metat)
-- make sure tp is closed if we get an exception
s.try = socket.newtry(function()
@ -245,7 +246,8 @@ end
-- High level SMTP API
-----------------------------------------------------------------------------
_M.send = socket.protect(function(mailt)
local s = _M.open(mailt.server, mailt.port, mailt.create)
mailt.create = mailt.create or socket.tcp
local s = _M.open(mailt)
local ext = s:greet(mailt.domain)
s:auth(mailt.user, mailt.password, ext)
s:send(mailt)