[local-sync] Allow logging parsed messages to disk with NYLAS_DEBUG env var

Summary:
I've found this useful for generating test cases and am tired
of adding and removing this code!

Test Plan: inspect output of /tmp/k2-parse-output

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3518
This commit is contained in:
Christine Spang 2016-12-15 10:18:41 -08:00
parent ac5c7e3d2c
commit e5a9e2cc9e

View file

@ -3,6 +3,11 @@ const mimelib = require('mimelib');
const encoding = require('encoding');
const he = require('he');
const os = require('os');
const fs = require('fs');
const path = require('path')
const mkdirp = require('mkdirp');
const {Imap} = require('isomorphic-core');
const Errors = require('./errors');
@ -163,6 +168,14 @@ async function parseFromImap(imapMessage, desiredParts, {db, accountId, folder})
parsedMessage.labels = await Label.findXGMLabels(xGmLabels)
}
if (process.env.NYLAS_DEBUG) {
const outJSON = JSON.stringify({imapMessage, desiredParts, result: parsedMessage});
const outDir = path.join(os.tmpdir(), "k2-parse-output", folder.name)
const outFile = path.join(outDir, imapMessage.attributes.uid.toString());
mkdirp.sync(outDir);
fs.writeFileSync(outFile, outJSON);
}
return parsedMessage;
}