webmcp
diff framework/env/encode/mime/quoted_printable_text_content.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/encode/mime/quoted_printable_text_content.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,31 @@ 1.4 +function encode.mime.quoted_printable_text_content(str) 1.5 + local parts = {} 1.6 + for str_part in string.gmatch(str, "[^\r\n]+[\r\n]*") do 1.7 + local line, extra_gap = string.match(str_part, "^([^\r\n]+)\r?\n?(.*)$") 1.8 + local line_length = 0 1.9 + for char in string.gmatch(line, ".") do 1.10 + if string.find(char, "^[\t -<>-~]$") then 1.11 + if line_length + 1 > 75 then 1.12 + parts[#parts+1] = "=\r\n" 1.13 + line_length = 0 1.14 + end 1.15 + parts[#parts+1] = char 1.16 + line_length = line_length + 1 1.17 + else 1.18 + if line_length + 3 > 75 then 1.19 + parts[#parts+1] = "=\r\n" 1.20 + line_length = 0 1.21 + end 1.22 + parts[#parts+1] = string.format("=%02X", string.byte(char)) 1.23 + line_length = line_length + 3 1.24 + end 1.25 + end 1.26 + for i = 1, #extra_gap do 1.27 + if string.sub(extra_gap, i, i) == "\n" then 1.28 + parts[#parts+1] = "\r\n" 1.29 + end 1.30 + end 1.31 + parts[#parts+1] = "\r\n" 1.32 + end 1.33 + return table.concat(parts) 1.34 +end