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