webmcp

view framework/env/encode/mime/mail.lua @ 560:75204c64cc5f

Use CRLF instead of LF for terminating raw header
author jbe
date Tue Jun 09 13:27:58 2020 +0200 (15 months ago)
parents 318fdbb5f0f4
children
line source
1 local un = encode.mime.unstructured_header_line
2 local mbl = encode.mime.mailbox_list_header_line
4 local function encode_container(parts, container)
5 if container.multipart then
6 local boundary
7 boundary = "BOUNDARY--" .. multirand.string(
8 24,
9 "123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz"
10 )
11 parts[#parts+1] = "Content-Type: "
12 parts[#parts+1] = "multipart/"
13 parts[#parts+1] = container.multipart
14 parts[#parts+1] = "; boundary="
15 parts[#parts+1] = boundary
16 parts[#parts+1] = "\r\n\r\nMIME multipart\r\n" -- last \r\n optional
17 for idx, sub_container in ipairs(container) do
18 parts[#parts+1] = "\r\n--"
19 parts[#parts+1] = boundary
20 parts[#parts+1] = "\r\n"
21 encode_container(parts, sub_container)
22 end
23 parts[#parts+1] = "\r\n--"
24 parts[#parts+1] = boundary
25 parts[#parts+1] = "--\r\n"
26 else
27 parts[#parts+1] = "Content-Type: "
28 parts[#parts+1] = container.content_type or "text/plain"
29 parts[#parts+1] = "\r\n"
30 if container.content_id then
31 parts[#parts+1] = "Content-ID: <"
32 parts[#parts+1] = container.content_id
33 parts[#parts+1] = ">\r\n"
34 end
35 if container.attachment_filename then
36 parts[#parts+1] = "Content-Disposition: attachment; filename="
37 parts[#parts+1] = encode.mime.atom_token(
38 container.attachment_filename
39 )
40 parts[#parts+1] = "\r\n"
41 end
42 if container.binary then
43 parts[#parts+1] = "Content-Transfer-Encoding: base64\r\n\r\n"
44 parts[#parts+1] = encode.mime.base64(container.content)
45 else
46 parts[#parts+1] =
47 "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
48 parts[#parts+1] =
49 encode.mime.quoted_printable_text_content(container.content)
50 end
51 end
52 end
54 function encode.mime.mail(args)
55 local parts = {}
56 parts[#parts+1] = mbl("From", args.from)
57 parts[#parts+1] = mbl("Sender", args.sender)
58 parts[#parts+1] = mbl("Reply-To", args.reply_to)
59 parts[#parts+1] = mbl("To", args.to)
60 parts[#parts+1] = mbl("Cc", args.cc)
61 parts[#parts+1] = mbl("Bcc", args.bcc)
62 parts[#parts+1] = un("Subject", args.subject)
63 if args.raw_headers then
64 for i, raw_header in ipairs(args.raw_headers) do
65 parts[#parts+1] = raw_header
66 parts[#parts+1] = "\r\n"
67 end
68 end
69 parts[#parts+1] = "MIME-Version: 1.0\r\n"
70 encode_container(parts, args)
71 return table.concat(parts)
72 end

Impressum / About Us