@postalsys/ee-client 1.11.0 → 1.11.1

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 +404 -192
  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;
@@ -433,26 +439,37 @@ export class EmailEngineClient {
433
439
  if (this.container && !this._destroyed) {
434
440
  this.renderMessage();
435
441
 
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' });
442
+ // The message opens at the top of the client: bring that into view when the
443
+ // page is scrolled past it (a long list on a phone), and leave the page alone
444
+ // otherwise. scrollIntoView honours the host's scroll-margin-top, which is how
445
+ // a page with a fixed header keeps the toolbar clear of it.
446
+ if (this.container.getBoundingClientRect().top < 0) {
447
+ this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
443
448
  }
444
449
  }
445
450
 
446
451
  return this.currentMessage;
447
452
  } catch (error) {
448
453
  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
- );
454
+ // A message that does not exist (deleted, moved, or a link with a mangled ID) is
455
+ // not worth retrying, and the API's validation text means nothing to a reader
456
+ if (error && (error.statusCode === 404 || error.statusCode === 400)) {
457
+ this._renderPaneError(
458
+ '.ee-message-viewer',
459
+ 'Message not found',
460
+ 'It may have been moved or deleted, or the link to it is incomplete.',
461
+ null,
462
+ this._messageToolbar()
463
+ );
464
+ } else {
465
+ this._renderPaneError(
466
+ '.ee-message-viewer',
467
+ 'Message unavailable',
468
+ error,
469
+ () => this._fireAndForget(this.loadMessage(messageId)),
470
+ this._messageToolbar()
471
+ );
472
+ }
456
473
  throw error;
457
474
  }
458
475
  }
