diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-19 05:04:03 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-03-19 05:04:03 +0000 |
commit | e896454e6c7fb574f405729e1ce94c223578e078 (patch) | |
tree | b9cbcb092ee8bc16fe21a9f6ae6bf07ed052fd50 /src/mime.lua | |
parent | 2c160627e51650f98d6ef01ae36bb86d6e91045f (diff) | |
download | luasocket-e896454e6c7fb574f405729e1ce94c223578e078.tar.gz luasocket-e896454e6c7fb574f405729e1ce94c223578e078.tar.bz2 luasocket-e896454e6c7fb574f405729e1ce94c223578e078.zip |
Seems to be working.
Diffstat (limited to 'src/mime.lua')
-rw-r--r-- | src/mime.lua | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/mime.lua b/src/mime.lua index 6db832d..8c2a5c0 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -6,9 +6,9 @@ setmetatable(mime, { __index = _G }) | |||
6 | setfenv(1, mime) | 6 | setfenv(1, mime) |
7 | 7 | ||
8 | -- encode, decode and wrap algorithm tables | 8 | -- encode, decode and wrap algorithm tables |
9 | local et = {} | 9 | encodet = {} |
10 | local dt = {} | 10 | decodet = {} |
11 | local wt = {} | 11 | wrapt = {} |
12 | 12 | ||
13 | -- creates a function that chooses a filter by name from a given table | 13 | -- creates a function that chooses a filter by name from a given table |
14 | local function choose(table) | 14 | local function choose(table) |
@@ -20,40 +20,40 @@ local function choose(table) | |||
20 | end | 20 | end |
21 | 21 | ||
22 | -- define the encoding filters | 22 | -- define the encoding filters |
23 | et['base64'] = function() | 23 | encodet['base64'] = function() |
24 | return ltn12.filter.cycle(b64, "") | 24 | return ltn12.filter.cycle(b64, "") |
25 | end | 25 | end |
26 | 26 | ||
27 | et['quoted-printable'] = function(mode) | 27 | encodet['quoted-printable'] = function(mode) |
28 | return ltn12.filter.cycle(qp, "", | 28 | return ltn12.filter.cycle(qp, "", |
29 | (mode == "binary") and "=0D=0A" or "\13\10") | 29 | (mode == "binary") and "=0D=0A" or "\13\10") |
30 | end | 30 | end |
31 | 31 | ||
32 | -- define the decoding filters | 32 | -- define the decoding filters |
33 | dt['base64'] = function() | 33 | decodet['base64'] = function() |
34 | return ltn12.filter.cycle(unb64, "") | 34 | return ltn12.filter.cycle(unb64, "") |
35 | end | 35 | end |
36 | 36 | ||
37 | dt['quoted-printable'] = function() | 37 | decodet['quoted-printable'] = function() |
38 | return ltn12.filter.cycle(unqp, "") | 38 | return ltn12.filter.cycle(unqp, "") |
39 | end | 39 | end |
40 | 40 | ||
41 | -- define the line-wrap filters | 41 | -- define the line-wrap filters |
42 | wt['text'] = function(length) | 42 | wrapt['text'] = function(length) |
43 | length = length or 76 | 43 | length = length or 76 |
44 | return ltn12.filter.cycle(wrp, length, length) | 44 | return ltn12.filter.cycle(wrp, length, length) |
45 | end | 45 | end |
46 | wt['base64'] = wt['text'] | 46 | wrapt['base64'] = wrapt['text'] |
47 | 47 | ||
48 | wt['quoted-printable'] = function() | 48 | wrapt['quoted-printable'] = function() |
49 | return ltn12.filter.cycle(qpwrp, 76, 76) | 49 | return ltn12.filter.cycle(qpwrp, 76, 76) |
50 | end | 50 | end |
51 | 51 | ||
52 | -- function that choose the encoding, decoding or wrap algorithm | 52 | -- function that choose the encoding, decoding or wrap algorithm |
53 | encode = choose(et) | 53 | encode = choose(encodet) |
54 | decode = choose(dt) | 54 | decode = choose(decodet) |
55 | -- there is different because there is a default wrap filter | 55 | -- it's different because there is a default wrap filter |
56 | local cwt = choose(wt) | 56 | local cwt = choose(wrapt) |
57 | function wrap(mode_or_length, length) | 57 | function wrap(mode_or_length, length) |
58 | if type(mode_or_length) ~= "string" then | 58 | if type(mode_or_length) ~= "string" then |
59 | length = mode_or_length | 59 | length = mode_or_length |