webmcp

view framework/env/encode/mime/mailbox_list_header_line.lua @ 562:328f120924a2

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

Impressum / About Us