From be2e467929be9f27fbe92fe7b94783635c920c06 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Mon, 12 Mar 2007 04:08:40 +0000 Subject: Couple bug fixes. --- src/http.lua | 5 +++-- src/makefile | 7 ++++--- src/smtp.lua | 24 +++++++++++++++--------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/http.lua b/src/http.lua index 558f347..9d739a4 100644 --- a/src/http.lua +++ b/src/http.lua @@ -107,7 +107,7 @@ local metat = { __index = {} } function open(host, port, create) -- create socket with user connect function, or with default - local c = socket.try(create or socket.tcp)() + local c = socket.try((create or socket.tcp)()) local h = base.setmetatable({ c = c }, metat) -- create finalized try h.try = socket.newtry(function() h:close() end) @@ -228,7 +228,8 @@ local function adjustrequest(reqt) -- explicit components override url for i,v in base.pairs(reqt) do nreqt[i] = v end if nreqt.port == "" then nreqt.port = 80 end - socket.try(nreqt.host, "invalid host '" .. base.tostring(nreqt.host) .. "'") + socket.try(nreqt.host and nreqt.host ~= "", + "invalid host '" .. base.tostring(nreqt.host) .. "'") -- compute uri if user hasn't overriden nreqt.uri = reqt.uri or adjusturi(nreqt) -- ajust host and port if there is a proxy diff --git a/src/makefile b/src/makefile index a21a346..b614f77 100644 --- a/src/makefile +++ b/src/makefile @@ -11,8 +11,9 @@ include ../config # Modules belonging to socket-core # +#$(COMPAT)/compat-5.1.o \ + SOCKET_OBJS:= \ - $(COMPAT)/compat-5.1.o \ luasocket.o \ timeout.o \ buffer.o \ @@ -29,11 +30,11 @@ SOCKET_OBJS:= \ #------ # Modules belonging mime-core # +#$(COMPAT)/compat-5.1.o \ + MIME_OBJS:=\ - $(COMPAT)/compat-5.1.o \ mime.o - #------ # Modules belonging unix (local domain sockets) # diff --git a/src/smtp.lua b/src/smtp.lua index 2257a69..9a204d8 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -122,6 +122,15 @@ function open(server, port, create) return s end +-- convert headers to lowercase +local function lower_headers(headers) + local lower = {} + for i,v in base.pairs(headers or lower) do + lower[string.lower(i)] = v + end + return lower +end + --------------------------------------------------------------------------- -- Multipart message source ----------------------------------------------------------------------------- @@ -149,7 +158,7 @@ end local function send_multipart(mesgt) -- make sure we have our boundary and send headers local bd = newboundary() - local headers = mesgt.headers or {} + local headers = lower_headers(mesgt.headers or {}) headers['content-type'] = headers['content-type'] or 'multipart/mixed' headers['content-type'] = headers['content-type'] .. '; boundary="' .. bd .. '"' @@ -176,7 +185,7 @@ end -- yield message body from a source local function send_source(mesgt) -- make sure we have a content-type - local headers = mesgt.headers or {} + local headers = lower_headers(mesgt.headers or {}) headers['content-type'] = headers['content-type'] or 'text/plain; charset="iso-8859-1"' send_headers(headers) @@ -192,7 +201,7 @@ end -- yield message body from a string local function send_string(mesgt) -- make sure we have a content-type - local headers = mesgt.headers or {} + local headers = lower_headers(mesgt.headers or {}) headers['content-type'] = headers['content-type'] or 'text/plain; charset="iso-8859-1"' send_headers(headers) @@ -209,20 +218,17 @@ end -- set defaul headers local function adjust_headers(mesgt) - local lower = {} - for i,v in base.pairs(mesgt.headers or lower) do - lower[string.lower(i)] = v - end + local lower = lower_headers(mesgt.headers) lower["date"] = lower["date"] or os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) lower["x-mailer"] = lower["x-mailer"] or socket._VERSION -- this can't be overriden lower["mime-version"] = "1.0" - mesgt.headers = lower + return lower end function message(mesgt) - adjust_headers(mesgt) + mesgt.headers = adjust_headers(mesgt) -- create and return message source local co = coroutine.create(function() send_message(mesgt) end) return function() -- cgit v1.2.3-55-g6feb