# `EmailWithName`

An email address with the name shown beside it: `Mary Somerville <mary@example.com>`.

Use it for the sender or recipient of a message when the name should appear in the reader's mail app. When you only need the address, use [`Email`](/docs/types/type-email.md).

## Shape

| Field | Type | Required? |
|---|---|---|
| `name` | `Text` | No |
| `address` | [`Email`](/docs/types/type-email.md) | Yes |

Write every field when you build one, and give a field that isn't required as `none`.

## Example

```jadpo
EmailWithName { name: "Mary Somerville" address: "mary@example.com" }
```

`text.parse(raw, as: EmailWithName)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `Mary Somerville`, `<mary@example.com>` or `Mary Somerville <mary>`.

## Good to know

- `text.parse` also reads a bare `mary@example.com`, and gives it `name: none`.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it, so sort by one of its parts instead.
- A field that holds one counts as personal data (`contact`), so you don't mark it yourself.

## In JSON

An object of its parts, in a request, a response or `json.write`:

```json
{"name":"Mary Somerville","address":"mary@example.com"}
{"name":"Somerville, Mary","address":"mary@example.com"}
{"name":null,"address":"mary@example.com"}
```

When you read one, a field that isn't required may be left out, or sent as `null`.

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`EmailWithName` is in the group People and contact, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `Mary Somerville <mary@example.com>`, `"Somerville, Mary" <mary@example.com>` and `mary@example.com`.

### How it is stored

It is stored in 2 columns, each named for the field, `_` and its suffix. This is `"Somerville, Mary" <mary@example.com>`:

| Column | Type | Holds |
|---|---|---|
| `<field>_name` | `text` | `'Somerville, Mary'` |
| `<field>_address` | `text` | `'mary@example.com'` |

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `Mary Somerville <mary@example.com>` | `Mary Somerville <mary@example.com>` |
| `"Somerville, Mary" <mary@example.com>` | `"Somerville, Mary" <mary@example.com>` |
| `mary@example.com` | `mary@example.com` |

### Operations

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
