aboutsummaryrefslogtreecommitdiff
path: root/src/mime.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/mime.lua')
-rw-r--r--src/mime.lua22
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 = {}
11wrapt = {} 11wrapt = {}
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
14local function choose(table) 14function 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
20end 23end
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)
45end 48end
46wrapt['base64'] = wrapt['text'] 49wrapt['base64'] = wrapt['text']
50wrapt['default'] = wrapt['text']
47 51
48wrapt['quoted-printable'] = function() 52wrapt['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
53encode = choose(encodet) 57encode = choose(encodet)
54decode = choose(decodet) 58decode = choose(decodet)
55-- it's different because there is a default wrap filter 59wrap = choose(wrapt)
56local cwt = choose(wrapt)
57function 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)
63end
64 60
65-- define the end-of-line normalization filter 61-- define the end-of-line normalization filter
66function normalize(marker) 62function normalize(marker)