<commit_before>const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const configRoutes = require("./routes");
const exphbs  = require('express-handlebars');
const data = ("../data");
const emails = data.emails;

var fs = require('fs'), fileStream;
const Imap = require('imap'),
	inspect = require('util').inspect;
const util = require('util');
const spawn = require('child_process').spawn;

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

configRoutes(app);


// Delete all files from eml_directory
function removeFilesFrom(dirPath) {
	try {
		var files = fs.readdirSync(dirPath);
	}
	catch(e) {
		console.log(e);
		return;
	}
	if (files.length > 0)
		for (var i = 0; i < files.length; i++) {
			var filePath = dirPath + '/' + files[i];
			if (fs.statSync(filePath).isFile())
				fs.unlinkSync(filePath);
			else
				removeFilesFrom(filePath);
		}

}
removeFilesFrom('eml_directory');


// Retrieve password
//TODO change this to asynchronous
var pw = fs.readFileSync("pw.txt", encoding='utf8'); /*{
	if (error) throw error;<commit_msg>Add passport middleware configuration<commit_after>const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const configRoutes = require("./routes");
const exphbs  = require('express-handlebars');
const data = ("../data");
const emails = data.emails;
const cookieParser = require('cookie-parser');
const passport = require('passport');
const expressSession = require('express-session');
const flash = require('connect-flash');

var fs = require('fs'), fileStream;
const Imap = require('imap'),
	inspect = require('util').inspect;
const util = require('util');
const spawn = require('child_process').spawn;

app.use(cookieParser());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Configuring Passport
app.use(expressSession({ secret: 'tiptopsecret',
                         resave: false,
                         saveUninitialized: false}));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');

configRoutes(app);

// Delete all files from eml_directory
function removeFilesFrom(dirPath) {
	try {
		var files = fs.readdirSync(dirPath);
	}
	catch(e) {
		console.log(e);
		return;
	}
	if (files.length > 0)
		for (var i = 0; i < files.length; i++) {
			var filePath = dirPath + '/' + files[i];
			if (fs.statSync(filePath).isFile())
				fs.unlinkSync(filePath);
			else
				removeFilesFrom(filePath);
		}

}
removeFilesFrom('eml_directory');


// Retrieve password
//TODO change this to asynchronous
var pw = fs.readFileSync("pw.txt", encoding='utf8'); /*{
	if (error) throw error;
{'fraction_non_alphanumeric': 0.16947984843265587, 'fraction_numerical': 0.0020668274199104374, 'mean_word_length': 4.739130434782608, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1123374', 'n_tokens_mistral': 973, 'n_tokens_neox': 929, 'n_words': 219}