@wtfalch/email 0.13.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +390 -12
- package/dist/imip/compose.d.ts +5 -0
- package/dist/imip/compose.js +84 -0
- package/dist/imip/index.d.ts +15 -0
- package/dist/imip/index.js +14 -0
- package/dist/imip/lookup.d.ts +21 -0
- package/dist/imip/lookup.js +26 -0
- package/dist/imip/parse.d.ts +11 -0
- package/dist/imip/parse.js +116 -0
- package/dist/imip/types.d.ts +57 -0
- package/dist/imip/types.js +9 -0
- package/dist/mailbox/client.d.ts +28 -1
- package/dist/mailbox/client.js +51 -0
- package/dist/mailbox/fake/mailbox.js +567 -7
- package/dist/mailbox/index.d.ts +16 -8
- package/dist/mailbox/index.js +8 -4
- package/dist/mailbox/mail.css +13 -0
- package/dist/mailbox/mailboxes.d.ts +95 -1
- package/dist/mailbox/mailboxes.js +243 -1
- package/dist/mailbox/mutate.d.ts +21 -0
- package/dist/mailbox/mutate.js +71 -0
- package/dist/mailbox/quoted.d.ts +94 -0
- package/dist/mailbox/quoted.js +158 -0
- package/dist/mailbox/react/Composer.js +13 -1
- package/dist/mailbox/react/Mail.js +273 -33
- package/dist/mailbox/react/ThreadView.d.ts +13 -1
- package/dist/mailbox/react/ThreadView.js +5 -4
- package/dist/mailbox/react/index.d.ts +3 -1
- package/dist/mailbox/react/index.js +2 -1
- package/dist/mailbox/react/quotedHtml.d.ts +105 -0
- package/dist/mailbox/react/quotedHtml.js +163 -0
- package/dist/mailbox/sieve.d.ts +76 -0
- package/dist/mailbox/sieve.js +241 -0
- package/dist/mailbox/snooze.d.ts +48 -0
- package/dist/mailbox/snooze.js +176 -0
- package/dist/mailbox/submit.d.ts +56 -2
- package/dist/mailbox/submit.js +145 -11
- package/dist/mailbox/threads.js +2 -0
- package/dist/mailbox/types.d.ts +60 -0
- package/dist/mailbox/vacation.d.ts +32 -0
- package/dist/mailbox/vacation.js +79 -0
- package/dist/postmaster/apply.d.ts +154 -1
- package/dist/postmaster/apply.js +336 -1
- package/dist/postmaster/audit.d.ts +22 -1
- package/dist/postmaster/audit.js +7 -0
- package/dist/postmaster/client.d.ts +49 -0
- package/dist/postmaster/client.js +43 -0
- package/dist/postmaster/index.d.ts +6 -3
- package/dist/postmaster/index.js +5 -2
- package/dist/postmaster/mail-copy.d.ts +169 -0
- package/dist/postmaster/mail-copy.js +259 -0
- package/dist/postmaster/objects.js +11 -0
- package/dist/postmaster/org-mail.d.ts +117 -0
- package/dist/postmaster/org-mail.js +206 -0
- package/dist/postmaster/overview.d.ts +4 -0
- package/dist/postmaster/queue.d.ts +111 -0
- package/dist/postmaster/queue.js +64 -0
- package/dist/postmaster/writes.d.ts +59 -0
- package/dist/postmaster/writes.js +106 -0
- package/package.json +8 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding the line where a received message's own words end and the quoted
|
|
3
|
+
* history it carries begins.
|
|
4
|
+
*
|
|
5
|
+
* This is `quoteText` (./drafts.ts) run backwards: that one takes a message
|
|
6
|
+
* and adds the `>` markers so a reply can carry the original along; this one
|
|
7
|
+
* takes a message that already has them and finds where they start.
|
|
8
|
+
* Composing a reply is pure text-building with no failure mode. Reading one
|
|
9
|
+
* is a heuristic that can guess wrong on a message this package never wrote,
|
|
10
|
+
* so it gets its own module, its own contract, and its own tests for the
|
|
11
|
+
* cases it is known not to cover.
|
|
12
|
+
*
|
|
13
|
+
* **The result is a boundary, not a summary.** A caller collapsing the
|
|
14
|
+
* thread view renders `body` and offers `quoted` behind a disclosure; a
|
|
15
|
+
* caller that wants everything just concatenates them back. `body + quoted`
|
|
16
|
+
* is always exactly the original string: nothing is trimmed, reformatted or
|
|
17
|
+
* thrown away in either half. A message with no quoted history returns the
|
|
18
|
+
* whole thing as `body` and `''` as `quoted`; a bare forward that is nothing
|
|
19
|
+
* but quoted history returns `''` as `body` and the whole thing as `quoted`.
|
|
20
|
+
*
|
|
21
|
+
* **HTML quote detection is not in this file, on purpose.** The natural tool
|
|
22
|
+
* for `<blockquote>`, Gmail's `gmail_quote` class and Outlook's `<div
|
|
23
|
+
* style="border-top:...">` divider is the inert-`DOMParser` walk this
|
|
24
|
+
* package already has, in `mailbox/react/sanitise.ts` — reusing it beats
|
|
25
|
+
* writing a second HTML parser or reaching for a regex over markup. But that
|
|
26
|
+
* file lives under `mailbox/react/`, the browser-only half of this package
|
|
27
|
+
* (`mailDocument`'s own doc comment: "Browser only: it needs `DOMParser`"),
|
|
28
|
+
* while this module is exported from `mailbox/index.ts`, the JMAP client
|
|
29
|
+
* core that has no `react` peer dependency and has to keep working with no
|
|
30
|
+
* DOM at all — `MailClient` is plain fetch and JSON. Importing
|
|
31
|
+
* `sanitise.ts` from here would make the core depend on the UI layer it is
|
|
32
|
+
* built under, and would make `@wtfalch/email/mailbox` throw in Node the
|
|
33
|
+
* first time a caller touched an HTML message. The HTML half belongs beside
|
|
34
|
+
* `sanitise.ts`, under `mailbox/react/`, as its own follow-up; this ships
|
|
35
|
+
* the text half only. See the PR body for the issue this opens.
|
|
36
|
+
*/
|
|
37
|
+
import type { Message } from './types.ts';
|
|
38
|
+
/** The boundary between a message's own text and the quoted history under
|
|
39
|
+
* it, materialised as the two slices on either side. Concatenating them
|
|
40
|
+
* always reproduces the original string. */
|
|
41
|
+
export type QuoteBoundary = {
|
|
42
|
+
/** The reader's own words: everything before the first quote marker. */
|
|
43
|
+
body: string;
|
|
44
|
+
/** The quoted history, verbatim from the first marker line to the end.
|
|
45
|
+
* `''` when the message carries none. */
|
|
46
|
+
quoted: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Where a received plain-text body's own words end and its quoted history
|
|
50
|
+
* begins.
|
|
51
|
+
*
|
|
52
|
+
* Covers three marker forms, deliberately not more:
|
|
53
|
+
* - `>` (and `>>`, nested) leading a line — but only when nothing but blank
|
|
54
|
+
* lines and further `>` lines follow it to the end of the message. A
|
|
55
|
+
* pasted diff (`> - old line`) or a Markdown quote (`> To be or not to
|
|
56
|
+
* be...`) followed by the sender's own text is not mail history and is
|
|
57
|
+
* left alone.
|
|
58
|
+
* - `On <when>, <who> wrote:` alone on a line.
|
|
59
|
+
* - `-----Original Message-----` alone on a line.
|
|
60
|
+
*
|
|
61
|
+
* Not covered, deliberately, because the issue budgets English and the
|
|
62
|
+
* marker forms above, not every locale:
|
|
63
|
+
* - a localised attribution or divider (French `Le ... a écrit :`, German
|
|
64
|
+
* `-----Ursprüngliche Nachricht-----`, Norwegian `-----Opprinnelig
|
|
65
|
+
* melding-----`, ...).
|
|
66
|
+
* - Apple Mail's `Begin forwarded message:` header (no dashes, no
|
|
67
|
+
* `wrote:`).
|
|
68
|
+
* - an attribution or divider line a client's own wrap split across two
|
|
69
|
+
* lines.
|
|
70
|
+
* - a genuine reply interleaved *between* two `>` blocks (quote, new text,
|
|
71
|
+
* quote): the trailing-only rule above is what keeps a pasted diff out of
|
|
72
|
+
* `quoted`, but it costs the same thing here on purpose — the first `>`
|
|
73
|
+
* line gets one attempt, finds real text after it, and gives up for the
|
|
74
|
+
* whole message rather than guessing which later `>` block is the real
|
|
75
|
+
* one. The entire message stays as `body`, unsplit. That is the safe
|
|
76
|
+
* direction to be wrong in: nothing new is ever lost into `quoted`, only
|
|
77
|
+
* nothing gets collapsed.
|
|
78
|
+
* - a stray `On ... wrote:` sentence that is someone's actual new writing,
|
|
79
|
+
* alone on its own line, rather than a header. Unlike the `>` leader this
|
|
80
|
+
* one is not checked for trailing content, so it is a real false
|
|
81
|
+
* positive: everything from that line to the end of the message —
|
|
82
|
+
* however much text that is — is read as quoted history and disappears
|
|
83
|
+
* from `body`.
|
|
84
|
+
*
|
|
85
|
+
* A message that trips none of the three markers keeps its whole text as
|
|
86
|
+
* `body` — the same answer this gives a message with no quoted history at
|
|
87
|
+
* all, which is the safe direction to be wrong in: nothing is hidden, it is
|
|
88
|
+
* just not collapsed.
|
|
89
|
+
*/
|
|
90
|
+
export declare function splitQuoted(text: string): QuoteBoundary;
|
|
91
|
+
/** `splitQuoted` against a received message's own plain-text body. A
|
|
92
|
+
* message with no text body (HTML-only) has nothing to split: the whole
|
|
93
|
+
* boundary is empty, not a guess. */
|
|
94
|
+
export declare function quoteBoundary(message: Pick<Message, 'text'>): QuoteBoundary;
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finding the line where a received message's own words end and the quoted
|
|
3
|
+
* history it carries begins.
|
|
4
|
+
*
|
|
5
|
+
* This is `quoteText` (./drafts.ts) run backwards: that one takes a message
|
|
6
|
+
* and adds the `>` markers so a reply can carry the original along; this one
|
|
7
|
+
* takes a message that already has them and finds where they start.
|
|
8
|
+
* Composing a reply is pure text-building with no failure mode. Reading one
|
|
9
|
+
* is a heuristic that can guess wrong on a message this package never wrote,
|
|
10
|
+
* so it gets its own module, its own contract, and its own tests for the
|
|
11
|
+
* cases it is known not to cover.
|
|
12
|
+
*
|
|
13
|
+
* **The result is a boundary, not a summary.** A caller collapsing the
|
|
14
|
+
* thread view renders `body` and offers `quoted` behind a disclosure; a
|
|
15
|
+
* caller that wants everything just concatenates them back. `body + quoted`
|
|
16
|
+
* is always exactly the original string: nothing is trimmed, reformatted or
|
|
17
|
+
* thrown away in either half. A message with no quoted history returns the
|
|
18
|
+
* whole thing as `body` and `''` as `quoted`; a bare forward that is nothing
|
|
19
|
+
* but quoted history returns `''` as `body` and the whole thing as `quoted`.
|
|
20
|
+
*
|
|
21
|
+
* **HTML quote detection is not in this file, on purpose.** The natural tool
|
|
22
|
+
* for `<blockquote>`, Gmail's `gmail_quote` class and Outlook's `<div
|
|
23
|
+
* style="border-top:...">` divider is the inert-`DOMParser` walk this
|
|
24
|
+
* package already has, in `mailbox/react/sanitise.ts` — reusing it beats
|
|
25
|
+
* writing a second HTML parser or reaching for a regex over markup. But that
|
|
26
|
+
* file lives under `mailbox/react/`, the browser-only half of this package
|
|
27
|
+
* (`mailDocument`'s own doc comment: "Browser only: it needs `DOMParser`"),
|
|
28
|
+
* while this module is exported from `mailbox/index.ts`, the JMAP client
|
|
29
|
+
* core that has no `react` peer dependency and has to keep working with no
|
|
30
|
+
* DOM at all — `MailClient` is plain fetch and JSON. Importing
|
|
31
|
+
* `sanitise.ts` from here would make the core depend on the UI layer it is
|
|
32
|
+
* built under, and would make `@wtfalch/email/mailbox` throw in Node the
|
|
33
|
+
* first time a caller touched an HTML message. The HTML half belongs beside
|
|
34
|
+
* `sanitise.ts`, under `mailbox/react/`, as its own follow-up; this ships
|
|
35
|
+
* the text half only. See the PR body for the issue this opens.
|
|
36
|
+
*/
|
|
37
|
+
/** The RFC 3676 quote leader: `>`, `>>`, `> >`... A line already inside a
|
|
38
|
+
* quote of a quote still starts with it, which is what lets a reply chain
|
|
39
|
+
* nest instead of losing its outer quote. Up to three leading spaces,
|
|
40
|
+
* because some clients indent a quoted block before the marker. */
|
|
41
|
+
const QUOTE_LEADER = /^ {0,3}>/;
|
|
42
|
+
/** Outlook's classic plain-text divider, any dash count either side. */
|
|
43
|
+
const ORIGINAL_MESSAGE_DIVIDER = /^ {0,3}-{2,}\s*Original Message\s*-{2,}\s*$/i;
|
|
44
|
+
/** Gmail's, Apple Mail's and this package's own (`attribution`, ./drafts.ts)
|
|
45
|
+
* attribution line, in whatever date format the sender's client wrote —
|
|
46
|
+
* `.{3,300}` is deliberately loose about the date and the name so long as
|
|
47
|
+
* the line reads `On <anything> wrote:` and nothing else. */
|
|
48
|
+
const ATTRIBUTION_LINE = /^ {0,3}On .{3,300} wrote:\s*$/i;
|
|
49
|
+
/** A line with nothing on it, so a client's unmarked blank line inside a
|
|
50
|
+
* multi-paragraph quote still counts as part of the trailing quote block. */
|
|
51
|
+
const BLANK_LINE = /^\s*$/;
|
|
52
|
+
function lines(text) {
|
|
53
|
+
const found = [];
|
|
54
|
+
let offset = 0;
|
|
55
|
+
while (offset <= text.length) {
|
|
56
|
+
const newline = text.indexOf('\n', offset);
|
|
57
|
+
const end = newline === -1 ? text.length : newline;
|
|
58
|
+
found.push({ start: offset, text: text.slice(offset, end) });
|
|
59
|
+
if (newline === -1)
|
|
60
|
+
break;
|
|
61
|
+
offset = newline + 1;
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether `rest` — a line and everything after it — is nothing but blank
|
|
67
|
+
* lines and further `>` lines, all the way to the end of the message.
|
|
68
|
+
*
|
|
69
|
+
* This is what tells a genuine trailing block of quoted history apart from
|
|
70
|
+
* a `>` used for something else in the middle of a message: mail history is
|
|
71
|
+
* always top-posted, so a real quote never has ordinary text *after* it. A
|
|
72
|
+
* pasted diff or a Markdown quote does.
|
|
73
|
+
*/
|
|
74
|
+
function onlyQuotedToEnd(rest) {
|
|
75
|
+
return rest.every((line) => BLANK_LINE.test(line.text) || QUOTE_LEADER.test(line.text));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The offset into `text` where its quoted history begins, or `text.length`
|
|
79
|
+
* when none of the three marker forms below appear.
|
|
80
|
+
*
|
|
81
|
+
* Walked one line at a time, not matched over the whole string, because `>`
|
|
82
|
+
* and `-----Original Message-----` are markers only at the start of a line —
|
|
83
|
+
* a `>` in the middle of a sentence is punctuation, not a quote. The
|
|
84
|
+
* attribution line and the Outlook divider open the boundary the moment
|
|
85
|
+
* either is seen; the `>` leader only gets one attempt, at the *first* `>`
|
|
86
|
+
* line in the message, and only opens the boundary there if the rest of the
|
|
87
|
+
* message is quote all the way down — see `onlyQuotedToEnd`. A `>` line
|
|
88
|
+
* that fails that check is not retried further down: the leader has nothing
|
|
89
|
+
* left to say about this message, on purpose (see `splitQuoted`'s doc
|
|
90
|
+
* comment on the interleaved case).
|
|
91
|
+
*/
|
|
92
|
+
function boundaryOffset(text) {
|
|
93
|
+
const found = lines(text);
|
|
94
|
+
let quoteLeaderTried = false;
|
|
95
|
+
for (const [index, line] of found.entries()) {
|
|
96
|
+
if (ORIGINAL_MESSAGE_DIVIDER.test(line.text) || ATTRIBUTION_LINE.test(line.text)) {
|
|
97
|
+
return line.start;
|
|
98
|
+
}
|
|
99
|
+
if (!quoteLeaderTried && QUOTE_LEADER.test(line.text)) {
|
|
100
|
+
quoteLeaderTried = true;
|
|
101
|
+
if (onlyQuotedToEnd(found.slice(index)))
|
|
102
|
+
return line.start;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return text.length;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Where a received plain-text body's own words end and its quoted history
|
|
109
|
+
* begins.
|
|
110
|
+
*
|
|
111
|
+
* Covers three marker forms, deliberately not more:
|
|
112
|
+
* - `>` (and `>>`, nested) leading a line — but only when nothing but blank
|
|
113
|
+
* lines and further `>` lines follow it to the end of the message. A
|
|
114
|
+
* pasted diff (`> - old line`) or a Markdown quote (`> To be or not to
|
|
115
|
+
* be...`) followed by the sender's own text is not mail history and is
|
|
116
|
+
* left alone.
|
|
117
|
+
* - `On <when>, <who> wrote:` alone on a line.
|
|
118
|
+
* - `-----Original Message-----` alone on a line.
|
|
119
|
+
*
|
|
120
|
+
* Not covered, deliberately, because the issue budgets English and the
|
|
121
|
+
* marker forms above, not every locale:
|
|
122
|
+
* - a localised attribution or divider (French `Le ... a écrit :`, German
|
|
123
|
+
* `-----Ursprüngliche Nachricht-----`, Norwegian `-----Opprinnelig
|
|
124
|
+
* melding-----`, ...).
|
|
125
|
+
* - Apple Mail's `Begin forwarded message:` header (no dashes, no
|
|
126
|
+
* `wrote:`).
|
|
127
|
+
* - an attribution or divider line a client's own wrap split across two
|
|
128
|
+
* lines.
|
|
129
|
+
* - a genuine reply interleaved *between* two `>` blocks (quote, new text,
|
|
130
|
+
* quote): the trailing-only rule above is what keeps a pasted diff out of
|
|
131
|
+
* `quoted`, but it costs the same thing here on purpose — the first `>`
|
|
132
|
+
* line gets one attempt, finds real text after it, and gives up for the
|
|
133
|
+
* whole message rather than guessing which later `>` block is the real
|
|
134
|
+
* one. The entire message stays as `body`, unsplit. That is the safe
|
|
135
|
+
* direction to be wrong in: nothing new is ever lost into `quoted`, only
|
|
136
|
+
* nothing gets collapsed.
|
|
137
|
+
* - a stray `On ... wrote:` sentence that is someone's actual new writing,
|
|
138
|
+
* alone on its own line, rather than a header. Unlike the `>` leader this
|
|
139
|
+
* one is not checked for trailing content, so it is a real false
|
|
140
|
+
* positive: everything from that line to the end of the message —
|
|
141
|
+
* however much text that is — is read as quoted history and disappears
|
|
142
|
+
* from `body`.
|
|
143
|
+
*
|
|
144
|
+
* A message that trips none of the three markers keeps its whole text as
|
|
145
|
+
* `body` — the same answer this gives a message with no quoted history at
|
|
146
|
+
* all, which is the safe direction to be wrong in: nothing is hidden, it is
|
|
147
|
+
* just not collapsed.
|
|
148
|
+
*/
|
|
149
|
+
export function splitQuoted(text) {
|
|
150
|
+
const offset = boundaryOffset(text);
|
|
151
|
+
return { body: text.slice(0, offset), quoted: text.slice(offset) };
|
|
152
|
+
}
|
|
153
|
+
/** `splitQuoted` against a received message's own plain-text body. A
|
|
154
|
+
* message with no text body (HTML-only) has nothing to split: the whole
|
|
155
|
+
* boundary is empty, not a guess. */
|
|
156
|
+
export function quoteBoundary(message) {
|
|
157
|
+
return splitQuoted(message.text ?? '');
|
|
158
|
+
}
|
|
@@ -39,8 +39,20 @@ export function Composer({ draft, onChange, onSend, onCancel, identities, onAtta
|
|
|
39
39
|
const [uploads, setUploads] = useState([]);
|
|
40
40
|
const [dropping, setDropping] = useState(false);
|
|
41
41
|
const picker = useRef(null);
|
|
42
|
+
const root = useRef(null);
|
|
42
43
|
const controllers = useRef(new Map());
|
|
43
44
|
const counter = useRef(0);
|
|
45
|
+
/* Scrolls itself into view the moment it mounts. `ThreadView` inserts a
|
|
46
|
+
reply where three small buttons used to be, at whatever scroll position
|
|
47
|
+
the reader was already at, and nothing else moves the page to show the
|
|
48
|
+
newly-tall form -- or the message directly above it, which is what
|
|
49
|
+
`block: 'nearest'` keeps in frame rather than re-centring past it (#56).
|
|
50
|
+
`key={drafted}` (`Mail.tsx`) remounts this on every new reply, forward
|
|
51
|
+
or "New message", including a second reply started while the first is
|
|
52
|
+
still open, so an empty dependency list still fires once per compose. */
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
root.current?.scrollIntoView({ block: 'nearest' });
|
|
55
|
+
}, []);
|
|
44
56
|
/* dragenter and dragleave fire for every child the pointer crosses, so
|
|
45
57
|
"is something over the composer" is a count, not the last event seen. */
|
|
46
58
|
const depth = useRef(0);
|
|
@@ -149,7 +161,7 @@ export function Composer({ draft, onChange, onSend, onCancel, identities, onAtta
|
|
|
149
161
|
browser in place of the page -- and the page here is somebody's
|
|
150
162
|
half-written message. Text dragged into the body is left alone. */
|
|
151
163
|
const carriesFiles = (event) => Array.from(event.dataTransfer?.types ?? []).includes('Files');
|
|
152
|
-
return (_jsxs("form", { className: `composer${dropping ? ' is-dropping' : ''}${className ? ` ${className}` : ''}`, onSubmit: (event) => {
|
|
164
|
+
return (_jsxs("form", { ref: root, className: `composer${dropping ? ' is-dropping' : ''}${className ? ` ${className}` : ''}`, onSubmit: (event) => {
|
|
153
165
|
event.preventDefault();
|
|
154
166
|
if (canSend)
|
|
155
167
|
void onSend();
|