Introduce a new logger (modules/logger.js) that prints colorized console output, writes timestamped logs to a file in a logs/ directory, strips ANSI colors for file output, and handles process exit/SIGINT cleanup. Add service stubs (services/security.js, services/storage.js, services/smtp/actions.js, services/smtp/authenticate.js) and a test.js. Add package.json and package-lock.json with runtime deps (colors, dotenv, zod) and dev tooling (eslint, nodemon) to support the new code.
44 lines
922 B
JavaScript
44 lines
922 B
JavaScript
const { z } = require("zod")
|
|
|
|
const LIMITS = {
|
|
MAX_LINE_LENGTH: 512,
|
|
MAX_MAIL_SIZE: 10 * 1024 * 1024,
|
|
TIMEOUT_MS: 30000
|
|
}
|
|
|
|
function validateEmail(email) {
|
|
const schema = z.string().email().max(255)
|
|
const result = schema.safeParse(email)
|
|
return result.success
|
|
}
|
|
|
|
function isLineSafe(line) {
|
|
if (!line || line.length > LIMITS.MAX_LINE_LENGTH) {
|
|
return false
|
|
}
|
|
|
|
const dangerousPattern = /[\0\b\v\f]/
|
|
return !dangerousPattern.test(line)
|
|
}
|
|
|
|
function sanitizePath(input) {
|
|
return input.replace(/[^a-zA-Z0-9_\-]/g, "")
|
|
}
|
|
|
|
function createSizeChecker(maxSize = LIMITS.MAX_MAIL_SIZE) {
|
|
let currentSize = 0
|
|
return function(chunkLength) {
|
|
currentSize += chunkLength
|
|
if (currentSize > maxSize) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
isLineSafe,
|
|
sanitizePath,
|
|
validateEmail,
|
|
createSizeChecker
|
|
} |