jbe/bsw@0: function encode.mime.quoted_printable_text_content(str) jbe/bsw@0: local parts = {} jbe/bsw@0: for str_part in string.gmatch(str, "[^\r\n]+[\r\n]*") do jbe/bsw@0: local line, extra_gap = string.match(str_part, "^([^\r\n]+)\r?\n?(.*)$") jbe/bsw@0: local line_length = 0 jbe/bsw@0: for char in string.gmatch(line, ".") do jbe/bsw@0: if string.find(char, "^[\t -<>-~]$") then jbe/bsw@0: if line_length + 1 > 75 then jbe/bsw@0: parts[#parts+1] = "=\r\n" jbe/bsw@0: line_length = 0 jbe/bsw@0: end jbe/bsw@0: parts[#parts+1] = char jbe/bsw@0: line_length = line_length + 1 jbe/bsw@0: else jbe/bsw@0: if line_length + 3 > 75 then jbe/bsw@0: parts[#parts+1] = "=\r\n" jbe/bsw@0: line_length = 0 jbe/bsw@0: end jbe/bsw@0: parts[#parts+1] = string.format("=%02X", string.byte(char)) jbe/bsw@0: line_length = line_length + 3 jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: for i = 1, #extra_gap do jbe/bsw@0: if string.sub(extra_gap, i, i) == "\n" then jbe/bsw@0: parts[#parts+1] = "\r\n" jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: parts[#parts+1] = "\r\n" jbe/bsw@0: end jbe/bsw@0: return table.concat(parts) jbe/bsw@0: end