mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-07 00:17:37 +08:00
80 lines
2.6 KiB
JavaScript
80 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
let packageInfo = require('../../../package');
|
|
let imapHandler = require('../handler/imap-handler');
|
|
|
|
let allowedKeys = ['name', 'version', 'os', 'os-version', 'vendor', 'support-url', 'address', 'date', 'command', 'arguments', 'environment'];
|
|
|
|
module.exports = {
|
|
schema: [{
|
|
name: 'id',
|
|
type: ['null', 'array']
|
|
}],
|
|
handler(command, callback) {
|
|
let clientId = {};
|
|
let serverId = {};
|
|
let serverIdList = [];
|
|
let key = false;
|
|
let maxKeyLen = 0;
|
|
|
|
if (this._server.options.id && typeof this._server.options.id === 'object') {
|
|
Object.keys(this._server.options.id).forEach(key => {
|
|
serverId[key] = this._server.options.id[key];
|
|
});
|
|
} else {
|
|
serverId.name = packageInfo.name;
|
|
serverId.version = packageInfo.version;
|
|
serverId.vendor = 'Kreata';
|
|
}
|
|
|
|
// Log ID information proviced by the client
|
|
if (Array.isArray(command.attributes[0])) {
|
|
command.attributes[0].forEach(val => {
|
|
if (key === false) {
|
|
key = (val.value || '').toString().toLowerCase().trim();
|
|
} else {
|
|
if (allowedKeys.indexOf(key) >= 0) {
|
|
clientId[key] = (val.value || '').toString();
|
|
maxKeyLen = Math.max(maxKeyLen, key.length);
|
|
}
|
|
key = false;
|
|
}
|
|
});
|
|
|
|
this._server.logger.info('[%s] Client identification data received', this.id);
|
|
|
|
Object.keys(clientId).
|
|
sort((a, b) => (allowedKeys.indexOf(a) - allowedKeys.indexOf(b))).
|
|
forEach(key => {
|
|
this._server.logger.info('[%s] %s%s: %s', this.id, key, new Array(maxKeyLen - key.length + 1).join(' '), clientId[key]);
|
|
});
|
|
}
|
|
|
|
// Create response ID serverIdList
|
|
if (Object.keys(serverId).length) {
|
|
Object.keys(serverId).forEach(key => {
|
|
serverIdList.push({
|
|
type: 'string',
|
|
value: (key || '').toString()
|
|
});
|
|
serverIdList.push({
|
|
type: 'string',
|
|
value: (serverId[key] || '').toString()
|
|
});
|
|
});
|
|
}
|
|
|
|
this.send(imapHandler.compiler({
|
|
tag: '*',
|
|
command: 'ID',
|
|
attributes: serverIdList.length ? [serverIdList] : {
|
|
type: 'atom',
|
|
value: 'NIL'
|
|
}
|
|
}));
|
|
|
|
callback(null, {
|
|
response: 'OK'
|
|
});
|
|
}
|
|
};
|