data/MailAddressIndex.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | #include "Models.h" | ||
| 3 | |||
| 4 | #include <QList> | ||
| 5 | #include <QString> | ||
| 6 | #include <QStringList> | ||
| 7 | |||
| 8 | // Sprint 105 S105.5.1 (D-7): the addresses of a mail header as rows of the | ||
| 9 | // cache's address index (`message_addresses`), so a contact's mails are one | ||
| 10 | // indexed query instead of a leading-wildcard LIKE per address. Pure. | ||
| 11 | // | ||
| 12 | // Invariants: an address is lower case, has exactly one "@", no display | ||
| 13 | // name, and its domain in ASCII (IDNA/punycode); the card addresses of a | ||
| 14 | // contact are normalized with the same function before they are looked up. | ||
| 15 | namespace MailAddressIndex { | ||
| 16 | |||
| 17 | enum Role { From = 0, To = 1, Cc = 2 }; | ||
| 18 | |||
| 19 | struct Entry { | ||
| 20 | 4 | QString address; | |
| 21 | 4 | int role = From; | |
| 22 |
2/4✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 7 taken 4 times.
|
4 | bool operator==(const Entry &other) const = default; |
| 23 | }; | ||
| 24 | |||
| 25 | // The normalized form of one address ("Ana <Ana@Bücher.Example>" works too); | ||
| 26 | // "" when the text holds no address. | ||
| 27 | QString normalize(const QString &address); | ||
| 28 | |||
| 29 | // Every address of a header field ("A <a@x>, \"B, C\" <b@y>, c@z"). | ||
| 30 | QStringList parse(const QString &headerValue); | ||
| 31 | |||
| 32 | // The rows of one header: From, To and Cc, each address once per role, at | ||
| 33 | // most MaxEntries (a mail to a thousand recipients indexes the first ones). | ||
| 34 | constexpr int MaxEntries = 64; | ||
| 35 | QList<Entry> entriesOf(const MailHeader &header); | ||
| 36 | |||
| 37 | } // namespace MailAddressIndex | ||
| 38 |