diff options
Diffstat (limited to 'src/mime.lua')
-rw-r--r-- | src/mime.lua | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/mime.lua b/src/mime.lua index 8c2a5c0..d263d48 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -11,11 +11,14 @@ decodet = {} | |||
11 | wrapt = {} | 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 | function choose(table) |
15 | return function(name, opt) | 15 | return function(name, opt1, opt2) |
16 | if type(name) ~= "string" then | ||
17 | name, opt1, opt2 = "default", name, opt1 | ||
18 | end | ||
16 | local f = table[name or "nil"] | 19 | local f = table[name or "nil"] |
17 | if not f then error("unknown filter (" .. tostring(name) .. ")", 3) | 20 | if not f then error("unknown key (" .. tostring(name) .. ")", 3) |
18 | else return f(opt) end | 21 | else return f(opt1, opt2) end |
19 | end | 22 | end |
20 | end | 23 | end |
21 | 24 | ||
@@ -44,6 +47,7 @@ wrapt['text'] = function(length) | |||
44 | return ltn12.filter.cycle(wrp, length, length) | 47 | return ltn12.filter.cycle(wrp, length, length) |
45 | end | 48 | end |
46 | wrapt['base64'] = wrapt['text'] | 49 | wrapt['base64'] = wrapt['text'] |
50 | wrapt['default'] = wrapt['text'] | ||
47 | 51 | ||
48 | wrapt['quoted-printable'] = function() | 52 | wrapt['quoted-printable'] = function() |
49 | return ltn12.filter.cycle(qpwrp, 76, 76) | 53 | return ltn12.filter.cycle(qpwrp, 76, 76) |
@@ -52,15 +56,7 @@ end | |||
52 | -- function that choose the encoding, decoding or wrap algorithm | 56 | -- function that choose the encoding, decoding or wrap algorithm |
53 | encode = choose(encodet) | 57 | encode = choose(encodet) |
54 | decode = choose(decodet) | 58 | decode = choose(decodet) |
55 | -- it's different because there is a default wrap filter | 59 | wrap = choose(wrapt) |
56 | local cwt = choose(wrapt) | ||
57 | function wrap(mode_or_length, length) | ||
58 | if type(mode_or_length) ~= "string" then | ||
59 | length = mode_or_length | ||
60 | mode_or_length = "text" | ||
61 | end | ||
62 | return cwt(mode_or_length, length) | ||
63 | end | ||
64 | 60 | ||
65 | -- define the end-of-line normalization filter | 61 | -- define the end-of-line normalization filter |
66 | function normalize(marker) | 62 | function normalize(marker) |