mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-20 02:36:21 +08:00
v1.0.23
This commit is contained in:
parent
cc54a44f98
commit
292aa14d42
3 changed files with 19 additions and 13 deletions
|
@ -55,7 +55,7 @@ class POP3Connection extends EventEmitter {
|
||||||
tnx: 'send',
|
tnx: 'send',
|
||||||
cid: this._id,
|
cid: this._id,
|
||||||
host: this.remoteAddress
|
host: this.remoteAddress
|
||||||
}, 'S:', (payload.length < 128 ? payload : payload.substr(0, 128) + '... +' + (payload.length - 128) + ' B').replace(/\r?\n/g,'\\n'));
|
}, 'S:', (payload.length < 128 ? payload : payload.substr(0, 128) + '... +' + (payload.length - 128) + ' B').replace(/\r?\n/g, '\\n'));
|
||||||
this.write(payload + '\r\n');
|
this.write(payload + '\r\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,8 @@ class POP3Connection extends EventEmitter {
|
||||||
|
|
||||||
_resetSession() {
|
_resetSession() {
|
||||||
this.session = {
|
this.session = {
|
||||||
state: 'AUTHORIZATION'
|
state: 'AUTHORIZATION',
|
||||||
|
remoteAddress: this.remoteAddress
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "wildduck",
|
"name": "wildduck",
|
||||||
"version": "1.0.22",
|
"version": "1.0.23",
|
||||||
"description": "IMAP server built with Node.js and MongoDB",
|
"description": "IMAP server built with Node.js and MongoDB",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
25
pop3.js
25
pop3.js
|
@ -4,7 +4,7 @@ const config = require('config');
|
||||||
const log = require('npmlog');
|
const log = require('npmlog');
|
||||||
const POP3Server = require('./lib/pop3-server');
|
const POP3Server = require('./lib/pop3-server');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const bcrypt = require('bcryptjs');
|
const UserHandler = require('./lib/user-handler');
|
||||||
const MessageHandler = require('./lib/message-handler');
|
const MessageHandler = require('./lib/message-handler');
|
||||||
const ObjectID = require('mongodb').ObjectID;
|
const ObjectID = require('mongodb').ObjectID;
|
||||||
const db = require('./lib/db');
|
const db = require('./lib/db');
|
||||||
|
@ -12,6 +12,7 @@ const db = require('./lib/db');
|
||||||
const MAX_MESSAGES = 250;
|
const MAX_MESSAGES = 250;
|
||||||
|
|
||||||
let messageHandler;
|
let messageHandler;
|
||||||
|
let userHandler;
|
||||||
|
|
||||||
const serverOptions = {
|
const serverOptions = {
|
||||||
port: config.pop3.port,
|
port: config.pop3.port,
|
||||||
|
@ -35,23 +36,26 @@ const serverOptions = {
|
||||||
},
|
},
|
||||||
|
|
||||||
onAuth(auth, session, callback) {
|
onAuth(auth, session, callback) {
|
||||||
db.database.collection('users').findOne({
|
userHandler.authenticate(auth.username, auth.password, {
|
||||||
username: auth.username
|
protocol: 'POP3',
|
||||||
}, (err, user) => {
|
ip: session.remoteAddress
|
||||||
|
}, (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
if (!result) {
|
||||||
|
return callback();
|
||||||
|
}
|
||||||
|
|
||||||
if (!user || !bcrypt.compareSync(auth.password, user.password)) {
|
if (result.scope === 'master' && result.enabled2fa) {
|
||||||
return callback(null, {
|
// master password not allowed if 2fa is enabled!
|
||||||
message: 'Authentication failed'
|
return callback();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, {
|
callback(null, {
|
||||||
user: {
|
user: {
|
||||||
id: user._id,
|
id: result.user,
|
||||||
username: user.username
|
username: result.username
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -280,6 +284,7 @@ module.exports = done => {
|
||||||
let started = false;
|
let started = false;
|
||||||
|
|
||||||
messageHandler = new MessageHandler(db.database);
|
messageHandler = new MessageHandler(db.database);
|
||||||
|
userHandler = new UserHandler(db.database, db.redis);
|
||||||
|
|
||||||
server.on('error', err => {
|
server.on('error', err => {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue