Repository navigation
fix(email-testing-inbox): prefer the real code when an email has several numbers - #492
Merged
Merged
Conversation
…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.
🟢 Tier S · Ready to merge
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.
📂 Walkthrough · 4
Reviewed |
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.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the code that
node/email-testing-inboxextracts from an email. An email with both a 5-digit number and the code482913showed the 5-digit number as its code in Catchall.extractCodereturned 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:
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 testruns the newtest/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.55123. The other 5 pass on both.prettier --check .andnode --checkon thesrcfiles pass.inboxfunction throughcreateTemplateDeploymentwithtype: branch, emails went through edge's SMTP gateway. "Order 55123: verify your email" with "Your verification code is 482913." stored482913. With the1.5.0build active instead, the same email stored55124. "Account 55123 is almost ready. Your security code is 482913." also stored482913.Related PRs and Issues
1.5.0today. It picks up this fix once it's released and the site'sFUNCTION_TEMPLATE_TAGnames the new tag. Functions already deployed keep the old extractor until they're redeployed.Have you read the Contributing Guidelines on issues?
Yes.