syncova-ticket/server/recipients.js
Weapie 2974c7eb65
All checks were successful
Tests und Docker-Image / Tests und Frontend-Build (push) Successful in 46s
Tests und Docker-Image / Leeres Produktionsimage bauen und veröffentlichen (push) Successful in 1m49s
Add CC and BCC replies, customer contact editing and global full-text search
2026-11-04 11:27:08 +01:00

33 lines
1.1 KiB
JavaScript

import { HttpError } from './service.js'
export const validEmail = (value) =>
typeof value === 'string' &&
value.length <= 254 &&
/^[a-z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?\.[a-z]{2,63}$/i.test(value)
export function replyCopies(data, customer) {
const used = new Set([customer.toLowerCase()])
const result = {}
for (const field of ['cc', 'bcc']) {
const value = data[field] ?? []
const entries = typeof value === 'string' ? value.split(/[;,]/).filter((v) => v.trim()) : value
if (!Array.isArray(entries) || entries.length > 20)
throw new HttpError(400, `${field.toUpperCase()}: höchstens 20 E-Mail-Adressen angeben.`)
result[field] = []
for (const entry of entries) {
if (typeof entry !== 'string' || /[\r\n]/.test(entry) || !validEmail(entry.trim()))
throw new HttpError(
400,
`${field.toUpperCase()}: gültige E-Mail-Adressen mit Komma oder Semikolon trennen.`,
)
const email = entry.trim(),
key = email.toLowerCase()
if (!used.has(key)) {
result[field].push(email)
used.add(key)
}
}
}
return result
}