Skip to content
Snippets Groups Projects
Commit c72bd201 authored by rswindell's avatar rswindell
Browse files

Fix decode() - encoded-words are not space-delimited

Add to_cp437() - returns a CP437 representation of the passed header value
parent 86125363
No related branches found
No related tags found
No related merge requests found
...@@ -5,14 +5,17 @@ ...@@ -5,14 +5,17 @@
// MIME (Multipurpose Internet Mail Extensions) Part Three: // MIME (Multipurpose Internet Mail Extensions) Part Three:
// Message Header Extensions for Non-ASCII Text // Message Header Extensions for Non-ASCII Text
require("utf8_cp437.js", 'utf8_cp437');
// Returns an array of 'encoded-words' // Returns an array of 'encoded-words'
function decode(hvalue) function decode(hvalue)
{ {
var result = []; var result = [];
var regex = /(\=\?[a-zA-Z0-9-]+\?.\?[^ ?]+\?\=|\s*\w+\s*|\s+)/g;
var word;
var list = hvalue.split(/\s+/); while(hvalue && (word = regex.exec(hvalue)) !== null) {
for(var i in list) { var str = word[1];
var str = list[i];
var retval = { charset: 'unspecified (US-ASCII)', data: str }; var retval = { charset: 'unspecified (US-ASCII)', data: str };
var match = str.match(/^\=\?([a-zA-Z0-9-]+)\?(.)\?([^ ?]+)\?\=$/); var match = str.match(/^\=\?([a-zA-Z0-9-]+)\?(.)\?([^ ?]+)\?\=$/);
...@@ -35,4 +38,23 @@ function decode(hvalue) ...@@ -35,4 +38,23 @@ function decode(hvalue)
return result; return result;
} }
// Translate a MIME-encoded header field value to a CP437 string
function to_cp437(val)
{
var result = [];
var words = mimehdr.decode(val);
for(i in words) {
var word = words[i];
switch(word.charset) {
case 'utf-8':
result.push(utf8_cp437(word.data));
break;
default:
result.push(word.data);
break;
}
}
return result.join('');
}
this; this;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment