@postalsys/ee-client 1.11.0 → 1.11.2

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.
Files changed (4) hide show
  1. package/README.md +24 -4
  2. package/index.d.ts +6 -1
  3. package/index.js +411 -196
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -169,9 +169,9 @@ When the message carries a one-time passcode (the `otp` field EmailEngine 2.87+
169
169
 
170
170
  Add or remove the `\Seen` flag. Pass `false` to mark as unread.
171
171
 
172
- ### `deleteMessage(messageId: string): Promise<boolean>`
172
+ ### `deleteMessage(messageId: string): Promise<object>`
173
173
 
174
- Delete a message (EmailEngine moves it to Trash, or removes it if already in Trash).
174
+ Delete a message. EmailEngine moves it to Trash, or removes it when that is what the backend does for the folder it is in (an IMAP message already in Trash or Junk). Resolves to EmailEngine's answer, `{ deleted, moved }`, where `moved` (`{ destination, message }`) is set when the message went to Trash.
175
175
 
176
176
  ### `moveMessage(messageId: string, targetPath: string): Promise<boolean>`
177
177
 
@@ -245,13 +245,33 @@ When a `container` is provided the client builds a full webmail interface:
245
245
  - Replied and forwarded markers in the list and the viewer, from the `\Answered` and `$Forwarded` flags (IMAP accounts)
246
246
  - Draft messages show a "Send Draft" button that submits the stored draft for delivery after confirmation (requires EmailEngine v2.76.0 or later; editing the draft first is not supported)
247
247
  - Quoted thread history collapsed behind a "Show quoted text" control
248
- - Compose modal (floating button) for sending plain-text mail: To, Cc and Bcc fields that take several addresses, file attachments, and a Save Draft option that stores the message in the Drafts folder instead of sending it. Replies and forwards show the original under the text box and can include the original attachments
248
+ - Compose form for sending plain-text mail: To, Cc and Bcc fields that take several addresses, file attachments, and a Save Draft option that stores the message in the Drafts folder instead of sending it. Replies and forwards show the original under the text box and can include the original attachments
249
249
  - Dark mode toggle with the preference persisted to `localStorage`
250
250
  - Failed requests replace the affected pane's placeholder with an error panel and a Retry button
251
251
 
252
+ ### Theming
253
+
254
+ The accent colour (buttons, the selected folder, links in the compose form) comes from CSS custom properties that a host page can set on the container element:
255
+
256
+ ```html
257
+ <div id="email-client" style="--ee-accent: #4c5cc5; --ee-accent-hover: #3d4bb0; --ee-accent-light: #9ba6ee"></div>
258
+ ```
259
+
260
+ `--ee-accent` is the colour behind white text, `--ee-accent-hover` its pressed and hover shade, and `--ee-accent-light` the shade used for text and outlines in dark mode. Without them the client uses its own blue.
261
+
262
+ When opening a message the client scrolls the page only if its top is scrolled out of view, and it honours the container's `scroll-margin-top`, so a page with a sticky header can keep the toolbar clear of it.
263
+
264
+ ### Compose and notices
265
+
266
+ On wide layouts the Compose button sits at the top of the folder pane; in the one-pane layout it is a floating button. Problems with a message (no recipient, an address that is not one, a send the server refused) are shown inside the compose form next to its buttons, and the form keeps what was typed. Outcomes that need no answer ("Message queued for delivery.", "Draft saved to the Drafts folder.", "Message moved to Trash.") appear as a short notice at the bottom of the client, which `notify(message)` can show from the host too. `alertMethod` is used for failures outside the form.
267
+
268
+ ### Dark mode and styled messages
269
+
270
+ A message that sets its own colours or backgrounds (most newsletters) was designed for a light page, so in dark mode it is shown on a light surface. Plain messages follow the theme.
271
+
252
272
  ### Failed requests
253
273
 
254
- When a request behind a pane fails, that pane shows why instead of sitting on its "Loading..." placeholder. The reason is the message EmailEngine returned - for example "Requested account is not yet initialized" for an account that has not connected yet, or "Requested mailbox folder was not found" - and a Retry button re-runs the request. If the server could not be reached at all, the panel says so and names the configured `apiUrl`. The underlying promise still rejects, so callers driving the client programmatically can handle the error themselves.
274
+ When a request behind a pane fails, that pane shows why instead of sitting on its "Loading..." placeholder. The reason is the message EmailEngine returned - for example "Requested account is not yet initialized" for an account that has not connected yet, or "Requested mailbox folder was not found" - and a Retry button re-runs the request. If the server could not be reached at all, the panel says so and names the configured `apiUrl`. A message that does not exist (deleted, moved, or a link with a broken ID) is reported as "Message not found" without a Retry button, since retrying cannot help. The underlying promise still rejects, so callers driving the client programmatically can handle the error themselves.
255
275
 
256
276
  ### Quoted thread history
257
277
 
package/index.d.ts CHANGED
@@ -201,7 +201,8 @@ export declare class EmailEngineClient {
201
201
  openFolder(path: string): Promise<MessageListResponse>;
202
202
  loadMessage(messageId: string): Promise<Message>;
203
203
  markAsRead(messageId: string, seen?: boolean): Promise<boolean>;
204
- deleteMessage(messageId: string): Promise<boolean>;
204
+ /** Resolves to EmailEngine's answer; `moved` is set when the message went to Trash instead of being removed */
205
+ deleteMessage(messageId: string): Promise<{ deleted?: boolean; moved?: { destination?: string; message?: string } }>;
205
206
  moveMessage(messageId: string, targetPath: string): Promise<boolean>;
206
207
  /** Opens a message by ID and lists the folder that holds it */
207
208
  openMessage(messageId: string): Promise<Message | null>;
@@ -223,6 +224,10 @@ export declare class EmailEngineClient {
223
224
  downloadAttachment(attachmentId: string, suggestedFilename?: string): Promise<void>;
224
225
  downloadOriginalMessage(messageId: string, subject?: string): Promise<void>;
225
226
  formatDate(dateStr: string): string;
227
+ /** The date shown in the message header: weekday, date and time to the minute */
228
+ formatFullDate(dateStr: string): string;
229
+ /** Shows a short notice at the bottom of the client that goes away on its own (needs the UI) */
230
+ notify(message: string): void;
226
231
  formatFileSize(bytes: number): string;
227
232
  escapeHtml(value: unknown): string;
228
233
  /** HTML of the "Code requested" box for a message's one-time passcode, empty without one */
package/index.js CHANGED
@@ -29,6 +29,12 @@ const MESSAGE_BODY_STYLES = `
29
29
  height: auto;
30
30
  }
31
31
 
32
+ /* A message laid out wider than the viewer (a 600px newsletter on a phone) scrolls
33
+ sideways inside the clipped host instead of losing its right edge */
34
+ .ee-message-body-content {
35
+ overflow-x: auto;
36
+ }
37
+
32
38
  /* Quoted thread history, folded away by EmailEngine - see _labelCollapsedThreads() */
33
39
  .ee-collapsed-thread {
34
40
  margin-top: 12px;
@@ -128,15 +134,18 @@ function splitAddressField(value) {
128
134
  }
129
135
 
130
136
  function parseAddressEntry(entry) {
131
- const match = entry.match(/^(.*)<([^>]*)>$/);
132
- if (!match) {
137
+ // "Name <address>": the address is between the last "<" and a closing ">" at the end.
138
+ // Found by index rather than a /^(.*)<([^>]*)>$/ match, which backtracks in quadratic
139
+ // time on a long run of "<" without the closing ">"
140
+ const open = entry.lastIndexOf('<');
141
+ if (open < 0 || !entry.endsWith('>') || entry.indexOf('>', open) !== entry.length - 1 || /[\n\r\u2028\u2029]/.test(entry.slice(0, open))) {
133
142
  return { address: entry };
134
143
  }
135
- let name = match[1].trim();
144
+ let name = entry.slice(0, open).trim();
136
145
  if (name.length > 1 && name.startsWith('"') && name.endsWith('"')) {
137
146
  name = name.slice(1, -1).replace(/\\(.)/g, '$1');
138
147
  }
139
- const address = match[2].trim();
148
+ const address = entry.slice(open + 1, -1).trim();
140
149
  return name ? { name, address } : { address };
141
150
  }
142
151
 
@@ -433,26 +442,37 @@ export class EmailEngineClient {
433
442
  if (this.container && !this._destroyed) {
434
443
  this.renderMessage();
435
444
 
436
- // Scroll to top of the email client container
437
- this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
438
-
439
- // Also scroll the window to ensure visibility
440
- if (typeof window !== 'undefined') {
441
- const containerTop = this.container.getBoundingClientRect().top + window.pageYOffset;
442
- window.scrollTo({ top: containerTop, behavior: 'smooth' });
445
+ // The message opens at the top of the client: bring that into view when the
446
+ // page is scrolled past it (a long list on a phone), and leave the page alone
447
+ // otherwise. scrollIntoView honours the host's scroll-margin-top, which is how
448
+ // a page with a fixed header keeps the toolbar clear of it.
449
+ if (this.container.getBoundingClientRect().top < 0) {
450
+ this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
443
451
  }
444
452
  }
445
453
 
446
454
  return this.currentMessage;
447
455
  } catch (error) {
448
456
  console.error('Failed to load message:', error);
449
- this._renderPaneError(
450
- '.ee-message-viewer',
451
- 'Message unavailable',
452
- error,
453
- () => this._fireAndForget(this.loadMessage(messageId)),
454
- this._messageToolbar()
455
- );
457
+ // A message that does not exist (deleted, moved, or a link with a mangled ID) is
458
+ // not worth retrying, and the API's validation text means nothing to a reader
459
+ if (error && (error.statusCode === 404 || error.statusCode === 400)) {
460
+ this._renderPaneError(
461
+ '.ee-message-viewer',
462
+ 'Message not found',
463
+ 'It may have been moved or deleted, or the link to it is incomplete.',
464
+ null,
465
+ this._messageToolbar()
466
+ );
467
+ } else {
468
+ this._renderPaneError(
469
+ '.ee-message-viewer',
470
+ 'Message unavailable',
471
+ error,
472
+ () => this._fireAndForget(this.loadMessage(messageId)),
473
+ this._messageToolbar()
474
+ );
475
+ }
456
476
  throw error;
457
477
  }
458
478
  }
@@ -504,11 +524,13 @@ export class EmailEngineClient {
504
524
 
505
525
  async deleteMessage(messageId) {
506
526
  try {
507
- await this.apiRequest('DELETE', this._messagePath(messageId));
527
+ const response = await this.apiRequest('DELETE', this._messagePath(messageId));
508
528
 
509
529
  this._dropMessage(messageId);
510
530
 
511
- return true;
531
+ // { deleted, moved: { destination, message } } - moved is set when the message went
532
+ // to Trash instead of being removed
533
+ return response || { deleted: true };
512
534
  } catch (error) {
513
535
  console.error('Failed to delete message:', error);
514
536
  throw error;
@@ -779,8 +801,9 @@ export class EmailEngineClient {
779
801
  // missing, optionally with a Retry button. Without this a failed request
780
802
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
781
803
  // only trace of the failure in the developer console.
804
+ // error is the failed request's error, or a plain explanation to show instead
782
805
  _renderPaneError(selector, title, error, retry = null, header = '') {
783
- const detail = this._errorMessage(error, '');
806
+ const detail = typeof error === 'string' ? error : this._errorMessage(error, '');
784
807
  const pane = this._setPaneHtml(
785
808
  selector,
786
809
  `
@@ -817,6 +840,19 @@ export class EmailEngineClient {
817
840
  promise.catch(() => {});
818
841
  }
819
842
 
843
+ // A short notice at the bottom of the client that goes away on its own, for outcomes that
844
+ // need no answer (a message queued, a draft saved). Errors keep using alertMethod.
845
+ notify(message) {
846
+ const toast = this.container && this.container.querySelector('.ee-toast');
847
+ if (!toast || this._destroyed) {
848
+ return;
849
+ }
850
+ toast.textContent = message;
851
+ toast.classList.add('show');
852
+ clearTimeout(this._toastTimer);
853
+ this._toastTimer = setTimeout(() => toast.classList.remove('show'), 4000);
854
+ }
855
+
820
856
  // Message actions (flag, delete, move) have no pane of their own to report into:
821
857
  // when one fails the message simply stays put, which is indistinguishable from
822
858
  // nothing having happened. Say so instead.
@@ -890,6 +926,30 @@ export class EmailEngineClient {
890
926
  }
891
927
  }
892
928
 
929
+ // The date in the message header: weekday, date and time to the minute
930
+ formatFullDate(dateStr) {
931
+ const date = new Date(dateStr);
932
+ if (isNaN(date.getTime())) {
933
+ return '';
934
+ }
935
+ return date.toLocaleString(undefined, { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
936
+ }
937
+
938
+ // Header addresses as escaped HTML: "Name <address>" with the address muted, the bare address
939
+ // when there is no name, and the name alone for a name-only entry
940
+ _addressListHtml(list) {
941
+ return (Array.isArray(list) ? list : list ? [list] : [])
942
+ .map(entry => (typeof entry === 'string' ? { address: entry } : entry))
943
+ .filter(entry => entry && (entry.name || entry.address))
944
+ .map(entry => {
945
+ if (entry.name && entry.address) {
946
+ return `${this.escapeHtml(entry.name)} <span class="ee-address">&lt;${this.escapeHtml(entry.address)}&gt;</span>`;
947
+ }
948
+ return this.escapeHtml(entry.name || entry.address);
949
+ })
950
+ .join(', ');
951
+ }
952
+
893
953
  formatFileSize(bytes) {
894
954
  if (!bytes) {
895
955
  return '';
@@ -1082,6 +1142,18 @@ export class EmailEngineClient {
1082
1142
  }
1083
1143
 
1084
1144
  const style = this._createStyle(`
1145
+ /* The accent comes from the host's --ee-accent, --ee-accent-hover and --ee-accent-light
1146
+ (set on the container). They are resolved into private names once per root
1147
+ element: setting --ee-accent itself here would hide the host's value. */
1148
+ .ee-client,
1149
+ .ee-compose-button,
1150
+ .ee-compose-modal,
1151
+ .ee-toast {
1152
+ --_accent: var(--ee-accent, #007bff);
1153
+ --_accent-hover: var(--ee-accent-hover, #0056b3);
1154
+ --_accent-light: var(--ee-accent-light, #66b2ff);
1155
+ }
1156
+
1085
1157
  .ee-client {
1086
1158
  --ee-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
1087
1159
  display: flex;
@@ -1129,7 +1201,7 @@ export class EmailEngineClient {
1129
1201
  }
1130
1202
 
1131
1203
  .ee-folder-item.active {
1132
- background: #007bff;
1204
+ background: var(--_accent);
1133
1205
  color: white;
1134
1206
  }
1135
1207
 
@@ -1140,7 +1212,7 @@ export class EmailEngineClient {
1140
1212
  top: 0;
1141
1213
  bottom: 0;
1142
1214
  width: 3px;
1143
- background: #0056b3;
1215
+ background: var(--_accent-hover);
1144
1216
  }
1145
1217
 
1146
1218
  .ee-folder-content {
@@ -1204,7 +1276,7 @@ export class EmailEngineClient {
1204
1276
  }
1205
1277
 
1206
1278
  .ee-message-item.active {
1207
- background: #e3f2fd;
1279
+ background: color-mix(in srgb, var(--_accent) 12%, white);
1208
1280
  }
1209
1281
 
1210
1282
  .ee-message-item.unread {
@@ -1346,7 +1418,7 @@ export class EmailEngineClient {
1346
1418
  .ee-button:focus-visible,
1347
1419
  .ee-move-button:focus-within,
1348
1420
  .ee-compose-button:focus-visible {
1349
- outline: 2px solid #4d9fff;
1421
+ outline: 2px solid var(--_accent);
1350
1422
  outline-offset: 1px;
1351
1423
  }
1352
1424
 
@@ -1376,13 +1448,13 @@ export class EmailEngineClient {
1376
1448
  }
1377
1449
 
1378
1450
  .ee-button-primary {
1379
- background: #007bff;
1380
- border-color: #007bff;
1451
+ background: var(--_accent);
1452
+ border-color: var(--_accent);
1381
1453
  color: white;
1382
1454
  }
1383
1455
 
1384
1456
  .ee-button-primary:hover:not(:disabled) {
1385
- background: #0069d9;
1457
+ background: var(--_accent-hover);
1386
1458
  }
1387
1459
 
1388
1460
  .ee-button-danger:hover:not(:disabled) {
@@ -1416,9 +1488,7 @@ export class EmailEngineClient {
1416
1488
 
1417
1489
  .ee-message-content {
1418
1490
  flex: 1;
1419
- /* The bottom padding lets the end of the message scroll clear of
1420
- the floating compose button */
1421
- padding: 20px 20px 88px;
1491
+ padding: 20px;
1422
1492
  overflow-y: auto;
1423
1493
  }
1424
1494
 
@@ -1450,7 +1520,7 @@ export class EmailEngineClient {
1450
1520
  .ee-otp {
1451
1521
  margin-bottom: 16px;
1452
1522
  padding: 14px 16px;
1453
- background: #eef3fb;
1523
+ background: color-mix(in srgb, var(--_accent) 7%, white);
1454
1524
  border-radius: 8px;
1455
1525
  }
1456
1526
 
@@ -1503,14 +1573,14 @@ export class EmailEngineClient {
1503
1573
  height: 32px;
1504
1574
  padding: 0 16px;
1505
1575
  font-size: 13px;
1506
- background: #007bff;
1507
- border-color: #007bff;
1576
+ background: var(--_accent);
1577
+ border-color: var(--_accent);
1508
1578
  color: white;
1509
1579
  border-radius: 16px;
1510
1580
  }
1511
1581
 
1512
1582
  .ee-otp .ee-otp-copy:hover:not(:disabled) {
1513
- background: #0069d9;
1583
+ background: var(--_accent-hover);
1514
1584
  }
1515
1585
 
1516
1586
  .ee-otp-status,
@@ -1695,7 +1765,6 @@ export class EmailEngineClient {
1695
1765
  .ee-message-items {
1696
1766
  flex: 1;
1697
1767
  overflow-y: auto;
1698
- padding-bottom: 88px;
1699
1768
  }
1700
1769
 
1701
1770
  .ee-compose-button {
@@ -1704,48 +1773,34 @@ export class EmailEngineClient {
1704
1773
  right: 20px;
1705
1774
  display: inline-flex;
1706
1775
  align-items: center;
1707
- gap: 10px;
1708
- height: 52px;
1709
- padding: 0 22px 0 18px;
1710
- background: #007bff;
1776
+ justify-content: center;
1777
+ width: 56px;
1778
+ height: 56px;
1779
+ padding: 0;
1780
+ background: var(--_accent);
1711
1781
  border: none;
1712
- border-radius: 16px;
1782
+ border-radius: 50%;
1713
1783
  color: white;
1714
- font-family: var(--ee-font, inherit);
1715
- font-size: 15px;
1716
- font-weight: 600;
1717
1784
  cursor: pointer;
1718
- box-shadow: 0 4px 12px rgba(0,123,255,0.3);
1785
+ box-shadow: 0 4px 12px color-mix(in srgb, var(--_accent) 30%, transparent);
1719
1786
  z-index: 1000;
1720
1787
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1721
1788
  }
1722
1789
 
1723
1790
  .ee-compose-button:hover {
1724
- background: #0056b3;
1791
+ background: var(--_accent-hover);
1725
1792
  transform: translateY(-1px);
1726
- box-shadow: 0 6px 16px rgba(0,123,255,0.4);
1727
- }
1728
-
1729
- .ee-compose-button.ee-compose-compact {
1730
- width: 56px;
1731
- height: 56px;
1732
- padding: 0;
1733
- justify-content: center;
1734
- border-radius: 50%;
1735
- }
1736
-
1737
- .ee-compose-compact .ee-compose-button-label {
1738
- display: none;
1793
+ box-shadow: 0 6px 16px color-mix(in srgb, var(--_accent) 40%, transparent);
1739
1794
  }
1740
1795
 
1741
1796
  /* Medium widths: the viewer is too narrow for labelled buttons, so the
1742
1797
  toolbar goes icon-only, as webmail toolbars usually are */
1743
- @container ee-viewer (max-width: 559px) {
1744
- .ee-message-actions .ee-button:not(.ee-keep-label) .ee-button-label {
1798
+ @container ee-viewer (max-width: 699px) {
1799
+ .ee-message-actions .ee-button:not(.ee-keep-label):not(.ee-label-priority) .ee-button-label {
1745
1800
  display: none;
1746
1801
  }
1747
1802
 
1748
- .ee-message-actions .ee-button:not(.ee-keep-label) {
1803
+ .ee-message-actions .ee-button:not(.ee-keep-label):not(.ee-label-priority) {
1749
1804
  width: 30px;
1750
1805
  padding: 0;
1751
1806
  }
@@ -1756,6 +1811,22 @@ export class EmailEngineClient {
1756
1811
  }
1757
1812
  }
1758
1813
 
1814
+ /* Below this even the reply group goes icon-only */
1815
+ @container ee-viewer (max-width: 439px) {
1816
+ .ee-message-actions .ee-label-priority .ee-button-label {
1817
+ display: none;
1818
+ }
1819
+
1820
+ .ee-message-actions .ee-label-priority {
1821
+ width: 30px;
1822
+ padding: 0;
1823
+ }
1824
+
1825
+ .ee-toolbar-divider {
1826
+ display: none;
1827
+ }
1828
+ }
1829
+
1759
1830
  /* Narrow widths: one pane at a time, in the order a phone mail app uses
1760
1831
  (folders, list, message), with back buttons in the pane headers. The
1761
1832
  shown pane follows data-view on .ee-client. */
@@ -1782,6 +1853,15 @@ export class EmailEngineClient {
1782
1853
  .ee-message-content {
1783
1854
  padding: 16px 16px 88px;
1784
1855
  }
1856
+
1857
+ .ee-message-items {
1858
+ padding-bottom: 88px;
1859
+ }
1860
+
1861
+ /* the floating button is the Compose button here */
1862
+ .ee-sidebar-compose {
1863
+ display: none;
1864
+ }
1785
1865
  }
1786
1866
 
1787
1867
  .ee-compose-modal {
@@ -1846,37 +1926,56 @@ export class EmailEngineClient {
1846
1926
  }
1847
1927
 
1848
1928
  .ee-compose-form {
1849
- padding: 20px;
1929
+ padding: 16px 20px;
1850
1930
  display: flex;
1851
1931
  flex-direction: column;
1852
- gap: 16px;
1932
+ gap: 10px;
1853
1933
  flex: 1;
1854
1934
  overflow-y: auto;
1855
1935
  }
1856
-
1857
- .ee-compose-field {
1936
+
1937
+ /* One line per header field: the label beside its input, as mail clients lay out
1938
+ their compose headers, so the text box and the quote get the height */
1939
+ .ee-compose-row {
1858
1940
  display: flex;
1859
- flex-direction: column;
1860
- gap: 4px;
1941
+ align-items: center;
1942
+ gap: 10px;
1861
1943
  }
1862
-
1944
+
1863
1945
  .ee-compose-label {
1946
+ flex: 0 0 56px;
1947
+ font-size: 13px;
1864
1948
  font-weight: 500;
1865
- color: #333;
1949
+ color: #555;
1866
1950
  }
1867
-
1951
+
1868
1952
  .ee-compose-input {
1953
+ flex: 1;
1954
+ min-width: 0;
1869
1955
  padding: 8px 12px;
1870
1956
  border: 1px solid #ddd;
1871
1957
  border-radius: 4px;
1872
1958
  font-size: 14px;
1873
1959
  font-family: inherit;
1874
1960
  }
1875
-
1876
- .ee-compose-input:focus {
1877
- outline: none;
1878
- border-color: #007bff;
1879
- box-shadow: 0 0 0 2px rgba(0,123,255,0.1);
1961
+
1962
+ .ee-compose-input[aria-invalid="true"],
1963
+ .ee-compose-textarea[aria-invalid="true"] {
1964
+ border-color: #dc3545;
1965
+ }
1966
+
1967
+ /* Why the form did not go out, between the form and its buttons so it is on
1968
+ screen however far the form is scrolled */
1969
+ .ee-compose-error {
1970
+ margin: 0 20px 4px;
1971
+ padding: 8px 12px;
1972
+ border: 1px solid #fcc;
1973
+ border-radius: 4px;
1974
+ background: #fee;
1975
+ color: #c00;
1976
+ font-size: 13px;
1977
+ white-space: pre-line;
1978
+ flex-shrink: 0;
1880
1979
  }
1881
1980
 
1882
1981
  .ee-compose-textarea {
@@ -1886,13 +1985,14 @@ export class EmailEngineClient {
1886
1985
  font-size: 14px;
1887
1986
  font-family: inherit;
1888
1987
  resize: vertical;
1889
- min-height: 160px;
1988
+ min-height: 180px;
1890
1989
  }
1891
-
1990
+
1991
+ .ee-compose-input:focus,
1892
1992
  .ee-compose-textarea:focus {
1893
1993
  outline: none;
1894
- border-color: #007bff;
1895
- box-shadow: 0 0 0 2px rgba(0,123,255,0.1);
1994
+ border-color: var(--_accent);
1995
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--_accent) 12%, transparent);
1896
1996
  }
1897
1997
 
1898
1998
  .ee-compose-actions {
@@ -1905,7 +2005,7 @@ export class EmailEngineClient {
1905
2005
  }
1906
2006
 
1907
2007
  .ee-compose-send {
1908
- background: #007bff;
2008
+ background: var(--_accent);
1909
2009
  color: white;
1910
2010
  border: none;
1911
2011
  padding: 10px 20px;
@@ -1916,7 +2016,7 @@ export class EmailEngineClient {
1916
2016
  }
1917
2017
 
1918
2018
  .ee-compose-send:hover:not(:disabled) {
1919
- background: #0056b3;
2019
+ background: var(--_accent-hover);
1920
2020
  }
1921
2021
 
1922
2022
  .ee-compose-send:disabled {
@@ -1925,24 +2025,26 @@ export class EmailEngineClient {
1925
2025
  opacity: 0.6;
1926
2026
  }
1927
2027
 
2028
+ /* Cancel is the quiet way out, not a third weighted button */
1928
2029
  .ee-compose-cancel {
1929
- background: #6c757d;
1930
- color: white;
2030
+ margin-right: auto;
2031
+ background: transparent;
2032
+ color: #555;
1931
2033
  border: none;
1932
- padding: 10px 20px;
2034
+ padding: 10px 12px;
1933
2035
  border-radius: 4px;
1934
2036
  font-size: 14px;
1935
2037
  cursor: pointer;
1936
2038
  }
1937
2039
 
1938
2040
  .ee-compose-cancel:hover {
1939
- background: #545b62;
2041
+ background: #f0f0f0;
1940
2042
  }
1941
2043
 
1942
2044
  .ee-compose-save-draft {
1943
2045
  background: transparent;
1944
- color: #007bff;
1945
- border: 1px solid #007bff;
2046
+ color: var(--_accent);
2047
+ border: 1px solid var(--_accent);
1946
2048
  padding: 10px 20px;
1947
2049
  border-radius: 4px;
1948
2050
  font-size: 14px;
@@ -1951,7 +2053,7 @@ export class EmailEngineClient {
1951
2053
  }
1952
2054
 
1953
2055
  .ee-compose-save-draft:hover:not(:disabled) {
1954
- background: #007bff;
2056
+ background: var(--_accent);
1955
2057
  color: white;
1956
2058
  }
1957
2059
 
@@ -1962,25 +2064,97 @@ export class EmailEngineClient {
1962
2064
  opacity: 0.6;
1963
2065
  }
1964
2066
 
2067
+ .ee-sidebar-compose {
2068
+ padding: 12px;
2069
+ border-bottom: 1px solid #e0e0e0;
2070
+ }
2071
+
2072
+ .ee-sidebar-compose-button {
2073
+ display: flex;
2074
+ align-items: center;
2075
+ justify-content: center;
2076
+ gap: 8px;
2077
+ width: 100%;
2078
+ height: 38px;
2079
+ border: none;
2080
+ border-radius: 6px;
2081
+ background: var(--_accent);
2082
+ color: white;
2083
+ font: inherit;
2084
+ font-size: 14px;
2085
+ font-weight: 600;
2086
+ cursor: pointer;
2087
+ }
2088
+
2089
+ .ee-sidebar-compose-button:hover {
2090
+ background: var(--_accent-hover);
2091
+ }
2092
+
2093
+ .ee-toolbar-divider {
2094
+ width: 1px;
2095
+ height: 20px;
2096
+ margin: 0 4px;
2097
+ background: #ddd;
2098
+ flex-shrink: 0;
2099
+ }
2100
+
2101
+ .ee-address {
2102
+ color: #666;
2103
+ }
2104
+
2105
+ /* A styled message on the light surface its colours were chosen for (see
2106
+ _renderMessageBody); plain messages follow the theme */
2107
+ .ee-dark-mode .ee-message-body[data-styled],
2108
+ .ee-dark-mode .ee-compose-quote-body[data-styled] {
2109
+ background: #ffffff;
2110
+ color: #222;
2111
+ padding: 12px;
2112
+ border-radius: 6px;
2113
+ }
2114
+
2115
+ .ee-toast {
2116
+ position: fixed;
2117
+ left: 50%;
2118
+ bottom: 24px;
2119
+ transform: translate(-50%, 16px);
2120
+ max-width: calc(100vw - 32px);
2121
+ padding: 10px 16px;
2122
+ border-radius: 6px;
2123
+ background: #323232;
2124
+ color: #fff;
2125
+ font-family: var(--ee-font, inherit);
2126
+ font-size: 14px;
2127
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
2128
+ opacity: 0;
2129
+ pointer-events: none;
2130
+ transition: opacity 0.2s ease, transform 0.2s ease;
2131
+ z-index: 2100;
2132
+ }
2133
+
2134
+ .ee-toast.show {
2135
+ opacity: 1;
2136
+ transform: translate(-50%, 0);
2137
+ }
2138
+
2139
+ .ee-toast.ee-dark-mode {
2140
+ background: #e0e0e0;
2141
+ color: #1a1a1a;
2142
+ }
2143
+
1965
2144
  /* Parts of the compose form that come and go (Cc/Bcc, the forward checkbox, the
1966
2145
  quote) use the hidden attribute, which a display rule would otherwise override */
1967
2146
  .ee-compose-modal [hidden] {
1968
2147
  display: none !important;
1969
2148
  }
1970
2149
 
1971
- .ee-compose-label-row {
1972
- display: flex;
1973
- justify-content: space-between;
1974
- align-items: baseline;
1975
- }
1976
-
1977
2150
  .ee-compose-link {
2151
+ flex-shrink: 0;
1978
2152
  background: none;
1979
2153
  border: none;
1980
- padding: 0;
2154
+ padding: 4px 0;
1981
2155
  font: inherit;
1982
2156
  font-size: 13px;
1983
- color: #007bff;
2157
+ color: var(--_accent);
1984
2158
  cursor: pointer;
1985
2159
  }
1986
2160
 
@@ -2157,7 +2331,7 @@ export class EmailEngineClient {
2157
2331
  }
2158
2332
 
2159
2333
  .ee-dark-mode .ee-folder-item.active {
2160
- background: #0056b3;
2334
+ background: var(--_accent-hover);
2161
2335
  }
2162
2336
 
2163
2337
  .ee-dark-mode .ee-message-list {
@@ -2174,7 +2348,7 @@ export class EmailEngineClient {
2174
2348
  }
2175
2349
 
2176
2350
  .ee-dark-mode .ee-message-item.active {
2177
- background: #1a3d5c;
2351
+ background: color-mix(in srgb, var(--_accent) 35%, #1a1a1a);
2178
2352
  }
2179
2353
 
2180
2354
  .ee-dark-mode .ee-message-date,
@@ -2227,9 +2401,10 @@ export class EmailEngineClient {
2227
2401
  }
2228
2402
 
2229
2403
  .ee-dark-mode .ee-button-primary,
2230
- .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
2231
- background: #0056b3;
2232
- border-color: #0056b3;
2404
+ .ee-dark-mode .ee-button-primary:hover:not(:disabled),
2405
+ .ee-dark-mode .ee-sidebar-compose-button {
2406
+ background: var(--_accent-hover);
2407
+ border-color: var(--_accent-hover);
2233
2408
  color: white;
2234
2409
  }
2235
2410
 
@@ -2297,7 +2472,7 @@ export class EmailEngineClient {
2297
2472
  }
2298
2473
 
2299
2474
  .ee-dark-mode .ee-otp {
2300
- background: #23303f;
2475
+ background: color-mix(in srgb, var(--_accent) 18%, #1a1a1a);
2301
2476
  }
2302
2477
 
2303
2478
  .ee-dark-mode .ee-otp-title {
@@ -2311,8 +2486,8 @@ export class EmailEngineClient {
2311
2486
  }
2312
2487
 
2313
2488
  .ee-dark-mode .ee-otp .ee-otp-copy {
2314
- background: #0056b3;
2315
- border-color: #0056b3;
2489
+ background: var(--_accent-hover);
2490
+ border-color: var(--_accent-hover);
2316
2491
  color: white;
2317
2492
  }
2318
2493
 
@@ -2329,14 +2504,10 @@ export class EmailEngineClient {
2329
2504
  /* The compose button and modal sit beside .ee-client, not inside it, so
2330
2505
  setDarkMode puts the ee-dark-mode class on them directly */
2331
2506
  .ee-compose-button.ee-dark-mode {
2332
- background: #0056b3;
2507
+ background: var(--_accent-hover);
2333
2508
  color: white;
2334
2509
  }
2335
2510
 
2336
- .ee-compose-button.ee-dark-mode:hover {
2337
- background: #004a99;
2338
- }
2339
-
2340
2511
  .ee-compose-modal.ee-dark-mode {
2341
2512
  background: rgba(0, 0, 0, 0.7);
2342
2513
  }
@@ -2346,10 +2517,6 @@ export class EmailEngineClient {
2346
2517
  color: #e0e0e0;
2347
2518
  }
2348
2519
 
2349
- .ee-dark-mode .ee-compose-label {
2350
- color: #ccc;
2351
- }
2352
-
2353
2520
  .ee-dark-mode .ee-compose-header {
2354
2521
  background: linear-gradient(to bottom, #2a2a2a, #252525);
2355
2522
  border-color: #333;
@@ -2372,8 +2539,8 @@ export class EmailEngineClient {
2372
2539
 
2373
2540
  .ee-dark-mode .ee-compose-input:focus,
2374
2541
  .ee-dark-mode .ee-compose-textarea:focus {
2375
- border-color: #0056b3;
2376
- box-shadow: 0 0 0 2px rgba(0,86,179,0.2);
2542
+ border-color: var(--_accent-hover);
2543
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--_accent) 25%, transparent);
2377
2544
  }
2378
2545
 
2379
2546
  .ee-dark-mode .ee-compose-actions {
@@ -2381,25 +2548,44 @@ export class EmailEngineClient {
2381
2548
  }
2382
2549
 
2383
2550
  .ee-dark-mode .ee-compose-cancel {
2384
- background: #444;
2551
+ color: #ccc;
2385
2552
  }
2386
2553
 
2387
2554
  .ee-dark-mode .ee-compose-cancel:hover {
2388
- background: #555;
2555
+ background: #333;
2389
2556
  }
2390
2557
 
2391
2558
  .ee-dark-mode .ee-compose-save-draft {
2392
- color: #66b2ff;
2393
- border-color: #66b2ff;
2559
+ color: var(--_accent-light);
2560
+ border-color: var(--_accent-light);
2394
2561
  }
2395
2562
 
2396
2563
  .ee-dark-mode .ee-compose-save-draft:hover:not(:disabled) {
2397
- background: #66b2ff;
2564
+ background: var(--_accent-light);
2398
2565
  color: #1a1a1a;
2399
2566
  }
2400
2567
 
2568
+ .ee-dark-mode .ee-sidebar-compose {
2569
+ border-color: #333;
2570
+ }
2571
+
2572
+ .ee-dark-mode .ee-toolbar-divider {
2573
+ background: #444;
2574
+ }
2575
+
2576
+ .ee-dark-mode .ee-address,
2577
+ .ee-dark-mode .ee-compose-label {
2578
+ color: #aaa;
2579
+ }
2580
+
2581
+ .ee-dark-mode .ee-compose-error {
2582
+ background: #3a2222;
2583
+ border-color: #5c3030;
2584
+ color: #f0a5a5;
2585
+ }
2586
+
2401
2587
  .ee-dark-mode .ee-compose-link {
2402
- color: #66b2ff;
2588
+ color: var(--_accent-light);
2403
2589
  }
2404
2590
 
2405
2591
  .ee-dark-mode .ee-compose-attach {
@@ -2687,9 +2873,10 @@ export class EmailEngineClient {
2687
2873
  // the toolbar while keeping the platform's own folder picker.
2688
2874
  const respond = isDraft
2689
2875
  ? ''
2690
- : `${this._toolbarButton('reply', 'reply', 'Reply', 'Reply to the sender')}
2691
- ${addressEntries(msg.to).length + addressEntries(msg.cc).length > 1 ? this._toolbarButton('reply-all', 'replyAll', 'Reply all', 'Reply to everyone') : ''}
2692
- ${this._toolbarButton('forward', 'forward', 'Forward', 'Forward this message')}`;
2876
+ : `${this._toolbarButton('reply', 'reply', 'Reply', 'Reply to the sender', 'ee-label-priority')}
2877
+ ${addressEntries(msg.to).length + addressEntries(msg.cc).length > 1 ? this._toolbarButton('reply-all', 'replyAll', 'Reply all', 'Reply to everyone', 'ee-label-priority') : ''}
2878
+ ${this._toolbarButton('forward', 'forward', 'Forward', 'Forward this message', 'ee-label-priority')}
2879
+ <span class="ee-toolbar-divider"></span>`;
2693
2880
  const actions = `
2694
2881
  ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : respond}
2695
2882
  ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
@@ -2718,25 +2905,25 @@ export class EmailEngineClient {
2718
2905
  <div class="ee-message-meta">
2719
2906
  <div class="ee-message-meta-row">
2720
2907
  <span class="ee-message-meta-label">From</span>
2721
- <span class="ee-message-meta-value">${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}</span>
2908
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.from) || 'Unknown'}</span>
2722
2909
  </div>
2723
2910
  <div class="ee-message-meta-row">
2724
2911
  <span class="ee-message-meta-label">To</span>
2725
- <span class="ee-message-meta-value">${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}</span>
2912
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.to)}</span>
2726
2913
  </div>
2727
2914
  ${
2728
2915
  msg.cc && msg.cc.length
2729
2916
  ? `
2730
2917
  <div class="ee-message-meta-row">
2731
2918
  <span class="ee-message-meta-label">Cc</span>
2732
- <span class="ee-message-meta-value">${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}</span>
2919
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.cc)}</span>
2733
2920
  </div>
2734
2921
  `
2735
2922
  : ''
2736
2923
  }
2737
2924
  <div class="ee-message-meta-row">
2738
2925
  <span class="ee-message-meta-label">Date</span>
2739
- <span class="ee-message-meta-value">${this.escapeHtml(new Date(msg.date).toLocaleString())}</span>
2926
+ <span class="ee-message-meta-value">${this.escapeHtml(this.formatFullDate(msg.date))}</span>
2740
2927
  </div>
2741
2928
  </div>
2742
2929
  ${this.renderOtpBox(msg.otp)}
@@ -2791,7 +2978,7 @@ export class EmailEngineClient {
2791
2978
 
2792
2979
  try {
2793
2980
  await this.submitDraft(msg.id);
2794
- await this.alertMethod('Draft queued for delivery.', 'Success', null, 'OK');
2981
+ this.notify('Draft queued for delivery.');
2795
2982
  // Refresh the folder view - the provider removes the draft once it is sent,
2796
2983
  // immediately for Gmail and MS Graph, after SMTP delivery for IMAP accounts.
2797
2984
  if (!this._destroyed && this.currentFolder) {
@@ -2819,14 +3006,14 @@ export class EmailEngineClient {
2819
3006
  });
2820
3007
 
2821
3008
  viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
2822
- const result = await this.confirmMethod(
2823
- 'Are you sure you want to delete this message? This action cannot be undone.',
2824
- 'Delete Message',
2825
- 'Cancel',
2826
- 'Delete'
2827
- );
3009
+ // Whether a delete moves the message to Trash or removes it depends on the backend
3010
+ // and the folder (IMAP removes it from Trash and Junk, Gmail always moves it), so the
3011
+ // question makes no promise and the notice reports what the server did
3012
+ const result = await this.confirmMethod('Delete this message?', 'Delete Message', 'Cancel', 'Delete');
2828
3013
  if (result) {
2829
- this.deleteMessage(msg.id).catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
3014
+ this.deleteMessage(msg.id)
3015
+ .then(response => this.notify(response && response.moved ? 'Message moved to Trash.' : 'Message deleted.'))
3016
+ .catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
2830
3017
  }
2831
3018
  });
2832
3019
 
@@ -2925,6 +3112,16 @@ export class EmailEngineClient {
2925
3112
  }
2926
3113
 
2927
3114
  root.replaceChildren(style, content);
3115
+ // A message that sets its own colours or backgrounds was designed for a light page;
3116
+ // in dark mode its dark text would land on a dark background, or the client's light
3117
+ // text on its white tables, so it is shown on a light surface instead (see the
3118
+ // [data-styled] rule). A plain message has none and follows the theme.
3119
+ const styled = Array.from(content.querySelectorAll('[style], [bgcolor], [color]')).some(
3120
+ el => el.hasAttribute('bgcolor') || el.hasAttribute('color') || el.style.color || el.style.backgroundColor || el.style.backgroundImage
3121
+ );
3122
+ if (styled) {
3123
+ host.dataset.styled = 'true';
3124
+ }
2928
3125
  return root;
2929
3126
  }
2930
3127
 
@@ -2965,42 +3162,41 @@ export class EmailEngineClient {
2965
3162
  : ''
2966
3163
  }
2967
3164
  </div>
3165
+ <div class="ee-sidebar-compose">
3166
+ <button type="button" class="ee-sidebar-compose-button" data-action="compose">${icon('compose', 16)}<span>Compose</span></button>
3167
+ </div>
2968
3168
  <div class="ee-folder-tree"></div>
2969
3169
  </div>
2970
3170
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2971
3171
  <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2972
3172
  </div>
2973
- <button type="button" class="ee-compose-button${this.darkMode ? ' ee-dark-mode' : ''}" title="Compose email" aria-label="Compose">${icon('compose', 22)}<span class="ee-compose-button-label">Compose</span></button>
3173
+ <button type="button" class="ee-compose-button${this.darkMode ? ' ee-dark-mode' : ''}" title="Compose email" aria-label="Compose">${icon('compose', 22)}</button>
3174
+ <div class="ee-toast${this.darkMode ? ' ee-dark-mode' : ''}" role="status" aria-live="polite"></div>
2974
3175
  <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2975
3176
  <div class="ee-compose-dialog" role="dialog" aria-modal="true" aria-label="Compose">
2976
3177
  <div class="ee-compose-header">
2977
3178
  <h3 class="ee-compose-title">${COMPOSE_TITLES.new}</h3>
2978
3179
  <button type="button" class="ee-compose-close" aria-label="Close" title="Close">${icon('close', 18)}</button>
2979
3180
  </div>
2980
- <form class="ee-compose-form">
2981
- <div class="ee-compose-field">
2982
- <div class="ee-compose-label-row">
2983
- <label class="ee-compose-label" for="${this._composeId('to')}">To:</label>
2984
- <button type="button" class="ee-compose-link" data-action="show-cc">Cc / Bcc</button>
2985
- </div>
2986
- <input type="text" class="ee-compose-input" id="${this._composeId('to')}" name="to" placeholder="recipient@example.com" autocomplete="off" spellcheck="false">
3181
+ <form class="ee-compose-form" novalidate>
3182
+ <div class="ee-compose-row">
3183
+ <label class="ee-compose-label" for="${this._composeId('to')}">To</label>
3184
+ <input type="text" class="ee-compose-input" id="${this._composeId('to')}" name="to" autocomplete="off" spellcheck="false">
3185
+ <button type="button" class="ee-compose-link" data-action="show-cc">Cc / Bcc</button>
2987
3186
  </div>
2988
- <div class="ee-compose-field" data-field="cc" hidden>
2989
- <label class="ee-compose-label" for="${this._composeId('cc')}">Cc:</label>
3187
+ <div class="ee-compose-row" data-field="cc" hidden>
3188
+ <label class="ee-compose-label" for="${this._composeId('cc')}">Cc</label>
2990
3189
  <input type="text" class="ee-compose-input" id="${this._composeId('cc')}" name="cc" autocomplete="off" spellcheck="false">
2991
3190
  </div>
2992
- <div class="ee-compose-field" data-field="bcc" hidden>
2993
- <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc:</label>
3191
+ <div class="ee-compose-row" data-field="bcc" hidden>
3192
+ <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc</label>
2994
3193
  <input type="text" class="ee-compose-input" id="${this._composeId('bcc')}" name="bcc" autocomplete="off" spellcheck="false">
2995
3194
  </div>
2996
- <div class="ee-compose-field">
2997
- <label class="ee-compose-label" for="${this._composeId('subject')}">Subject:</label>
2998
- <input type="text" class="ee-compose-input" id="${this._composeId('subject')}" name="subject" placeholder="Enter subject">
2999
- </div>
3000
- <div class="ee-compose-field">
3001
- <label class="ee-compose-label" for="${this._composeId('message')}">Message:</label>
3002
- <textarea class="ee-compose-textarea" id="${this._composeId('message')}" name="message" placeholder="Type your message here..."></textarea>
3195
+ <div class="ee-compose-row">
3196
+ <label class="ee-compose-label" for="${this._composeId('subject')}">Subject</label>
3197
+ <input type="text" class="ee-compose-input" id="${this._composeId('subject')}" name="subject">
3003
3198
  </div>
3199
+ <textarea class="ee-compose-textarea" name="message" aria-label="Message" placeholder="Write your message"></textarea>
3004
3200
  <div class="ee-compose-files">
3005
3201
  <div class="ee-compose-chips"></div>
3006
3202
  <div class="ee-compose-files-row">
@@ -3017,6 +3213,7 @@ export class EmailEngineClient {
3017
3213
  <div class="ee-compose-quote-frame"></div>
3018
3214
  </div>
3019
3215
  </form>
3216
+ <div class="ee-compose-error" role="alert" hidden></div>
3020
3217
  <div class="ee-compose-actions">
3021
3218
  <button type="button" class="ee-compose-cancel">Cancel</button>
3022
3219
  <button type="button" class="ee-compose-save-draft">Save Draft</button>
@@ -3134,6 +3331,7 @@ export class EmailEngineClient {
3134
3331
  mode === 'forward' ? 'The forwarded message is added below your text:' : `${sender}'s message is quoted below your reply:`;
3135
3332
  // A shadow root cannot be attached twice, so each quote gets a fresh host
3136
3333
  const host = document.createElement('div');
3334
+ host.className = 'ee-compose-quote-body';
3137
3335
  quote.querySelector('.ee-compose-quote-frame').replaceChildren(host);
3138
3336
  this._labelCollapsedThreads(this._renderMessageBody(host, original));
3139
3337
  quote.hidden = false;
@@ -3163,6 +3361,7 @@ export class EmailEngineClient {
3163
3361
  els.forwardAttachments.hidden = true;
3164
3362
  els.quote.hidden = true;
3165
3363
  els.quote.querySelector('.ee-compose-quote-frame').replaceChildren();
3364
+ this._clearComposeError();
3166
3365
  this._compose = { els, reference: null, files: [] };
3167
3366
  this._showCopyFields({ cc: false, bcc: false });
3168
3367
  }
@@ -3174,22 +3373,26 @@ export class EmailEngineClient {
3174
3373
  }
3175
3374
  }
3176
3375
 
3177
- // An alert shown from inside the compose form: the modal steps aside so the host's dialog is
3178
- // not stacked under it, and comes back with the form as it was
3179
- async _composeAlert(message, title, focusField = null) {
3180
- const { modal, form } = this._compose.els;
3181
- modal.classList.remove('show');
3182
- await this.alertMethod(message, title, null, 'OK');
3183
- if (this._destroyed) {
3184
- return;
3185
- }
3186
- modal.classList.add('show');
3187
- const field = focusField ? form.elements[focusField] : null;
3188
- if (field) {
3189
- setTimeout(() => field.focus(), 100);
3376
+ // Shows why the form cannot go out, inside the form itself, and marks the field it is about.
3377
+ // The message stays until the form is changed or closed.
3378
+ _showComposeError(message, field = null) {
3379
+ const { form, error } = this._compose.els;
3380
+ this._clearComposeError();
3381
+ error.textContent = message;
3382
+ error.hidden = false;
3383
+ const input = field ? form.elements[field] : null;
3384
+ if (input) {
3385
+ input.setAttribute('aria-invalid', 'true');
3386
+ input.focus();
3190
3387
  }
3191
3388
  }
3192
3389
 
3390
+ _clearComposeError() {
3391
+ const { form, error } = this._compose.els;
3392
+ error.hidden = true;
3393
+ form.querySelectorAll('[aria-invalid]').forEach(input => input.removeAttribute('aria-invalid'));
3394
+ }
3395
+
3193
3396
  _renderComposeChips() {
3194
3397
  this._compose.els.chips.innerHTML = this._compose.files
3195
3398
  .map(
@@ -3218,7 +3421,7 @@ export class EmailEngineClient {
3218
3421
 
3219
3422
  // Takes picked files into the form within the size limit. They are kept as File objects and
3220
3423
  // read only when the message is sent, so a removed file is never read at all.
3221
- async _addComposeFiles(files) {
3424
+ _addComposeFiles(files) {
3222
3425
  let total = this._compose.files.reduce((sum, file) => sum + file.size, 0);
3223
3426
  const skipped = [];
3224
3427
  for (const file of files) {
@@ -3231,10 +3434,7 @@ export class EmailEngineClient {
3231
3434
  }
3232
3435
  this._renderComposeChips();
3233
3436
  if (skipped.length) {
3234
- await this._composeAlert(
3235
- `Attachments are limited to ${this.formatFileSize(this.maxAttachmentSize)} in total. Not attached: ${skipped.join(', ')}`,
3236
- 'Attachment Too Large'
3237
- );
3437
+ this._showComposeError(`Attachments are limited to ${this.formatFileSize(this.maxAttachmentSize)} in total. Not attached: ${skipped.join(', ')}`);
3238
3438
  }
3239
3439
  }
3240
3440
 
@@ -3294,9 +3494,10 @@ export class EmailEngineClient {
3294
3494
  async _runComposeAction(button, busyText, errorTitle, requireMessage, submit) {
3295
3495
  const draft = this._readComposeForm(requireMessage);
3296
3496
  if (draft.problem) {
3297
- await this._composeAlert(draft.problem.message, 'Validation Error', draft.problem.field);
3497
+ this._showComposeError(draft.problem.message, draft.problem.field);
3298
3498
  return null;
3299
3499
  }
3500
+ this._clearComposeError();
3300
3501
 
3301
3502
  const originalText = button.textContent;
3302
3503
  button.disabled = true;
@@ -3308,7 +3509,7 @@ export class EmailEngineClient {
3308
3509
  return result || {};
3309
3510
  } catch (error) {
3310
3511
  console.error(`${errorTitle}:`, error);
3311
- await this._composeAlert(this._formatSendError(error), errorTitle, 'to');
3512
+ this._showComposeError(`${errorTitle}: ${this._formatSendError(error)}`);
3312
3513
  return null;
3313
3514
  } finally {
3314
3515
  button.disabled = false;
@@ -3329,12 +3530,15 @@ export class EmailEngineClient {
3329
3530
  chips: modal.querySelector('.ee-compose-chips'),
3330
3531
  fileInput: modal.querySelector('.ee-compose-file-input'),
3331
3532
  forwardAttachments: modal.querySelector('.ee-compose-forward-attachments'),
3332
- quote: modal.querySelector('.ee-compose-quote')
3533
+ quote: modal.querySelector('.ee-compose-quote'),
3534
+ error: modal.querySelector('.ee-compose-error')
3333
3535
  };
3334
3536
  const { form, fileInput, chips } = els;
3335
3537
  this._compose = { els, reference: null, files: [] };
3336
3538
 
3337
- this.container.querySelector('.ee-compose-button').addEventListener('click', () => this.compose());
3539
+ this.container
3540
+ .querySelectorAll('.ee-compose-button, .ee-sidebar-compose-button')
3541
+ .forEach(button => button.addEventListener('click', () => this.compose()));
3338
3542
 
3339
3543
  const closeCompose = () => this._closeCompose();
3340
3544
  modal.querySelector('.ee-compose-close').addEventListener('click', closeCompose);
@@ -3355,6 +3559,12 @@ export class EmailEngineClient {
3355
3559
  };
3356
3560
  document.addEventListener('keydown', this._composeKeydownHandler);
3357
3561
 
3562
+ form.addEventListener('input', () => {
3563
+ if (!els.error.hidden) {
3564
+ this._clearComposeError();
3565
+ }
3566
+ });
3567
+
3358
3568
  form.querySelector('[data-action="show-cc"]').addEventListener('click', () => {
3359
3569
  const ccShown = !form.querySelector('[data-field="cc"]').hidden;
3360
3570
  this._showCopyFields({ cc: true, bcc: true });
@@ -3365,7 +3575,7 @@ export class EmailEngineClient {
3365
3575
  fileInput.addEventListener('change', () => {
3366
3576
  const files = Array.from(fileInput.files || []);
3367
3577
  fileInput.value = '';
3368
- this._fireAndForget(this._addComposeFiles(files));
3578
+ this._addComposeFiles(files);
3369
3579
  });
3370
3580
  chips.addEventListener('click', e => {
3371
3581
  const remove = e.target.closest('.ee-compose-chip-remove');
@@ -3378,11 +3588,13 @@ export class EmailEngineClient {
3378
3588
  // Save the composed message as a draft instead of sending it
3379
3589
  const saveDraftButton = modal.querySelector('.ee-compose-save-draft');
3380
3590
  saveDraftButton.addEventListener('click', async () => {
3381
- const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Save Error', false, (...args) => this.saveDraft(...args));
3591
+ const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Could not save the draft', false, (...args) =>
3592
+ this.saveDraft(...args)
3593
+ );
3382
3594
  if (!response) {
3383
3595
  return;
3384
3596
  }
3385
- await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
3597
+ this.notify('Draft saved to the Drafts folder.');
3386
3598
  // Refresh the list when the user is looking at the Drafts folder
3387
3599
  if (!this._destroyed && response.path && this.currentFolder === response.path) {
3388
3600
  this._fireAndForget(this.loadMessages(this.currentFolder));
@@ -3392,10 +3604,10 @@ export class EmailEngineClient {
3392
3604
  // Send email
3393
3605
  const sendButton = modal.querySelector('.ee-compose-send');
3394
3606
  sendButton.addEventListener('click', async () => {
3395
- const response = await this._runComposeAction(sendButton, 'Sending...', 'Send Error', true, (...args) => this.sendMessage(...args));
3607
+ const response = await this._runComposeAction(sendButton, 'Sending...', 'Could not send the message', true, (...args) => this.sendMessage(...args));
3396
3608
  if (response) {
3397
3609
  // Submitting only queues the message; delivery happens afterwards and can still fail
3398
- await this.alertMethod('Message queued for delivery.', 'Queued', null, 'OK');
3610
+ this.notify('Message queued for delivery.');
3399
3611
  }
3400
3612
  });
3401
3613
 
@@ -3418,26 +3630,24 @@ export class EmailEngineClient {
3418
3630
  return;
3419
3631
  }
3420
3632
 
3633
+ const sidebarCompose = this.container.querySelector('.ee-sidebar-compose');
3421
3634
  const updateButtonPosition = () => {
3422
3635
  const containerRect = this.container.getBoundingClientRect();
3423
3636
  const margin = 20; // Desired margin from edges
3424
-
3425
- // A hidden container (display: none) reports a zero-size rect; positioning
3426
- // against it would push the fixed-position button off-screen. Hide the button
3427
- // instead and let the ResizeObserver below restore it once the container is
3428
- // shown - hosts often create the client inside a container that is only made
3429
- // visible afterwards.
3430
- if (!containerRect.width && !containerRect.height) {
3637
+ const buttonSize = 56;
3638
+
3639
+ // The floating button is the Compose button of the one-pane layout only. Whether
3640
+ // that layout is on is the stylesheet's container query to decide, so read its
3641
+ // answer (the folder pane's own Compose button is laid out) rather than repeat
3642
+ // the breakpoint. A hidden container (display: none) reports a zero-size rect;
3643
+ // the ResizeObserver below brings the button back once the container is shown.
3644
+ const wide = sidebarCompose && sidebarCompose.offsetParent !== null;
3645
+ if (wide || (!containerRect.width && !containerRect.height)) {
3431
3646
  composeButton.style.display = 'none';
3432
3647
  return;
3433
3648
  }
3434
3649
  composeButton.style.display = '';
3435
3650
 
3436
- // A labelled pill on roomy layouts, a round icon button where width is
3437
- // short and the button would cover too much of the single pane
3438
- composeButton.classList.toggle('ee-compose-compact', containerRect.width < NARROW_WIDTH);
3439
- const buttonSize = composeButton.offsetWidth || 56;
3440
-
3441
3651
  // Calculate the ideal position (bottom-right of container with margin)
3442
3652
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
3443
3653
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -3627,7 +3837,9 @@ export class EmailEngineClient {
3627
3837
 
3628
3838
  // Update UI. The compose button and modal are siblings of .ee-client, so
3629
3839
  // they carry the class themselves.
3630
- this.container.querySelectorAll('.ee-client, .ee-compose-button, .ee-compose-modal').forEach(el => el.classList.toggle('ee-dark-mode', this.darkMode));
3840
+ this.container
3841
+ .querySelectorAll('.ee-client, .ee-compose-button, .ee-compose-modal, .ee-toast')
3842
+ .forEach(el => el.classList.toggle('ee-dark-mode', this.darkMode));
3631
3843
 
3632
3844
  // Update toggle button icon
3633
3845
  const toggleIcon = this.container.querySelector('.ee-dark-mode-icon');
@@ -3656,6 +3868,9 @@ export class EmailEngineClient {
3656
3868
  this.keepAliveTimer = null;
3657
3869
  }
3658
3870
 
3871
+ clearTimeout(this._toastTimer);
3872
+ clearTimeout(this._otpCopyTimer);
3873
+
3659
3874
  // Remove the compose button's window scroll/resize listeners
3660
3875
  if (this._composeButtonCleanup) {
3661
3876
  this._composeButtonCleanup();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postalsys/ee-client",
3
- "version": "1.11.0",
3
+ "version": "1.11.2",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",