<commit_before>var fs = require('fs');
var util = require('util');
var request = require('request-json');
var winston = require('winston');
var config = require('../config');
var manifest = require('./manifest');
var csCore = require('./csCore.js');
var sendEmail = require('./sendEmail');
var crypto = require('cryptofunc');
var selectUtils = require('selectUtils');

///////////////////////////////////////////////////////////////////////////////////////
// State

var otp_store = {};
var mail_timestamp = {};

var electionID = manifest.hash;
var colSerSigKey = config.signing_key;
var cs = csCore.create(electionID, colSerSigKey);
var openElection = (manifest.voters.length === 0); // emtpy list of voters means that the election is open (everybody can vote)
if (openElection)
    console.log('Empty list of voters => election is open (it ballots from everybody)')
var listOfEligibleVoters = manifest.voters.map(function(k){ return k.email; });
var printableElID = makeBreakable(manifest.hash.slice(0,16).toUpperCase()); // only the first 16 hex chars (out of 64, for backward compatibility with SHA-1 in the GUI)

// Map of eligible voters
var eligibleVoters = {};
for (var i=0; i<listOfEligibleVoters.length; ++i) eligibleVoters[listOfEligibleVoters[i]] = true;

//Check for hidden Voters
var votersFileExists = fs.existsSync('./eligibleVoters.json');
if(votersFileExists){
	var votersFile = JSON.parse(fs.readFileSync("./eligibleVoters.json"));
	var listOfHiddenVoters = votersFile.voters.map(function(k){ return k.email; });
	for (var i=0; i<listOfHiddenVoters.length; ++i) eligibleVoters[listOfHiddenVoters[i]] = true;
}
	

// Checks if the voter is eligible. In an election is open, then every voter is eligible.
function isEligibleVoter(voter) {
    return  (openElection && validEmail(voter)) || (eligibleVoters.hasOwnProperty(voter) && eligibleVoters[voter]===true);
}

var emailPattern = /^\S+@\S+$/;
var emailNegPattern = /[';\n\r]/;
function validEmail(email) {
    return emailPattern.test(email) && !emailNegPattern.test(email);
}

//  status and opening/closing time
var resultReady = fs.existsSync(config.RESULT_FILE);

// If there is no result yet, but there are some accepted
// ballots, we need to read these ballots to resume the operation:
if (!resultReady && fs.existsSync(config.ACCEPTED_BALLOTS_LOG_FILE)) {
    console.log('Resuming (reading already accepted ballots)');<commit_msg>"voters" field now takes an array of email addresses<commit_after>var fs = require('fs');
var util = require('util');
var request = require('request-json');
var winston = require('winston');
var config = require('../config');
var manifest = require('./manifest');
var csCore = require('./csCore.js');
var sendEmail = require('./sendEmail');
var crypto = require('cryptofunc');
var selectUtils = require('selectUtils');

///////////////////////////////////////////////////////////////////////////////////////
// State

var otp_store = {};
var mail_timestamp = {};

var electionID = manifest.hash;
var colSerSigKey = config.signing_key;
var cs = csCore.create(electionID, colSerSigKey);
var openElection = (manifest.voters.length === 0); // emtpy list of voters means that the election is open (everybody can vote)
if (openElection)
    console.log('Empty list of voters => election is open (it ballots from everybody)')
var listOfEligibleVoters = manifest.voters;
var printableElID = makeBreakable(manifest.hash.slice(0,16).toUpperCase()); // only the first 16 hex chars (out of 64, for backward compatibility with SHA-1 in the GUI)

// Map of eligible voters
var eligibleVoters = {};
for (var i=0; i<listOfEligibleVoters.length; ++i) eligibleVoters[listOfEligibleVoters[i]] = true;

//Check for hidden Voters
var votersFileExists = fs.existsSync('./eligibleVoters.json');
if(votersFileExists){
	var votersFile = JSON.parse(fs.readFileSync("./eligibleVoters.json"));
	var listOfHiddenVoters = votersFile.voters;
	for (var i=0; i<listOfHiddenVoters.length; ++i) eligibleVoters[listOfHiddenVoters[i]] = true;
}
	

// Checks if the voter is eligible. In an election is open, then every voter is eligible.
function isEligibleVoter(voter) {
    return  (openElection && validEmail(voter)) || (eligibleVoters.hasOwnProperty(voter) && eligibleVoters[voter]===true);
}

var emailPattern = /^\S+@\S+$/;
var emailNegPattern = /[';\n\r]/;
function validEmail(email) {
    return emailPattern.test(email) && !emailNegPattern.test(email);
}

//  status and opening/closing time
var resultReady = fs.existsSync(config.RESULT_FILE);

// If there is no result yet, but there are some accepted
// ballots, we need to read these ballots to resume the operation:
if (!resultReady && fs.existsSync(config.ACCEPTED_BALLOTS_LOG_FILE)) {
    console.log('Resuming (reading already accepted ballots)');
{'fraction_non_alphanumeric': 0.16920827240442865, 'fraction_numerical': 0.004595780238144976, 'mean_word_length': 4.278941565600882, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2204545', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1451, 'n_words': 417}