master131 / msg2eml.js

A javascript library to convert Outlook *.msg files to *.eml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Convert MSG to EML in CLI ?

Erwane opened this issue · comments

Hi, this is the best msg to eml convert i've found.
There is a possibility to run it in command line ?
Thanks

Should be possible to write a simple script in Node.js that calls the msg2eml function which can be called from command line.

Don't have an example, otherwise you can look at the below Python script which most of my web version is based on:

https://github.com/JoshData/convert-outlook-msg-file

Hi, There is a npm package or not for this repository ?

Here my CLI code

mkdir convert-msg
cd convert-msg
git clone https://github.com/master131/msg2eml.js.git msg2eml
cd msg2eml
npm install
npm run build
cd ..

Create a package.json

{
  "name": "convert-msg",
  "version": "1.0.0",
  "description": "Convert Outlook .msg Files to .eml in CLI",
  "main": "convert.js",
  "bin": {
    "convert-msg": "convert.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "filereader": "^0.10",
    "file-api": "^0.10",
    "mime": "^1"
  }
}

Then
npm install --no-fund

Create a convert.js

let msg2eml = require('./msg2eml/lib/msg2eml');
const FileReader = require("filereader/FileReader");
const FileApi = require('file-api');

const args = process.argv.slice(2);
let filePath = args[0];

function convertMsgToEml(path) {
    let file = new FileApi.File(path);

    let fileReader = new FileReader();

    fileReader.onload = function (e) {
        let buffer = fileReader.result;
        let arrayBuffer = Array.from(buffer);
        msg2eml(arrayBuffer)
            .then(function (eml) {
                fileReader = null;
                process.stdout.write(eml);
            })
            .catch(()  => {
                process.exit(1);
            });
    };

    fileReader.readAsArrayBuffer(file);
}

convertMsgToEml(filePath);

then
node convert.js /path/to/msg >/path/to/eml

Improvements welcome :)