--- spec: openflange.org/pipe/v0.1 id: mask-email version: 0.1.0 title: Mask email description: Masks the middle of the local part of e-mail addresses; routes invalid addresses to `rejected`. license: Apache-2.0 keywords: [email, mask, privacy, pii] maturity: experimental scope: record deterministic: true inputs: email: description: E-mail addresses, one JSON string per NDJSON line. schema: format: json-schema definition: {type: string} outputs: email: description: Masked addresses, in input order (invalid inputs are not included). schema: format: json-schema definition: {type: string} rejected: required: false description: Inputs that are not valid addresses, as {"value", "reason"}. If this port is not connected an invalid input fails the run. schema: format: json-schema definition: type: object properties: value: {} reason: {type: string} required: [value, reason] parameters: character: type: string default: "*" minLength: 1 maxLength: 1 description: Masking character; exactly one Unicode code point. preserveFirst: type: integer default: 1 minimum: 0 maximum: 8 description: Number of leading characters of the local part to keep. preserveLast: type: integer default: 1 minimum: 0 maximum: 8 description: Number of trailing characters of the local part to keep. implementation: type: script language: starlark path: mask.star --- # Mask email Implements the [OpenFlange](https://openflange.org/) specification. Masks the middle of the local part of an e-mail address and keeps the domain: `alice@example.com` becomes `a***e@example.com`. > **Masking is not anonymisation.** The domain and the edge characters are > preserved and can still identify a person, especially in small domains. > Treat masked addresses as personal data. ## Semantics All lengths are counted in Unicode code points. - The address is split at the **last** `@`. It is valid when it is a string with exactly one `@`, a non-empty local part, a non-empty domain and no whitespace. - Let `L` be the length of the local part, `f = preserveFirst`, `l = preserveLast`. - `L > f + l`: the first `f` characters, then `L − f − l` masking characters, then the last `l` characters. - `L ≤ f + l` (short local part): the whole local part is replaced by `L` masking characters, so a short name is never revealed entirely (`ab@x.io` → `**@x.io`). - The domain is copied unchanged (this pipe does not change case; put `lowercase` in front of it to normalise). - **Invalid input is never masked and never silently dropped.** It is emitted on the optional output `rejected` as `{"value": , "reason": "..."}`. If `rejected` is not connected, the first invalid item fails the run with `E_RUNTIME`. Because an item goes either to `email` or to `rejected`, the pipe is not one-to-one. ## Parameters | name | type | default | bounds | |---|---|---|---| | `character` | string | `*` | exactly one Unicode code point (otherwise `E_PARAM`) | | `preserveFirst` | integer | 1 | 0 … 8 | | `preserveLast` | integer | 1 | 0 … 8 | ## Examples | input | output | |---|---| | `alice@example.com` | `a***e@example.com` | | `ab@x.io` | `**@x.io` | | `ünïcödé@example.com` | `ü*****é@example.com` | | `not-an-address` | rejected: `expected exactly one @` | ```sh printf '"alice@example.com"\n' | openflange run ./pipes/mask-email # "a***e@example.com" ```