/usr/share/ettercap/lua/third-party/mbox.lua is in ettercap-common 1:0.8.2-10build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | --- mbox parser.
-- Based on code by Diego Nahab.
local function headers (s)
local header = {}
s = "\n" .. s .. "$$$:\n"
local i, j = 1, 1
while true do
j = string.find (s, "\n%S-:", i + 1)
if not j then
break
end
local _, _, name, val = string.find (string.sub (s, i + 1, j - 1),
"(%S-):(.*)")
val = string.gsub (val or "", "\r\n", "\n")
val = string.gsub (val, "\n%s*", " ")
name = string.lower (name)
if header[name] then
header[name] = header[name] .. ", " .. val
else
header[name] = val
end
i, j = j, i
end
header["$$$"] = nil
return header
end
local function message (s)
s = string.gsub (s, "^.-\n", "")
local _, s, body
_, _, s, body = string.find(s, "^(.-\n)\n(.*)")
return {header = headers (s or ""), body = body or ""}
end
--- Parse a mailbox into messages.
-- @param s mailbox as a string
-- @return list of messages, each of form <code>{header = {...}, body = "..."}</code>
local function parse (s)
local mbox = {}
s = "\n" .. s .. "\nFrom "
local i, j = 1, 1
while true do
j = string.find (s, "\nFrom ", i + 1)
if not j then
break
end
table.insert (mbox, message (string.sub (s, i + 1, j - 1)))
i, j = j, i
end
return mbox
end
-- Public interface
local M = {
parse = parse,
}
return M
|