Skip to content

fix(email-testing-inbox): prefer the real code when an email has several numbers - #492

Merged
atharvadeosthale merged 1 commit into
mainfrom
fix/email-testing-inbox-code-extraction
Nov 6, 2026
Merged

atharvadeosthale merged 1 commit into
mainfrom
fix/email-testing-inbox-code-extraction

Conversation

@atharvadeosthale

@atharvadeosthale atharvadeosthale commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Fixes the code that node/email-testing-inbox extracts from an email. An email with both a 5-digit number and the code 482913 showed the 5-digit number as its code in Catchall.

extractCode returned the first code-shaped value it met near code wording. A number in the subject, such as "Order 55123: verify your email", or a number between the wording and the code won over the code itself.

It now scores each code-shaped value and returns the best one:

  1. Wording right before the value: "code: 482913", "your code is 482913", "OTP 482913".
  2. A line that's only the code.
  3. Code wording on the same line.
  4. Code wording in the two lines above.

A 6-digit value wins a tie, and so does the earlier value. A value still counts only near code wording, or anywhere when the subject promises a code, so an email without code wording still has no code.

Test Plan

  • npm test runs the new test/extract.test.js (node --test, 8 cases): the code against a number in the subject, a number between the wording and the code, and a 5-digit number on the same line. It also keeps a 5-digit code right after "code:", a code on its own line, a mixed code (K7Q-2XM), and skips years, prices and percentages. Without code wording, it finds nothing.
  • The 3 cases for this bug fail on the code before this change, each returning 55123. The other 5 pass on both.
  • prettier --check . and node --check on the src files pass.
  • On a local Cloud stack (Cloud and edge on a dev box), with Catchall deployed and this branch deployed as its inbox function through createTemplateDeployment with type: branch, emails went through edge's SMTP gateway. "Order 55123: verify your email" with "Your verification code is 482913." stored 482913. With the 1.5.0 build active instead, the same email stored 55124. "Account 55123 is almost ready. Your security code is 482913." also stored 482913.

Related PRs and Issues

  • Catchall (appwrite/templates-for-sites) deploys this function from a release tag, 1.5.0 today. It picks up this fix once it's released and the site's FUNCTION_TEMPLATE_TAG names the new tag. Functions already deployed keep the old extractor until they're redeployed.

Have you read the Contributing Guidelines on issues?

Yes.

…ral numbers

The extractor returned the first code-shaped value near code wording, so
an order or account number in the subject, or between the wording and
the code, won over the code itself. It now scores each value: wording
right before it counts most, then a line that's only the code, the same
line and the two lines above. A 6-digit value wins a tie. Adds node:test
cases for these and for the behaviour that stays.
@appwrite

appwrite Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The ranking handles the described competing-number cases, and the new tests exercise the key selection behaviors.

This change updates email code extraction to rank all code-shaped values by nearby wording, standalone placement, and digit length. It also adds focused extractor tests and documents the selection behavior in the template README.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
node/email-testing-inbox/README.md Documents how code candidates are prioritized.
node/email-testing-inbox/package.json Adds a Node test script.
node/email-testing-inbox/src/extract.js Scores code-shaped candidates and returns the highest-ranked value.
node/email-testing-inbox/test/extract.test.js Covers competing numbers, supported code formats, and false-positive exclusions.

Reviewed 5bb4304 · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@atharvadeosthale
atharvadeosthale merged commit 0508154 into main Nov 6, 2026
28 checks passed
atharvadeosthale added a commit to appwrite/templates-for-sites that referenced this pull request Nov 6, 2026
… 1.5.1

1.5.1 has the extractor fix from appwrite/templates#492: when an email
has several numbers, the code next to code wording wins, and a 6-digit
value wins a tie, instead of the first number found.
atharvadeosthale added a commit to appwrite/templates-for-sites that referenced this pull request Nov 6, 2026
)

* fix(email-testing): send the project ID when creating the realtime JWT

client.call() sends only the headers it's given plus the client's own,
and node-appwrite 31.1.0 doesn't keep the project ID among those. The
JWT request went out without X-Appwrite-Project, so Appwrite treated it
as a Console request and rejected the site's origin with 403 Invalid
Origin, and the live inbox stayed on Connecting.

* fix(email-testing): one realtime JWT per tab, and back off a socket that keeps dropping

- The backoff reset as soon as Appwrite confirmed a subscription, so a
  socket closed soon after subscribing reconnected about once a second,
  each time refetching the inbox and, after a 1008, making a new JWT.
  The backoff now starts over only after a socket stays live a minute.
- Each time the inbox mounted, it asked for a new JWT. The JWT now lives
  in the app layout and is reused while it has time left, so moving
  between pages doesn't make new ones. Signing out leaves the layout and
  drops it.

Rotation stays at one JWT about every 13 minutes per open tab.

* fix(email-testing): deploy the inbox function from appwrite/templates 1.5.1

1.5.1 has the extractor fix from appwrite/templates#492: when an email
has several numbers, the code next to code wording wins, and a 6-digit
value wins a tie, instead of the first number found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant