aboutsummaryrefslogtreecommitdiff
path: root/src/mime.lua
diff options
context:
space:
mode:
authormoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
committermoteus <mimir@newmail.ru>2013-05-27 12:45:09 +0400
commit920bc9762954454468d056a61391635cbd849406 (patch)
tree048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/mime.lua
parentbd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff)
downloadluasocket-920bc9762954454468d056a61391635cbd849406.tar.gz
luasocket-920bc9762954454468d056a61391635cbd849406.tar.bz2
luasocket-920bc9762954454468d056a61391635cbd849406.zip
Build with Lua 5.2 without LUA_COMPAT_MODULE flag.
LUASOCKET_USE_GLOBAL flag enable create global variables when load socket/mime modules.
Diffstat (limited to 'src/mime.lua')
-rw-r--r--src/mime.lua39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/mime.lua b/src/mime.lua
index 4aaccc8..642cd9c 100644
--- a/src/mime.lua
+++ b/src/mime.lua
@@ -10,13 +10,16 @@
10local base = _G 10local base = _G
11local ltn12 = require("ltn12") 11local ltn12 = require("ltn12")
12local mime = require("mime.core") 12local mime = require("mime.core")
13local io = require("io")
13local string = require("string") 14local string = require("string")
14module("mime") 15local _M = mime
15 16
16-- encode, decode and wrap algorithm tables 17-- encode, decode and wrap algorithm tables
17encodet = {} 18local encodet, decodet, wrapt = {},{},{}
18decodet = {} 19
19wrapt = {} 20_M.encodet = encodet
21_M.decodet = decodet
22_M.wrapt = wrapt
20 23
21-- creates a function that chooses a filter by name from a given table 24-- creates a function that chooses a filter by name from a given table
22local function choose(table) 25local function choose(table)
@@ -33,21 +36,21 @@ end
33 36
34-- define the encoding filters 37-- define the encoding filters
35encodet['base64'] = function() 38encodet['base64'] = function()
36 return ltn12.filter.cycle(b64, "") 39 return ltn12.filter.cycle(_M.b64, "")
37end 40end
38 41
39encodet['quoted-printable'] = function(mode) 42encodet['quoted-printable'] = function(mode)
40 return ltn12.filter.cycle(qp, "", 43 return ltn12.filter.cycle(_M.qp, "",
41 (mode == "binary") and "=0D=0A" or "\r\n") 44 (mode == "binary") and "=0D=0A" or "\r\n")
42end 45end
43 46
44-- define the decoding filters 47-- define the decoding filters
45decodet['base64'] = function() 48decodet['base64'] = function()
46 return ltn12.filter.cycle(unb64, "") 49 return ltn12.filter.cycle(_M.unb64, "")
47end 50end
48 51
49decodet['quoted-printable'] = function() 52decodet['quoted-printable'] = function()
50 return ltn12.filter.cycle(unqp, "") 53 return ltn12.filter.cycle(_M.unqp, "")
51end 54end
52 55
53local function format(chunk) 56local function format(chunk)
@@ -60,26 +63,28 @@ end
60-- define the line-wrap filters 63-- define the line-wrap filters
61wrapt['text'] = function(length) 64wrapt['text'] = function(length)
62 length = length or 76 65 length = length or 76
63 return ltn12.filter.cycle(wrp, length, length) 66 return ltn12.filter.cycle(_M.wrp, length, length)
64end 67end
65wrapt['base64'] = wrapt['text'] 68wrapt['base64'] = wrapt['text']
66wrapt['default'] = wrapt['text'] 69wrapt['default'] = wrapt['text']
67 70
68wrapt['quoted-printable'] = function() 71wrapt['quoted-printable'] = function()
69 return ltn12.filter.cycle(qpwrp, 76, 76) 72 return ltn12.filter.cycle(_M.qpwrp, 76, 76)
70end 73end
71 74
72-- function that choose the encoding, decoding or wrap algorithm 75-- function that choose the encoding, decoding or wrap algorithm
73encode = choose(encodet) 76_M.encode = choose(encodet)
74decode = choose(decodet) 77_M.decode = choose(decodet)
75wrap = choose(wrapt) 78_M.wrap = choose(wrapt)
76 79
77-- define the end-of-line normalization filter 80-- define the end-of-line normalization filter
78function normalize(marker) 81function _M.normalize(marker)
79 return ltn12.filter.cycle(eol, 0, marker) 82 return ltn12.filter.cycle(_M.eol, 0, marker)
80end 83end
81 84
82-- high level stuffing filter 85-- high level stuffing filter
83function stuff() 86function _M.stuff()
84 return ltn12.filter.cycle(dot, 2) 87 return ltn12.filter.cycle(_M.dot, 2)
85end 88end
89
90return _M \ No newline at end of file