diff options
Diffstat (limited to 'src/mime.lua')
-rw-r--r-- | src/mime.lua | 19 |
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 = {} | |||
19 | local function choose(table) | 19 | local 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 |
25 | end | 25 | end |
@@ -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 |
38 | encode = choose(et) | 38 | encode = choose(et) |
39 | decode = choose(dt) | 39 | decode = choose(dt) |
40 | wrap = choose(wt) | 40 | |
41 | -- the wrap filter has default parameters | ||
42 | local cwt = choose(wt) | ||
43 | function 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)) | ||
48 | end | ||
41 | 49 | ||
42 | -- define the encoding algorithms | 50 | -- define the encoding algorithms |
43 | et['base64'] = function() | 51 | et['base64'] = function() |
@@ -58,15 +66,14 @@ dt['quoted-printable'] = function() | |||
58 | end | 66 | end |
59 | 67 | ||
60 | -- define the wrap algorithms | 68 | -- define the wrap algorithms |
61 | wt['character'] = function(length) | 69 | wt['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) |
64 | end | 72 | end |
65 | wt['base64'] = wt['character'] | ||
66 | 73 | ||
67 | wt['quoted-printable'] = function(length) | 74 | wt['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) |
70 | end | 77 | end |
71 | 78 | ||
72 | -- define the end-of-line translation function | 79 | -- define the end-of-line translation function |