Created
January 30, 2021 04:39
-
-
Save alexanderbird/f6361d2287bcb583766496da282b8bbb to your computer and use it in GitHub Desktop.
Convert .eml file to .html with node
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
const EmlParser = require('eml-parser'); | |
const fs = require('fs'); | |
const inputFile = process.argv[2]; | |
if (!inputFile) throw new Error("Missing input file path argument"); | |
if (!inputFile.match(/\.eml$/)) throw new Error("Only .eml files supported"); | |
if (!fs.existsSync(inputFile)) throw new Error(`Couldn't find file ${inputFile}`); | |
const emailFile = fs.createReadStream(inputFile); | |
new EmlParser(emailFile) | |
.getEmailAsHtml() | |
.then(htmlString => { | |
process.stdout.write(htmlString); | |
}) | |
.catch(error => { console.log(error) }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment