aboutsummaryrefslogtreecommitdiff
path: root/src/mime.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/mime.lua')
-rw-r--r--src/mime.lua19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/mime.lua b/src/mime.lua
index 0251f6e..30c6b38 100644
--- a/src/mime.lua
+++ b/src/mime.lua
@@ -19,7 +19,7 @@ local wt = {}
19local function choose(table) 19local function choose(table)
20 return function(method, ...) 20 return function(method, ...)
21 local f = table[method or "nil"] 21 local f = table[method or "nil"]
22 if not f then return nil, "unknown method (" .. tostring(method) .. ")" 22 if not f then error("unknown method (" .. tostring(method) .. ")", 3)
23 else return f(unpack(arg)) end 23 else return f(unpack(arg)) end
24 end 24 end
25end 25end
@@ -37,7 +37,15 @@ end
37-- function that choose the encoding, decoding or wrap algorithm 37-- function that choose the encoding, decoding or wrap algorithm
38encode = choose(et) 38encode = choose(et)
39decode = choose(dt) 39decode = choose(dt)
40wrap = choose(wt) 40
41-- the wrap filter has default parameters
42local cwt = choose(wt)
43function wrap(...)
44 if not arg[1] or type(arg[1]) ~= "string" then
45 table.insert(arg, 1, "base64")
46 end
47 return cwt(unpack(arg))
48end
41 49
42-- define the encoding algorithms 50-- define the encoding algorithms
43et['base64'] = function() 51et['base64'] = function()
@@ -58,15 +66,14 @@ dt['quoted-printable'] = function()
58end 66end
59 67
60-- define the wrap algorithms 68-- define the wrap algorithms
61wt['character'] = function(length) 69wt['base64'] = function(length, marker)
62 length = length or 76 70 length = length or 76
63 return cicle(fmt, length, length) 71 return cicle(wrp, length, length, marker)
64end 72end
65wt['base64'] = wt['character']
66 73
67wt['quoted-printable'] = function(length) 74wt['quoted-printable'] = function(length)
68 length = length or 76 75 length = length or 76
69 return cicle(qpfmt, length, length) 76 return cicle(qpwrp, length, length)
70end 77end
71 78
72-- define the end-of-line translation function 79-- define the end-of-line translation function