@@ -504,11 +521,13 @@ export class EmailEngineClient {
504
521
 
505
522
  async deleteMessage(messageId) {
506
523
  try {
507
- await this.apiRequest('DELETE', this._messagePath(messageId));
524
+ const response = await this.apiRequest('DELETE', this._messagePath(messageId));
508
525
 
509
526
  this._dropMessage(messageId);
510
527
 
511
- return true;
528
+ // { deleted, moved: { destination, message } } - moved is set when the message went
529
+ // to Trash instead of being removed
530
+ return response || { deleted: true };
512
531
  } catch (error) {
513
532
  console.error('Failed to delete message:', error);
514
533
  throw error;
@@ -779,8 +798,9 @@ export class EmailEngineClient {
779
798
  // missing, optionally with a Retry button. Without this a failed request
780
799
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
781
800
  // only trace of the failure in the developer console.
801
+ // error is the failed request's error, or a plain explanation to show instead
782
802
  _renderPaneError(selector, title, error, retry = null, header = '') {
783
- const detail = this._errorMessage(error, '');
803
+ const detail = typeof error === 'string' ? error : this._errorMessage(error, '');
784
804
  const pane = this._setPaneHtml(
785
805
  selector,
786
806
  `
@@ -817,6 +837,19 @@ export class EmailEngineClient {
817
837
  promise.catch(() => {});
818
838
  }
819
839
 
840
+ // A short notice at the bottom of the client that goes away on its own, for outcomes that
841
+ // need no answer (a message queued, a draft saved). Errors keep using alertMethod.
842
+ notify(message) {
843
+ const toast = this.container && this.container.querySelector('.ee-toast');
844
+ if (!toast || this._destroyed) {
845
+ return;
846
+ }
847
+ toast.textContent = message;
848
+ toast.classList.add('show');
849
+ clearTimeout(this._toastTimer);
850
+ this._toastTimer = setTimeout(() => toast.classList.remove('show'), 4000);
851
+ }
852
+
820
853
  // Message actions (flag, delete, move) have no pane of their own to report into:
821
854
  // when one fails the message simply stays put, which is indistinguishable from
822
855
  // nothing having happened. Say so instead.
@@ -890,6 +923,30 @@ export class EmailEngineClient {
890
923
  }
891
924
  }
892
925
 
926
+ // The date in the message header: weekday, date and time to the minute
927
+ formatFullDate(dateStr) {
928
+ const date = new Date(dateStr);
929
+ if (isNaN(date.getTime())) {
930
+ return '';
931
+ }
932
+ return date.toLocaleString(undefined, { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
933
+ }
934
+
935
+ // Header addresses as escaped HTML: "Name <address>" with the address muted, the bare address
936
+ // when there is no name, and the name alone for a name-only entry
937
+ _addressListHtml(list) {
938
+ return (Array.isArray(list) ? list : list ? [list] : [])
939
+ .map(entry => (typeof entry === 'string' ? { address: entry } : entry))
940
+ .filter(entry => entry && (entry.name || entry.address))
941
+ .map(entry => {
942
+ if (entry.name && entry.address) {
943
+ return `${this.escapeHtml(entry.name)} <span class="ee-address">&lt;${this.escapeHtml(entry.address)}&gt;</span>`;
944
+ }
945
+ return this.escapeHtml(entry.name || entry.address);
946
+ })
947
+ .join(', ');
948
+ }
949
+
893
950
  formatFileSize(bytes) {
894
951
  if (!bytes) {
895
952
  return '';
@@ -1082,6 +1139,18 @@ export class EmailEngineClient {
1082
1139
  }
1083
1140
 
1084
1141
  const style = this._createStyle(`
1142
+ /* The accent comes from the host's --ee-accent, --ee-accent-hover and --ee-accent-light
1143
+ (set on the container). They are resolved into private names once per root
1144
+ element: setting --ee-accent itself here would hide the host's value. */
1145
+ .ee-client,
1146
+ .ee-compose-button,
1147
+ .ee-compose-modal,
1148
+ .ee-toast {
1149
+ --_accent: var(--ee-accent, #007bff);
1150
+ --_accent-hover: var(--ee-accent-hover, #0056b3);
1151
+ --_accent-light: var(--ee-accent-light, #66b2ff);
1152
+ }
1153
+
1085
1154
  .ee-client {
1086
1155
  --ee-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
1087
1156
  display: flex;
@@ -1129,7 +1198,7 @@ export class EmailEngineClient {
1129
1198
  }
1130
1199
 
1131
1200
  .ee-folder-item.active {
1132
- background: #007bff;
1201
+ background: var(--_accent);
1133
1202
  color: white;
1134
1203
  }
1135
1204
 
@@ -1140,7 +1209,7 @@ export class EmailEngineClient {
1140
1209
  top: 0;
1141
1210
  bottom: 0;
1142
1211
  width: 3px;
1143
- background: #0056b3;
1212
+ background: var(--_accent-hover);
1144
1213
  }
1145
1214
 
1146
1215
  .ee-folder-content {
@@ -1204,7 +1273,7 @@ export class EmailEngineClient {
1204
1273
  }
1205
1274
 
1206
1275
  .ee-message-item.active {
1207
- background: #e3f2fd;
1276
+ background: color-mix(in srgb, var(--_accent) 12%, white);
1208
1277
  }
1209
1278
 
1210
1279
  .ee-message-item.unread {
@@ -1346,7 +1415,7 @@ export class EmailEngineClient {
1346
1415
  .ee-button:focus-visible,
1347
1416
  .ee-move-button:focus-within,
1348
1417
  .ee-compose-button:focus-visible {
1349
- outline: 2px solid #4d9fff;
1418
+ outline: 2px solid var(--_accent);
1350
1419
  outline-offset: 1px;
1351
1420
  }
1352
1421
 
@@ -1376,13 +1445,13 @@ export class EmailEngineClient {
1376
1445
  }
1377
1446
 
1378
1447
  .ee-button-primary {
1379
- background: #007bff;
1380
- border-color: #007bff;
1448
+ background: var(--_accent);
1449
+ border-color: var(--_accent);
1381
1450
  color: white;
1382
1451
  }
1383
1452
 
1384
1453
  .ee-button-primary:hover:not(:disabled) {
1385
- background: #0069d9;
1454
+ background: var(--_accent-hover);
1386
1455
  }
1387
1456
 
1388
1457
  .ee-button-danger:hover:not(:disabled) {
@@ -1416,9 +1485,7 @@ export class EmailEngineClient {
1416
1485
 
1417
1486
  .ee-message-content {
1418
1487
  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;
1488
+ padding: 20px;
1422
1489
  overflow-y: auto;
1423
1490
  }
1424
1491
 
@@ -1450,7 +1517,7 @@ export class EmailEngineClient {
1450
1517
  .ee-otp {
1451
1518
  margin-bottom: 16px;
1452
1519
  padding: 14px 16px;
1453
- background: #eef3fb;
1520
+ background: color-mix(in srgb, var(--_accent) 7%, white);
1454
1521
  border-radius: 8px;
1455
1522
  }
1456
1523
 
@@ -1503,14 +1570,14 @@ export class EmailEngineClient {
1503
1570
  height: 32px;
1504
1571
  padding: 0 16px;
1505
1572
  font-size: 13px;
1506
- background: #007bff;
1507
- border-color: #007bff;
1573
+ background: var(--_accent);
1574
+ border-color: var(--_accent);
1508
1575
  color: white;
1509
1576
  border-radius: 16px;
1510
1577
  }
1511
1578
 
1512
1579
  .ee-otp .ee-otp-copy:hover:not(:disabled) {
1513
- background: #0069d9;
1580
+ background: var(--_accent-hover);
1514
1581
  }
1515
1582
 
1516
1583
  .ee-otp-status,
@@ -1695,7 +1762,6 @@ export class EmailEngineClient {
1695
1762
  .ee-message-items {
1696
1763
  flex: 1;
1697
1764
  overflow-y: auto;
1698
- padding-bottom: 88px;
1699
1765
  }
1700
1766
 
1701
1767
  .ee-compose-button {
@@ -1704,48 +1770,34 @@ export class EmailEngineClient {
1704
1770
  right: 20px;
1705
1771
  display: inline-flex;
1706
1772
  align-items: center;
1707
- gap: 10px;
1708
- height: 52px;
1709
- padding: 0 22px 0 18px;
1710
- background: #007bff;
1773
+ justify-content: center;
1774
+ width: 56px;
1775
+ height: 56px;
1776
+ padding: 0;
1777
+ background: var(--_accent);
1711
1778
  border: none;
1712
- border-radius: 16px;
1779
+ border-radius: 50%;
1713
1780
  color: white;
1714
- font-family: var(--ee-font, inherit);
1715
- font-size: 15px;
1716
- font-weight: 600;
1717
1781
  cursor: pointer;
1718
- box-shadow: 0 4px 12px rgba(0,123,255,0.3);
1782
+ box-shadow: 0 4px 12px color-mix(in srgb, var(--_accent) 30%, transparent);
1719
1783
  z-index: 1000;
1720
1784
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1721
1785
  }
1722
1786
 
1723
1787
  .ee-compose-button:hover {
1724
- background: #0056b3;
1788
+ background: var(--_accent-hover);
1725
1789
  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;
1790
+ box-shadow: 0 6px 16px color-mix(in srgb, var(--_accent) 40%, transparent);
1739
1791
  }
1740
1792
 
1741
1793
  /* Medium widths: the viewer is too narrow for labelled buttons, so the
1742
1794
  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 {
1795
+ @container ee-viewer (max-width: 699px) {
1796
+ .ee-message-actions .ee-button:not(.ee-keep-label):not(.ee-label-priority) .ee-button-label {
1745
1797
  display: none;
1746
1798
  }
1747
1799
 
1748
- .ee-message-actions .ee-button:not(.ee-keep-label) {
1800
+ .ee-message-actions .ee-button:not(.ee-keep-label):not(.ee-label-priority) {
1749
1801
  width: 30px;
1750
1802
  padding: 0;
1751
1803
  }
@@ -1756,6 +1808,22 @@ export class EmailEngineClient {
1756
1808
  }
1757
1809
  }
1758
1810
 
1811
+ /* Below this even the reply group goes icon-only */
1812
+ @container ee-viewer (max-width: 439px) {
1813
+ .ee-message-actions .ee-label-priority .ee-button-label {
1814
+ display: none;
1815
+ }
1816
+
1817
+ .ee-message-actions .ee-label-priority {
1818
+ width: 30px;
1819
+ padding: 0;
1820
+ }
1821
+
1822
+ .ee-toolbar-divider {
1823
+ display: none;
1824
+ }
1825
+ }
1826
+
1759
1827
  /* Narrow widths: one pane at a time, in the order a phone mail app uses
1760
1828
  (folders, list, message), with back buttons in the pane headers. The
1761
1829
  shown pane follows data-view on .ee-client. */
@@ -1782,6 +1850,15 @@ export class EmailEngineClient {
1782
1850
  .ee-message-content {
1783
1851
  padding: 16px 16px 88px;
1784
1852
  }
1853
+
1854
+ .ee-message-items {
1855
+ padding-bottom: 88px;
1856
+ }
1857
+
1858
+ /* the floating button is the Compose button here */
1859
+ .ee-sidebar-compose {
1860
+ display: none;
1861
+ }
1785
1862
  }
1786
1863
 
1787
1864
  .ee-compose-modal {
@@ -1846,37 +1923,56 @@ export class EmailEngineClient {
1846
1923
  }
1847
1924
 
1848
1925
  .ee-compose-form {
1849
- padding: 20px;
1926
+ padding: 16px 20px;
1850
1927
  display: flex;
1851
1928
  flex-direction: column;
1852
- gap: 16px;
1929
+ gap: 10px;
1853
1930
  flex: 1;
1854
1931
  overflow-y: auto;
1855
1932
  }
1856
-
1857
- .ee-compose-field {
1933
+
1934
+ /* One line per header field: the label beside its input, as mail clients lay out
1935
+ their compose headers, so the text box and the quote get the height */
1936
+ .ee-compose-row {
1858
1937
  display: flex;
1859
- flex-direction: column;
1860
- gap: 4px;
1938
+ align-items: center;
1939
+ gap: 10px;
1861
1940
  }
1862
-
1941
+
1863
1942
  .ee-compose-label {
1943
+ flex: 0 0 56px;
1944
+ font-size: 13px;
1864
1945
  font-weight: 500;
1865
- color: #333;
1946
+ color: #555;
1866
1947
  }
1867
-
1948
+
1868
1949
  .ee-compose-input {
1950
+ flex: 1;
1951
+ min-width: 0;
1869
1952
  padding: 8px 12px;
1870
1953
  border: 1px solid #ddd;
1871
1954
  border-radius: 4px;
1872
1955
  font-size: 14px;
1873
1956
  font-family: inherit;
1874
1957
  }
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);
1958
+
1959
+ .ee-compose-input[aria-invalid="true"],
1960
+ .ee-compose-textarea[aria-invalid="true"] {
1961
+ border-color: #dc3545;
1962
+ }
1963
+
1964
+ /* Why the form did not go out, between the form and its buttons so it is on
1965
+ screen however far the form is scrolled */
1966
+ .ee-compose-error {
1967
+ margin: 0 20px 4px;
1968
+ padding: 8px 12px;
1969
+ border: 1px solid #fcc;
1970
+ border-radius: 4px;
1971
+ background: #fee;
1972
+ color: #c00;
1973
+ font-size: 13px;
1974
+ white-space: pre-line;
1975
+ flex-shrink: 0;
1880
1976
  }
1881
1977
 
1882
1978
  .ee-compose-textarea {
@@ -1886,13 +1982,14 @@ export class EmailEngineClient {
1886
1982
  font-size: 14px;
1887
1983
  font-family: inherit;
1888
1984
  resize: vertical;
1889
- min-height: 160px;
1985
+ min-height: 180px;
1890
1986
  }
1891
-
1987
+
1988
+ .ee-compose-input:focus,
1892
1989
  .ee-compose-textarea:focus {
1893
1990
  outline: none;
1894
- border-color: #007bff;
1895
- box-shadow: 0 0 0 2px rgba(0,123,255,0.1);
1991
+ border-color: var(--_accent);
1992
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--_accent) 12%, transparent);
1896
1993
  }
1897
1994
 
1898
1995
  .ee-compose-actions {
@@ -1905,7 +2002,7 @@ export class EmailEngineClient {
1905
2002
  }
1906
2003
 
1907
2004
  .ee-compose-send {
1908
- background: #007bff;
2005
+ background: var(--_accent);
1909
2006
  color: white;
1910
2007
  border: none;
1911
2008
  padding: 10px 20px;
@@ -1916,7 +2013,7 @@ export class EmailEngineClient {
1916
2013
  }
1917
2014
 
1918
2015
  .ee-compose-send:hover:not(:disabled) {
1919
- background: #0056b3;
2016
+ background: var(--_accent-hover);
1920
2017
  }
1921
2018
 
1922
2019
  .ee-compose-send:disabled {
@@ -1925,24 +2022,26 @@ export class EmailEngineClient {
1925
2022
  opacity: 0.6;
1926
2023
  }
1927
2024
 
2025
+ /* Cancel is the quiet way out, not a third weighted button */
1928
2026
  .ee-compose-cancel {
1929
- background: #6c757d;
1930
- color: white;
2027
+ margin-right: auto;
2028
+ background: transparent;
2029
+ color: #555;
1931
2030
  border: none;
1932
- padding: 10px 20px;
2031
+ padding: 10px 12px;
1933
2032
  border-radius: 4px;
1934
2033
  font-size: 14px;
1935
2034
  cursor: pointer;
1936
2035
  }
1937
2036
 
1938
2037
  .ee-compose-cancel:hover {
1939
- background: #545b62;
2038
+ background: #f0f0f0;
1940
2039
  }
1941
2040
 
1942
2041
  .ee-compose-save-draft {
1943
2042
  background: transparent;
1944
- color: #007bff;
1945
- border: 1px solid #007bff;
2043
+ color: var(--_accent);
2044
+ border: 1px solid var(--_accent);
1946
2045
  padding: 10px 20px;
1947
2046
  border-radius: 4px;
1948
2047
  font-size: 14px;
@@ -1951,7 +2050,7 @@ export class EmailEngineClient {
1951
2050
  }
1952
2051
 
1953
2052
  .ee-compose-save-draft:hover:not(:disabled) {
1954
- background: #007bff;
2053
+ background: var(--_accent);
1955
2054
  color: white;
1956
2055
  }
1957
2056
 
@@ -1962,25 +2061,97 @@ export class EmailEngineClient {
1962
2061
  opacity: 0.6;
1963
2062
  }
1964
2063
 
2064
+ .ee-sidebar-compose {
2065
+ padding: 12px;
2066
+ border-bottom: 1px solid #e0e0e0;
2067
+ }
2068
+
2069
+ .ee-sidebar-compose-button {
2070
+ display: flex;
2071
+ align-items: center;
2072
+ justify-content: center;
2073
+ gap: 8px;
2074
+ width: 100%;
2075
+ height: 38px;
2076
+ border: none;
2077
+ border-radius: 6px;
2078
+ background: var(--_accent);
2079
+ color: white;
2080
+ font: inherit;
2081
+ font-size: 14px;
2082
+ font-weight: 600;
2083
+ cursor: pointer;
2084
+ }
2085
+
2086
+ .ee-sidebar-compose-button:hover {
2087
+ background: var(--_accent-hover);
2088
+ }
2089
+
2090
+ .ee-toolbar-divider {
2091
+ width: 1px;
2092
+ height: 20px;
2093
+ margin: 0 4px;
2094
+ background: #ddd;
2095
+ flex-shrink: 0;
2096
+ }
2097
+
2098
+ .ee-address {
2099
+ color: #666;
2100
+ }
2101
+
2102
+ /* A styled message on the light surface its colours were chosen for (see
2103
+ _renderMessageBody); plain messages follow the theme */
2104
+ .ee-dark-mode .ee-message-body[data-styled],
2105
+ .ee-dark-mode .ee-compose-quote-body[data-styled] {
2106
+ background: #ffffff;
2107
+ color: #222;
2108
+ padding: 12px;
2109
+ border-radius: 6px;
2110
+ }
2111
+
2112
+ .ee-toast {
2113
+ position: fixed;
2114
+ left: 50%;
2115
+ bottom: 24px;
2116
+ transform: translate(-50%, 16px);
2117
+ max-width: calc(100vw - 32px);
2118
+ padding: 10px 16px;
2119
+ border-radius: 6px;
2120
+ background: #323232;
2121
+ color: #fff;
2122
+ font-family: var(--ee-font, inherit);
2123
+ font-size: 14px;
2124
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
2125
+ opacity: 0;
2126
+ pointer-events: none;
2127
+ transition: opacity 0.2s ease, transform 0.2s ease;
2128
+ z-index: 2100;
2129
+ }
2130
+
2131
+ .ee-toast.show {
2132
+ opacity: 1;
2133
+ transform: translate(-50%, 0);
2134
+ }
2135
+
2136
+ .ee-toast.ee-dark-mode {
2137
+ background: #e0e0e0;
2138
+ color: #1a1a1a;
2139
+ }
2140
+
1965
2141
  /* Parts of the compose form that come and go (Cc/Bcc, the forward checkbox, the
1966
2142
  quote) use the hidden attribute, which a display rule would otherwise override */
1967
2143
  .ee-compose-modal [hidden] {
1968
2144
  display: none !important;
1969
2145
  }
1970
2146
 
1971
- .ee-compose-label-row {
1972
- display: flex;
1973
- justify-content: space-between;
1974
- align-items: baseline;
1975
- }
1976
-
1977
2147
  .ee-compose-link {
2148
+ flex-shrink: 0;
1978
2149
  background: none;
1979
2150
  border: none;
1980
- padding: 0;
2151
+ padding: 4px 0;
1981
2152
  font: inherit;
1982
2153
  font-size: 13px;
1983
- color: #007bff;
2154
+ color: var(--_accent);
1984
2155
  cursor: pointer;
1985
2156
  }
1986
2157
 
@@ -2157,7 +2328,7 @@ export class EmailEngineClient {
2157
2328
  }
2158
2329
 
2159
2330
  .ee-dark-mode .ee-folder-item.active {
2160
- background: #0056b3;
2331
+ background: var(--_accent-hover);
2161
2332
  }
2162
2333
 
2163
2334
  .ee-dark-mode .ee-message-list {
@@ -2174,7 +2345,7 @@ export class EmailEngineClient {
2174
2345
  }
2175
2346
 
2176
2347
  .ee-dark-mode .ee-message-item.active {
2177
- background: #1a3d5c;
2348
+ background: color-mix(in srgb, var(--_accent) 35%, #1a1a1a);
2178
2349
  }
2179
2350
 
2180
2351
  .ee-dark-mode .ee-message-date,
@@ -2227,9 +2398,10 @@ export class EmailEngineClient {
2227
2398
  }
2228
2399
 
2229
2400
  .ee-dark-mode .ee-button-primary,
2230
- .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
2231
- background: #0056b3;
2232
- border-color: #0056b3;
2401
+ .ee-dark-mode .ee-button-primary:hover:not(:disabled),
2402
+ .ee-dark-mode .ee-sidebar-compose-button {
2403
+ background: var(--_accent-hover);
2404
+ border-color: var(--_accent-hover);
2233
2405
  color: white;
2234
2406
  }
2235
2407
 
@@ -2297,7 +2469,7 @@ export class EmailEngineClient {
2297
2469
  }
2298
2470
 
2299
2471
  .ee-dark-mode .ee-otp {
2300
- background: #23303f;
2472
+ background: color-mix(in srgb, var(--_accent) 18%, #1a1a1a);
2301
2473
  }
2302
2474
 
2303
2475
  .ee-dark-mode .ee-otp-title {
@@ -2311,8 +2483,8 @@ export class EmailEngineClient {
2311
2483
  }
2312
2484
 
2313
2485
  .ee-dark-mode .ee-otp .ee-otp-copy {
2314
- background: #0056b3;
2315
- border-color: #0056b3;
2486
+ background: var(--_accent-hover);
2487
+ border-color: var(--_accent-hover);
2316
2488
  color: white;
2317
2489
  }
2318
2490
 
@@ -2329,14 +2501,10 @@ export class EmailEngineClient {
2329
2501
  /* The compose button and modal sit beside .ee-client, not inside it, so
2330
2502
  setDarkMode puts the ee-dark-mode class on them directly */
2331
2503
  .ee-compose-button.ee-dark-mode {
2332
- background: #0056b3;
2504
+ background: var(--_accent-hover);
2333
2505
  color: white;
2334
2506
  }
2335
2507
 
2336
- .ee-compose-button.ee-dark-mode:hover {
2337
- background: #004a99;
2338
- }
2339
-
2340
2508
  .ee-compose-modal.ee-dark-mode {
2341
2509
  background: rgba(0, 0, 0, 0.7);
2342
2510
  }
@@ -2346,10 +2514,6 @@ export class EmailEngineClient {
2346
2514
  color: #e0e0e0;
2347
2515
  }
2348
2516
 
2349
- .ee-dark-mode .ee-compose-label {
2350
- color: #ccc;
2351
- }
2352
-
2353
2517
  .ee-dark-mode .ee-compose-header {
2354
2518
  background: linear-gradient(to bottom, #2a2a2a, #252525);
2355
2519
  border-color: #333;
@@ -2372,8 +2536,8 @@ export class EmailEngineClient {
2372
2536
 
2373
2537
  .ee-dark-mode .ee-compose-input:focus,
2374
2538
  .ee-dark-mode .ee-compose-textarea:focus {
2375
- border-color: #0056b3;
2376
- box-shadow: 0 0 0 2px rgba(0,86,179,0.2);
2539
+ border-color: var(--_accent-hover);
2540
+ box-shadow: 0 0 0 2px color-mix(in srgb, var(--_accent) 25%, transparent);
2377
2541
  }
2378
2542
 
2379
2543
  .ee-dark-mode .ee-compose-actions {
@@ -2381,25 +2545,44 @@ export class EmailEngineClient {
2381
2545
  }
2382
2546
 
2383
2547
  .ee-dark-mode .ee-compose-cancel {
2384
- background: #444;
2548
+ color: #ccc;
2385
2549
  }
2386
2550
 
2387
2551
  .ee-dark-mode .ee-compose-cancel:hover {
2388
- background: #555;
2552
+ background: #333;
2389
2553
  }
2390
2554
 
2391
2555
  .ee-dark-mode .ee-compose-save-draft {
2392
- color: #66b2ff;
2393
- border-color: #66b2ff;
2556
+ color: var(--_accent-light);
2557
+ border-color: var(--_accent-light);
2394
2558
  }
2395
2559
 
2396
2560
  .ee-dark-mode .ee-compose-save-draft:hover:not(:disabled) {
2397
- background: #66b2ff;
2561
+ background: var(--_accent-light);
2398
2562
  color: #1a1a1a;
2399
2563
  }
2400
2564
 
2565
+ .ee-dark-mode .ee-sidebar-compose {
2566
+ border-color: #333;
2567
+ }
2568
+
2569
+ .ee-dark-mode .ee-toolbar-divider {
2570
+ background: #444;
2571
+ }
2572
+
2573
+ .ee-dark-mode .ee-address,
2574
+ .ee-dark-mode .ee-compose-label {
2575
+ color: #aaa;
2576
+ }
2577
+
2578
+ .ee-dark-mode .ee-compose-error {
2579
+ background: #3a2222;
2580
+ border-color: #5c3030;
2581
+ color: #f0a5a5;
2582
+ }
2583
+
2401
2584
  .ee-dark-mode .ee-compose-link {
2402
- color: #66b2ff;
2585
+ color: var(--_accent-light);
2403
2586
  }
2404
2587
 
2405
2588
  .ee-dark-mode .ee-compose-attach {
@@ -2687,9 +2870,10 @@ export class EmailEngineClient {
2687
2870
  // the toolbar while keeping the platform's own folder picker.
2688
2871
  const respond = isDraft
2689
2872
  ? ''
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')}`;
2873
+ : `${this._toolbarButton('reply', 'reply', 'Reply', 'Reply to the sender', 'ee-label-priority')}
2874
+ ${addressEntries(msg.to).length + addressEntries(msg.cc).length > 1 ? this._toolbarButton('reply-all', 'replyAll', 'Reply all', 'Reply to everyone', 'ee-label-priority') : ''}
2875
+ ${this._toolbarButton('forward', 'forward', 'Forward', 'Forward this message', 'ee-label-priority')}
2876
+ <span class="ee-toolbar-divider"></span>`;
2693
2877
  const actions = `
2694
2878
  ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : respond}
2695
2879
  ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
@@ -2718,25 +2902,25 @@ export class EmailEngineClient {
2718
2902
  <div class="ee-message-meta">
2719
2903
  <div class="ee-message-meta-row">
2720
2904
  <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>
2905
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.from) || 'Unknown'}</span>
2722
2906
  </div>
2723
2907
  <div class="ee-message-meta-row">
2724
2908
  <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>
2909
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.to)}</span>
2726
2910
  </div>
2727
2911
  ${
2728
2912
  msg.cc && msg.cc.length
2729
2913
  ? `
2730
2914
  <div class="ee-message-meta-row">
2731
2915
  <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>
2916
+ <span class="ee-message-meta-value">${this._addressListHtml(msg.cc)}</span>
2733
2917
  </div>
2734
2918
  `
2735
2919
  : ''
2736
2920
  }
2737
2921
  <div class="ee-message-meta-row">
2738
2922
  <span class="ee-message-meta-label">Date</span>
2739
- <span class="ee-message-meta-value">${this.escapeHtml(new Date(msg.date).toLocaleString())}</span>
2923
+ <span class="ee-message-meta-value">${this.escapeHtml(this.formatFullDate(msg.date))}</span>
2740
2924
  </div>
2741
2925
  </div>
2742
2926
  ${this.renderOtpBox(msg.otp)}
@@ -2791,7 +2975,7 @@ export class EmailEngineClient {
2791
2975
 
2792
2976
  try {
2793
2977
  await this.submitDraft(msg.id);
2794
- await this.alertMethod('Draft queued for delivery.', 'Success', null, 'OK');
2978
+ this.notify('Draft queued for delivery.');
2795
2979
  // Refresh the folder view - the provider removes the draft once it is sent,
2796
2980
  // immediately for Gmail and MS Graph, after SMTP delivery for IMAP accounts.
2797
2981
  if (!this._destroyed && this.currentFolder) {
@@ -2819,14 +3003,14 @@ export class EmailEngineClient {
2819
3003
  });
2820
3004
 
2821
3005
  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
- );
3006
+ // Whether a delete moves the message to Trash or removes it depends on the backend
3007
+ // and the folder (IMAP removes it from Trash and Junk, Gmail always moves it), so the
3008
+ // question makes no promise and the notice reports what the server did
3009
+ const result = await this.confirmMethod('Delete this message?', 'Delete Message', 'Cancel', 'Delete');
2828
3010
  if (result) {
2829
- this.deleteMessage(msg.id).catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
3011
+ this.deleteMessage(msg.id)
3012
+ .then(response => this.notify(response && response.moved ? 'Message moved to Trash.' : 'Message deleted.'))
3013
+ .catch(error => this._alertActionFailed(error, 'Failed to delete the message'));
2830
3014
  }
2831
3015
  });
2832
3016
 
@@ -2925,6 +3109,16 @@ export class EmailEngineClient {
2925
3109
  }
2926
3110
 
2927
3111
  root.replaceChildren(style, content);
3112
+ // A message that sets its own colours or backgrounds was designed for a light page;
3113
+ // in dark mode its dark text would land on a dark background, or the client's light
3114
+ // text on its white tables, so it is shown on a light surface instead (see the
3115
+ // [data-styled] rule). A plain message has none and follows the theme.
3116
+ const styled = Array.from(content.querySelectorAll('[style], [bgcolor], [color]')).some(
3117
+ el => el.hasAttribute('bgcolor') || el.hasAttribute('color') || el.style.color || el.style.backgroundColor || el.style.backgroundImage
3118
+ );
3119
+ if (styled) {
3120
+ host.dataset.styled = 'true';
3121
+ }
2928
3122
  return root;
2929
3123
  }
2930
3124
 
@@ -2965,42 +3159,41 @@ export class EmailEngineClient {
2965
3159
  : ''
2966
3160
  }
2967
3161
  </div>
3162
+ <div class="ee-sidebar-compose">
3163
+ <button type="button" class="ee-sidebar-compose-button" data-action="compose">${icon('compose', 16)}<span>Compose</span></button>
3164
+ </div>
2968
3165
  <div class="ee-folder-tree"></div>
2969
3166
  </div>
2970
3167
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2971
3168
  <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2972
3169
  </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>
3170
+ <button type="button" class="ee-compose-button${this.darkMode ? ' ee-dark-mode' : ''}" title="Compose email" aria-label="Compose">${icon('compose', 22)}</button>
3171
+ <div class="ee-toast${this.darkMode ? ' ee-dark-mode' : ''}" role="status" aria-live="polite"></div>
2974
3172
  <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2975
3173
  <div class="ee-compose-dialog" role="dialog" aria-modal="true" aria-label="Compose">
2976
3174
  <div class="ee-compose-header">
2977
3175
  <h3 class="ee-compose-title">${COMPOSE_TITLES.new}</h3>
2978
3176
  <button type="button" class="ee-compose-close" aria-label="Close" title="Close">${icon('close', 18)}</button>
2979
3177
  </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">
3178
+ <form class="ee-compose-form" novalidate>
3179
+ <div class="ee-compose-row">
3180
+ <label class="ee-compose-label" for="${this._composeId('to')}">To</label>
3181
+ <input type="text" class="ee-compose-input" id="${this._composeId('to')}" name="to" autocomplete="off" spellcheck="false">
3182
+ <button type="button" class="ee-compose-link" data-action="show-cc">Cc / Bcc</button>
2987
3183
  </div>
2988
- <div class="ee-compose-field" data-field="cc" hidden>
2989
- <label class="ee-compose-label" for="${this._composeId('cc')}">Cc:</label>
3184
+ <div class="ee-compose-row" data-field="cc" hidden>
3185
+ <label class="ee-compose-label" for="${this._composeId('cc')}">Cc</label>
2990
3186
  <input type="text" class="ee-compose-input" id="${this._composeId('cc')}" name="cc" autocomplete="off" spellcheck="false">
2991
3187
  </div>
2992
- <div class="ee-compose-field" data-field="bcc" hidden>
2993
- <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc:</label>
3188
+ <div class="ee-compose-row" data-field="bcc" hidden>
3189
+ <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc</label>
2994
3190
  <input type="text" class="ee-compose-input" id="${this._composeId('bcc')}" name="bcc" autocomplete="off" spellcheck="false">
2995
3191
  </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>
3192
+ <div class="ee-compose-row">
3193
+ <label class="ee-compose-label" for="${this._composeId('subject')}">Subject</label>
3194
+ <input type="text" class="ee-compose-input" id="${this._composeId('subject')}" name="subject">
3003
3195
  </div>
3196
+ <textarea class="ee-compose-textarea" name="message" aria-label="Message" placeholder="Write your message"></textarea>
3004
3197
  <div class="ee-compose-files">
3005
3198
  <div class="ee-compose-chips"></div>
3006
3199
  <div class="ee-compose-files-row">
@@ -3017,6 +3210,7 @@ export class EmailEngineClient {
3017
3210
  <div class="ee-compose-quote-frame"></div>
3018
3211
  </div>
3019
3212
  </form>
3213
+ <div class="ee-compose-error" role="alert" hidden></div>
3020
3214
  <div class="ee-compose-actions">
3021
3215
  <button type="button" class="ee-compose-cancel">Cancel</button>
3022
3216
  <button type="button" class="ee-compose-save-draft">Save Draft</button>
@@ -3134,6 +3328,7 @@ export class EmailEngineClient {
3134
3328
  mode === 'forward' ? 'The forwarded message is added below your text:' : `${sender}'s message is quoted below your reply:`;
3135
3329
  // A shadow root cannot be attached twice, so each quote gets a fresh host
3136
3330
  const host = document.createElement('div');
3331
+ host.className = 'ee-compose-quote-body';
3137
3332
  quote.querySelector('.ee-compose-quote-frame').replaceChildren(host);
3138
3333
  this._labelCollapsedThreads(this._renderMessageBody(host, original));
3139
3334
  quote.hidden = false;
@@ -3163,6 +3358,7 @@ export class EmailEngineClient {
3163
3358
  els.forwardAttachments.hidden = true;
3164
3359
  els.quote.hidden = true;
3165
3360
  els.quote.querySelector('.ee-compose-quote-frame').replaceChildren();
3361
+ this._clearComposeError();
3166
3362
  this._compose = { els, reference: null, files: [] };
3167
3363
  this._showCopyFields({ cc: false, bcc: false });
3168
3364
  }
@@ -3174,22 +3370,26 @@ export class EmailEngineClient {
3174
3370
  }
3175
3371
  }
3176
3372
 
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);
3373
+ // Shows why the form cannot go out, inside the form itself, and marks the field it is about.
3374
+ // The message stays until the form is changed or closed.
3375
+ _showComposeError(message, field = null) {
3376
+ const { form, error } = this._compose.els;
3377
+ this._clearComposeError();
3378
+ error.textContent = message;
3379
+ error.hidden = false;
3380
+ const input = field ? form.elements[field] : null;
3381
+ if (input) {
3382
+ input.setAttribute('aria-invalid', 'true');
3383
+ input.focus();
3190
3384
  }
3191
3385
  }
3192
3386
 
3387
+ _clearComposeError() {
3388
+ const { form, error } = this._compose.els;
3389
+ error.hidden = true;
3390
+ form.querySelectorAll('[aria-invalid]').forEach(input => input.removeAttribute('aria-invalid'));
3391
+ }
3392
+
3193
3393
  _renderComposeChips() {
3194
3394
  this._compose.els.chips.innerHTML = this._compose.files
3195
3395
  .map(
@@ -3218,7 +3418,7 @@ export class EmailEngineClient {
3218
3418
 
3219
3419
  // Takes picked files into the form within the size limit. They are kept as File objects and
3220
3420
  // read only when the message is sent, so a removed file is never read at all.
3221
- async _addComposeFiles(files) {
3421
+ _addComposeFiles(files) {
3222
3422
  let total = this._compose.files.reduce((sum, file) => sum + file.size, 0);
3223
3423
  const skipped = [];
3224
3424
  for (const file of files) {
@@ -3231,10 +3431,7 @@ export class EmailEngineClient {
3231
3431
  }
3232
3432
  this._renderComposeChips();
3233
3433
  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
- );
3434
+ this._showComposeError(`Attachments are limited to ${this.formatFileSize(this.maxAttachmentSize)} in total. Not attached: ${skipped.join(', ')}`);
3238
3435
  }
3239
3436
  }
3240
3437
 
@@ -3294,9 +3491,10 @@ export class EmailEngineClient {
3294
3491
  async _runComposeAction(button, busyText, errorTitle, requireMessage, submit) {
3295
3492
  const draft = this._readComposeForm(requireMessage);
3296
3493
  if (draft.problem) {
3297
- await this._composeAlert(draft.problem.message, 'Validation Error', draft.problem.field);
3494
+ this._showComposeError(draft.problem.message, draft.problem.field);
3298
3495
  return null;
3299
3496
  }
3497
+ this._clearComposeError();
3300
3498
 
3301
3499
  const originalText = button.textContent;
3302
3500
  button.disabled = true;
@@ -3308,7 +3506,7 @@ export class EmailEngineClient {
3308
3506
  return result || {};
3309
3507
  } catch (error) {
3310
3508
  console.error(`${errorTitle}:`, error);
3311
- await this._composeAlert(this._formatSendError(error), errorTitle, 'to');
3509
+ this._showComposeError(`${errorTitle}: ${this._formatSendError(error)}`);
3312
3510
  return null;
3313
3511
  } finally {
3314
3512
  button.disabled = false;
@@ -3329,12 +3527,15 @@ export class EmailEngineClient {
3329
3527
  chips: modal.querySelector('.ee-compose-chips'),
3330
3528
  fileInput: modal.querySelector('.ee-compose-file-input'),
3331
3529
  forwardAttachments: modal.querySelector('.ee-compose-forward-attachments'),
3332
- quote: modal.querySelector('.ee-compose-quote')
3530
+ quote: modal.querySelector('.ee-compose-quote'),
3531
+ error: modal.querySelector('.ee-compose-error')
3333
3532
  };
3334
3533
  const { form, fileInput, chips } = els;
3335
3534
  this._compose = { els, reference: null, files: [] };
3336
3535
 
3337
- this.container.querySelector('.ee-compose-button').addEventListener('click', () => this.compose());
3536
+ this.container
3537
+ .querySelectorAll('.ee-compose-button, .ee-sidebar-compose-button')
3538
+ .forEach(button => button.addEventListener('click', () => this.compose()));
3338
3539
 
3339
3540
  const closeCompose = () => this._closeCompose();
3340
3541
  modal.querySelector('.ee-compose-close').addEventListener('click', closeCompose);
@@ -3355,6 +3556,12 @@ export class EmailEngineClient {
3355
3556
  };
3356
3557
  document.addEventListener('keydown', this._composeKeydownHandler);
3357
3558
 
3559
+ form.addEventListener('input', () => {
3560
+ if (!els.error.hidden) {
3561
+ this._clearComposeError();
3562
+ }
3563
+ });
3564
+
3358
3565
  form.querySelector('[data-action="show-cc"]').addEventListener('click', () => {
3359
3566
  const ccShown = !form.querySelector('[data-field="cc"]').hidden;
3360
3567
  this._showCopyFields({ cc: true, bcc: true });
@@ -3365,7 +3572,7 @@ export class EmailEngineClient {
3365
3572
  fileInput.addEventListener('change', () => {
3366
3573
  const files = Array.from(fileInput.files || []);
3367
3574
  fileInput.value = '';
3368
- this._fireAndForget(this._addComposeFiles(files));
3575
+ this._addComposeFiles(files);
3369
3576
  });
3370
3577
  chips.addEventListener('click', e => {
3371
3578
  const remove = e.target.closest('.ee-compose-chip-remove');
@@ -3378,11 +3585,13 @@ export class EmailEngineClient {
3378
3585
  // Save the composed message as a draft instead of sending it
3379
3586
  const saveDraftButton = modal.querySelector('.ee-compose-save-draft');
3380
3587
  saveDraftButton.addEventListener('click', async () => {
3381
- const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Save Error', false, (...args) => this.saveDraft(...args));
3588
+ const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Could not save the draft', false, (...args) =>
3589
+ this.saveDraft(...args)
3590
+ );
3382
3591
  if (!response) {
3383
3592
  return;
3384
3593
  }
3385
- await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
3594
+ this.notify('Draft saved to the Drafts folder.');
3386
3595
  // Refresh the list when the user is looking at the Drafts folder
3387
3596
  if (!this._destroyed && response.path && this.currentFolder === response.path) {
3388
3597
  this._fireAndForget(this.loadMessages(this.currentFolder));
@@ -3392,10 +3601,10 @@ export class EmailEngineClient {
3392
3601
  // Send email
3393
3602
  const sendButton = modal.querySelector('.ee-compose-send');
3394
3603
  sendButton.addEventListener('click', async () => {
3395
- const response = await this._runComposeAction(sendButton, 'Sending...', 'Send Error', true, (...args) => this.sendMessage(...args));
3604
+ const response = await this._runComposeAction(sendButton, 'Sending...', 'Could not send the message', true, (...args) => this.sendMessage(...args));
3396
3605
  if (response) {
3397
3606
  // Submitting only queues the message; delivery happens afterwards and can still fail
3398
- await this.alertMethod('Message queued for delivery.', 'Queued', null, 'OK');
3607
+ this.notify('Message queued for delivery.');
3399
3608
  }
3400
3609
  });
3401
3610
 
@@ -3418,26 +3627,24 @@ export class EmailEngineClient {
3418
3627
  return;
3419
3628
  }
3420
3629
 
3630
+ const sidebarCompose = this.container.querySelector('.ee-sidebar-compose');
3421
3631
  const updateButtonPosition = () => {
3422
3632
  const containerRect = this.container.getBoundingClientRect();
3423
3633
  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) {
3634
+ const buttonSize = 56;
3635
+
3636
+ // The floating button is the Compose button of the one-pane layout only. Whether
3637
+ // that layout is on is the stylesheet's container query to decide, so read its
3638
+ // answer (the folder pane's own Compose button is laid out) rather than repeat
3639
+ // the breakpoint. A hidden container (display: none) reports a zero-size rect;
3640
+ // the ResizeObserver below brings the button back once the container is shown.
3641
+ const wide = sidebarCompose && sidebarCompose.offsetParent !== null;
3642
+ if (wide || (!containerRect.width && !containerRect.height)) {
3431
3643
  composeButton.style.display = 'none';
3432
3644
  return;
3433
3645
  }
3434
3646
  composeButton.style.display = '';
3435
3647
 
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
3648
  // Calculate the ideal position (bottom-right of container with margin)
3442
3649
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
3443
3650
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -3627,7 +3834,9 @@ export class EmailEngineClient {
3627
3834
 
3628
3835
  // Update UI. The compose button and modal are siblings of .ee-client, so
3629
3836
  // 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));
3837
+ this.container
3838
+ .querySelectorAll('.ee-client, .ee-compose-button, .ee-compose-modal, .ee-toast')
3839
+ .forEach(el => el.classList.toggle('ee-dark-mode', this.darkMode));
3631
3840
 
3632
3841
  // Update toggle button icon
3633
3842
  const toggleIcon = this.container.querySelector('.ee-dark-mode-icon');
@@ -3656,6 +3865,9 @@ export class EmailEngineClient {
3656
3865
  this.keepAliveTimer = null;
3657
3866
  }
3658
3867
 
3868
+ clearTimeout(this._toastTimer);
3869
+ clearTimeout(this._otpCopyTimer);
3870
+
3659
3871
  // Remove the compose button's window scroll/resize listeners
3660
3872
  if (this._composeButtonCleanup) {
3661
3873
  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.1",
4
4
  "description": "EmailEngine client library for browser and Node.js applications",
5
5
  "main": "index.js",
6
6
  "module": "index.js",