Skip to content

Instantly share code, notes, and snippets.

@Echooff3
Created August 24, 2017 22:01
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 Echooff3/d991a9ea19efef1100a3643da597eb86 to your computer and use it in GitHub Desktop.
Save Echooff3/d991a9ea19efef1100a3643da597eb86 to your computer and use it in GitHub Desktop.
Node parsing base64 content of email text
var fs = require('fs');
var eml = fs.readFileSync('./eml.txt').toString('utf8').split('\r\n');
function parseEmailText(eml) {
var sectionFound = false;
var found = [];
var tmp = "";
for (var x in eml) {
var l = eml[x];
if(sectionFound) {
if(l.length == 0 && tmp.length > 0) {
//End of block
sectionFound = false;
found.push(Buffer(tmp, 'base64').toString('utf8'))
} else if(l.length > 0) {
tmp += l;
}
}
sectionFound = l.indexOf('Content-Transfer-Encoding: base64') >= 0 || sectionFound
}
return found;
}
console.log(parseEmailText(eml).join("\r\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment