{"record":{"id":"ad8bf0bf99eaefd6","repo":"hcengineering/platform","slug":"platform-status-mailboxerror","errorCode":"platform.status.MailboxError","errorMessage":"throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'invalid-name' }))","messagePattern":"throw new PlatformError\\(new Status\\(Severity\\.ERROR, platform\\.status\\.MailboxError, (.+?)\\)\\)","errorType":"exception","errorClass":"PlatformError","httpStatus":400,"severity":"error","filePath":"server/account/src/operations.ts","lineNumber":2602,"sourceCode":"  params: {\n    name: string\n    domain: string\n  }\n): Promise<{ mailbox: string, socialId: PersonId }> {\n  const { name, domain } = params\n\n  if (name == null || name === '' || domain == null || domain === '') {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.BadRequest, {}))\n  }\n\n  const { account } = decodeTokenVerbose(ctx, token)\n  const normalizedName = cleanEmail(name)\n  const normalizedDomain = cleanEmail(domain)\n  const mailbox = normalizedName + '@' + normalizedDomain\n  const opts = await getMailboxOptions(ctx, db, branding, token)\n\n  if (normalizedName.length === 0 || normalizedDomain.length === 0 || !isEmail(mailbox)) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'invalid-name' }))\n  }\n  if (!opts.availableDomains.includes(normalizedDomain)) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'domain-not-found' }))\n  }\n  if (normalizedName.length < opts.minNameLength || normalizedName.length > opts.maxNameLength) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'name-rules-violated' }))\n  }\n\n  if ((await db.mailbox.findOne({ mailbox })) !== null) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'mailbox-exists' }))\n  }\n  const mailboxes = await db.mailbox.find({ accountUuid: account })\n  if (mailboxes.length >= opts.maxMailboxCount) {\n    throw new PlatformError(new Status(Severity.ERROR, platform.status.MailboxError, { reason: 'mailbox-count-limit' }))\n  }\n\n  await db.mailbox.insertOne({ accountUuid: account, mailbox })\n  await db.mailboxSecret.insertOne({ mailbox, secret: generatePassword() })","sourceCodeStart":2584,"sourceCodeEnd":2620,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/operations.ts#L2584-L2620","documentation":"createMailbox throws MailboxError with reason 'invalid-name' when, after cleaning, the name or domain normalizes to an empty string or the composed mailbox fails the isEmail check. Unlike the earlier BadRequest, the raw inputs were present but did not form a valid email address.","triggerScenarios":"name contains only characters stripped by cleanEmail (e.g. '@', spaces), domain is malformed, or the combination 'name@domain' is not a syntactically valid email.","commonSituations":"User enters a full email ('user@x.com') in the name field, producing 'user@x.com@domain'; name made entirely of illegal characters; domain with typos like 'com' or 'domain .com'.","solutions":["Pass only the local part (no '@') as name and a valid domain separately","Check the composed name@domain with an email regex before calling","Strip/reject characters that cleanEmail will remove"],"exampleFix":"// before\nawait createMailbox(ctx, db, branding, token, { name: 'john doe@x.com', domain: 'example.com' })\n// after\nawait createMailbox(ctx, db, branding, token, { name: 'john.doe', domain: 'example.com' })","handlingStrategy":"validation","validationCode":"const emailRe = /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/\nfunction validMailboxShape(name, domain) {\n  const n = name.replace(/[^a-z0-9._-]/gi, '')\n  return n.length > 0 && domain.length > 0 && emailRe.test(`${n}@${domain}`) && !name.includes('@')\n}","typeGuard":"function isValidMailboxInput(p: { name: string, domain: string }): boolean {\n  return p.name.length > 0 && p.domain.length > 0 && /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(`${p.name}@${p.domain}`)\n}","tryCatchPattern":"try {\n  return await createMailbox(ctx, db, branding, token, params)\n} catch (err) {\n  if (getErrorReason(err) === 'invalid-name') {\n    throw new InvalidMailboxName('name/domain must form a valid email after cleaning')\n  } throw err\n}","preventionTips":["Never pass a full email address in the name field","Pre-validate with the same email regex the server uses (isEmail)","Reject names consisting only of characters cleanEmail strips"],"tags":["mailbox","validation","email-format"],"backgroundTag":"mailbox-invalid-name","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}