Skip to content

Instantly share code, notes, and snippets.

@tastapod
Created July 23, 2012 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tastapod/3163056 to your computer and use it in GitHub Desktop.
Save tastapod/3163056 to your computer and use it in GitHub Desktop.
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