aboutsummaryrefslogtreecommitdiff
path: root/src/mime.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-21 01:09:50 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-01-21 01:09:50 +0000
commit3a7ac1e04361e12ddfcbf344e9e1db82fb88157b (patch)
tree166d452836a474541e1054f77b0b586bbe68dd6e /src/mime.lua
parent0b61b577f5d65a9c8bd5e690c4010c1e28b70e66 (diff)
downloadluasocket-3a7ac1e04361e12ddfcbf344e9e1db82fb88157b.tar.gz
luasocket-3a7ac1e04361e12ddfcbf344e9e1db82fb88157b.tar.bz2
luasocket-3a7ac1e04361e12ddfcbf344e9e1db82fb88157b.zip
Changed the naming convention of the mime module.
Looks beautiful.
Diffstat (limited to 'src/mime.lua')
-rw-r--r--src/mime.lua92
1 files changed, 44 insertions, 48 deletions
diff --git a/src/mime.lua b/src/mime.lua
index 86b3af2..0251f6e 100644
--- a/src/mime.lua
+++ b/src/mime.lua
@@ -10,75 +10,71 @@ socket.mime = mime
10setmetatable(mime, { __index = _G }) 10setmetatable(mime, { __index = _G })
11setfenv(1, mime) 11setfenv(1, mime)
12 12
13base64 = {} 13-- encode, decode and wrap algorithm tables
14qprint = {} 14local et = {}
15local dt = {}
16local wt = {}
15 17
16function base64.encode() 18-- creates a function that chooses an algorithm from a given table
17 local unfinished = "" 19local function choose(table)
18 return function(chunk) 20 return function(method, ...)
19 local done 21 local f = table[method or "nil"]
20 done, unfinished = b64(unfinished, chunk) 22 if not f then return nil, "unknown method (" .. tostring(method) .. ")"
21 return done 23 else return f(unpack(arg)) end
22 end 24 end
23end 25end
24 26
25function base64.decode() 27-- creates a function that cicles a filter with a given initial
26 local unfinished = "" 28-- context and extra arguments
29local function cicle(f, ctx, ...)
27 return function(chunk) 30 return function(chunk)
28 local done 31 local ret
29 done, unfinished = unb64(unfinished, chunk) 32 ret, ctx = f(ctx, chunk, unpack(arg))
30 return done 33 return ret
31 end 34 end
32end 35end
33 36
34function qprint.encode(mode) 37-- function that choose the encoding, decoding or wrap algorithm
35 mode = (mode == "binary") and "=0D=0A" or "\13\10" 38encode = choose(et)
36 local unfinished = "" 39decode = choose(dt)
37 return function(chunk) 40wrap = choose(wt)
38 local done 41
39 done, unfinished = qp(unfinished, chunk, mode) 42-- define the encoding algorithms
40 return done 43et['base64'] = function()
41 end 44 return cicle(b64, "")
42end 45end
43 46
44function qprint.decode() 47et['quoted-printable'] = function(mode)
45 local unfinished = "" 48 return cicle(qp, "", (mode == "binary") and "=0D=0A" or "\13\10")
46 return function(chunk) 49end
47 local done 50
48 done, unfinished = unqp(unfinished, chunk) 51-- define the decoding algorithms
49 return done 52dt['base64'] = function()
50 end 53 return cicle(unb64, "")
51end 54end
52 55
53function split(length, marker) 56dt['quoted-printable'] = function()
57 return cicle(unqp, "")
58end
59
60-- define the wrap algorithms
61wt['character'] = function(length)
54 length = length or 76 62 length = length or 76
55 local left = length 63 return cicle(fmt, length, length)
56 return function(chunk)
57 local done
58 done, left = fmt(chunk, length, left, marker)
59 return done
60 end
61end 64end
65wt['base64'] = wt['character']
62 66
63function qprint.split(length) 67wt['quoted-printable'] = function(length)
64 length = length or 76 68 length = length or 76
65 local left = length 69 return cicle(qpfmt, length, length)
66 return function(chunk)
67 local done
68 done, left = qpfmt(chunk, length, left)
69 return done
70 end
71end 70end
72 71
72-- define the end-of-line translation function
73function canonic(marker) 73function canonic(marker)
74 local unfinished = "" 74 return cicle(eol, "", marker)
75 return function(chunk)
76 local done
77 done, unfinished = eol(unfinished, chunk, marker)
78 return done
79 end
80end 75end
81 76
77-- chains several filters together
82function chain(...) 78function chain(...)
83 local layers = table.getn(arg) 79 local layers = table.getn(arg)
84 return function (chunk) 80 return function (chunk)