diff options
| author | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
|---|---|---|
| committer | moteus <mimir@newmail.ru> | 2013-05-27 12:45:09 +0400 |
| commit | 920bc9762954454468d056a61391635cbd849406 (patch) | |
| tree | 048c112f95fa578d239ae3e35b2aec0a482f0c23 /src/mime.lua | |
| parent | bd51d8c1a5bb30e6a358dee6e85963f777edfff4 (diff) | |
| download | luasocket-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.lua | 39 |
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 @@ | |||
| 10 | local base = _G | 10 | local base = _G |
| 11 | local ltn12 = require("ltn12") | 11 | local ltn12 = require("ltn12") |
| 12 | local mime = require("mime.core") | 12 | local mime = require("mime.core") |
| 13 | local io = require("io") | ||
| 13 | local string = require("string") | 14 | local string = require("string") |
| 14 | module("mime") | 15 | local _M = mime |
| 15 | 16 | ||
| 16 | -- encode, decode and wrap algorithm tables | 17 | -- encode, decode and wrap algorithm tables |
| 17 | encodet = {} | 18 | local encodet, decodet, wrapt = {},{},{} |
| 18 | decodet = {} | 19 | |
| 19 | wrapt = {} | 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 |
| 22 | local function choose(table) | 25 | local function choose(table) |
| @@ -33,21 +36,21 @@ end | |||
| 33 | 36 | ||
| 34 | -- define the encoding filters | 37 | -- define the encoding filters |
| 35 | encodet['base64'] = function() | 38 | encodet['base64'] = function() |
| 36 | return ltn12.filter.cycle(b64, "") | 39 | return ltn12.filter.cycle(_M.b64, "") |
| 37 | end | 40 | end |
| 38 | 41 | ||
| 39 | encodet['quoted-printable'] = function(mode) | 42 | encodet['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") |
| 42 | end | 45 | end |
| 43 | 46 | ||
| 44 | -- define the decoding filters | 47 | -- define the decoding filters |
| 45 | decodet['base64'] = function() | 48 | decodet['base64'] = function() |
| 46 | return ltn12.filter.cycle(unb64, "") | 49 | return ltn12.filter.cycle(_M.unb64, "") |
| 47 | end | 50 | end |
| 48 | 51 | ||
| 49 | decodet['quoted-printable'] = function() | 52 | decodet['quoted-printable'] = function() |
| 50 | return ltn12.filter.cycle(unqp, "") | 53 | return ltn12.filter.cycle(_M.unqp, "") |
| 51 | end | 54 | end |
| 52 | 55 | ||
| 53 | local function format(chunk) | 56 | local function format(chunk) |
| @@ -60,26 +63,28 @@ end | |||
| 60 | -- define the line-wrap filters | 63 | -- define the line-wrap filters |
| 61 | wrapt['text'] = function(length) | 64 | wrapt['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) |
| 64 | end | 67 | end |
| 65 | wrapt['base64'] = wrapt['text'] | 68 | wrapt['base64'] = wrapt['text'] |
| 66 | wrapt['default'] = wrapt['text'] | 69 | wrapt['default'] = wrapt['text'] |
| 67 | 70 | ||
| 68 | wrapt['quoted-printable'] = function() | 71 | wrapt['quoted-printable'] = function() |
| 69 | return ltn12.filter.cycle(qpwrp, 76, 76) | 72 | return ltn12.filter.cycle(_M.qpwrp, 76, 76) |
| 70 | end | 73 | end |
| 71 | 74 | ||
| 72 | -- function that choose the encoding, decoding or wrap algorithm | 75 | -- function that choose the encoding, decoding or wrap algorithm |
| 73 | encode = choose(encodet) | 76 | _M.encode = choose(encodet) |
| 74 | decode = choose(decodet) | 77 | _M.decode = choose(decodet) |
| 75 | wrap = 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 |
| 78 | function normalize(marker) | 81 | function _M.normalize(marker) |
| 79 | return ltn12.filter.cycle(eol, 0, marker) | 82 | return ltn12.filter.cycle(_M.eol, 0, marker) |
| 80 | end | 83 | end |
| 81 | 84 | ||
| 82 | -- high level stuffing filter | 85 | -- high level stuffing filter |
| 83 | function stuff() | 86 | function _M.stuff() |
| 84 | return ltn12.filter.cycle(dot, 2) | 87 | return ltn12.filter.cycle(_M.dot, 2) |
| 85 | end | 88 | end |
| 89 | |||
| 90 | return _M \ No newline at end of file | ||
