Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- qp.build(qp)
- local function fail(...)
- io.write("Error! ")
- io.write(...)
- io.write(".\nPress enter to exit...\n")
- io.flush()
- io.read()
- os.exit()
- end
- local function done(tab, key)
- tab[key] = true
- return true
- end
- local function conv(utf)
- function conv(tab, key)
- local val = iconv.fromto(key, "utf8")
- if not val then return utf end
- tab[key] = val
- return val
- end
- end
- local function fold(pat)
- function fold(pth, eml)
- for key in lfs.dir(pth) do
- if key ~= "." and key ~= ".." then
- key = pth .. key
- if lfs.attributes(key, "mode") == "file" then
- key = io.open(key, "rb")
- pat:match(key:read("*a"), nil, eml)
- key:close()
- end
- end
- end
- end
- end
- local function mail(dir)
- function mail(pth, eml)
- for key in lfs.dir(pth) do
- if key ~= "." and key ~= ".." and dir[key] then
- key = pth .. key
- if lfs.attributes(key, "mode") == "directory" then
- fold(key .. "/", eml)
- end
- end
- end
- end
- end
- local function main()
- for key in lfs.dir(".") do
- if key ~= "." and key ~= ".." then
- if lfs.attributes(key, "mode") == "directory" then
- mail("./" .. key .. "/", key)
- end
- end
- end
- end
- local function init()
- local ext = {}
- local dir = {}
- local utf = {}
- local pat = (qp.g - "?" + qp.b) ^ 1
- local eql = qp.re(qp.b ^ 0, 2, "=")
- local new = ("\r\n" * qp.b ^ 1) ^ -1
- local any = (qp.g - "\"" + qp.b) ^ 1
- lfs.chdir(arg[-1]:match("(.*/).+$"))
- local cfg = dofile("./lua/conf.lua")
- local mod = lfs.attributes("messages", "mode") == "directory"
- if not mod then fail("Directory is not found: messages") end
- lfs.mkdir("files")
- lfs.chdir("files")
- for key = 1, #arg do
- mod = arg[key]:match("^%-?%-?(.*)$")
- key = mod:match("^%.?(%w+)$")
- if not key then fail("Invalid argument: ", mod) end
- key = key:lower()
- ext[key] = true
- lfs.mkdir(key)
- end
- lfs.chdir("../messages")
- conv(iconv.fromto("utf8", "utf8"))
- setmetatable(utf, {__index = conv})
- any = (qp.g - qp.az"=;") ^ 1 * (eql * new * (qp.re('"', 2, new * any
- * ("\r\n" * qp.b ^ 1 * any) ^ 0) + (qp.g - ";") ^ 1)) ^ -1
- pat = "=?" * (pat / string.lower / utf) * "?" * ((qp.nc"b" * "?"
- * (pat / mime.unb64) + qp.nc"q" * "?" * (pat / mime.unqp))
- / tostring) * "?=" / iconv.recode / tostring
- pat = qp.cs(pat * qp.cg(qp.b ^ 0 * "\r\n" * qp.b ^ 1 * pat) ^ 0)
- pat = qp.nc"name" * eql * new * qp.re('"', 2, new * qp.cg(pat, 1))
- pat = {pat, qp.nc"attachment", qp.nc"base64"}
- mod = qp.re(qp.b ^ 0, 2, new * any)
- for key, val in next, {"type", "disposition", "transfer-encoding"} do
- val = qp.nc"content-" * qp.nc(val) * ":" * qp.b ^ 0 * new
- * ((any - pat[key]) * qp.re(qp.b ^ 0, 2, ";") * new) ^ 0
- pat[key] = val * pat[key] * qp.b ^ 0 * (";" * mod) ^ 0 * "\r\n"
- end
- any = qp.w * (qp.g - ":") ^ 0 * ":" * mod * (";" * mod) ^ 0 * "\r\n"
- pat = ("--" * qp.g ^ 1 * "\r\n" * qp.s ^ 0 * (any - (pat[1] + pat[2]
- + pat[3])) ^ 0 * ((pat[1] * (any - (pat[2] + pat[3])) ^ 0 * (pat[2]
- * (any - pat[3]) ^ 0 * pat[3] + pat[3] * (any - pat[2]) ^ 0 * pat[2])
- + pat[2] * (any - (pat[1] + pat[3])) ^ 0 * (pat[1] * (any - pat[3]) ^ 0
- * pat[3] + pat[3] * (any - pat[1]) ^ 0 * pat[1]) + pat[3] * (any
- - (pat[1] + pat[2])) ^ 0 * (pat[1] * (any - pat[2]) ^ 0 * pat[2]
- + pat[2] * (any - pat[1]) ^ 0 * pat[1])) * any ^ 0 * qp.s ^ 0
- * qp.cg(qp.cb(1) * qp.cc"(%w*)$" / string.match / string.lower, 2)
- * qp.cf(qp.cc(ext) * qp.cb(2), rawget) * qp.cs(qp.cc"../files/"
- * qp.cb(2) * qp.cc"/" * qp.ca(1) * qp.cc"\n" * qp.cb(1)) / io.output / 0
- * (qp.cs(qp.cg(qp.cp((qp.w + qp.az"+/=") ^ 1) * "\r\n") ^ 1) / mime.unb64
- / 1) / io.write / io.close / 0) ^ -1 + 1) ^ 0
- if cfg.catalogs.undef then setmetatable(dir, {__index = done}) end
- for key, val in next, cfg.catalogs do dir[key] = val end
- fold(pat)
- mail(dir)
- end
- init()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement