webmcp
view framework/env/encode/mime/mail.lua @ 2:72860d232f32
Version 1.0.2
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
Fixed bug with explicit garbage collection (requests > 256kB caused an error)
Views prefixed with an underscore can't be called externally
ui.paginate now displays the last page, if the selected page number is too high.
author | jbe/bsw |
---|---|
date | Thu Dec 10 12:00:00 2009 +0100 (2009-12-10) |
parents | 9fdfb27f8e67 |
children | b7596f5158d4 |
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 parts[#parts+1] = "MIME-Version: 1.0\r\n"
64 encode_container(parts, args)
65 return table.concat(parts)
66 end