diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:55:35 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2002-07-08 21:55:35 +0000 |
commit | af181244d9670ec8f6ef83c3548060c35fa9bf0e (patch) | |
tree | 1015d024129982f6dde426803bc0ee156a426b80 | |
parent | 0fc2302221e80a8f2d55808320073024a02517e8 (diff) | |
download | luasocket-af181244d9670ec8f6ef83c3548060c35fa9bf0e.tar.gz luasocket-af181244d9670ec8f6ef83c3548060c35fa9bf0e.tar.bz2 luasocket-af181244d9670ec8f6ef83c3548060c35fa9bf0e.zip |
Usando noglobals.lua e parsembox.lua
-rw-r--r-- | test/smtptest.lua | 60 |
1 files changed, 3 insertions, 57 deletions
diff --git a/test/smtptest.lua b/test/smtptest.lua index fcd238b..6b01134 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua | |||
@@ -4,26 +4,14 @@ local from = "luasock@tecgraf.puc-rio.br" | |||
4 | local server = "mail.tecgraf.puc-rio.br" | 4 | local server = "mail.tecgraf.puc-rio.br" |
5 | local rcpt = "luasock@tecgraf.puc-rio.br" | 5 | local rcpt = "luasock@tecgraf.puc-rio.br" |
6 | 6 | ||
7 | local parse = {} | ||
8 | |||
9 | local name = "/var/spool/mail/luasock" | 7 | local name = "/var/spool/mail/luasock" |
10 | 8 | ||
11 | local t = _time() | 9 | local t = _time() |
12 | local err | 10 | local err |
13 | 11 | ||
14 | function mysetglobal (varname, oldvalue, newvalue) | 12 | dofile("parsembox.lua") |
15 | print("changing " .. varname) | 13 | local parse = parse |
16 | %rawset(%globals(), varname, newvalue) | 14 | dofile("noglobals.lua") |
17 | end | ||
18 | function mygetglobal (varname, newvalue) | ||
19 | print("checking " .. varname) | ||
20 | return %rawget(%globals(), varname) | ||
21 | end | ||
22 | settagmethod(tag(nil), "setglobal", mysetglobal) | ||
23 | settagmethod(tag(nil), "getglobal", mygetglobal) | ||
24 | |||
25 | assert(dofile("../lua/smtp.lua")) | ||
26 | assert(dofile("../lua/cl-compat.lua")) | ||
27 | 15 | ||
28 | local total = function() | 16 | local total = function() |
29 | local t = 0 | 17 | local t = 0 |
@@ -37,48 +25,6 @@ local similar = function(s1, s2) | |||
37 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) | 25 | return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) |
38 | end | 26 | end |
39 | 27 | ||
40 | function parse.headers(headers_s) | ||
41 | local headers = {} | ||
42 | headers_s = "\n" .. headers_s .. "$$$:\n" | ||
43 | local i, j = 1, 1 | ||
44 | local name, value, _ | ||
45 | while 1 do | ||
46 | j = strfind(headers_s, "\n%S-:", i+1) | ||
47 | if not j then break end | ||
48 | _, _, name, value = strfind(strsub(headers_s, i+1, j-1), "(%S-): (.*)") | ||
49 | value = gsub(value, "\r\n", "\n") | ||
50 | value = gsub(value, "\n%s*", " ") | ||
51 | name = strlower(name) | ||
52 | if headers[name] then headers[name] = headers[name] .. ", " .. value | ||
53 | else headers[name] = value end | ||
54 | i, j = j, i | ||
55 | end | ||
56 | headers["$$$"] = nil | ||
57 | return headers | ||
58 | end | ||
59 | |||
60 | function parse.message(message_s) | ||
61 | message_s = gsub(message_s, "^.-\n", "") | ||
62 | local _, headers_s, body | ||
63 | _, _, headers_s, body = strfind(message_s, "^(.-\n)\n(.*)") | ||
64 | headers_s = headers_s or "" | ||
65 | body = body or "" | ||
66 | return { headers = %parse.headers(headers_s), body = body } | ||
67 | end | ||
68 | |||
69 | function parse.mbox(mbox_s) | ||
70 | local mbox = {} | ||
71 | mbox_s = "\n" .. mbox_s .. "\nFrom " | ||
72 | local i, j = 1, 1 | ||
73 | while 1 do | ||
74 | j = strfind(mbox_s, "\nFrom ", i + 1) | ||
75 | if not j then break end | ||
76 | tinsert(mbox, %parse.message(strsub(mbox_s, i + 1, j - 1))) | ||
77 | i, j = j, i | ||
78 | end | ||
79 | return mbox | ||
80 | end | ||
81 | |||
82 | local readfile = function(name) | 28 | local readfile = function(name) |
83 | local f = readfrom(name) | 29 | local f = readfrom(name) |
84 | if not f then return nil end | 30 | if not f then return nil end |