aboutsummaryrefslogtreecommitdiff
path: root/test/testmesg.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/testmesg.lua')
-rw-r--r--test/testmesg.lua95
1 files changed, 50 insertions, 45 deletions
diff --git a/test/testmesg.lua b/test/testmesg.lua
index 15b0eb7..449f4c2 100644
--- a/test/testmesg.lua
+++ b/test/testmesg.lua
@@ -1,52 +1,57 @@
1require("smtp") 1-- load the smtp support and its friends
2require("mime") 2local smtp = require("smtp")
3local mime = require("mime")
4local ltn12 = require("ltn12")
3 5
4mesgt = { 6-- creates a source to send a message with two parts. The first part is
5 headers = { 7-- plain text, the second part is a PNG image, encoded as base64.
6 to = "D Burgess <db@werx4.com>", 8source = smtp.message{
7 subject = "Looking good! (please check headers)" 9 headers = {
10 -- Remember that headers are *ignored* by smtp.send.
11 from = "Sicrano <sicrano@tecgraf.puc-rio.br>",
12 to = "Fulano <fulano@tecgraf.puc-rio.br>",
13 subject = "Here is a message with attachments"
14 },
15 body = {
16 preamble = "If your client doesn't understand attachments, \r\n" ..
17 "it will still display the preamble and the epilogue.\r\n",
18 "Preamble might show up even in a MIME enabled client.",
19 -- first part: No headers means plain text, us-ascii.
20 -- The mime.eol low-level filter normalizes end-of-line markers.
21 [1] = {
22 body = mime.eol(0, [[
23 Lines in a message body should always end with CRLF.
24 The smtp module will *NOT* perform translation. It will
25 perform necessary stuffing, though.
26 ]])
8 }, 27 },
9 body = { 28 -- second part: Headers describe content the to be an image,
10 preamble = "Some attatched stuff", 29 -- sent under the base64 transfer content encoding.
11 [1] = { 30 -- Notice that nothing happens until the message is sent. Small
12 body = mime.eol(0, "Testing stuffing.\n.\nGot you.\n.Hehehe.\n") 31 -- chunks are loaded into memory and translation happens on the fly.
13 }, 32 [2] = {
14 [2] = { 33 headers = {
15 headers = { 34 ["content-type"] = 'image/png; name="image.png"',
16 ["content-type"] = 'application/octet-stream; name="testmesg.lua"', 35 ["content-disposition"] = 'attachment; filename="image.png"',
17 ["content-disposition"] = 'attachment; filename="testmesg.lua"', 36 ["content-description"] = 'a beautiful image',
18 ["content-transfer-encoding"] = "BASE64" 37 ["content-transfer-encoding"] = "BASE64"
19 }, 38 },
20 body = ltn12.source.chain( 39 body = ltn12.source.chain(
21 ltn12.source.file(io.open("testmesg.lua", "rb")), 40 ltn12.source.file(io.open("image.png", "rb")),
22 ltn12.filter.chain( 41 ltn12.filter.chain(
23 mime.encode("base64"), 42 mime.encode("base64"),
24 mime.wrap() 43 mime.wrap()
25 ) 44 )
26 ) 45 )
27 }, 46 },
28 [3] = { 47 epilogue = "This might also show up, but after the attachments"
29 headers = { 48 }
30 ["content-type"] = 'text/plain; name="testmesg.lua"',
31 ["content-disposition"] = 'attachment; filename="testmesg.lua"',
32 ["content-transfer-encoding"] = "QUOTED-PRINTABLE"
33 },
34 body = ltn12.source.chain(
35 ltn12.source.file(io.open("testmesg.lua", "rb")),
36 ltn12.filter.chain(
37 mime.normalize(),
38 mime.encode("quoted-printable"),
39 mime.wrap("quoted-printable")
40 )
41 )
42 },
43 epilogue = "Done attaching stuff",
44 }
45} 49}
46 50
47print(socket.smtp.send { 51-- finally send it
52r, e = smtp.send{
48 rcpt = "<diego@cs.princeton.edu>", 53 rcpt = "<diego@cs.princeton.edu>",
49 from = "<diego@cs.princeton.edu>", 54 from = "<diego@cs.princeton.edu>",
50 source = socket.smtp.message(mesgt), 55 source = source,
51 server = "mail.cs.princeton.edu" 56 server = "mail.cs.princeton.edu"
52}) 57}