diff --git a/exec/load/mimehdr.js b/exec/load/mimehdr.js index 0de20bb142a34cd1b80f8eff6af3148061c317ef..e88e0d0c9f8a7e4942c4c08c1e9921e885624e70 100644 --- a/exec/load/mimehdr.js +++ b/exec/load/mimehdr.js @@ -66,4 +66,39 @@ function to_cp437(val) return result.join(''); } -this; \ No newline at end of file +function encode_word(word) +{ + var output = "=?utf-8?q?"; + for(var i in word) { + var ch = word[i]; + if(ascii(ch) < 0x80 && ch != '=') + output += ch; + else + output += format("=%02X", ascii(ch)); + } + return output + "?="; +} + +function encode(val) +{ + if(str_is_ascii(val)) + return val; + + var output = ''; + var words = val.split(/\s+/g); + for(var i in words) { + if(output.length) + output += " "; + var word = words[i]; + if(str_is_ascii(word)) { + output += word; + continue; + } + if(!str_is_utf8(word)) + word = utf8_encode(word); + output += encode_word(word); + } + return output; +} + +this; diff --git a/exec/load/newsutil.js b/exec/load/newsutil.js index 4b4d64983973a0d2a50763cf33fd6cb0013fe1ab..af27e1e8f974c7e844dc5dfd2fbd57608abed801 100755 --- a/exec/load/newsutil.js +++ b/exec/load/newsutil.js @@ -4,6 +4,8 @@ require("mailutil.js", 'mail_get_name'); require("smbdefs.js", 'RFC822HEADER'); +const mimehdr = load("mimehdr.js"); + function get_news_subject(hdr) { if(hdr.field_list !== undefined) @@ -11,7 +13,7 @@ function get_news_subject(hdr) if(hdr.field_list[i].type == RFC822SUBJECT) return hdr.field_list[i].data; } - return hdr.subject; + return mimehdr.encode(hdr.subject); } function get_news_from(hdr)