webmcp

view framework/env/encode/mime/atom_token.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 9fdfb27f8e67
children
line source
1 function encode.mime.atom_token(str)
2 local charset = "UTF-8" -- TODO: support other charsets via locale system
3 if
4 string.find(str, "^[0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~]+$")
5 then
6 return str
7 elseif
8 string.find(str, "^[\t 0-9A-Za-z!#%$%%&'%*%+%-/=%?%^_`{|}~]+$")
9 then
10 return '"' .. str .. '"'
11 elseif
12 string.find(str, "^[\t -~]*$")
13 then
14 local parts = { '"' }
15 for char in string.gmatch(str, ".") do
16 if char == '"' or char == "\\" then
17 parts[#parts+1] = "\\"
18 end
19 parts[#parts+1] = char
20 end
21 parts[#parts+1] = '"'
22 return table.concat(parts)
23 else
24 local parts = { "=?", charset, "?Q?" }
25 for char in string.gmatch(str, ".") do
26 local byte = string.byte(char)
27 if string.find(char, "^[0-9A-Za-z%.%-]$") then
28 parts[#parts+1] = char
29 else
30 local byte = string.byte(char)
31 if byte == 32 then
32 parts[#parts+1] = "_"
33 else
34 parts[#parts+1] = string.format("=%02X", byte)
35 end
36 end
37 end
38 parts[#parts+1] = "?="
39 return table.concat(parts)
40 end
41 end

Impressum / About Us