源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 rivejä
2.8 KiB

1 kuukausi sitten
  1. -- local _M = {}
  2. -- if module then
  3. -- mbox = _M
  4. -- end
  5. -- function _M.split_message(message_s)
  6. -- local message = {}
  7. -- message_s = string.gsub(message_s, "\r\n", "\n")
  8. -- string.gsub(message_s, "^(.-\n)\n", function (h) message.headers = h end)
  9. -- string.gsub(message_s, "^.-\n\n(.*)", function (b) message.body = b end)
  10. -- if not message.body then
  11. -- string.gsub(message_s, "^\n(.*)", function (b) message.body = b end)
  12. -- end
  13. -- if not message.headers and not message.body then
  14. -- message.headers = message_s
  15. -- end
  16. -- return message.headers or "", message.body or ""
  17. -- end
  18. -- function _M.split_headers(headers_s)
  19. -- local headers = {}
  20. -- headers_s = string.gsub(headers_s, "\r\n", "\n")
  21. -- headers_s = string.gsub(headers_s, "\n[ ]+", " ")
  22. -- string.gsub("\n" .. headers_s, "\n([^\n]+)", function (h) table.insert(headers, h) end)
  23. -- return headers
  24. -- end
  25. -- function _M.parse_header(header_s)
  26. -- header_s = string.gsub(header_s, "\n[ ]+", " ")
  27. -- header_s = string.gsub(header_s, "\n+", "")
  28. -- local _, __, name, value = string.find(header_s, "([^%s:]-):%s*(.*)")
  29. -- return name, value
  30. -- end
  31. -- function _M.parse_headers(headers_s)
  32. -- local headers_t = _M.split_headers(headers_s)
  33. -- local headers = {}
  34. -- for i = 1, #headers_t do
  35. -- local name, value = _M.parse_header(headers_t[i])
  36. -- if name then
  37. -- name = string.lower(name)
  38. -- if headers[name] then
  39. -- headers[name] = headers[name] .. ", " .. value
  40. -- else headers[name] = value end
  41. -- end
  42. -- end
  43. -- return headers
  44. -- end
  45. -- function _M.parse_from(from)
  46. -- local _, __, name, address = string.find(from, "^%s*(.-)%s*%<(.-)%>")
  47. -- if not address then
  48. -- _, __, address = string.find(from, "%s*(.+)%s*")
  49. -- end
  50. -- name = name or ""
  51. -- address = address or ""
  52. -- if name == "" then name = address end
  53. -- name = string.gsub(name, '"', "")
  54. -- return name, address
  55. -- end
  56. -- function _M.split_mbox(mbox_s)
  57. -- local mbox = {}
  58. -- mbox_s = string.gsub(mbox_s, "\r\n", "\n") .."\n\nFrom \n"
  59. -- local nj, i, j = 1, 1, 1
  60. -- while 1 do
  61. -- i, nj = string.find(mbox_s, "\n\nFrom .-\n", j)
  62. -- if not i then break end
  63. -- local message = string.sub(mbox_s, j, i-1)
  64. -- table.insert(mbox, message)
  65. -- j = nj+1
  66. -- end
  67. -- return mbox
  68. -- end
  69. -- function _M.parse(mbox_s)
  70. -- local mbox = _M.split_mbox(mbox_s)
  71. -- for i = 1, #mbox do
  72. -- mbox[i] = _M.parse_message(mbox[i])
  73. -- end
  74. -- return mbox
  75. -- end
  76. -- function _M.parse_message(message_s)
  77. -- local message = {}
  78. -- message.headers, message.body = _M.split_message(message_s)
  79. -- message.headers = _M.parse_headers(message.headers)
  80. -- return message
  81. -- end
  82. -- return _M