aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/smtp.lua6
-rw-r--r--test/testmesg.lua53
2 files changed, 56 insertions, 3 deletions
diff --git a/src/smtp.lua b/src/smtp.lua
index d256388..c823c97 100644
--- a/src/smtp.lua
+++ b/src/smtp.lua
@@ -87,7 +87,7 @@ end
87local function sendsource(mesgt) 87local function sendsource(mesgt)
88 -- set content-type if user didn't override 88 -- set content-type if user didn't override
89 if not mesgt.headers or not mesgt.headers["content-type"] then 89 if not mesgt.headers or not mesgt.headers["content-type"] then
90 coroutine.yield('content-type: text/plain; charset="iso-88591"\r\n') 90 coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n')
91 end 91 end
92 -- finish headers 92 -- finish headers
93 coroutine.yield("\r\n") 93 coroutine.yield("\r\n")
@@ -104,7 +104,7 @@ end
104local function sendstring(mesgt) 104local function sendstring(mesgt)
105 -- set content-type if user didn't override 105 -- set content-type if user didn't override
106 if not mesgt.headers or not mesgt.headers["content-type"] then 106 if not mesgt.headers or not mesgt.headers["content-type"] then
107 coroutine.yield('content-type: text/plain; charset="iso-88591"\r\n') 107 coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n')
108 end 108 end
109 -- finish headers 109 -- finish headers
110 coroutine.yield("\r\n") 110 coroutine.yield("\r\n")
@@ -135,7 +135,7 @@ local function adjustheaders(mesgt)
135 mesgt.headers = mesgt.headers or {} 135 mesgt.headers = mesgt.headers or {}
136 mesgt.headers["mime-version"] = "1.0" 136 mesgt.headers["mime-version"] = "1.0"
137 mesgt.headers["date"] = mesgt.headers["date"] or 137 mesgt.headers["date"] = mesgt.headers["date"] or
138 os.date("%a, %d %b %Y %H:%M:%S") .. (mesgt.zone or ZONE) 138 os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
139 mesgt.headers["x-mailer"] = mesgt.headers["x-mailer"] or socket.version 139 mesgt.headers["x-mailer"] = mesgt.headers["x-mailer"] or socket.version
140end 140end
141 141
diff --git a/test/testmesg.lua b/test/testmesg.lua
new file mode 100644
index 0000000..228bbe4
--- /dev/null
+++ b/test/testmesg.lua
@@ -0,0 +1,53 @@
1mesgt = {
2 headers = {
3 to = "D Burgess <db@werx4.com>",
4 subject = "Looking good! (please check headers)"
5 },
6 body = {
7 preamble = "Some attatched stuff",
8 [1] = {
9 body = "Testing stuffing.\r\n.\r\nGot you.\r\n.Hehehe.\r\n"
10 },
11 [2] = {
12 headers = {
13 ["content-type"] = 'application/octet-stream; name="luasocket"',
14 ["content-disposition"] = 'attachment; filename="luasocket"',
15 ["content-transfer-encoding"] = "BASE64"
16 },
17 body = ltn12.source.chain(
18 ltn12.source.file(io.open("luasocket", "rb")),
19 ltn12.filter.chain(
20 mime.encode("base64"),
21 mime.wrap()
22 )
23 )
24 },
25 [3] = {
26 headers = {
27 ["content-type"] = 'text/plain; name="testmesg.lua"',
28 ["content-disposition"] = 'attachment; filename="testmesg.lua"',
29 ["content-transfer-encoding"] = "QUOTED-PRINTABLE"
30 },
31 body = ltn12.source.chain(
32 ltn12.source.file(io.open("message.lua", "rb")),
33 ltn12.filter.chain(
34 mime.normalize(),
35 mime.encode("quoted-printable"),
36 mime.wrap("quoted-printable")
37 )
38 )
39 },
40 epilogue = "Done attaching stuff",
41 }
42}
43
44-- sink = ltn12.sink.file(io.stdout)
45-- source = ltn12.source.chain(socket.smtp.message(mesgt), socket.smtp.stuff())
46-- ltn12.pump(source, sink)
47
48print(socket.smtp.send {
49 rcpt = {"<db@werx4.com>", "<diego@cs.princeton.edu>"},
50 from = "<diego@cs.princeton.edu>",
51 source = socket.smtp.message(mesgt),
52 server = "smtp.princeton.edu"
53})