Created
July 23, 2012 10:49
-
-
Save tastapod/3163056 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function decodeBody(content, encoding) { | |
switch (encoding.toLocaleLowerCase()) { | |
case "base64": | |
content = content.replace(/\r/g, ''); | |
return new Buffer(content, 'base64').toString('utf8'); | |
case "quoted-printable": | |
case "7bit": | |
case "8bit": | |
content = content.replace(/\r/g, ''); | |
return unquotedPrintable(content); | |
default: | |
console.warn("Unknown encoding: " + encoding); | |
return content; | |
} | |
} | |
function unquotedPrintable(content) { | |
return content | |
.replace(/=\n/g, '') | |
.replace(/=([\da-f]{2})/ig, function(_, m) { | |
return String.fromCharCode(parseInt(m, 16)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment