Skip to content

Commit

Permalink
add coveralls, eslint and update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Tiertant committed Apr 27, 2018
1 parent f989a7a commit dc50d8c
Show file tree
Hide file tree
Showing 11 changed files with 681 additions and 650 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/
26 changes: 21 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
{
"root": true,
"rules": {
"no-unused-vars": [0],
"no-undef": [0]
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": "eslint:recommended",
"env": {
"es6": true,
"node": true
},
"rules": {
"indent": [1, 2, { "SwitchCase": 1 }],
"no-undef": 1,
"no-console": 1,
"keyword-spacing": 1,
"no-trailing-spaces": 1,
"no-unused-vars": 1,
"no-redeclare": 1,
"no-unused-labels": 1,
"no-unreachable": 1,
"semi": [1, "always"],
"no-extra-semi": 1,
"no-fallthrough": 1,
"no-constant-condition": 1,
"no-mixed-spaces-and-tabs": 1,
"no-case-declarations": 1
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.DS_Store
*.log
.nyc_output/
package-lock.json
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
node_modules
.gitignore
package-lock.json
test
.nyc_output/
92 changes: 46 additions & 46 deletions connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ const TEN_MINUTES = 10 * 60 * 1000;
const States = require('./states');

var POP3Connnection = module.exports = function(server, socket, connection_id) {
debug('connection ' + connection_id, socket.remoteAddress);
var self = this;
this.socket = socket;
this.server = server;
this.connection_id = connection_id;
this.state = States.AUTHENTICATION;
this.UID = this.connection_id + "." + (+new Date());
this.response("+OK POP3 Server ready <" + self.UID + "@" + self.server_name + ">");
}
debug('connection ' + connection_id, socket.remoteAddress);
var self = this;
this.socket = socket;
this.server = server;
this.connection_id = connection_id;
this.state = States.AUTHENTICATION;
this.UID = this.connection_id + "." + (+new Date());
this.response("+OK POP3 Server ready <" + self.UID + "@" + self.server_name + ">");
};

POP3Connnection.prototype.response = function response(message) {
let resBuffer;
if (message.toString) {
message = message.toString();
}
if (typeof message == "string") {
debug('responding', this.user, message.substring(0, 60));
resBuffer = new Buffer(message + "\r\n", "utf-8");
} else {
resBuffer = Buffer.concat([message, new Buffer("\r\n", "utf-8")]);
}
let resBuffer;
if (message.toString) {
message = message.toString();
}
if (typeof message == "string") {
debug('responding', this.user, message.substring(0, 60));
resBuffer = new Buffer(message + "\r\n", "utf-8");
} else {
resBuffer = Buffer.concat([message, new Buffer("\r\n", "utf-8")]);
}

this.socket.write(resBuffer);
}
this.socket.write(resBuffer);
};

/**
* POP3Server#destroy() -> undefined
Expand All @@ -36,33 +36,33 @@ POP3Connnection.prototype.response = function response(message) {
* do this by itself)
**/
POP3Connnection.prototype.destroy = function destroy() {
const remoteAddress = this.socket ? this.socket.remoteAddress : null;
debug('destroying connection', this.user, this.connection_id, remoteAddress);
const remoteAddress = this.socket ? this.socket.remoteAddress : null;
debug('destroying connection', this.user, this.connection_id, remoteAddress);

if (this.timer) {
clearTimeout(this.timer);
}
this.timer = null;
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = null;

if (this.server.connected_users[this.user]) {
delete this.server.connected_users[this.user];
}
if (this.server.connected_users[this.user]) {
delete this.server.connected_users[this.user];
}

if (this.socket && this.socket.end) {
this.socket.end();
}
}
if (this.socket && this.socket.end) {
this.socket.end();
}
};

// kill client after inactivity
POP3Connnection.prototype.updateTimeout = function () {
if (this.timer) clearTimeout(this.timer);
this.timer = setTimeout((function () {
if (!this.socket)
return;
if (this.state == States.TRANSACTION) {
this.state = States.UPDATE;
}
debug("Connection closed for client inactivity", this.user);
this.destroy();
}).bind(this), TEN_MINUTES);
}
POP3Connnection.prototype.updateTimeout = function() {
if (this.timer) clearTimeout(this.timer);
this.timer = setTimeout((function() {
if (!this.socket)
return;
if (this.state == States.TRANSACTION) {
this.state = States.UPDATE;
}
debug("Connection closed for client inactivity", this.user);
this.destroy();
}).bind(this), TEN_MINUTES);
};
142 changes: 71 additions & 71 deletions messagestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,111 +6,111 @@ var debug = require('debug')('messagestore');
* register, read and removeDeleted should be overriden on pop3server store option.
*/
var MessageStore = module.exports = function(connection) {
debug('MessageStore created', connection.user);
this.user = connection.user;
this.messages = [];
this.deletedMessages = [];
this.connection = connection;
debug('MessageStore created', connection.user);
this.user = connection.user;
this.messages = [];
this.deletedMessages = [];
this.connection = connection;
};

MessageStore.prototype.register = function noopRegister(cb) {
debug('register has not been overridden by your implementation of MessageStore');
cb();
debug('register has not been overridden by your implementation of MessageStore');
cb();
};

MessageStore.prototype.read = function noopRead(uid, cb) {
debug('read has not been overridden by your implementation of MessageStore');
cb(null, '');
debug('read has not been overridden by your implementation of MessageStore');
cb(null, '');
};

