<commit_before>'use strict';
var net = require('net')
	, util = require('util')
	, EventEmitter = require('events').EventEmitter
	, tls = require('tls')
	, fs = require('fs')
	;

/**
 * connection states
 * @readonly
 * @enum {number}
 */
var state = {
	NOOP: 0
	, CONNECTING: 1
	, USER: 2
	, PASS: 3
	, STAT: 4
	, LIST: 5
	, RETR: 6
	, DELE: 7
	, QUIT: 8
	, RSET: 9
	, TOP: 10
};

/**
 * POP3 client class
 * @param {object} options
 * @param {string} options.hostname
 * @param {number} options.port
 * @constructor
 */
var Client = function(options) {
	EventEmitter.call(this);

	this.debug = false;

	/**
	 * Mail server hostname
	 * @type {string}
	 */
	this.hostname = options.hostname;
	/**
	 * Mail server port
	 * @type {number}
	 */
	this.port = options.port || 110;
	this.username = options.username;
	this.password = <PASSWORD>;
	/**
	 * Connected state
	 * @type {boolean}
	 */
	this.connected = false;
	/**
	 * Use TLS
	 * @type {boolean}
	 */
	this.tls = options.tls || false;
	/**
	 * socket property
	 * @type {null|net.Socket}
	 * @private
	 */
	this._socket = null;
	/**
	 * Command stack
	 * @type {Array}
	 * @private
	 */
	this._queue = [];
	this.mailparser = options.mailparser || false;
	this._command = { cmd: state.NOOP };
	// this.connect()
};

util.inherits(Client, EventEmitter);

/**
 * Data event handler
 * @param {Buffer} data
 */
function onData(data) {
	var err = null
		, succ = ''
		, sData = data.toString()
		;
	if (typeof this.flow === 'undefined') { // if we have first data chunk from server
		if (sData.substr(0, 4) === '-ERR') {
			err = new Error(sData.substring(5, sData.indexOf('\r\n')));
		} else if (sData.substr(0, 3) === '+OK') {
			succ = sData.substring(4, sData.indexOf('\r\n'));
		} else {
			err = new Error(sData);
		}
		// RETR, LIST and TOP are multiline commands
		if (
			this._command.cmd === state.RETR
			|| this._command.cmd === state.LIST && typeof this._command.number === 'undefined'
			|| this._command.cmd === state.TOP
			) {
			if (err) {
				if (this._command.callback) {
					this._command.callback.call(this, err);
				}
				this._command = {cmd: state.NOOP};
				this._runCommand();
			} else {
				data = data.slice(data.indexOf('\r\n') + 2); // extract first line of answer
				this.flow = new Buffer(''); // initialise buffer, all other work is below
			}
		} else if (this._command.cmd === state.USER || this._command.cmd === state.CONNECTING) {
			if (err) {
				this._queue = []; // remove commands from stack
				if (this._command.callback) {
					this._command.callback.call(this, err);
				}
			} else {
				this._command = {cmd: state.NOOP};
				this._runCommand(); // run PASS or USER command
			}
		} else if (this._command.cmd === state.QUIT) {
			this._socket.end();
			this.connected = false;
			if (this._command.callback) {
				this._command.callback.call(this, err);
			}
		} else {
			if (this._command.cmd === state.PASS && !err) {
				this.connected = true;
			} else if (this._command.cmd === state.STAT) {
				succ = succ.split(' ');
				succ = {
					count: parseInt(succ[0])
					, length: parseInt(succ[1])
				}
			}
			if (this._command.callback) {
				this._command.callback.call(this, err, succ);<commit_msg>Fix for nodejs 0.12 which lacks .indexOf method in Buffer class<commit_after>'use strict';
var net = require('net')
	, util = require('util')
	, EventEmitter = require('events').EventEmitter
	, tls = require('tls')
	, fs = require('fs')
	;

/**
 * connection states
 * @readonly
 * @enum {number}
 */
var state = {
	NOOP: 0
	, CONNECTING: 1
	, USER: 2
	, PASS: 3
	, STAT: 4
	, LIST: 5
	, RETR: 6
	, DELE: 7
	, QUIT: 8
	, RSET: 9
	, TOP: 10
};

/**
 * POP3 client class
 * @param {object} options
 * @param {string} options.hostname
 * @param {number} options.port
 * @constructor
 */
var Client = function(options) {
	EventEmitter.call(this);

	this.debug = false;

	/**
	 * Mail server hostname
	 * @type {string}
	 */
	this.hostname = options.hostname;
	/**
	 * Mail server port
	 * @type {number}
	 */
	this.port = options.port || 110;
	this.username = options.username;
	this.password = options.password;
	/**
	 * Connected state
	 * @type {boolean}
	 */
	this.connected = false;
	/**
	 * Use TLS
	 * @type {boolean}
	 */
	this.tls = options.tls || false;
	/**
	 * socket property
	 * @type {null|net.Socket}
	 * @private
	 */
	this._socket = null;
	/**
	 * Command stack
	 * @type {Array}
	 * @private
	 */
	this._queue = [];
	this.mailparser = options.mailparser || false;
	this._command = { cmd: state.NOOP };
	// this.connect()
};

util.inherits(Client, EventEmitter);

/**
 * Data event handler
 * @param {Buffer} data
 */
function onData(data) {
	var err = null
		, succ = ''
		, sData = data.toString()
		;
	if (typeof this.flow === 'undefined') { // if we have first data chunk from server
		if (sData.substr(0, 4) === '-ERR') {
			err = new Error(sData.substring(5, sData.indexOf('\r\n')));
		} else if (sData.substr(0, 3) === '+OK') {
			succ = sData.substring(4, sData.indexOf('\r\n'));
		} else {
			err = new Error(sData);
		}
		// RETR, LIST and TOP are multiline commands
		if (
			this._command.cmd === state.RETR
			|| this._command.cmd === state.LIST && typeof this._command.number === 'undefined'
			|| this._command.cmd === state.TOP
			) {
			if (err) {
				if (this._command.callback) {
					this._command.callback.call(this, err);
				}
				this._command = {cmd: state.NOOP};
				this._runCommand();
			} else {
				data = data.slice(sData.indexOf('\r\n') + 2); // extract first line of answer
				this.flow = new Buffer(''); // initialise buffer, all other work is below
			}
		} else if (this._command.cmd === state.USER || this._command.cmd === state.CONNECTING) {
			if (err) {
				this._queue = []; // remove commands from stack
				if (this._command.callback) {
					this._command.callback.call(this, err);
				}
			} else {
				this._command = {cmd: state.NOOP};
				this._runCommand(); // run PASS or USER command
			}
		} else if (this._command.cmd === state.QUIT) {
			this._socket.end();
			this.connected = false;
			if (this._command.callback) {
				this._command.callback.call(this, err);
			}
		} else {
			if (this._command.cmd === state.PASS && !err) {
				this.connected = true;
			} else if (this._command.cmd === state.STAT) {
				succ = succ.split(' ');
				succ = {
					count: parseInt(succ[0])
					, length: parseInt(succ[1])
				}
			}
			if (this._command.callback) {
				this._command.callback.call(this, err, succ);
{'fraction_non_alphanumeric': 0.17686969930609098, 'fraction_numerical': 0.008172706245181188, 'mean_word_length': 2.8288075560802834, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1301312', 'n_tokens_mistral': 2595, 'n_tokens_neox': 2267, 'n_words': 545}