aboutsummaryrefslogtreecommitdiff
path: root/vendor/luasocket/src/mime.lua
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/luasocket/src/mime.lua')
-rw-r--r--vendor/luasocket/src/mime.lua81
1 files changed, 81 insertions, 0 deletions
diff --git a/vendor/luasocket/src/mime.lua b/vendor/luasocket/src/mime.lua
new file mode 100644
index 00000000..93539de6
--- /dev/null
+++ b/vendor/luasocket/src/mime.lua
@@ -0,0 +1,81 @@
1-----------------------------------------------------------------------------
2-- MIME support for the Lua language.
3-- Author: Diego Nehab
4-- Conforming to RFCs 2045-2049
5-----------------------------------------------------------------------------
6
7-----------------------------------------------------------------------------
8-- Declare module and import dependencies
9-----------------------------------------------------------------------------
10local base = _G
11local ltn12 = require("ltn12")
12local mime = require("mime.core")
13local _M = mime
14
15-- encode, decode and wrap algorithm tables
16local encodet, decodet, wrapt = {},{},{}
17
18_M.encodet = encodet
19_M.decodet = decodet
20_M.wrapt = wrapt
21
22-- creates a function that chooses a filter by name from a given table
23local function choose(table)
24 return function(name, opt1, opt2)
25 if base.type(name) ~= "string" then
26 name, opt1, opt2 = "default", name, opt1
27 end
28 local f = table[name or "nil"]
29 if not f then
30 base.error("unknown key (" .. base.tostring(name) .. ")", 3)
31 else return f(opt1, opt2) end
32 end
33end
34
35-- define the encoding filters
36encodet['base64'] = function()
37 return ltn12.filter.cycle(_M.b64, "")
38end
39
40encodet['quoted-printable'] = function(mode)
41 return ltn12.filter.cycle(_M.qp, "",
42 (mode == "binary") and "=0D=0A" or "\r\n")
43end
44
45-- define the decoding filters
46decodet['base64'] = function()
47 return ltn12.filter.cycle(_M.unb64, "")
48end
49
50decodet['quoted-printable'] = function()
51 return ltn12.filter.cycle(_M.unqp, "")
52end
53
54-- define the line-wrap filters
55wrapt['text'] = function(length)
56 length = length or 76
57 return ltn12.filter.cycle(_M.wrp, length, length)
58end
59wrapt['base64'] = wrapt['text']
60wrapt['default'] = wrapt['text']
61
62wrapt['quoted-printable'] = function()
63 return ltn12.filter.cycle(_M.qpwrp, 76, 76)
64end
65
66-- function that choose the encoding, decoding or wrap algorithm
67_M.encode = choose(encodet)
68_M.decode = choose(decodet)
69_M.wrap = choose(wrapt)
70
71-- define the end-of-line normalization filter
72function _M.normalize(marker)
73 return ltn12.filter.cycle(_M.eol, 0, marker)
74end
75
76-- high level stuffing filter
77function _M.stuff()
78 return ltn12.filter.cycle(_M.dot, 2)
79end
80
81return _M