aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.lua5
-rw-r--r--src/makefile7
-rw-r--r--src/smtp.lua24
3 files changed, 22 insertions, 14 deletions
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 = {} }
107 107
108function open(host, port, create) 108function open(host, port, create)
109 -- create socket with user connect function, or with default 109 -- create socket with user connect function, or with default
110 local c = socket.try(create or socket.tcp)() 110 local c = socket.try((create or socket.tcp)())
111 local h = base.setmetatable({ c = c }, metat) 111 local h = base.setmetatable({ c = c }, metat)
112 -- create finalized try 112 -- create finalized try
113 h.try = socket.newtry(function() h:close() end) 113 h.try = socket.newtry(function() h:close() end)
@@ -228,7 +228,8 @@ local function adjustrequest(reqt)
228 -- explicit components override url 228 -- explicit components override url
229 for i,v in base.pairs(reqt) do nreqt[i] = v end 229 for i,v in base.pairs(reqt) do nreqt[i] = v end
230 if nreqt.port == "" then nreqt.port = 80 end 230 if nreqt.port == "" then nreqt.port = 80 end
231 socket.try(nreqt.host, "invalid host '" .. base.tostring(nreqt.host) .. "'") 231 socket.try(nreqt.host and nreqt.host ~= "",
232 "invalid host '" .. base.tostring(nreqt.host) .. "'")
232 -- compute uri if user hasn't overriden 233 -- compute uri if user hasn't overriden
233 nreqt.uri = reqt.uri or adjusturi(nreqt) 234 nreqt.uri = reqt.uri or adjusturi(nreqt)
234 -- ajust host and port if there is a proxy 235 -- 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
11# Modules belonging to socket-core 11# Modules belonging to socket-core
12# 12#
13 13
14#$(COMPAT)/compat-5.1.o \
15
14SOCKET_OBJS:= \ 16SOCKET_OBJS:= \
15 $(COMPAT)/compat-5.1.o \
16 luasocket.o \ 17 luasocket.o \
17 timeout.o \ 18 timeout.o \
18 buffer.o \ 19 buffer.o \
@@ -29,11 +30,11 @@ SOCKET_OBJS:= \
29#------ 30#------
30# Modules belonging mime-core 31# Modules belonging mime-core
31# 32#
33#$(COMPAT)/compat-5.1.o \
34
32MIME_OBJS:=\ 35MIME_OBJS:=\
33 $(COMPAT)/compat-5.1.o \
34 mime.o 36 mime.o
35 37
36
37#------ 38#------
38# Modules belonging unix (local domain sockets) 39# Modules belonging unix (local domain sockets)
39# 40#
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)
122 return s 122 return s
123end 123end
124 124
125-- convert headers to lowercase
126local function lower_headers(headers)
127 local lower = {}
128 for i,v in base.pairs(headers or lower) do
129 lower[string.lower(i)] = v
130 end
131 return lower
132end
133
125--------------------------------------------------------------------------- 134---------------------------------------------------------------------------
126-- Multipart message source 135-- Multipart message source
127----------------------------------------------------------------------------- 136-----------------------------------------------------------------------------
@@ -149,7 +158,7 @@ end
149local function send_multipart(mesgt) 158local function send_multipart(mesgt)
150 -- make sure we have our boundary and send headers 159 -- make sure we have our boundary and send headers
151 local bd = newboundary() 160 local bd = newboundary()
152 local headers = mesgt.headers or {} 161 local headers = lower_headers(mesgt.headers or {})
153 headers['content-type'] = headers['content-type'] or 'multipart/mixed' 162 headers['content-type'] = headers['content-type'] or 'multipart/mixed'
154 headers['content-type'] = headers['content-type'] .. 163 headers['content-type'] = headers['content-type'] ..
155 '; boundary="' .. bd .. '"' 164 '; boundary="' .. bd .. '"'
@@ -176,7 +185,7 @@ end
176-- yield message body from a source 185-- yield message body from a source
177local function send_source(mesgt) 186local function send_source(mesgt)
178 -- make sure we have a content-type 187 -- make sure we have a content-type
179 local headers = mesgt.headers or {} 188 local headers = lower_headers(mesgt.headers or {})
180 headers['content-type'] = headers['content-type'] or 189 headers['content-type'] = headers['content-type'] or
181 'text/plain; charset="iso-8859-1"' 190 'text/plain; charset="iso-8859-1"'
182 send_headers(headers) 191 send_headers(headers)
@@ -192,7 +201,7 @@ end
192-- yield message body from a string 201-- yield message body from a string
193local function send_string(mesgt) 202local function send_string(mesgt)
194 -- make sure we have a content-type 203 -- make sure we have a content-type
195 local headers = mesgt.headers or {} 204 local headers = lower_headers(mesgt.headers or {})
196 headers['content-type'] = headers['content-type'] or 205 headers['content-type'] = headers['content-type'] or
197 'text/plain; charset="iso-8859-1"' 206 'text/plain; charset="iso-8859-1"'
198 send_headers(headers) 207 send_headers(headers)
@@ -209,20 +218,17 @@ end
209 218
210-- set defaul headers 219-- set defaul headers
211local function adjust_headers(mesgt) 220local function adjust_headers(mesgt)
212 local lower = {} 221 local lower = lower_headers(mesgt.headers)
213 for i,v in base.pairs(mesgt.headers or lower) do
214 lower[string.lower(i)] = v
215 end
216 lower["date"] = lower["date"] or 222 lower["date"] = lower["date"] or
217 os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) 223 os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
218 lower["x-mailer"] = lower["x-mailer"] or socket._VERSION 224 lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
219 -- this can't be overriden 225 -- this can't be overriden
220 lower["mime-version"] = "1.0" 226 lower["mime-version"] = "1.0"
221 mesgt.headers = lower 227 return lower
222end 228end
223 229
224function message(mesgt) 230function message(mesgt)
225 adjust_headers(mesgt) 231 mesgt.headers = adjust_headers(mesgt)
226 -- create and return message source 232 -- create and return message source
227 local co = coroutine.create(function() send_message(mesgt) end) 233 local co = coroutine.create(function() send_message(mesgt) end)
228 return function() 234 return function()