Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions THIRD_PARTY_NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,24 @@ restrictions (https://ai.google.dev/gemma/prohibited_use_policy).
The domain-to-sector table (src/domain/organization-sectors.generated.ts) is built from Wikidata
(https://www.wikidata.org), whose structured data is available under CC0 1.0
(https://creativecommons.org/publicdomain/zero/1.0/). The export date is in the file's header.

The order of the checks and two sender patterns in src/mail/mail-types.ts are ported from Zero's header classifier
(https://github.com/Mail-0/Zero, apps/server/src/lib/imap/categorize.ts at commit
4b642dfd9890a1fdcb1b98a177fe74ca3142c445), under the MIT License:

MIT License

Copyright (c) 2025 Zero Email

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 3 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@
"noExcessiveLinesPerFile": {
"level": "error",
"options": {
"maxLines": 1893
"maxLines": 1902
}
}
}
Expand All @@ -792,7 +792,7 @@
"noExcessiveLinesPerFile": {
"level": "error",
"options": {
"maxLines": 1012
"maxLines": 1024
}
}
}
Expand Down Expand Up @@ -822,7 +822,7 @@
"noExcessiveLinesPerFile": {
"level": "error",
"options": {
"maxLines": 3260
"maxLines": 3265
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions changes/feat-mail-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
### Added

- **Each email has a type of its own, apart from its sender (store version 76).** `Email.mailType` is one of
`auto_reply`, `security`, `calendar`, `travel`, `event_ticket`, `order`, `shipping`, `bill`, `social_notification`,
`discussion_list`, `newsletter`, `promotion`, `system_alert`, `account_notice`, `personal` or `other`, worked out
locally from the stored headers, recipients, attachment types, schema.org markup in a kept HTML body, the sender's bot
and its organization's sector, and whether the owner wrote to the sender. `Email.reach` (`direct`, `group`,
`broadcast`) is worked out per email too, and `Email.typeSignal` says what decided the type. They are kept on the
email and cleared by triggers when what decides them changes; a store's existing mail gets them in batches on the
first read that filters by them. The words are in the [glossary](../docs/dev/GLOSSARY.md#mail-types).
- **`store.mail.emails` filters by `types` and `reaches`**, and **`store.mail.mailSenders`** lists the senders of
incoming mail with their mail counted by type and reach: a sender is listed when any of its mail passes the filter,
so a shop that sends receipts and sales shows under both. Both are experimental.
2 changes: 1 addition & 1 deletion docs/dev/COORDINATION.md

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions docs/dev/GLOSSARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Verbs used but not in cli-base's vocabulary, by CLI (2026-10-12). Each needs a r
| organization | a company, team, family or community | entity | none |
| person | one human, across every messenger and mail (`person:<uid>`) | user, people | tg bot help: "user:<id> for a person", "the person's user id"; drive `people` |
| bot | a program that writes to the owner: a no-reply or alert address, a messenger's bot, a service's mail; an entity apart from people, with a name, identities and an optional organization, and no ties, tasks or merge review (`sender-bot:<id>`, the `sender_bots` table). Not an agent: `bot:<id>` and the `bots` table are agents that work here | automated person, sender (for a bot) | `people list kind:automated` still lists people a name or a bulk mailbox marks; memo's `{ bot }` author and `bot list` mean agents and a messenger's bot account |
| mail type | what one email is, apart from who sent it: one of the words in [Mail types](#mail-types), worked out per email from what the store keeps of it (`emails.mail_type`, key `mailType`). A sender's view is a summary of its mail, so a shop that sends receipts and sales counts under `order` and under `promotion` | category, kind (a person's `kind` is another thing), label | none |
| reach | how a message reached the owner: `direct` (to the owner or a few people), `group` (a large group or a discussion list), `broadcast` (one sender to many readers who cannot answer in place). Worked out per email (`emails.reach`) and per sender (`people list`) | audience, scope | none |
| contact | one person as one source knows them: a mail correspondent, a Telegram user, a Drive owner, a calendar attendee; an `identities` row | user | none found beyond the above |
| entity | the thing the owner means — a person, an event, a document; it carries no provider id ([WC-DATA-2](https://github.com/WireCatLabs/cli-base/blob/main/docs/standards/data-model.md)) | record, object | none |
| source record | one source's copy of an entity, keyed by account and `external_id`: a contact, a Zoom meeting, an email, a message | entity, item | none |
Expand All @@ -98,6 +100,32 @@ Verbs used but not in cli-base's vocabulary, by CLI (2026-10-12). Each needs a r
| search hit | one result of a search | result, match, item | JSON key is `items` in some searches and `hits` in others; see below |
| context | **open (NEED-987)**: two meanings | — | entity card: memo `context`, `projects context`, `organizations context`, drive `documents context`, tg/max `contacts context`; messages around one message: tg/max `messages context` |

### Mail types

The values of `mailType`, in the order they are tried: the first that matches wins. One exception: mail with
List-Unsubscribe but no one-click unsubscribe or campaign marker, from an automated address such as `notifications@`,
is an `account_notice` before the list types are tried. Mail from someone the owner wrote to is typed by what the
email itself carries (a part, schema.org markup, list headers), never by an address word or a subject alone.

| Word | One meaning | Not |
|---|---|---|
| `auto_reply` | a machine's answer to a mail: a bounce, a delivery or read report, an out-of-office reply | bounce (one case of it) |
| `security` | a sign-in code, a sign-in alert, a password reset | alert (that is `system_alert`), 2FA |
| `calendar` | an invitation, its update or its cancellation (a `text/calendar` part) | meeting, event |
| `travel` | a flight, train, bus, hotel or car booking | trip, booking |
| `event_ticket` | a ticket to a concert, a match, a show | ticket (a support ticket is `account_notice` or `personal`) |
| `order` | an order confirmation or a receipt | purchase, receipt |
| `shipping` | a parcel sent, on its way or delivered | delivery, tracking |
| `bill` | an invoice, a statement, a payment due or made | invoice, payment |
| `social_notification` | a social network's notice: a reply, a like, a new follower | social |
| `discussion_list` | a mailing list whose members write to each other (a List-Id three or more addresses send to) | forum, group |
| `newsletter` | one sender's mail to its subscribers, written to be read | digest, subscription |
| `promotion` | marketing mail: a sale, an offer, a campaign | ad, spam |
| `system_alert` | a program watching a system: monitoring, CI, cron | alert, notification |
| `account_notice` | a service's notice about the owner's account: terms, activity, a ticket update | notification, update |
| `personal` | a person writing, to the owner or to a few people | primary, direct |
| `other` | a program's mail no rule above names | unknown |

## Output keys

Read from source, not run.
Expand Down
5 changes: 4 additions & 1 deletion docs/storage/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,11 @@ One email.
| `updated_at` | integer | not null | | when this row last changed here |
| `deleted_at` | integer | | | gone at the source; sync never hard-deletes |
| `mail_rule_id` | integer | | | the `mail_rules` row that decided how this email is stored; no constraint, removing the rule clears it |
| `mail_type` | text | | | what the email is (`order`, `newsletter`, `personal`, …, docs/dev/GLOSSARY.md); null until worked out, and nulled by triggers on its inputs |
| `reach` | text | | | `direct`, `group` or `broadcast`: how it reached the owner; kept with `mail_type` |
| `type_signal` | text | | | what decided `mail_type`, such as `list-id`; kept with it |

*Keys and indexes:* `UNIQUE (account_id, external_id)`, `INDEX (account_id, sent_at DESC)`, `INDEX (mail_rule_id) WHERE mail_rule_id IS NOT NULL`, `INDEX (coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId')))`, `INDEX (email_thread_id)`, `INDEX (from_identity_id)`
*Keys and indexes:* `UNIQUE (account_id, external_id)`, `INDEX (account_id, sent_at DESC)`, `INDEX (mail_rule_id) WHERE mail_rule_id IS NOT NULL`, `INDEX (mail_type)`, `INDEX (id) WHERE mail_type IS NULL`, `INDEX (coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId')))`, `INDEX (email_thread_id)`, `INDEX (from_identity_id)`

*Checks:* `CHECK ("references" IS NULL OR json_valid("references"))`, `CHECK ("headers" IS NULL OR json_valid("headers"))`, `CHECK ("metadata" IS NULL OR json_valid("metadata"))`

Expand Down
5 changes: 5 additions & 0 deletions drizzle/20261125183530_version-76-mail-types/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE `emails` ADD `mail_type` text;--> statement-breakpoint
ALTER TABLE `emails` ADD `reach` text;--> statement-breakpoint
ALTER TABLE `emails` ADD `type_signal` text;--> statement-breakpoint
CREATE INDEX `emails_by_mail_type` ON `emails` (`mail_type`);--> statement-breakpoint
CREATE INDEX `emails_type_to_work_out` ON `emails` (`id`) WHERE mail_type IS NULL;
Loading
Loading