Created
August 24, 2017 22:01
-
-
Save Echooff3/d991a9ea19efef1100a3643da597eb86 to your computer and use it in GitHub Desktop.
Node parsing base64 content of email text
This file contains hidden or 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
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