diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2007-03-12 04:08:40 +0000 |
commit | be2e467929be9f27fbe92fe7b94783635c920c06 (patch) | |
tree | 94054e38f33178d805a6144d3bd9cb76da4a4c76 /src/smtp.lua | |
parent | 8bf9fb51dd09fb066483247fccbfc979acc84071 (diff) | |
download | luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.gz luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.bz2 luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.zip |
Couple bug fixes.
Diffstat (limited to 'src/smtp.lua')
-rw-r--r-- | src/smtp.lua | 24 |
1 files changed, 15 insertions, 9 deletions
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 |
123 | end | 123 | end |
124 | 124 | ||
125 | -- convert headers to lowercase | ||
126 | local 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 | ||
132 | end | ||
133 | |||
125 | --------------------------------------------------------------------------- | 134 | --------------------------------------------------------------------------- |
126 | -- Multipart message source | 135 | -- Multipart message source |
127 | ----------------------------------------------------------------------------- | 136 | ----------------------------------------------------------------------------- |
@@ -149,7 +158,7 @@ end | |||
149 | local function send_multipart(mesgt) | 158 | local 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 |
177 | local function send_source(mesgt) | 186 | local 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 |
193 | local function send_string(mesgt) | 202 | local 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 |
211 | local function adjust_headers(mesgt) | 220 | local 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 |
222 | end | 228 | end |
223 | 229 | ||
224 | function message(mesgt) | 230 | function 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() |