Skip to main content
Email local parts can contain apostrophes and equals signs, and the same characters also separate labels from values. Text scanning resolves that by treating a leading identifier= prefix and a wrapping opening quote as label syntax, so email=alice@example.com reports alice@example.com by default and the authored text around it is untouched. Text mode also trims query/field delimiters (&, ?, ;, |), dotted keys such as user.email=, and opening *, {, or URL slashes. A dot in front of an address never drops it, in any format: the match starts after the dot or dots, so see [1].alice@example.com, me...alice@example.com and .alice@example.com find alice@example.com. For bob..x@example.com the finding is x@example.com; the text before the doubled dot is not part of the span. A dot that follows other local-part punctuation stays inside the span with that punctuation: in text mode EMAIL='.alice@example.com' finds '.alice@example.com and =.alice@example.com finds =.alice@example.com. Text-mode field/label refinement applies as well: bob..x|alice@example.com and .email=.alice@example.com find alice@example.com. Explicit ENV/SQL slices keep field punctuation in the value, so EMAIL=bob..x|alice@example.com finds x|alice@example.com. A dot directly before the @ (alice.@example.com) is still not an address. Unicode letters and digits are accepted in both the local part and domain, so jörg@müller.de retains its full span. Use an explicit source format when mailbox punctuation is part of a field value. Inner = stays in the local part: EMAIL=customer=tag@example.com reports customer=tag@example.com. format: "env" and format: "sql" remain available for documents where the whole scan should follow one source syntax, including the parts of a value that text mode leaves alone. This setting changes email boundaries only; other detectors keep their existing behavior. It does not validate the file or guarantee syntax preservation for every entity type or SQL dialect.

Addresses next to other scripts

Unicode letters are valid in addresses, and text in many languages is written without spaces, so the letters around an address cannot all belong to it. In text that contains non-ASCII letters, a match is narrowed as follows:
  • A domain made of ASCII or accented-Latin labels ends at the first letter of another script in its last label: alice@example.comです reports alice@example.com.
  • A domain ends at its first non-ASCII letter when another address begins there: alice@example.comとbob@example.net and alice@example.comébob@example.net each report two addresses. With an accented Latin letter the letter is reported with the second address (ébob@example.net), because it could belong to it.
  • When a non-Latin domain runs into the next address with no such point (用户@例子.中文网bob@example.net), the trailing ASCII letters go to the second address. If there are none, the two addresses are reported as one span, so the second domain is always covered.
  • In front of an ASCII or accented-Latin domain, the local part starts after the last letter of another script: メールはalice@example.com reports alice@example.com, so a sentence and the SSN, card or phone number in it are not covered by the EMAIL finding. 用户alice@example.com is therefore reported as alice@example.com.
Addresses such as 用户@例子.广告, jörg@müller.de, josé@example.com, and joséalice@example.com each report their full span. A local part that ends in a non-Latin script (用户@example.com) or belongs to a non-Latin domain is not narrowed, since nothing marks where it starts; in unspaced text such a finding can still include the words before it. The full-width at sign @ and full-width dot . are not treated as address syntax. ASCII-only text is unaffected. These rules deliberately narrow some mixed-script addresses as well as prose. δοκιμήtest@example.com reports test@example.com, leaving δοκιμή visible. alice@example.coм (a Cyrillic final м) reports alice@example.co, leaving that final letter visible. The scanner cannot distinguish those valid address shapes from surrounding unspaced text. Complete coverage of every mixed-script mailbox is therefore not guaranteed.

Usage

Rust uses ScanConfig::new().with_format(ScanFormat::Env) or ScanFormat::Sql. The serialized configuration accepts exactly "text", "env", and "sql"; invalid types or values report /format (or /scan/format in the combined envelope). Omission is equivalent to "text". Locale and UUID settings can be combined with format. Structured scanning applies the selected format to each string leaf; supply it only when those strings contain source text.

Environment assignments

Recognized assignments begin at the start of a line, after optional horizontal whitespace and export. Keys use [A-Za-z_][A-Za-z0-9_]*, with optional whitespace around the first =. Only that first delimiter separates the key and value: EMAIL=customer=tag@example.com finds customer=tag@example.com. A value beginning with a single or double quote is scanned inside the enclosing quotes. Values may span lines. Single quotes are literal; backslash escapes skip the following source character when locating a double-quoted value’s closing delimiter. Unquoted values retain apostrophes, equals signs, and other supported local-part characters. A # at the start of an unquoted region or after whitespace starts a comment; person#tag@example.com remains a complete address. Comments are also scanned for emails, preserving their comment marker. Lines that do not match the assignment grammar use ordinary text email matching. An unterminated quoted value is scanned through EOF, preserving its opening quote. Core does not perform interpolation, shell evaluation, or escape decoding.

SQL source

Single-quoted string literals and double-quoted identifiers are scanned inside their enclosing delimiters. A doubled delimiter is an escape inside the same source region. Line comments (--) and block comments (/* ... */, including nested comments) are scanned separately, preserving their comment markers; quotes inside comments do not alter subsequent string boundaries. Findings describe the original source, including escapes. For example, 'o''connor=tag@example.com' finds o''connor=tag@example.com and redacts to '[EMAIL]'. Matching and allowlists use that raw source spelling, rather than the decoded database value. Byte, code-point, and JavaScript UTF-16 ranges refer to the original input. No normalization or decoded-value offset mapping occurs. An unterminated quoted region is scanned through EOF, preserving its opening delimiter. SQL backslash escapes, PostgreSQL dollar quoting, and dialect-specific quote prefixes are not interpreted. Encoded email characters can therefore be missed or partially matched. Use a dialect-aware source extractor for such inputs; this mode is a bounded lexical policy, not a general SQL parser.

MCP adoption

This is the upstream work for datafog-mcp issue #31. MCP must pass the applicable format when it calls scan, and use those findings for transform. Updating the dependency alone does not change default scanning. The downstream change should require a released core version containing this API, update its lockfile, and exercise scan offsets plus redact, mask, and remove on actual .env and SQL fixture files while verifying that originals stay unchanged. Review corpus span changes explicitly; this fix targets damage to surrounding syntax, while preserving the strict type-and-span correctness measure.