Ignore email tags in inbound mail (#8451)

Signed-off-by: Nikolay Chunosov <Chunosov.N@gmail.com>
This commit is contained in:
Chunosov 2025-04-03 16:30:34 +07:00 committed by GitHub
parent cacb6036ee
commit 4a7ecf44d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 4 deletions

View File

@ -38,7 +38,7 @@
function validateName (name: string): boolean {
const n = name.trim()
return n.length >= mailboxOptions.minNameLength && n.length <= mailboxOptions.maxNameLength
return n.length >= mailboxOptions.minNameLength && n.length <= mailboxOptions.maxNameLength && !name.includes('+')
}
async function createMailbox (): Promise<void> {

View File

@ -17,11 +17,12 @@
"_phase:bundle": "rushx bundle",
"_phase:docker-build": "rushx docker:build",
"_phase:docker-staging": "rushx docker:staging",
"bundle": "node ../../../common/scripts/esbuild.js --external=ws",
"bundle": "node ../../../common/scripts/esbuild.js --external=ws --external=jsdom",
"docker:build": "../../../common/scripts/docker_build.sh hardcoreeng/inbound-mail",
"docker:staging": "../../../common/scripts/docker_tag.sh hardcoreeng/inbound-mail staging",
"docker:abuild": "docker build -t hardcoreeng/inbound-mail . --platform=linux/arm64 && ../../../common/scripts/docker_tag_push.sh hardcoreeng/inbound-mail",
"docker:push": "../../../common/scripts/docker_tag.sh hardcoreeng/inbound-mail",
"run-bundle": "rushx bundle --to @hcengineering/pod-inbound-mail && cross-env NODE_ENV=production node --inspect bundle/bundle.js",
"run-local": "ts-node src/index.ts",
"format": "format src",
"_phase:build": "compile transpile src",
@ -37,6 +38,7 @@
"@types/jest": "^29.5.5",
"@types/node": "~20.11.16",
"@types/turndown": "^5.0.5",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"cross-env": "~7.0.3",
@ -66,7 +68,6 @@
"@hcengineering/mail": "^0.6.0",
"@hcengineering/server-core": "^0.6.1",
"@hcengineering/server-storage": "^0.6.0",
"@types/uuid": "^8.3.1",
"cors": "^2.8.5",
"dotenv": "~16.0.0",
"eml-parse-js": "^1.2.0-beta.0",

View File

@ -56,7 +56,7 @@ export async function handleMtaHook (req: Request, res: Response, ctx: MeasureCo
from.name = extractContactName(ctx, fromHeader)
}
const tos = mta.envelope.to.map((to) => ({ address: to.address, name: '' }))
const tos = mta.envelope.to.map((to) => ({ address: stripTags(to.address), name: '' }))
const toHeader = mta.message.headers.find((header) => header[0] === 'To')?.[1]
if (toHeader !== undefined) {
for (const part of toHeader.split(',')) {
@ -192,3 +192,13 @@ function decodeMimeWord (ctx: MeasureContext, text: string): string {
}
})
}
function stripTags (email: string): string {
const [name, domain] = email.split('@')
const tagStart = name.indexOf('+')
if (tagStart === -1) {
return email
}
const clearName = name.substring(0, tagStart)
return `${clearName}@${domain}`
}