Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. qp.build(qp)
  2.  
  3. local function fail(...)
  4.    io.write("Error! ")
  5.    io.write(...)
  6.    io.write(".\nPress enter to exit...\n")
  7.    io.flush()
  8.    io.read()
  9.    os.exit()
  10. end
  11.  
  12. local function done(tab, key)
  13.    tab[key] = true
  14.    return true
  15. end
  16.  
  17. local function conv(utf)
  18.    function conv(tab, key)
  19.       local val = iconv.fromto(key, "utf8")
  20.       if not val then return utf end
  21.       tab[key] = val
  22.       return val
  23.    end
  24. end
  25.  
  26. local function fold(pat)
  27.    function fold(pth, eml)
  28.       for key in lfs.dir(pth) do
  29.          if key ~= "." and key ~= ".." then
  30.             key = pth .. key
  31.             if lfs.attributes(key, "mode") == "file" then
  32.                key = io.open(key, "rb")
  33.                pat:match(key:read("*a"), nil, eml)
  34.                key:close()
  35.             end
  36.          end
  37.       end
  38.    end
  39. end
  40.  
  41. local function mail(dir)
  42.    function mail(pth, eml)
  43.       for key in lfs.dir(pth) do
  44.          if key ~= "." and key ~= ".." and dir[key] then
  45.             key = pth .. key
  46.             if lfs.attributes(key, "mode") == "directory" then
  47.                fold(key .. "/", eml)
  48.             end
  49.          end
  50.       end
  51.    end
  52. end
  53.  
  54. local function main()
  55.    for key in lfs.dir(".") do
  56.       if key ~= "." and key ~= ".." then
  57.          if lfs.attributes(key, "mode") == "directory" then
  58.             mail("./" .. key .. "/", key)
  59.          end
  60.       end
  61.    end
  62. end
  63.  
  64. local function init()
  65.    local ext = {}
  66.    local dir = {}
  67.    local utf = {}
  68.    local pat = (qp.g - "?" + qp.b) ^ 1
  69.    local eql = qp.re(qp.b ^ 0, 2, "=")
  70.    local new = ("\r\n" * qp.b ^ 1) ^ -1
  71.    local any = (qp.g - "\"" + qp.b) ^ 1
  72.    lfs.chdir(arg[-1]:match("(.*/).+$"))
  73.    local cfg = dofile("./lua/conf.lua")
  74.    local mod = lfs.attributes("messages", "mode") == "directory"
  75.    if not mod then fail("Directory is not found: messages") end
  76.    lfs.mkdir("files")
  77.    lfs.chdir("files")
  78.    for key = 1, #arg do
  79.       mod = arg[key]:match("^%-?%-?(.*)$")
  80.       key = mod:match("^%.?(%w+)$")
  81.       if not key then fail("Invalid argument: ", mod) end
  82.       key = key:lower()
  83.       ext[key] = true
  84.       lfs.mkdir(key)
  85.    end
  86.    lfs.chdir("../messages")
  87.    conv(iconv.fromto("utf8", "utf8"))
  88.    setmetatable(utf, {__index = conv})
  89.    any = (qp.g - qp.az"=;") ^ 1 * (eql * new * (qp.re('"', 2, new * any
  90.        * ("\r\n" * qp.b ^ 1 * any) ^ 0) + (qp.g - ";") ^ 1)) ^ -1
  91.    pat = "=?" * (pat / string.lower / utf) * "?" * ((qp.nc"b" * "?"
  92.        * (pat / mime.unb64) + qp.nc"q" * "?" * (pat / mime.unqp))
  93.        / tostring) * "?=" / iconv.recode / tostring
  94.    pat = qp.cs(pat * qp.cg(qp.b ^ 0 * "\r\n" * qp.b ^ 1 * pat) ^ 0)
  95.    pat = qp.nc"name" * eql * new * qp.re('"', 2, new * qp.cg(pat, 1))
  96.    pat = {pat, qp.nc"attachment", qp.nc"base64"}
  97.    mod = qp.re(qp.b ^ 0, 2, new * any)
  98.    for key, val in next, {"type", "disposition", "transfer-encoding"} do
  99.       val = qp.nc"content-" * qp.nc(val) * ":" * qp.b ^ 0 * new
  100.           * ((any - pat[key]) * qp.re(qp.b ^ 0, 2, ";") * new) ^ 0
  101.       pat[key] = val * pat[key] * qp.b ^ 0 * (";" * mod) ^ 0 * "\r\n"
  102.    end
  103.    any = qp.w * (qp.g - ":") ^ 0 * ":" * mod * (";" * mod) ^ 0 * "\r\n"
  104.    pat = ("--" * qp.g ^ 1 * "\r\n" * qp.s ^ 0 * (any - (pat[1] + pat[2]
  105.        + pat[3])) ^ 0 * ((pat[1] * (any - (pat[2] + pat[3])) ^ 0 * (pat[2]
  106.        * (any - pat[3]) ^ 0 * pat[3] + pat[3] * (any - pat[2]) ^ 0 * pat[2])
  107.        + pat[2] * (any - (pat[1] + pat[3])) ^ 0 * (pat[1] * (any - pat[3]) ^ 0
  108.        * pat[3] + pat[3] * (any - pat[1]) ^ 0 * pat[1]) + pat[3] * (any
  109.        - (pat[1] + pat[2])) ^ 0 * (pat[1] * (any - pat[2]) ^ 0 * pat[2]
  110.        + pat[2] * (any - pat[1]) ^ 0 * pat[1])) * any ^ 0 * qp.s ^ 0
  111.        * qp.cg(qp.cb(1) * qp.cc"(%w*)$" / string.match / string.lower, 2)
  112.        * qp.cf(qp.cc(ext) * qp.cb(2), rawget) * qp.cs(qp.cc"../files/"
  113.        * qp.cb(2) * qp.cc"/" * qp.ca(1) * qp.cc"\n" * qp.cb(1)) / io.output / 0
  114.        * (qp.cs(qp.cg(qp.cp((qp.w + qp.az"+/=") ^ 1) * "\r\n") ^ 1) / mime.unb64
  115.        / 1) / io.write / io.close / 0) ^ -1 + 1) ^ 0
  116.    if cfg.catalogs.undef then setmetatable(dir, {__index = done}) end
  117.    for key, val in next, cfg.catalogs do dir[key] = val end
  118.    fold(pat)
  119.    mail(dir)
  120. end
  121.  
  122. init()
  123. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement