rev |
line source |
jbe/bsw@0
|
1 function encode.mime.mailbox_list_header_line(key, mailboxes)
|
jbe/bsw@0
|
2 local mailboxes = mailboxes
|
jbe/bsw@0
|
3 if not mailboxes then
|
jbe/bsw@0
|
4 mailboxes = {}
|
jbe/bsw@0
|
5 elseif type(mailboxes) == "string" then
|
jbe/bsw@0
|
6 mailboxes = { mailboxes }
|
jbe/bsw@0
|
7 elseif mailboxes.address or mailboxes.name then
|
jbe/bsw@0
|
8 table.insert(mailboxes, mailboxes)
|
jbe/bsw@0
|
9 end
|
jbe/bsw@0
|
10 local indentation = ""
|
jbe/bsw@0
|
11 for i = 1, #key + #(": ") do
|
jbe/bsw@0
|
12 indentation = indentation .. " "
|
jbe/bsw@0
|
13 end
|
jbe/bsw@0
|
14 local parts = { key, ": " }
|
jbe/bsw@0
|
15 local first = true
|
jbe/bsw@0
|
16 for idx, mailbox in ipairs(mailboxes) do
|
jbe/bsw@0
|
17 local name, address
|
jbe/bsw@0
|
18 if type(mailbox) == "string" then
|
jbe/bsw@0
|
19 name, address = nil, mailbox
|
jbe/bsw@0
|
20 else
|
jbe/bsw@0
|
21 name, address = mailbox.name, mailbox.address
|
jbe/bsw@0
|
22 end
|
jbe/bsw@0
|
23 if address and not string.find(
|
jbe/bsw@0
|
24 address,
|
jbe/bsw@0
|
25 "^[0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~%.]+" ..
|
jbe/bsw@0
|
26 "@[0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~%.]+$"
|
jbe/bsw@0
|
27 )
|
jbe/bsw@0
|
28 then
|
jbe/bsw@0
|
29 if name then
|
jbe/bsw@0
|
30 name, address = name .. " <" .. address .. ">", nil
|
jbe/bsw@0
|
31 else
|
jbe/bsw@0
|
32 name, address = address, nil
|
jbe/bsw@0
|
33 end
|
jbe/bsw@0
|
34 end
|
jbe/bsw@0
|
35 if name or address then
|
jbe/bsw@0
|
36 if not first then
|
jbe/bsw@0
|
37 parts[#parts+1] = ",\r\n"
|
jbe/bsw@0
|
38 parts[#parts+1] = indentation
|
jbe/bsw@0
|
39 end
|
jbe/bsw@0
|
40 if name then
|
jbe/bsw@0
|
41 parts[#parts+1] = encode.mime.atom_token(name)
|
jbe/bsw@0
|
42 parts[#parts+1] = " <"
|
jbe/bsw@0
|
43 if address then
|
jbe/bsw@0
|
44 parts[#parts+1] = address
|
jbe/bsw@0
|
45 end
|
jbe/bsw@0
|
46 parts[#parts+1] = ">"
|
jbe/bsw@0
|
47 else
|
jbe/bsw@0
|
48 parts[#parts+1] = address
|
jbe/bsw@0
|
49 end
|
jbe/bsw@0
|
50 first = false
|
jbe/bsw@0
|
51 end
|
jbe/bsw@0
|
52 end
|
jbe/bsw@0
|
53 if first then
|
jbe/bsw@0
|
54 return ""
|
jbe/bsw@0
|
55 end
|
jbe/bsw@0
|
56 parts[#parts+1] = "\r\n"
|
jbe/bsw@0
|
57 return table.concat(parts)
|
jbe/bsw@0
|
58 end
|