MessageStore.prototype.removeDeleted = function noopRemoveDeleted(deleted, cb) {
debug('removeDeleted has not been overridden by your implementation of MessageStore');
cb();
debug('removeDeleted has not been overridden by your implementation of MessageStore');
cb();
};

MessageStore.prototype.addMessage = function (uid, length) {
this.messages.push({uid: uid, length: length});
debug('addMessage', length, uid, this.user);
MessageStore.prototype.addMessage = function(uid, length) {
this.messages.push({ uid: uid, length: length });
debug('addMessage', length, uid, this.user);
};

MessageStore.prototype.stat = function (callback) {
var count = 0;
var size = 0;
this.messages.forEach(function(msg){
if (!msg.deleted) {
count++;
size += msg.length;
}
});
debug('stat', this.user, size);
callback(null, count, size);
MessageStore.prototype.stat = function(callback) {
var count = 0;
var size = 0;
this.messages.forEach(function(msg) {
if (!msg.deleted) {
count++;
size += msg.length;
}

});
debug('stat', this.user, size);
callback(null, count, size);
};

MessageStore.prototype.list = function (_msg, callback) {
debug('list', this.user, _msg);
var msg = _msg - 1;
if (msg >= 0 && typeof msg === 'number') {
if (!this.messages[msg]) {
return callback(null, null);
}
return callback(_msg + ' ' + this.messages[msg].length);
MessageStore.prototype.list = function(_msg, callback) {
debug('list', this.user, _msg);
var msg = _msg - 1;
if (msg >= 0 && typeof msg === 'number') {
if (!this.messages[msg]) {
return callback(null, null);
}
var result = this.messages.map(
(m, index) => (index + 1) + ' ' + m.length
);
callback(null, result);
return callback(_msg + ' ' + this.messages[msg].length);
}
var result = this.messages.map(
(m, index) => (index + 1) + ' ' + m.length
);
callback(null, result);
};
/**
* Unique ID List
* @param {int} _msg - index +1, optional to only respond with one
* @param {Function} callback [description]
* @return {[type]} [description]
*/
MessageStore.prototype.uidl = function (_msg, callback) {
debug('uidl', this.user, _msg);
var msg = _msg - 1;
if (msg >= 0 && typeof msg === 'number') {
if (!this.messages[msg]) {
return callback(null, null);
}
return callback(null, _msg + ' ' + this.messages[msg].uid);
MessageStore.prototype.uidl = function(_msg, callback) {
debug('uidl', this.user, _msg);
var msg = _msg - 1;
if (msg >= 0 && typeof msg === 'number') {
if (!this.messages[msg]) {
return callback(null, null);
}
var result = this.messages.map(
(m, index) => (index + 1) + ' ' + m.uid
);
callback(null, result);
return callback(null, _msg + ' ' + this.messages[msg].uid);
}
var result = this.messages.map(
(m, index) => (index + 1) + ' ' + m.uid
);
callback(null, result);
};
/**
* Retrieve the message
* @param {int} _msg - index +1 of the message (0 is not allowed in pop3 protocol)
* @param {Function} callback (err, Message)
*/
MessageStore.prototype.retr = function retr(_msg, callback) {
var msg = _msg - 1;
debug('retr', this.user, _msg);
var invalidIndex = isNaN(msg) || !this.messages[msg];
if (invalidIndex) {
return callback(null, false);
}
this.read(this.messages[msg].uid, callback);
var msg = _msg - 1;
debug('retr', this.user, _msg);
var invalidIndex = isNaN(msg) || !this.messages[msg];
if (invalidIndex) {
return callback(null, false);
}
this.read(this.messages[msg].uid, callback);
};

MessageStore.prototype.dele = function dele(_msg, callback) {
var msg = _msg - 1;
debug('dele', this.user, msg);
var invalidIndex = isNaN(msg) || !this.messages[msg];
if (invalidIndex) {
return callback(null, false);
}
// not actually removed at this time - will be removed when connection closes
this.messages[msg].deleted = true;
return callback(null, true);
var msg = _msg - 1;
debug('dele', this.user, msg);
var invalidIndex = isNaN(msg) || !this.messages[msg];
if (invalidIndex) {
return callback(null, false);
}
// not actually removed at this time - will be removed when connection closes
this.messages[msg].deleted = true;
return callback(null, true);
};

MessageStore.prototype.rset = function () {
debug('rset', this.user);
this.messages.forEach(function(msg, index){
delete msg.deleted;
});
MessageStore.prototype.rset = function() {
debug('rset', this.user);
this.messages.forEach(function(msg) {
delete msg.deleted;
});
};
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "POP3 server for node.js",
"main": "server.js",
"scripts": {
"test": "mocha -R spec tests/"
"test": "nyc mocha --timeout=10000 --exit",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint ./"
},
"repository": {
"type": "git",
Expand All @@ -15,12 +17,16 @@
"node": ">=4.0.0"
},
"dependencies": {
"debug": "^2.2.0"
"debug": "^3.1.0"
},
"devDependencies": {
"chai": "~3.5.0",
"chai": "~4.1.2",
"coveralls": "^3.0.0",
"eslint": "~3.11.1",
"istanbul": "0.4.5",
"mailx": "~0.0.11",
"mocha": "~3.0.2",
"mailcomposer": "~0.1.29"
"mocha": "~5.1.1",
"nodemailer": "~4.6.4",
"nyc": "~11.7.1"
}
}
Loading

0 comments on commit dc50d8c

Please sign in to comment.