From 920bc9762954454468d056a61391635cbd849406 Mon Sep 17 00:00:00 2001 From: moteus Date: Mon, 27 May 2013 12:45:09 +0400 Subject: Build with Lua 5.2 without LUA_COMPAT_MODULE flag. LUASOCKET_USE_GLOBAL flag enable create global variables when load socket/mime modules. --- src/mime.lua | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/mime.lua') 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 @@ local base = _G local ltn12 = require("ltn12") local mime = require("mime.core") +local io = require("io") local string = require("string") -module("mime") +local _M = mime -- encode, decode and wrap algorithm tables -encodet = {} -decodet = {} -wrapt = {} +local encodet, decodet, wrapt = {},{},{} + +_M.encodet = encodet +_M.decodet = decodet +_M.wrapt = wrapt -- creates a function that chooses a filter by name from a given table local function choose(table) @@ -33,21 +36,21 @@ end -- define the encoding filters encodet['base64'] = function() - return ltn12.filter.cycle(b64, "") + return ltn12.filter.cycle(_M.b64, "") end encodet['quoted-printable'] = function(mode) - return ltn12.filter.cycle(qp, "", + return ltn12.filter.cycle(_M.qp, "", (mode == "binary") and "=0D=0A" or "\r\n") end -- define the decoding filters decodet['base64'] = function() - return ltn12.filter.cycle(unb64, "") + return ltn12.filter.cycle(_M.unb64, "") end decodet['quoted-printable'] = function() - return ltn12.filter.cycle(unqp, "") + return ltn12.filter.cycle(_M.unqp, "") end local function format(chunk) @@ -60,26 +63,28 @@ end -- define the line-wrap filters wrapt['text'] = function(length) length = length or 76 - return ltn12.filter.cycle(wrp, length, length) + return ltn12.filter.cycle(_M.wrp, length, length) end wrapt['base64'] = wrapt['text'] wrapt['default'] = wrapt['text'] wrapt['quoted-printable'] = function() - return ltn12.filter.cycle(qpwrp, 76, 76) + return ltn12.filter.cycle(_M.qpwrp, 76, 76) end -- function that choose the encoding, decoding or wrap algorithm -encode = choose(encodet) -decode = choose(decodet) -wrap = choose(wrapt) +_M.encode = choose(encodet) +_M.decode = choose(decodet) +_M.wrap = choose(wrapt) -- define the end-of-line normalization filter -function normalize(marker) - return ltn12.filter.cycle(eol, 0, marker) +function _M.normalize(marker) + return ltn12.filter.cycle(_M.eol, 0, marker) end -- high level stuffing filter -function stuff() - return ltn12.filter.cycle(dot, 2) +function _M.stuff() + return ltn12.filter.cycle(_M.dot, 2) end + +return _M \ No newline at end of file -- cgit v1.2.3-55-g6feb