aboutsummaryrefslogtreecommitdiff
path: root/src/smtp.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2005-08-23 05:53:14 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2005-08-23 05:53:14 +0000
commit773e35ced30fa2c03ddb2a332bf8a9aebb56aa44 (patch)
tree03e8e9a4bd64b9424006315c8e720c3f2841a751 /src/smtp.lua
parent5e8ae76248ed31496dc6fef7855498a0479159ed (diff)
downloadluasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.tar.gz
luasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.tar.bz2
luasocket-773e35ced30fa2c03ddb2a332bf8a9aebb56aa44.zip
Compiled on Windows. Fixed a bunch of stuff. Almost ready to release.
Implemented a nice dispatcher! Non-blocking check-links and forward server use the dispatcher.
Diffstat (limited to 'src/smtp.lua')
-rw-r--r--src/smtp.lua49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/smtp.lua b/src/smtp.lua
index 46df1ab..5c485c2 100644
--- a/src/smtp.lua
+++ b/src/smtp.lua
@@ -137,12 +137,24 @@ end
137-- send_message forward declaration 137-- send_message forward declaration
138local send_message 138local send_message
139 139
140-- yield the headers all at once, it's faster
141local function send_headers(headers)
142 local h = "\r\n"
143 for i,v in base.pairs(headers) do
144 h = i .. ': ' .. v .. "\r\n" .. h
145 end
146 coroutine.yield(h)
147end
148
140-- yield multipart message body from a multipart message table 149-- yield multipart message body from a multipart message table
141local function send_multipart(mesgt) 150local function send_multipart(mesgt)
151 -- make sure we have our boundary and send headers
142 local bd = newboundary() 152 local bd = newboundary()
143 -- define boundary and finish headers 153 local headers = mesgt.headers or {}
144 coroutine.yield('content-type: multipart/mixed; boundary="' .. 154 headers['content-type'] = headers['content-type'] or 'multipart/mixed'
145 bd .. '"\r\n\r\n') 155 headers['content-type'] = headers['content-type'] ..
156 '; boundary="' .. bd .. '"'
157 send_headers(headers)
146 -- send preamble 158 -- send preamble
147 if mesgt.body.preamble then 159 if mesgt.body.preamble then
148 coroutine.yield(mesgt.body.preamble) 160 coroutine.yield(mesgt.body.preamble)
@@ -164,11 +176,11 @@ end
164 176
165-- yield message body from a source 177-- yield message body from a source
166local function send_source(mesgt) 178local function send_source(mesgt)
167 -- set content-type if user didn't override 179 -- make sure we have a content-type
168 if not mesgt.headers or not mesgt.headers["content-type"] then 180 local headers = mesgt.headers or {}
169 coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') 181 headers['content-type'] = headers['content-type'] or
170 else coroutine.yield("\r\n") end 182 'text/plain; charset="iso-8859-1"'
171 -- finish headers 183 send_headers(headers)
172 -- send body from source 184 -- send body from source
173 while true do 185 while true do
174 local chunk, err = mesgt.body() 186 local chunk, err = mesgt.body()
@@ -180,28 +192,17 @@ end
180 192
181-- yield message body from a string 193-- yield message body from a string
182local function send_string(mesgt) 194local function send_string(mesgt)
183 -- set content-type if user didn't override 195 -- make sure we have a content-type
184 if not mesgt.headers or not mesgt.headers["content-type"] then 196 local headers = mesgt.headers or {}
185 coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') 197 headers['content-type'] = headers['content-type'] or
186 else coroutine.yield("\r\n") end 198 'text/plain; charset="iso-8859-1"'
199 send_headers(headers)
187 -- send body from string 200 -- send body from string
188 coroutine.yield(mesgt.body) 201 coroutine.yield(mesgt.body)
189end 202end
190 203
191-- yield the headers all at once
192local function send_headers(mesgt)
193 if mesgt.headers then
194 local h = ""
195 for i,v in base.pairs(mesgt.headers) do
196 h = i .. ': ' .. v .. "\r\n" .. h
197 end
198 coroutine.yield(h)
199 end
200end
201
202-- message source 204-- message source
203function send_message(mesgt) 205function send_message(mesgt)
204 send_headers(mesgt)
205 if base.type(mesgt.body) == "table" then send_multipart(mesgt) 206 if base.type(mesgt.body) == "table" then send_multipart(mesgt)
206 elseif base.type(mesgt.body) == "function" then send_source(mesgt) 207 elseif base.type(mesgt.body) == "function" then send_source(mesgt)
207 else send_string(mesgt) end 208 else send_string(mesgt) end