@carlgo11/smtp-server
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "@carlgo11/smtp-server", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Simple lightweight SMTP server written in Node.js", | ||
@@ -5,0 +5,0 @@ "main": "src/core/SMTPServer.js", |
import Response from '../models/Response.js'; | ||
import context from '../core/ServerContext.js'; | ||
@@ -18,5 +19,13 @@ let commandHandlers = {}; | ||
handler ? | ||
handler(args, session): | ||
if (handler) { | ||
handler(args, session); | ||
} else { | ||
session.unknownCommands += 1; | ||
if (session.unknownCommands < context.maxUnknownCommands) | ||
session.send(new Response('Command not implemented', 502, [5, 5, 1])); | ||
else { | ||
session.send(new Response('Too many unknown commands.', 421, [4, 7, 0])); | ||
session.socket.end(); | ||
} | ||
} | ||
} |
import context from '../core/ServerContext.js'; | ||
import events from '../core/Event.js'; | ||
import Response from '../models/Response.js'; | ||
import isValidEHLO from '../utils/ValidEHLO.js'; | ||
@@ -15,2 +16,5 @@ export default function EHLO(args, session) { | ||
if(!isValidEHLO(domain)) | ||
return session.send(new Response(null, 501, [5, 5, 2])); | ||
events.emit('EHLO', session, domain); | ||
@@ -17,0 +21,0 @@ |
@@ -38,3 +38,3 @@ import context from '../core/ServerContext.js'; | ||
err: | ||
new Response(null, 451, [4, 3, 0]))); | ||
new Response(null, 451, [4, 1, 1]))); | ||
} |
@@ -10,2 +10,3 @@ import {hostname} from 'os'; | ||
this.logLevel = 'INFO'; | ||
this.maxUnknownCommands = 3; | ||
// Default hooks | ||
@@ -12,0 +13,0 @@ this.onConnect = () => {}; |
@@ -17,5 +17,7 @@ import net from 'net'; | ||
import DATA from '../commands/DATA.js'; | ||
import HELO from '../commands/HELO.js'; | ||
const activeSessions = new Set(); | ||
registerCommand('HELO', HELO); | ||
registerCommand('EHLO', EHLO); | ||
@@ -22,0 +24,0 @@ registerCommand('STARTTLS', STARTTLS); |
const statuses = { | ||
'4.1.1': 'Bad destination mailbox address', | ||
'4.3.0': 'Requested action aborted: local error in processing', | ||
@@ -3,0 +4,0 @@ '5.3.0': 'Transaction failed: internal server error', |
@@ -16,2 +16,3 @@ import os from 'os'; | ||
this.ehlo = null; | ||
this.unknownCommands = 0; | ||
this.mailFrom = null; | ||
@@ -18,0 +19,0 @@ this.rcptTo = []; |
@@ -41,3 +41,4 @@ import context from '../core/ServerContext.js'; | ||
return `${colors[level]}[${level}]${colors.RESET} [${time}]${session}${message}`; | ||
return `${colors[level]}[${level}]${colors.RESET} ${' '.repeat(5 - level.length)}[${time}]${session}${message}`; | ||
} | ||
@@ -44,0 +45,0 @@ |
67239
20
608
3