@postalsys/ee-client 1.10.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 +56 -10
  2. package/index.d.ts +85 -3
  3. package/index.js +1219 -320
  4. package/package.json +8 -4
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;
@@ -78,7 +84,90 @@ const ICON_PATHS = {
78
84
  move: '<path d="M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1"/><path d="M2 13h10"/><path d="m9 16 3-3-3-3"/>',
79
85
  download: '<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/><path d="M12 15V3"/>',
80
86
  send: '<path d="m22 2-7 20-4-9-9-4Z"/><path d="M22 2 11 13"/>',
81
- compose: '<path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/>'
87
+ compose: '<path d="M12 20h9"/><path d="M16.5 3.5a2.12 2.12 0 0 1 3 3L7 19l-4 1 1-4Z"/>',
88
+ reply: '<polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/>',
89
+ replyAll: '<polyline points="7 17 2 12 7 7"/><polyline points="12 17 7 12 12 7"/><path d="M22 18v-2a4 4 0 0 0-4-4H7"/>',
90
+ forward: '<polyline points="15 17 20 12 15 7"/><path d="M4 18v-2a4 4 0 0 1 4-4h12"/>',
91
+ paperclip: '<path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/>',
92
+ close: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
93
+ sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="m4.93 4.93 1.41 1.41"/><path d="m17.66 17.66 1.41 1.41"/><path d="M2 12h2"/><path d="M20 12h2"/><path d="m6.34 17.66-1.41 1.41"/><path d="m19.07 4.93-1.41 1.41"/>',
94
+ moon: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>'
95
+ };
96
+
97
+ // Default cap on the files attached in the compose form, in bytes. They travel base64 encoded
98
+ // inside one JSON request, which grows them by a third, and most providers refuse a message
99
+ // much larger than this anyway. Hosts that know their limit pass maxAttachmentSize.
100
+ const DEFAULT_MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
101
+
102
+ // What a compose form address has to look like before it is sent. Deliberately loose: the
103
+ // server validates properly, this only catches a name typed without its address.
104
+ const ADDRESS_PATTERN = /^[^\s@<>",;]+@[^\s@<>",;]+$/;
105
+
106
+ // Splits an address field on commas and semicolons that are not inside a quoted name or an
107
+ // angle-bracketed address, so "Doe, John" <john@example.com> stays one entry.
108
+ function splitAddressField(value) {
109
+ const parts = [];
110
+ let current = '';
111
+ let quoted = false;
112
+ let bracketed = false;
113
+ for (let i = 0; i < value.length; i++) {
114
+ const chr = value[i];
115
+ if (chr === '\\' && quoted && i + 1 < value.length) {
116
+ current += chr + value[++i];
117
+ continue;
118
+ }
119
+ if (chr === '"' && !bracketed) {
120
+ quoted = !quoted;
121
+ } else if (chr === '<' && !quoted) {
122
+ bracketed = true;
123
+ } else if (chr === '>' && !quoted) {
124
+ bracketed = false;
125
+ } else if ((chr === ',' || chr === ';') && !quoted && !bracketed) {
126
+ parts.push(current);
127
+ current = '';
128
+ continue;
129
+ }
130
+ current += chr;
131
+ }
132
+ parts.push(current);
133
+ return parts.map(part => part.trim()).filter(Boolean);
134
+ }
135
+
136
+ function parseAddressEntry(entry) {
137
+ const match = entry.match(/^(.*)<([^>]*)>$/);
138
+ if (!match) {
139
+ return { address: entry };
140
+ }
141
+ let name = match[1].trim();
142
+ if (name.length > 1 && name.startsWith('"') && name.endsWith('"')) {
143
+ name = name.slice(1, -1).replace(/\\(.)/g, '$1');
144
+ }
145
+ const address = match[2].trim();
146
+ return name ? { name, address } : { address };
147
+ }
148
+
149
+ // Adds "Re: " or "Fwd: " unless the subject already starts with that prefix, so a long
150
+ // thread does not read "Re: Re: Re:"
151
+ function prefixSubject(subject, prefix) {
152
+ const value = (subject || '').trim();
153
+ const pattern = prefix === 'Re' ? /^re\s*:/i : /^fwd?\s*:/i;
154
+ return pattern.test(value) ? value : `${prefix}: ${value}`.trim();
155
+ }
156
+
157
+ // Address entries that carry an address, from a list, a single entry or a bare address string.
158
+ // The server can return name-only entries and a single object where a list is expected.
159
+ function addressEntries(value) {
160
+ return (Array.isArray(value) ? value : value ? [value] : [])
161
+ .map(entry => (typeof entry === 'string' ? { address: entry } : entry))
162
+ .filter(entry => entry && typeof entry.address === 'string' && entry.address);
163
+ }
164
+
165
+ // Compose form titles, by mode
166
+ const COMPOSE_TITLES = {
167
+ new: 'New Message',
168
+ reply: 'Reply',
169
+ 'reply-all': 'Reply All',
170
+ forward: 'Forward'
82
171
  };
83
172
 
84
173
  // Below this container width the UI shows one pane at a time and the compose button
@@ -112,6 +201,14 @@ export class EmailEngineClient {
112
201
 
113
202
  this.currentFolder = null;
114
203
  this.currentMessage = null;
204
+ // A message to open on startup instead of the inbox listing (a deep link). Its folder
205
+ // is listed next to it, so the reader lands where the message lives.
206
+ this.initialMessage = typeof options.message === 'string' && options.message ? options.message : null;
207
+ // Told whenever the open folder or message changes, so a host page can keep its address
208
+ // bar in step (see _notifyNavigate)
209
+ this.onNavigate = typeof options.onNavigate === 'function' ? options.onNavigate : null;
210
+ const maxAttachmentSize = Number(options.maxAttachmentSize);
211
+ this.maxAttachmentSize = maxAttachmentSize > 0 ? maxAttachmentSize : DEFAULT_MAX_ATTACHMENT_SIZE;
115
212
  this.folders = [];
116
213
  this.messages = [];
117
214
  this.nextPageCursor = null;
@@ -266,8 +363,9 @@ export class EmailEngineClient {
266
363
  }
267
364
  }
268
365
 
366
+ // Loads and renders one page of a folder's message list. The open message stays open: it is
367
+ // the folder click (openFolder()) that closes it, while paging and refreshes keep it.
269
368
  async loadMessages(path, cursor = null) {
270
- this._setView('list');
271
369
  this._setPaneHtml('.ee-message-list', `${this._messageListHeader(path)}<div class="ee-loading">Loading messages...</div>`);
272
370
 
273
371
  try {
@@ -282,15 +380,13 @@ export class EmailEngineClient {
282
380
  this.nextPageCursor = data.nextPageCursor || null;
283
381
  this.prevPageCursor = data.prevPageCursor || null;
284
382
 
285
- // Clear active email selection when folder changes
286
- this.currentMessage = null;
287
-
288
383
  if (this.container) {
289
384
  this.renderMessageList();
290
385
  this.renderFolderList(); // Re-render to update active state
291
- this.renderMessage(); // Clear message viewer
292
386
  }
293
387
 
388
+ this._notifyNavigate();
389
+
294
390
  return {
295
391
  messages: this.messages,
296
392
  nextPageCursor: this.nextPageCursor,
@@ -309,6 +405,14 @@ export class EmailEngineClient {
309
405
  }
310
406
  }
311
407
 
408
+ // Switches to another folder: closes the open message and lists the folder
409
+ openFolder(path) {
410
+ this.currentMessage = null;
411
+ this.renderMessage();
412
+ this._setView('list');
413
+ return this.loadMessages(path);
414
+ }
415
+
312
416
  async loadMessage(messageId) {
313
417
  this._setView('message');
314
418
  this._setPaneHtml('.ee-message-viewer', `${this._messageToolbar()}<div class="ee-loading">Loading message...</div>`);
@@ -322,6 +426,7 @@ export class EmailEngineClient {
322
426
  this.currentMessage = data;
323
427
 
324
428
  this.currentMessage.unseen = false;
429
+ this._notifyNavigate();
325
430
 
326
431
  const msg = this.messages.find(m => m.id === messageId);
327
432
  if (msg) {
@@ -334,26 +439,37 @@ export class EmailEngineClient {
334
439
  if (this.container && !this._destroyed) {
335
440
  this.renderMessage();
336
441
 
337
- // Scroll to top of the email client container
338
- this.container.scrollIntoView({ behavior: 'smooth', block: 'start' });
339
-
340
- // Also scroll the window to ensure visibility
341
- if (typeof window !== 'undefined') {
342
- const containerTop = this.container.getBoundingClientRect().top + window.pageYOffset;
343
- 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' });
344
448
  }
345
449
  }
346
450
 
347
451
  return this.currentMessage;
348
452
  } catch (error) {
349
453
  console.error('Failed to load message:', error);
350
- this._renderPaneError(
351
- '.ee-message-viewer',
352
- 'Message unavailable',
353
- error,
354
- () => this._fireAndForget(this.loadMessage(messageId)),
355
- this._messageToolbar()
356
- );
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
+ }
357
473
  throw error;
358
474
  }
359
475
  }
@@ -386,23 +502,32 @@ export class EmailEngineClient {
386
502
  }
387
503
  }
388
504
 
389
- async deleteMessage(messageId) {
390
- try {
391
- await this.apiRequest('DELETE', this._messagePath(messageId));
505
+ // Takes a message that left the folder (deleted or moved) off the list, and out of the
506
+ // viewer when it was the open one
507
+ _dropMessage(messageId) {
508
+ this.messages = this.messages.filter(m => m.id !== messageId);
509
+ if (this.container) {
510
+ this.renderMessageList();
511
+ }
392
512
 
393
- this.messages = this.messages.filter(m => m.id !== messageId);
513
+ if (this.currentMessage && this.currentMessage.id === messageId) {
514
+ this.currentMessage = null;
394
515
  if (this.container) {
395
- this.renderMessageList();
516
+ this.renderMessage();
396
517
  }
518
+ this._notifyNavigate();
519
+ }
520
+ }
397
521
 
398
- if (this.currentMessage && this.currentMessage.id === messageId) {
399
- this.currentMessage = null;
400
- if (this.container) {
401
- this.renderMessage();
402
- }
403
- }
522
+ async deleteMessage(messageId) {
523
+ try {
524
+ const response = await this.apiRequest('DELETE', this._messagePath(messageId));
404
525
 
405
- return true;
526
+ this._dropMessage(messageId);
527
+
528
+ // { deleted, moved: { destination, message } } - moved is set when the message went
529
+ // to Trash instead of being removed
530
+ return response || { deleted: true };
406
531
  } catch (error) {
407
532
  console.error('Failed to delete message:', error);
408
533
  throw error;
@@ -415,17 +540,7 @@ export class EmailEngineClient {
415
540
  path: targetPath
416
541
  });
417
542
 
418
- this.messages = this.messages.filter(m => m.id !== messageId);
419
- if (this.container) {
420
- this.renderMessageList();
421
- }
422
-
423
- if (this.currentMessage && this.currentMessage.id === messageId) {
424
- this.currentMessage = null;
425
- if (this.container) {
426
- this.renderMessage();
427
- }
428
- }
543
+ this._dropMessage(messageId);
429
544
 
430
545
  return true;
431
546
  } catch (error) {
@@ -434,10 +549,6 @@ export class EmailEngineClient {
434
549
  }
435
550
  }
436
551
 
437
- _normalizeRecipients(to) {
438
- return Array.isArray(to) ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr)) : [typeof to === 'string' ? { address: to } : to];
439
- }
440
-
441
552
  // Account details (name, email address) fetched once and cached for the lifetime
442
553
  // of the instance; used as the From identity of saved drafts.
443
554
  async _getAccountInfo() {
@@ -447,13 +558,35 @@ export class EmailEngineClient {
447
558
  return this._accountInfo;
448
559
  }
449
560
 
450
- async sendMessage(to, subject, text) {
561
+ // The address and content fields shared by a submission and a draft upload. Empty recipient
562
+ // lists are left out rather than sent as [].
563
+ _messagePayload(to, subject, text, { cc, bcc, attachments, reference } = {}) {
564
+ const data = { subject, text };
565
+ for (const [key, value] of [
566
+ ['to', to],
567
+ ['cc', cc],
568
+ ['bcc', bcc]
569
+ ]) {
570
+ const list = addressEntries(value);
571
+ if (list.length) {
572
+ data[key] = list;
573
+ }
574
+ }
575
+ if (Array.isArray(attachments) && attachments.length) {
576
+ data.attachments = attachments.map(({ filename, contentType, content }) => ({ filename, contentType, content }));
577
+ }
578
+ if (reference) {
579
+ data.reference = reference;
580
+ }
581
+ return data;
582
+ }
583
+
584
+ // options: { cc, bcc, attachments: [{ filename, contentType, content (base64) }], reference }.
585
+ // reference is EmailEngine's submit reference block ({ message, action, inline,
586
+ // forwardAttachments }); with it the server adds the threading headers and the quote.
587
+ async sendMessage(to, subject, text, options = {}) {
451
588
  try {
452
- const messageData = {
453
- to: this._normalizeRecipients(to),
454
- subject,
455
- text
456
- };
589
+ const messageData = this._messagePayload(to, subject, text, options);
457
590
 
458
591
  const response = await this.apiRequest('POST', `${this._accountPath()}/submit`, messageData);
459
592
  return response;
@@ -463,7 +596,7 @@ export class EmailEngineClient {
463
596
  }
464
597
  }
465
598
 
466
- async saveDraft(to, subject, text) {
599
+ async saveDraft(to, subject, text, options = {}) {
467
600
  try {
468
601
  if (!this.folders.length) {
469
602
  await this.loadFolders();
@@ -476,15 +609,9 @@ export class EmailEngineClient {
476
609
  const messageData = {
477
610
  path: draftsFolder.path,
478
611
  flags: ['\\Draft'],
479
- subject,
480
- text
612
+ ...this._messagePayload(to, subject, text, options)
481
613
  };
482
614
 
483
- const recipients = to ? this._normalizeRecipients(to) : [];
484
- if (recipients.length) {
485
- messageData.to = recipients;
486
- }
487
-
488
615
  // The upload endpoint does not add a From header on its own, but the draft
489
616
  // needs one to be deliverable later - use the account's own identity.
490
617
  try {
@@ -504,6 +631,82 @@ export class EmailEngineClient {
504
631
  }
505
632
  }
506
633
 
634
+ // Parses a typed address field ("Name <a@example.com>, b@example.com") into address entries
635
+ parseAddressList(value) {
636
+ return splitAddressField(String(value || '')).map(parseAddressEntry);
637
+ }
638
+
639
+ // The reverse of parseAddressList, for filling a compose field
640
+ formatAddressList(list) {
641
+ return addressEntries(list)
642
+ .map(entry => {
643
+ if (!entry.name) {
644
+ return entry.address;
645
+ }
646
+ const name = /[",;<>@\\]/.test(entry.name) ? `"${entry.name.replace(/(["\\])/g, '\\$1')}"` : entry.name;
647
+ return `${name} <${entry.address}>`;
648
+ })
649
+ .join(', ');
650
+ }
651
+
652
+ // Recipients, subject and submit reference for a reply, reply-all or forward of msg, as the
653
+ // compose form shows them. ownAddress (the account's) is left out of the recipients.
654
+ //
655
+ // Reply-all is resolved here rather than by the server: EmailEngine's reply-all merges the
656
+ // original recipients into whatever is sent, so one the user removed from the form would be
657
+ // put back. It goes out as a reply with every recipient spelled out instead, which the server
658
+ // leaves alone, and what the form shows is what is sent.
659
+ prepareResponse(msg, action, ownAddress = null) {
660
+ if (action === 'forward') {
661
+ return { to: [], cc: [], subject: prefixSubject(msg.subject, 'Fwd'), reference: { message: msg.id, action: 'forward', inline: true } };
662
+ }
663
+
664
+ const own = typeof ownAddress === 'string' ? ownAddress.toLowerCase() : '';
665
+ const seen = new Set(own ? [own] : []);
666
+ const take = list =>
667
+ addressEntries(list)
668
+ .filter(entry => {
669
+ const key = entry.address.toLowerCase();
670
+ if (seen.has(key)) {
671
+ return false;
672
+ }
673
+ seen.add(key);
674
+ return true;
675
+ })
676
+ .map(entry => (entry.name ? { name: entry.name, address: entry.address } : { address: entry.address }));
677
+
678
+ // Answer the address the message nominates, otherwise its sender - or, for a message the
679
+ // account sent itself (Sent folder), the people it went to. The account's own address is
680
+ // never an answer, so a Reply-To naming the account falls through to the next candidate.
681
+ const fromSelf = !!own && addressEntries(msg.from).some(entry => entry.address.toLowerCase() === own);
682
+ let to = [];
683
+ for (const candidate of [msg.replyTo, fromSelf ? msg.to : msg.from]) {
684
+ to = take(candidate);
685
+ if (to.length) {
686
+ break;
687
+ }
688
+ }
689
+ if (!to.length) {
690
+ // A message from the account to itself: answer it anyway
691
+ to = addressEntries(msg.from).map(entry => ({ ...entry }));
692
+ }
693
+ const cc = action === 'reply-all' ? take(addressEntries(msg.to).concat(addressEntries(msg.cc))) : [];
694
+
695
+ return { to, cc, subject: prefixSubject(msg.subject, 'Re'), reference: { message: msg.id, action: 'reply', inline: true } };
696
+ }
697
+
698
+ // Tells the host which folder and message are open. A host error must not break the client.
699
+ _notifyNavigate() {
700
+ if (!this.onNavigate || this._destroyed) {
701
+ return;
702
+ }
703
+ try {
704
+ this.onNavigate({ path: this.currentFolder, messageId: this.currentMessage ? this.currentMessage.id : null });
705
+ } catch (error) {
706
+ console.error('onNavigate handler failed:', error);
707
+ }
708
+ }
709
+
507
710
  async submitDraft(messageId, options = null) {
508
711
  try {
509
712
  const response = await this.apiRequest('POST', this._messagePath(messageId, '/submit'), options);
@@ -550,7 +753,7 @@ export class EmailEngineClient {
550
753
  // are needed - and to[N] for any index is handled, not just to[0].
551
754
  .map(field =>
552
755
  field.message
553
- .replace(/to\[\d+\]\.address|"address"/g, 'email address')
756
+ .replace(/(?:to|cc|bcc)\[\d+\]\.address|"address"/g, 'email address')
554
757
  .replace(/"subject"/g, 'subject')
555
758
  .replace(/"text"/g, 'message')
556
759
  );
@@ -595,8 +798,9 @@ export class EmailEngineClient {
595
798
  // missing, optionally with a Retry button. Without this a failed request
596
799
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
597
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
598
802
  _renderPaneError(selector, title, error, retry = null, header = '') {
599
- const detail = this._errorMessage(error, '');
803
+ const detail = typeof error === 'string' ? error : this._errorMessage(error, '');
600
804
  const pane = this._setPaneHtml(
601
805
  selector,
602
806
  `
@@ -633,6 +837,19 @@ export class EmailEngineClient {
633
837
  promise.catch(() => {});
634
838
  }
635
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
+
636
853
  // Message actions (flag, delete, move) have no pane of their own to report into:
637
854
  // when one fails the message simply stays put, which is indistinguishable from
638
855
  // nothing having happened. Say so instead.
@@ -706,6 +923,30 @@ export class EmailEngineClient {
706
923
  }
707
924
  }
708
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
+
709
950
  formatFileSize(bytes) {
710
951
  if (!bytes) {
711
952
  return '';
@@ -898,6 +1139,18 @@ export class EmailEngineClient {
898
1139
  }
899
1140
 
900
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
+
901
1154
  .ee-client {
902
1155
  --ee-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
903
1156
  display: flex;
@@ -945,7 +1198,7 @@ export class EmailEngineClient {
945
1198
  }
946
1199
 
947
1200
  .ee-folder-item.active {
948
- background: #007bff;
1201
+ background: var(--_accent);
949
1202
  color: white;
950
1203
  }
951
1204
 
@@ -956,7 +1209,7 @@ export class EmailEngineClient {
956
1209
  top: 0;
957
1210
  bottom: 0;
958
1211
  width: 3px;
959
- background: #0056b3;
1212
+ background: var(--_accent-hover);
960
1213
  }
961
1214
 
962
1215
  .ee-folder-content {
@@ -1020,7 +1273,7 @@ export class EmailEngineClient {
1020
1273
  }
1021
1274
 
1022
1275
  .ee-message-item.active {
1023
- background: #e3f2fd;
1276
+ background: color-mix(in srgb, var(--_accent) 12%, white);
1024
1277
  }
1025
1278
 
1026
1279
  .ee-message-item.unread {
@@ -1071,14 +1324,42 @@ export class EmailEngineClient {
1071
1324
  }
1072
1325
 
1073
1326
  .ee-attachment-indicator {
1074
- display: inline-block;
1327
+ display: inline-flex;
1328
+ align-items: center;
1329
+ white-space: nowrap;
1330
+ flex-shrink: 0;
1075
1331
  font-size: 11px;
1076
1332
  color: #666;
1077
1333
  margin-left: 8px;
1078
1334
  }
1079
1335
 
1080
- .ee-attachment-indicator::before {
1081
- content: "📎 ";
1336
+ .ee-attachment-indicator .ee-icon {
1337
+ margin-right: 2px;
1338
+ }
1339
+
1340
+ /* Replied / forwarded markers, from the message flags (see _responseMarkers) */
1341
+ .ee-response-marker {
1342
+ display: inline-flex;
1343
+ align-items: center;
1344
+ gap: 4px;
1345
+ color: #666;
1346
+ margin-right: 6px;
1347
+ flex-shrink: 0;
1348
+ }
1349
+
1350
+ .ee-message-title-markers {
1351
+ display: flex;
1352
+ gap: 4px;
1353
+ margin: -8px 0 12px;
1354
+ font-size: 12px;
1355
+ }
1356
+
1357
+ .ee-message-title-markers:empty {
1358
+ display: none;
1359
+ }
1360
+
1361
+ .ee-dark-mode .ee-response-marker {
1362
+ color: #999;
1082
1363
  }
1083
1364
 
1084
1365
  .ee-message-viewer {
@@ -1134,7 +1415,7 @@ export class EmailEngineClient {
1134
1415
  .ee-button:focus-visible,
1135
1416
  .ee-move-button:focus-within,
1136
1417
  .ee-compose-button:focus-visible {
1137
- outline: 2px solid #4d9fff;
1418
+ outline: 2px solid var(--_accent);
1138
1419
  outline-offset: 1px;
1139
1420
  }
1140
1421
 
@@ -1164,13 +1445,13 @@ export class EmailEngineClient {
1164
1445
  }
1165
1446
 
1166
1447
  .ee-button-primary {
1167
- background: #007bff;
1168
- border-color: #007bff;
1448
+ background: var(--_accent);
1449
+ border-color: var(--_accent);
1169
1450
  color: white;
1170
1451
  }
1171
1452
 
1172
1453
  .ee-button-primary:hover:not(:disabled) {
1173
- background: #0069d9;
1454
+ background: var(--_accent-hover);
1174
1455
  }
1175
1456
 
1176
1457
  .ee-button-danger:hover:not(:disabled) {
@@ -1204,9 +1485,7 @@ export class EmailEngineClient {
1204
1485
 
1205
1486
  .ee-message-content {
1206
1487
  flex: 1;
1207
- /* The bottom padding lets the end of the message scroll clear of
1208
- the floating compose button */
1209
- padding: 20px 20px 88px;
1488
+ padding: 20px;
1210
1489
  overflow-y: auto;
1211
1490
  }
1212
1491
 
@@ -1238,7 +1517,7 @@ export class EmailEngineClient {
1238
1517
  .ee-otp {
1239
1518
  margin-bottom: 16px;
1240
1519
  padding: 14px 16px;
1241
- background: #eef3fb;
1520
+ background: color-mix(in srgb, var(--_accent) 7%, white);
1242
1521
  border-radius: 8px;
1243
1522
  }
1244
1523
 
@@ -1291,14 +1570,14 @@ export class EmailEngineClient {
1291
1570
  height: 32px;
1292
1571
  padding: 0 16px;
1293
1572
  font-size: 13px;
1294
- background: #007bff;
1295
- border-color: #007bff;
1573
+ background: var(--_accent);
1574
+ border-color: var(--_accent);
1296
1575
  color: white;
1297
1576
  border-radius: 16px;
1298
1577
  }
1299
1578
 
1300
1579
  .ee-otp .ee-otp-copy:hover:not(:disabled) {
1301
- background: #0069d9;
1580
+ background: var(--_accent-hover);
1302
1581
  }
1303
1582
 
1304
1583
  .ee-otp-status,
@@ -1345,8 +1624,9 @@ export class EmailEngineClient {
1345
1624
  }
1346
1625
 
1347
1626
  .ee-attachment-icon {
1627
+ display: flex;
1348
1628
  margin-right: 8px;
1349
- font-size: 18px;
1629
+ color: #666;
1350
1630
  }
1351
1631
 
1352
1632
  .ee-attachment-info {
@@ -1482,7 +1762,6 @@ export class EmailEngineClient {
1482
1762
  .ee-message-items {
1483
1763
  flex: 1;
1484
1764
  overflow-y: auto;
1485
- padding-bottom: 88px;
1486
1765
  }
1487
1766
 
1488
1767
  .ee-compose-button {
@@ -1491,48 +1770,34 @@ export class EmailEngineClient {
1491
1770
  right: 20px;
1492
1771
  display: inline-flex;
1493
1772
  align-items: center;
1494
- gap: 10px;
1495
- height: 52px;
1496
- padding: 0 22px 0 18px;
1497
- background: #007bff;
1773
+ justify-content: center;
1774
+ width: 56px;
1775
+ height: 56px;
1776
+ padding: 0;
1777
+ background: var(--_accent);
1498
1778
  border: none;
1499
- border-radius: 16px;
1779
+ border-radius: 50%;
1500
1780
  color: white;
1501
- font-family: var(--ee-font, inherit);
1502
- font-size: 15px;
1503
- font-weight: 600;
1504
1781
  cursor: pointer;
1505
- 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);
1506
1783
  z-index: 1000;
1507
1784
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1508
1785
  }
1509
1786
 
1510
1787
  .ee-compose-button:hover {
1511
- background: #0056b3;
1788
+ background: var(--_accent-hover);
1512
1789
  transform: translateY(-1px);
1513
- box-shadow: 0 6px 16px rgba(0,123,255,0.4);
1514
- }
1515
-
1516
- .ee-compose-button.ee-compose-compact {
1517
- width: 56px;
1518
- height: 56px;
1519
- padding: 0;
1520
- justify-content: center;
1521
- border-radius: 50%;
1522
- }
1523
-
1524
- .ee-compose-compact .ee-compose-button-label {
1525
- display: none;
1790
+ box-shadow: 0 6px 16px color-mix(in srgb, var(--_accent) 40%, transparent);
1526
1791
  }
1527
1792
 
1528
1793
  /* Medium widths: the viewer is too narrow for labelled buttons, so the
1529
1794
  toolbar goes icon-only, as webmail toolbars usually are */
1530
- @container ee-viewer (max-width: 559px) {
1531
- .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 {
1532
1797
  display: none;
1533
1798
  }
1534
1799
 
1535
- .ee-message-actions .ee-button:not(.ee-keep-label) {
1800
+ .ee-message-actions .ee-button:not(.ee-keep-label):not(.ee-label-priority) {
1536
1801
  width: 30px;
1537
1802
  padding: 0;
1538
1803
  }
@@ -1543,6 +1808,22 @@ export class EmailEngineClient {
1543
1808
  }
1544
1809
  }
1545
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
+
1546
1827
  /* Narrow widths: one pane at a time, in the order a phone mail app uses
1547
1828
  (folders, list, message), with back buttons in the pane headers. The
1548
1829
  shown pane follows data-view on .ee-client. */
@@ -1569,6 +1850,15 @@ export class EmailEngineClient {
1569
1850
  .ee-message-content {
1570
1851
  padding: 16px 16px 88px;
1571
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
+ }
1572
1862
  }
1573
1863
 
1574
1864
  .ee-compose-modal {
@@ -1593,7 +1883,7 @@ export class EmailEngineClient {
1593
1883
  border-radius: 8px;
1594
1884
  width: 90%;
1595
1885
  max-width: 600px;
1596
- max-height: 80vh;
1886
+ max-height: 90vh;
1597
1887
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
1598
1888
  display: flex;
1599
1889
  flex-direction: column;
@@ -1617,7 +1907,6 @@ export class EmailEngineClient {
1617
1907
  .ee-compose-close {
1618
1908
  background: none;
1619
1909
  border: none;
1620
- font-size: 24px;
1621
1910
  color: #666;
1622
1911
  cursor: pointer;
1623
1912
  padding: 0;
@@ -1634,37 +1923,56 @@ export class EmailEngineClient {
1634
1923
  }
1635
1924
 
1636
1925
  .ee-compose-form {
1637
- padding: 20px;
1926
+ padding: 16px 20px;
1638
1927
  display: flex;
1639
1928
  flex-direction: column;
1640
- gap: 16px;
1929
+ gap: 10px;
1641
1930
  flex: 1;
1642
1931
  overflow-y: auto;
1643
1932
  }
1644
-
1645
- .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 {
1646
1937
  display: flex;
1647
- flex-direction: column;
1648
- gap: 4px;
1938
+ align-items: center;
1939
+ gap: 10px;
1649
1940
  }
1650
-
1941
+
1651
1942
  .ee-compose-label {
1943
+ flex: 0 0 56px;
1944
+ font-size: 13px;
1652
1945
  font-weight: 500;
1653
- color: #333;
1946
+ color: #555;
1654
1947
  }
1655
-
1948
+
1656
1949
  .ee-compose-input {
1950
+ flex: 1;
1951
+ min-width: 0;
1657
1952
  padding: 8px 12px;
1658
1953
  border: 1px solid #ddd;
1659
1954
  border-radius: 4px;
1660
1955
  font-size: 14px;
1661
1956
  font-family: inherit;
1662
1957
  }
1663
-
1664
- .ee-compose-input:focus {
1665
- outline: none;
1666
- border-color: #007bff;
1667
- 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;
1668
1976
  }
1669
1977
 
1670
1978
  .ee-compose-textarea {
@@ -1674,13 +1982,14 @@ export class EmailEngineClient {
1674
1982
  font-size: 14px;
1675
1983
  font-family: inherit;
1676
1984
  resize: vertical;
1677
- min-height: 200px;
1985
+ min-height: 180px;
1678
1986
  }
1679
-
1987
+
1988
+ .ee-compose-input:focus,
1680
1989
  .ee-compose-textarea:focus {
1681
1990
  outline: none;
1682
- border-color: #007bff;
1683
- 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);
1684
1993
  }
1685
1994
 
1686
1995
  .ee-compose-actions {
@@ -1693,7 +2002,7 @@ export class EmailEngineClient {
1693
2002
  }
1694
2003
 
1695
2004
  .ee-compose-send {
1696
- background: #007bff;
2005
+ background: var(--_accent);
1697
2006
  color: white;
1698
2007
  border: none;
1699
2008
  padding: 10px 20px;
@@ -1704,7 +2013,7 @@ export class EmailEngineClient {
1704
2013
  }
1705
2014
 
1706
2015
  .ee-compose-send:hover:not(:disabled) {
1707
- background: #0056b3;
2016
+ background: var(--_accent-hover);
1708
2017
  }
1709
2018
 
1710
2019
  .ee-compose-send:disabled {
@@ -1713,24 +2022,26 @@ export class EmailEngineClient {
1713
2022
  opacity: 0.6;
1714
2023
  }
1715
2024
 
2025
+ /* Cancel is the quiet way out, not a third weighted button */
1716
2026
  .ee-compose-cancel {
1717
- background: #6c757d;
1718
- color: white;
2027
+ margin-right: auto;
2028
+ background: transparent;
2029
+ color: #555;
1719
2030
  border: none;
1720
- padding: 10px 20px;
2031
+ padding: 10px 12px;
1721
2032
  border-radius: 4px;
1722
2033
  font-size: 14px;
1723
2034
  cursor: pointer;
1724
2035
  }
1725
2036
 
1726
2037
  .ee-compose-cancel:hover {
1727
- background: #545b62;
2038
+ background: #f0f0f0;
1728
2039
  }
1729
2040
 
1730
2041
  .ee-compose-save-draft {
1731
2042
  background: transparent;
1732
- color: #007bff;
1733
- border: 1px solid #007bff;
2043
+ color: var(--_accent);
2044
+ border: 1px solid var(--_accent);
1734
2045
  padding: 10px 20px;
1735
2046
  border-radius: 4px;
1736
2047
  font-size: 14px;
@@ -1739,7 +2050,7 @@ export class EmailEngineClient {
1739
2050
  }
1740
2051
 
1741
2052
  .ee-compose-save-draft:hover:not(:disabled) {
1742
- background: #007bff;
2053
+ background: var(--_accent);
1743
2054
  color: white;
1744
2055
  }
1745
2056
 
@@ -1750,6 +2061,216 @@ export class EmailEngineClient {
1750
2061
  opacity: 0.6;
1751
2062
  }
1752
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
+
2141
+ /* Parts of the compose form that come and go (Cc/Bcc, the forward checkbox, the
2142
+ quote) use the hidden attribute, which a display rule would otherwise override */
2143
+ .ee-compose-modal [hidden] {
2144
+ display: none !important;
2145
+ }
2146
+
2147
+ .ee-compose-link {
2148
+ flex-shrink: 0;
2149
+ background: none;
2150
+ border: none;
2151
+ padding: 4px 0;
2152
+ font: inherit;
2153
+ font-size: 13px;
2154
+ color: var(--_accent);
2155
+ cursor: pointer;
2156
+ }
2157
+
2158
+ .ee-compose-link:hover {
2159
+ text-decoration: underline;
2160
+ }
2161
+
2162
+ .ee-compose-files {
2163
+ display: flex;
2164
+ flex-direction: column;
2165
+ gap: 8px;
2166
+ }
2167
+
2168
+ .ee-compose-files-row {
2169
+ display: flex;
2170
+ flex-wrap: wrap;
2171
+ align-items: center;
2172
+ gap: 8px 16px;
2173
+ }
2174
+
2175
+ .ee-compose-attach {
2176
+ display: inline-flex;
2177
+ align-items: center;
2178
+ gap: 6px;
2179
+ background: transparent;
2180
+ border: 1px solid #ddd;
2181
+ border-radius: 4px;
2182
+ padding: 6px 12px;
2183
+ font: inherit;
2184
+ font-size: 13px;
2185
+ color: inherit;
2186
+ cursor: pointer;
2187
+ }
2188
+
2189
+ .ee-compose-attach:hover {
2190
+ background: #f0f0f0;
2191
+ }
2192
+
2193
+ .ee-compose-forward-attachments {
2194
+ display: inline-flex;
2195
+ align-items: center;
2196
+ gap: 6px;
2197
+ font-size: 13px;
2198
+ cursor: pointer;
2199
+ }
2200
+
2201
+ .ee-compose-chips {
2202
+ display: flex;
2203
+ flex-wrap: wrap;
2204
+ gap: 6px;
2205
+ }
2206
+
2207
+ .ee-compose-chips:empty {
2208
+ display: none;
2209
+ }
2210
+
2211
+ .ee-compose-chip {
2212
+ display: inline-flex;
2213
+ align-items: center;
2214
+ gap: 6px;
2215
+ max-width: 100%;
2216
+ padding: 4px 4px 4px 10px;
2217
+ border: 1px solid #ddd;
2218
+ border-radius: 16px;
2219
+ background: #f8f9fa;
2220
+ font-size: 13px;
2221
+ }
2222
+
2223
+ .ee-compose-chip-name {
2224
+ overflow: hidden;
2225
+ text-overflow: ellipsis;
2226
+ white-space: nowrap;
2227
+ min-width: 0;
2228
+ }
2229
+
2230
+ .ee-compose-chip-size {
2231
+ color: #666;
2232
+ flex-shrink: 0;
2233
+ }
2234
+
2235
+ .ee-compose-chip-remove {
2236
+ display: inline-flex;
2237
+ align-items: center;
2238
+ justify-content: center;
2239
+ width: 22px;
2240
+ height: 22px;
2241
+ padding: 0;
2242
+ border: none;
2243
+ border-radius: 50%;
2244
+ background: transparent;
2245
+ color: #666;
2246
+ cursor: pointer;
2247
+ flex-shrink: 0;
2248
+ }
2249
+
2250
+ .ee-compose-chip-remove:hover {
2251
+ background: #e0e0e0;
2252
+ }
2253
+
2254
+ .ee-compose-quote {
2255
+ display: flex;
2256
+ flex-direction: column;
2257
+ gap: 6px;
2258
+ }
2259
+
2260
+ .ee-compose-quote-label {
2261
+ font-size: 13px;
2262
+ color: #666;
2263
+ }
2264
+
2265
+ .ee-compose-quote-frame {
2266
+ max-height: 220px;
2267
+ overflow: auto;
2268
+ padding: 8px 12px;
2269
+ border-left: 3px solid #ddd;
2270
+ background: #fafafa;
2271
+ border-radius: 0 4px 4px 0;
2272
+ }
2273
+
1753
2274
  /* Dark mode toggle button, in the Folders pane header */
1754
2275
  .ee-dark-mode-toggle {
1755
2276
  background: #f8f9fa;
@@ -1773,8 +2294,7 @@ export class EmailEngineClient {
1773
2294
  }
1774
2295
 
1775
2296
  .ee-dark-mode-icon {
1776
- font-size: 14px;
1777
- line-height: 1;
2297
+ display: flex;
1778
2298
  }
1779
2299
 
1780
2300
  /* Dark mode styles */
@@ -1808,7 +2328,7 @@ export class EmailEngineClient {
1808
2328
  }
1809
2329
 
1810
2330
  .ee-dark-mode .ee-folder-item.active {
1811
- background: #0056b3;
2331
+ background: var(--_accent-hover);
1812
2332
  }
1813
2333
 
1814
2334
  .ee-dark-mode .ee-message-list {
@@ -1825,7 +2345,7 @@ export class EmailEngineClient {
1825
2345
  }
1826
2346
 
1827
2347
  .ee-dark-mode .ee-message-item.active {
1828
- background: #1a3d5c;
2348
+ background: color-mix(in srgb, var(--_accent) 35%, #1a1a1a);
1829
2349
  }
1830
2350
 
1831
2351
  .ee-dark-mode .ee-message-date,
@@ -1878,9 +2398,10 @@ export class EmailEngineClient {
1878
2398
  }
1879
2399
 
1880
2400
  .ee-dark-mode .ee-button-primary,
1881
- .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
1882
- background: #0056b3;
1883
- 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);
1884
2405
  color: white;
1885
2406
  }
1886
2407
 
@@ -1948,7 +2469,7 @@ export class EmailEngineClient {
1948
2469
  }
1949
2470
 
1950
2471
  .ee-dark-mode .ee-otp {
1951
- background: #23303f;
2472
+ background: color-mix(in srgb, var(--_accent) 18%, #1a1a1a);
1952
2473
  }
1953
2474
 
1954
2475
  .ee-dark-mode .ee-otp-title {
@@ -1962,8 +2483,8 @@ export class EmailEngineClient {
1962
2483
  }
1963
2484
 
1964
2485
  .ee-dark-mode .ee-otp .ee-otp-copy {
1965
- background: #0056b3;
1966
- border-color: #0056b3;
2486
+ background: var(--_accent-hover);
2487
+ border-color: var(--_accent-hover);
1967
2488
  color: white;
1968
2489
  }
1969
2490
 
@@ -1980,14 +2501,10 @@ export class EmailEngineClient {
1980
2501
  /* The compose button and modal sit beside .ee-client, not inside it, so
1981
2502
  setDarkMode puts the ee-dark-mode class on them directly */
1982
2503
  .ee-compose-button.ee-dark-mode {
1983
- background: #0056b3;
2504
+ background: var(--_accent-hover);
1984
2505
  color: white;
1985
2506
  }
1986
2507
 
1987
- .ee-compose-button.ee-dark-mode:hover {
1988
- background: #004a99;
1989
- }
1990
-
1991
2508
  .ee-compose-modal.ee-dark-mode {
1992
2509
  background: rgba(0, 0, 0, 0.7);
1993
2510
  }
@@ -1997,10 +2514,6 @@ export class EmailEngineClient {
1997
2514
  color: #e0e0e0;
1998
2515
  }
1999
2516
 
2000
- .ee-dark-mode .ee-compose-label {
2001
- color: #ccc;
2002
- }
2003
-
2004
2517
  .ee-dark-mode .ee-compose-header {
2005
2518
  background: linear-gradient(to bottom, #2a2a2a, #252525);
2006
2519
  border-color: #333;
@@ -2023,8 +2536,8 @@ export class EmailEngineClient {
2023
2536
 
2024
2537
  .ee-dark-mode .ee-compose-input:focus,
2025
2538
  .ee-dark-mode .ee-compose-textarea:focus {
2026
- border-color: #0056b3;
2027
- 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);
2028
2541
  }
2029
2542
 
2030
2543
  .ee-dark-mode .ee-compose-actions {
@@ -2032,22 +2545,70 @@ export class EmailEngineClient {
2032
2545
  }
2033
2546
 
2034
2547
  .ee-dark-mode .ee-compose-cancel {
2035
- background: #444;
2548
+ color: #ccc;
2036
2549
  }
2037
2550
 
2038
2551
  .ee-dark-mode .ee-compose-cancel:hover {
2039
- background: #555;
2552
+ background: #333;
2040
2553
  }
2041
2554
 
2042
2555
  .ee-dark-mode .ee-compose-save-draft {
2043
- color: #66b2ff;
2044
- border-color: #66b2ff;
2556
+ color: var(--_accent-light);
2557
+ border-color: var(--_accent-light);
2045
2558
  }
2046
2559
 
2047
2560
  .ee-dark-mode .ee-compose-save-draft:hover:not(:disabled) {
2048
- background: #66b2ff;
2561
+ background: var(--_accent-light);
2049
2562
  color: #1a1a1a;
2050
2563
  }
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
+
2584
+ .ee-dark-mode .ee-compose-link {
2585
+ color: var(--_accent-light);
2586
+ }
2587
+
2588
+ .ee-dark-mode .ee-compose-attach {
2589
+ border-color: #444;
2590
+ }
2591
+
2592
+ .ee-dark-mode .ee-compose-attach:hover,
2593
+ .ee-dark-mode .ee-compose-chip-remove:hover {
2594
+ background: #333;
2595
+ }
2596
+
2597
+ .ee-dark-mode .ee-compose-chip {
2598
+ background: #2a2a2a;
2599
+ border-color: #444;
2600
+ }
2601
+
2602
+ .ee-dark-mode .ee-compose-chip-size,
2603
+ .ee-dark-mode .ee-compose-chip-remove,
2604
+ .ee-dark-mode .ee-compose-quote-label {
2605
+ color: #999;
2606
+ }
2607
+
2608
+ .ee-dark-mode .ee-compose-quote-frame {
2609
+ background: #1a1a1a;
2610
+ border-color: #444;
2611
+ }
2051
2612
  `);
2052
2613
  document.head.appendChild(style);
2053
2614
  this._styleElement = style;
@@ -2176,7 +2737,7 @@ export class EmailEngineClient {
2176
2737
  folderTree.querySelectorAll('.ee-folder-item').forEach(item => {
2177
2738
  item.addEventListener('click', () => {
2178
2739
  const path = item.getAttribute('data-path');
2179
- this._fireAndForget(this.loadMessages(path));
2740
+ this._fireAndForget(this.openFolder(path));
2180
2741
  });
2181
2742
  });
2182
2743
  }
@@ -2235,8 +2796,9 @@ export class EmailEngineClient {
2235
2796
  <span class="ee-message-date">${this.formatDate(msg.date)}</span>
2236
2797
  </div>
2237
2798
  <div class="ee-message-subject">
2799
+ ${this._responseMarkers(msg)}
2238
2800
  <span class="ee-message-subject-text">${this.escapeHtml(msg.subject || '(no subject)')}</span>
2239
- ${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator">${msg.attachments.length}</span>` : ''}
2801
+ ${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator" title="Attachments">${icon('paperclip', 12)}${msg.attachments.length}</span>` : ''}
2240
2802
  </div>
2241
2803
  <div class="ee-message-preview">${this.escapeHtml(msg.intro || '')}</div>
2242
2804
  </div>
@@ -2306,8 +2868,14 @@ export class EmailEngineClient {
2306
2868
  // query); aria-label and title carry the full name either way. The move control
2307
2869
  // is a native select laid invisibly over a button so it looks like the rest of
2308
2870
  // the toolbar while keeping the platform's own folder picker.
2871
+ const respond = isDraft
2872
+ ? ''
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>`;
2309
2877
  const actions = `
2310
- ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : ''}
2878
+ ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : respond}
2311
2879
  ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
2312
2880
  <span class="ee-button ee-move-button" title="Move to folder">
2313
2881
  ${icon('move')}<span class="ee-button-label">Move</span>${icon('chevronDown', 12)}
@@ -2330,28 +2898,29 @@ export class EmailEngineClient {
2330
2898
  ${this._messageToolbar(actions)}
2331
2899
  <div class="ee-message-content">
2332
2900
  <h2 class="ee-message-title">${this.escapeHtml(msg.subject || '(no subject)')}</h2>
2901
+ <div class="ee-message-title-markers">${this._responseMarkers(msg, true)}</div>
2333
2902
  <div class="ee-message-meta">
2334
2903
  <div class="ee-message-meta-row">
2335
2904
  <span class="ee-message-meta-label">From</span>
2336
- <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>
2337
2906
  </div>
2338
2907
  <div class="ee-message-meta-row">
2339
2908
  <span class="ee-message-meta-label">To</span>
2340
- <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>
2341
2910
  </div>
2342
2911
  ${
2343
2912
  msg.cc && msg.cc.length
2344
2913
  ? `
2345
2914
  <div class="ee-message-meta-row">
2346
2915
  <span class="ee-message-meta-label">Cc</span>
2347
- <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>
2348
2917
  </div>
2349
2918
  `
2350
2919
  : ''
2351
2920
  }
2352
2921
  <div class="ee-message-meta-row">
2353
2922
  <span class="ee-message-meta-label">Date</span>
2354
- <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>
2355
2924
  </div>
2356
2925
  </div>
2357
2926
  ${this.renderOtpBox(msg.otp)}
@@ -2365,7 +2934,7 @@ export class EmailEngineClient {
2365
2934
  .map(
2366
2935
  att => `
2367
2936
  <div class="ee-attachment-item" data-attachment-id="${this.escapeHtml(att.id)}">
2368
- <div class="ee-attachment-icon">📎</div>
2937
+ <div class="ee-attachment-icon">${icon('paperclip', 18)}</div>
2369
2938
  <div class="ee-attachment-info">
2370
2939
  <div class="ee-attachment-name">${this.escapeHtml(att.filename || 'Unnamed attachment')}</div>
2371
2940
  ${att.size ? `<div class="ee-attachment-size">${this.formatFileSize(att.size)}</div>` : ''}
@@ -2406,11 +2975,11 @@ export class EmailEngineClient {
2406
2975
 
2407
2976
  try {
2408
2977
  await this.submitDraft(msg.id);
2409
- await this.alertMethod('Draft queued for delivery.', 'Success', null, 'OK');
2978
+ this.notify('Draft queued for delivery.');
2410
2979
  // Refresh the folder view - the provider removes the draft once it is sent,
2411
2980
  // immediately for Gmail and MS Graph, after SMTP delivery for IMAP accounts.
2412
2981
  if (!this._destroyed && this.currentFolder) {
2413
- await this.loadMessages(this.currentFolder);
2982
+ await this.openFolder(this.currentFolder);
2414
2983
  }
2415
2984
  } catch (error) {
2416
2985
  console.error('Failed to send draft:', error);
@@ -2422,20 +2991,26 @@ export class EmailEngineClient {
2422
2991
  });
2423
2992
  }
2424
2993
 
2994
+ viewer.querySelectorAll('[data-action="reply"], [data-action="reply-all"], [data-action="forward"]').forEach(button => {
2995
+ button.addEventListener('click', () => {
2996
+ this._respond(msg.id, button.dataset.action).catch(error => this._alertActionFailed(error, 'Failed to open the compose form'));
2997
+ });
2998
+ });
2999
+
2425
3000
  viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
2426
3001
  const currentlyUnseen = msg.unseen;
2427
3002
  this.markAsRead(msg.id, currentlyUnseen).catch(error => this._alertActionFailed(error, 'Failed to update the message flags'));
2428
3003
  });
2429
3004
 
2430
3005
  viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
2431
- const result = await this.confirmMethod(
2432
- 'Are you sure you want to delete this message? This action cannot be undone.',
2433
- 'Delete Message',
2434
- 'Cancel',
2435
- 'Delete'
2436
- );
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');
2437
3010
  if (result) {
2438
- 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'));
2439
3014
  }
2440
3015
  });
2441
3016
 
@@ -2482,6 +3057,27 @@ export class EmailEngineClient {
2482
3057
  // Message content scrolling is now handled in loadMessage method
2483
3058
  }
2484
3059
 
3060
+ // Replied / forwarded markers from the flags the server sets on the original once a reply or
3061
+ // forward has been delivered (IMAP accounts; Gmail API and MS Graph report neither flag).
3062
+ // labelled shows the words next to the icons, otherwise they are the accessible name only.
3063
+ //
3064
+ // EmailEngine adds \Answered to a forwarded message as well as $Forwarded, so one marker is
3065
+ // shown: Forwarded when that flag is set, Replied otherwise.
3066
+ _responseMarkers(msg, labelled = false) {
3067
+ const flags = Array.isArray(msg.flags) ? msg.flags : [];
3068
+ const marker = flags.includes('$Forwarded')
3069
+ ? { icon: 'forward', label: 'Forwarded' }
3070
+ : flags.includes('\\Answered')
3071
+ ? { icon: 'reply', label: 'Replied' }
3072
+ : null;
3073
+ if (!marker) {
3074
+ return '';
3075
+ }
3076
+ return labelled
3077
+ ? `<span class="ee-response-marker">${icon(marker.icon, 12)}<span>${marker.label}</span></span>`
3078
+ : `<span class="ee-response-marker" role="img" aria-label="${marker.label}" title="${marker.label}">${icon(marker.icon, 12)}</span>`;
3079
+ }
3080
+
2485
3081
  // An icon-only button. Static arguments only, never message data.
2486
3082
  _iconButton(action, iconName, label, extraClass = '', disabled = false) {
2487
3083
  return `<button type="button" class="ee-button ee-icon-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${label}"${disabled ? ' disabled' : ''}>${icon(iconName)}</button>`;
@@ -2513,6 +3109,16 @@ export class EmailEngineClient {
2513
3109
  }
2514
3110
 
2515
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
+ }
2516
3122
  return root;
2517
3123
  }
2518
3124
 
@@ -2548,37 +3154,63 @@ export class EmailEngineClient {
2548
3154
  ${
2549
3155
  this.showDarkModeToggle
2550
3156
  ? `<button type="button" class="ee-dark-mode-toggle" title="Toggle dark mode" aria-label="Toggle dark mode">
2551
- <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
3157
+ <span class="ee-dark-mode-icon">${icon(this.darkMode ? 'sun' : 'moon', 14)}</span>
2552
3158
  </button>`
2553
3159
  : ''
2554
3160
  }
2555
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>
2556
3165
  <div class="ee-folder-tree"></div>
2557
3166
  </div>
2558
3167
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2559
3168
  <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2560
3169
  </div>
2561
- <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>
2562
3172
  <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2563
- <div class="ee-compose-dialog">
3173
+ <div class="ee-compose-dialog" role="dialog" aria-modal="true" aria-label="Compose">
2564
3174
  <div class="ee-compose-header">
2565
- <h3 class="ee-compose-title">Compose Email</h3>
2566
- <button class="ee-compose-close">×</button>
3175
+ <h3 class="ee-compose-title">${COMPOSE_TITLES.new}</h3>
3176
+ <button type="button" class="ee-compose-close" aria-label="Close" title="Close">${icon('close', 18)}</button>
2567
3177
  </div>
2568
- <form class="ee-compose-form">
2569
- <div class="ee-compose-field">
2570
- <label class="ee-compose-label">To:</label>
2571
- <input type="email" class="ee-compose-input" name="to" placeholder="recipient@example.com" required>
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>
3183
+ </div>
3184
+ <div class="ee-compose-row" data-field="cc" hidden>
3185
+ <label class="ee-compose-label" for="${this._composeId('cc')}">Cc</label>
3186
+ <input type="text" class="ee-compose-input" id="${this._composeId('cc')}" name="cc" autocomplete="off" spellcheck="false">
2572
3187
  </div>
2573
- <div class="ee-compose-field">
2574
- <label class="ee-compose-label">Subject:</label>
2575
- <input type="text" class="ee-compose-input" name="subject" placeholder="Enter subject">
3188
+ <div class="ee-compose-row" data-field="bcc" hidden>
3189
+ <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc</label>
3190
+ <input type="text" class="ee-compose-input" id="${this._composeId('bcc')}" name="bcc" autocomplete="off" spellcheck="false">
3191
+ </div>
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">
3195
+ </div>
3196
+ <textarea class="ee-compose-textarea" name="message" aria-label="Message" placeholder="Write your message"></textarea>
3197
+ <div class="ee-compose-files">
3198
+ <div class="ee-compose-chips"></div>
3199
+ <div class="ee-compose-files-row">
3200
+ <button type="button" class="ee-compose-attach" data-action="attach">${icon('paperclip', 14)}<span>Attach files</span></button>
3201
+ <input type="file" class="ee-compose-file-input" multiple hidden>
3202
+ <label class="ee-compose-forward-attachments" hidden>
3203
+ <input type="checkbox" name="forwardAttachments" checked>
3204
+ <span class="ee-compose-forward-attachments-label"></span>
3205
+ </label>
3206
+ </div>
2576
3207
  </div>
2577
- <div class="ee-compose-field">
2578
- <label class="ee-compose-label">Message:</label>
2579
- <textarea class="ee-compose-textarea" name="message" placeholder="Type your message here..." required></textarea>
3208
+ <div class="ee-compose-quote" hidden>
3209
+ <div class="ee-compose-quote-label"></div>
3210
+ <div class="ee-compose-quote-frame"></div>
2580
3211
  </div>
2581
3212
  </form>
3213
+ <div class="ee-compose-error" role="alert" hidden></div>
2582
3214
  <div class="ee-compose-actions">
2583
3215
  <button type="button" class="ee-compose-cancel">Cancel</button>
2584
3216
  <button type="button" class="ee-compose-save-draft">Save Draft</button>
@@ -2604,142 +3236,381 @@ export class EmailEngineClient {
2604
3236
  this.positionComposeButton();
2605
3237
  }
2606
3238
 
3239
+ // Unique element ids for the compose form labels, so two clients on one page do not share them
3240
+ _composeId(field) {
3241
+ if (!this._composeIdPrefix) {
3242
+ EmailEngineClient._composeCounter = (EmailEngineClient._composeCounter || 0) + 1;
3243
+ this._composeIdPrefix = `ee-compose-${EmailEngineClient._composeCounter}`;
3244
+ }
3245
+ return `${this._composeIdPrefix}-${field}`;
3246
+ }
3247
+
3248
+ // Opens a blank compose form, optionally prefilled: { to, cc, bcc, subject, text }. The
3249
+ // address fields take a string or address entries.
3250
+ compose(prefill = {}) {
3251
+ this._openCompose({ mode: 'new', ...prefill });
3252
+ }
3253
+
3254
+ // Opens the compose form as a reply to a message (the open one when messageId is omitted)
3255
+ reply(messageId = null, { all = false } = {}) {
3256
+ return this._respond(messageId, all ? 'reply-all' : 'reply');
3257
+ }
3258
+
3259
+ // Opens the compose form to forward a message (the open one when messageId is omitted)
3260
+ forward(messageId = null) {
3261
+ return this._respond(messageId, 'forward');
3262
+ }
3263
+
3264
+ async _respond(messageId, action) {
3265
+ const id = messageId || (this.currentMessage && this.currentMessage.id);
3266
+ if (!id) {
3267
+ throw new Error('No message to respond to');
3268
+ }
3269
+
3270
+ const [msg, ownAddress] = await Promise.all([
3271
+ this.currentMessage && this.currentMessage.id === id ? this.currentMessage : this.apiRequest('GET', this._messagePath(id, '?webSafeHtml=true')),
3272
+ // Without it the account's own address may stay among the reply-all recipients
3273
+ this._getAccountInfo().then(
3274
+ info => info && info.email,
3275
+ () => null
3276
+ )
3277
+ ]);
3278
+
3279
+ this._openCompose({ mode: action, original: msg, ...this.prepareResponse(msg, action, ownAddress) });
3280
+ }
3281
+
3282
+ _openCompose({ mode = 'new', to, cc, bcc, subject, text, reference = null, original = null } = {}) {
3283
+ const els = this._compose && this._compose.els;
3284
+ if (!els) {
3285
+ throw new Error('The compose form needs the client UI (a container)');
3286
+ }
3287
+ this._resetCompose();
3288
+ this._compose.reference = reference;
3289
+
3290
+ const asField = value => (typeof value === 'string' ? value : this.formatAddressList(value));
3291
+ const { form } = els;
3292
+ form.elements.to.value = asField(to);
3293
+ form.elements.cc.value = asField(cc);
3294
+ form.elements.bcc.value = asField(bcc);
3295
+ form.elements.subject.value = subject || '';
3296
+ form.elements.message.value = text || '';
3297
+ this._showCopyFields({ cc: !!form.elements.cc.value, bcc: !!form.elements.bcc.value });
3298
+
3299
+ els.title.textContent = COMPOSE_TITLES[mode] || COMPOSE_TITLES.new;
3300
+
3301
+ // The server carries the original's attachments over on request (all or none)
3302
+ const originalAttachments = original && mode === 'forward' ? (original.attachments || []).filter(att => !att.inline && !att.embedded) : [];
3303
+ els.forwardAttachments.hidden = !originalAttachments.length;
3304
+ els.forwardAttachments.querySelector('.ee-compose-forward-attachments-label').textContent =
3305
+ `Include the original attachments (${originalAttachments.length})`;
3306
+
3307
+ if (original && reference && reference.inline) {
3308
+ this._renderComposeQuote(original, mode);
3309
+ }
3310
+
3311
+ els.modal.classList.add('show');
3312
+ const focusTarget = form.elements.to.value ? form.elements.message : form.elements.to;
3313
+ setTimeout(() => {
3314
+ focusTarget.focus();
3315
+ if (focusTarget === form.elements.message) {
3316
+ focusTarget.setSelectionRange(0, 0);
3317
+ }
3318
+ }, 100);
3319
+ }
3320
+
3321
+ // A read-only copy of the message being answered, under the textarea. The quote that is sent
3322
+ // is built by the server from the stored original; this shows what it will contain.
3323
+ _renderComposeQuote(original, mode) {
3324
+ const { quote } = this._compose.els;
3325
+ const from = addressEntries(original.from)[0];
3326
+ const sender = from ? from.name || from.address : 'the sender';
3327
+ quote.querySelector('.ee-compose-quote-label').textContent =
3328
+ mode === 'forward' ? 'The forwarded message is added below your text:' : `${sender}'s message is quoted below your reply:`;
3329
+ // A shadow root cannot be attached twice, so each quote gets a fresh host
3330
+ const host = document.createElement('div');
3331
+ host.className = 'ee-compose-quote-body';
3332
+ quote.querySelector('.ee-compose-quote-frame').replaceChildren(host);
3333
+ this._labelCollapsedThreads(this._renderMessageBody(host, original));
3334
+ quote.hidden = false;
3335
+ }
3336
+
3337
+ // Shows the Cc and Bcc fields named true and hides the rest; the link offers whichever is hidden
3338
+ _showCopyFields(show) {
3339
+ const { form } = this._compose.els;
3340
+ const hidden = [];
3341
+ for (const key of ['cc', 'bcc']) {
3342
+ form.querySelector(`[data-field="${key}"]`).hidden = !show[key];
3343
+ if (!show[key]) {
3344
+ hidden.push(key === 'cc' ? 'Cc' : 'Bcc');
3345
+ }
3346
+ }
3347
+ const link = form.querySelector('[data-action="show-cc"]');
3348
+ link.hidden = !hidden.length;
3349
+ link.textContent = hidden.join(' / ');
3350
+ }
3351
+
3352
+ // Empties the form and starts a new compose state; the element references are kept
3353
+ _resetCompose() {
3354
+ const { els } = this._compose;
3355
+ els.form.reset();
3356
+ els.chips.replaceChildren();
3357
+ els.fileInput.value = '';
3358
+ els.forwardAttachments.hidden = true;
3359
+ els.quote.hidden = true;
3360
+ els.quote.querySelector('.ee-compose-quote-frame').replaceChildren();
3361
+ this._clearComposeError();
3362
+ this._compose = { els, reference: null, files: [] };
3363
+ this._showCopyFields({ cc: false, bcc: false });
3364
+ }
3365
+
3366
+ _closeCompose() {
3367
+ if (this._compose && this._compose.els) {
3368
+ this._compose.els.modal.classList.remove('show');
3369
+ this._resetCompose();
3370
+ }
3371
+ }
3372
+
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();
3384
+ }
3385
+ }
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
+
3393
+ _renderComposeChips() {
3394
+ this._compose.els.chips.innerHTML = this._compose.files
3395
+ .map(
3396
+ (file, index) => `
3397
+ <span class="ee-compose-chip">
3398
+ ${icon('paperclip', 12)}
3399
+ <span class="ee-compose-chip-name">${this.escapeHtml(file.name)}</span>
3400
+ <span class="ee-compose-chip-size">${this.formatFileSize(file.size)}</span>
3401
+ <button type="button" class="ee-compose-chip-remove" data-index="${index}" aria-label="Remove ${this.escapeHtml(file.name)}" title="Remove">${icon('close', 12)}</button>
3402
+ </span>`
3403
+ )
3404
+ .join('');
3405
+ }
3406
+
3407
+ _readFileAsBase64(file) {
3408
+ return new Promise((resolve, reject) => {
3409
+ const reader = new FileReader();
3410
+ reader.onload = () => {
3411
+ const result = String(reader.result || '');
3412
+ resolve(result.slice(result.indexOf(',') + 1));
3413
+ };
3414
+ reader.onerror = () => reject(reader.error || new Error(`Could not read ${file.name}`));
3415
+ reader.readAsDataURL(file);
3416
+ });
3417
+ }
3418
+
3419
+ // Takes picked files into the form within the size limit. They are kept as File objects and
3420
+ // read only when the message is sent, so a removed file is never read at all.
3421
+ _addComposeFiles(files) {
3422
+ let total = this._compose.files.reduce((sum, file) => sum + file.size, 0);
3423
+ const skipped = [];
3424
+ for (const file of files) {
3425
+ if (total + file.size > this.maxAttachmentSize) {
3426
+ skipped.push(file.name);
3427
+ continue;
3428
+ }
3429
+ total += file.size;
3430
+ this._compose.files.push(file);
3431
+ }
3432
+ this._renderComposeChips();
3433
+ if (skipped.length) {
3434
+ this._showComposeError(`Attachments are limited to ${this.formatFileSize(this.maxAttachmentSize)} in total. Not attached: ${skipped.join(', ')}`);
3435
+ }
3436
+ }
3437
+
3438
+ _readComposeAttachments(files) {
3439
+ return Promise.all(
3440
+ files.map(async file => ({
3441
+ filename: file.name,
3442
+ contentType: file.type || 'application/octet-stream',
3443
+ content: await this._readFileAsBase64(file)
3444
+ }))
3445
+ );
3446
+ }
3447
+
3448
+ // The form as a submission: parsed recipients, the text, the reference and the picked files,
3449
+ // plus the first reason it cannot go out as asked (null when it can). requireMessage applies
3450
+ // the send rules: a recipient, and some text unless the message is a forward.
3451
+ _readComposeForm(requireMessage) {
3452
+ const { form } = this._compose.els;
3453
+ const fields = {};
3454
+ const invalid = [];
3455
+ for (const key of ['to', 'cc', 'bcc']) {
3456
+ fields[key] = this.parseAddressList(form.elements[key].value);
3457
+ invalid.push(...fields[key].filter(entry => !ADDRESS_PATTERN.test(entry.address)).map(entry => entry.address || entry.name));
3458
+ }
3459
+
3460
+ let reference = this._compose.reference;
3461
+ const isForward = !!reference && reference.action === 'forward';
3462
+ if (isForward) {
3463
+ reference = { ...reference, forwardAttachments: form.elements.forwardAttachments.checked };
3464
+ }
3465
+
3466
+ const draft = {
3467
+ to: fields.to,
3468
+ subject: form.elements.subject.value.trim(),
3469
+ text: form.elements.message.value,
3470
+ files: this._compose.files,
3471
+ options: { cc: fields.cc, bcc: fields.bcc, reference }
3472
+ };
3473
+
3474
+ const empty = !fields.to.length && !fields.cc.length && !fields.bcc.length && !draft.subject && !draft.text.trim() && !draft.files.length && !reference;
3475
+ if (requireMessage && !fields.to.length) {
3476
+ draft.problem = { message: 'Add at least one recipient.', field: 'to' };
3477
+ } else if (!requireMessage && empty) {
3478
+ draft.problem = { message: 'Nothing to save - fill in at least one field first.', field: 'to' };
3479
+ } else if (invalid.length) {
3480
+ draft.problem = { message: `Not a valid email address: ${invalid.join(', ')}`, field: 'to' };
3481
+ } else if (requireMessage && !draft.text.trim() && !isForward) {
3482
+ // A forward can go without a note of its own; anything else needs some text
3483
+ draft.problem = { message: 'Write a message before sending.', field: 'message' };
3484
+ }
3485
+ return draft;
3486
+ }
3487
+
3488
+ // Runs a compose request with its button showing progress. The form is checked first, the
3489
+ // picked files are read, and on success the form closes and the result is returned; on any
3490
+ // failure the reason is shown over the form, kept as it was, and the result is null.
3491
+ async _runComposeAction(button, busyText, errorTitle, requireMessage, submit) {
3492
+ const draft = this._readComposeForm(requireMessage);
3493
+ if (draft.problem) {
3494
+ this._showComposeError(draft.problem.message, draft.problem.field);
3495
+ return null;
3496
+ }
3497
+ this._clearComposeError();
3498
+
3499
+ const originalText = button.textContent;
3500
+ button.disabled = true;
3501
+ button.textContent = busyText;
3502
+ try {
3503
+ const attachments = await this._readComposeAttachments(draft.files);
3504
+ const result = await submit(draft.to, draft.subject, draft.text, { ...draft.options, attachments });
3505
+ this._closeCompose();
3506
+ return result || {};
3507
+ } catch (error) {
3508
+ console.error(`${errorTitle}:`, error);
3509
+ this._showComposeError(`${errorTitle}: ${this._formatSendError(error)}`);
3510
+ return null;
3511
+ } finally {
3512
+ button.disabled = false;
3513
+ button.textContent = originalText;
3514
+ }
3515
+ }
3516
+
2607
3517
  setupComposeModal() {
2608
3518
  if (typeof document === 'undefined' || !this.container) {
2609
3519
  return;
2610
3520
  }
2611
3521
 
2612
- const composeButton = this.container.querySelector('.ee-compose-button');
2613
3522
  const modal = this.container.querySelector('.ee-compose-modal');
2614
- const closeButton = this.container.querySelector('.ee-compose-close');
2615
- const cancelButton = this.container.querySelector('.ee-compose-cancel');
2616
- const saveDraftButton = this.container.querySelector('.ee-compose-save-draft');
2617
- const sendButton = this.container.querySelector('.ee-compose-send');
2618
- const form = this.container.querySelector('.ee-compose-form');
2619
-
2620
- // Open modal
2621
- composeButton.addEventListener('click', () => {
2622
- modal.classList.add('show');
2623
- // Focus the To field
2624
- const toField = form.querySelector('input[name="to"]');
2625
- setTimeout(() => toField.focus(), 100);
2626
- });
2627
-
2628
- // Close modal handlers
2629
- const closeModal = () => {
2630
- modal.classList.remove('show');
2631
- form.reset();
3523
+ const els = {
3524
+ modal,
3525
+ form: modal.querySelector('.ee-compose-form'),
3526
+ title: modal.querySelector('.ee-compose-title'),
3527
+ chips: modal.querySelector('.ee-compose-chips'),
3528
+ fileInput: modal.querySelector('.ee-compose-file-input'),
3529
+ forwardAttachments: modal.querySelector('.ee-compose-forward-attachments'),
3530
+ quote: modal.querySelector('.ee-compose-quote'),
3531
+ error: modal.querySelector('.ee-compose-error')
2632
3532
  };
3533
+ const { form, fileInput, chips } = els;
3534
+ this._compose = { els, reference: null, files: [] };
3535
+
3536
+ this.container
3537
+ .querySelectorAll('.ee-compose-button, .ee-sidebar-compose-button')
3538
+ .forEach(button => button.addEventListener('click', () => this.compose()));
2633
3539
 
2634
- closeButton.addEventListener('click', closeModal);
2635
- cancelButton.addEventListener('click', closeModal);
3540
+ const closeCompose = () => this._closeCompose();
3541
+ modal.querySelector('.ee-compose-close').addEventListener('click', closeCompose);
3542
+ modal.querySelector('.ee-compose-cancel').addEventListener('click', closeCompose);
2636
3543
 
2637
3544
  // Close on backdrop click
2638
3545
  modal.addEventListener('click', e => {
2639
3546
  if (e.target === modal) {
2640
- closeModal();
3547
+ closeCompose();
2641
3548
  }
2642
3549
  });
2643
3550
 
2644
3551
  // Close on Escape key
2645
3552
  this._composeKeydownHandler = e => {
2646
3553
  if (e.key === 'Escape' && modal.classList.contains('show')) {
2647
- closeModal();
3554
+ closeCompose();
2648
3555
  }
2649
3556
  };
2650
3557
  document.addEventListener('keydown', this._composeKeydownHandler);
2651
3558
 
2652
- // Save the composed message as a draft instead of sending it
2653
- saveDraftButton.addEventListener('click', async () => {
2654
- const formData = new FormData(form);
2655
- const to = formData.get('to').trim();
2656
- const subject = formData.get('subject').trim();
2657
- const message = formData.get('message').trim();
2658
-
2659
- if (!to && !subject && !message) {
2660
- modal.classList.remove('show');
2661
- await this.alertMethod('Nothing to save - fill in at least one field first.', 'Validation Error', null, 'OK');
2662
- modal.classList.add('show');
2663
- setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
2664
- return;
3559
+ form.addEventListener('input', () => {
3560
+ if (!els.error.hidden) {
3561
+ this._clearComposeError();
2665
3562
  }
3563
+ });
2666
3564
 
2667
- const originalText = saveDraftButton.textContent;
2668
- saveDraftButton.disabled = true;
2669
- saveDraftButton.textContent = 'Saving...';
3565
+ form.querySelector('[data-action="show-cc"]').addEventListener('click', () => {
3566
+ const ccShown = !form.querySelector('[data-field="cc"]').hidden;
3567
+ this._showCopyFields({ cc: true, bcc: true });
3568
+ (ccShown ? form.elements.bcc : form.elements.cc).focus();
3569
+ });
2670
3570
 
2671
- try {
2672
- const response = await this.saveDraft(to || null, subject, message);
2673
- closeModal();
2674
- await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
2675
- // Refresh the list when the user is looking at the Drafts folder
2676
- if (!this._destroyed && response && response.path && this.currentFolder === response.path) {
2677
- await this.loadMessages(this.currentFolder);
2678
- }
2679
- } catch (error) {
2680
- console.error('Failed to save draft:', error);
2681
- // Close modal before showing error alert, then reopen with preserved values
2682
- modal.classList.remove('show');
2683
- const errorMessage = this._formatSendError(error);
2684
- await this.alertMethod(errorMessage, 'Save Error', null, 'OK');
2685
- modal.classList.add('show');
2686
- setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
2687
- } finally {
2688
- saveDraftButton.disabled = false;
2689
- saveDraftButton.textContent = originalText;
3571
+ form.querySelector('[data-action="attach"]').addEventListener('click', () => fileInput.click());
3572
+ fileInput.addEventListener('change', () => {
3573
+ const files = Array.from(fileInput.files || []);
3574
+ fileInput.value = '';
3575
+ this._addComposeFiles(files);
3576
+ });
3577
+ chips.addEventListener('click', e => {
3578
+ const remove = e.target.closest('.ee-compose-chip-remove');
3579
+ if (remove) {
3580
+ this._compose.files.splice(Number(remove.dataset.index), 1);
3581
+ this._renderComposeChips();
2690
3582
  }
2691
3583
  });
2692
3584
 
2693
- // Send email
2694
- sendButton.addEventListener('click', async () => {
2695
- const formData = new FormData(form);
2696
- const to = formData.get('to').trim();
2697
- const subject = formData.get('subject').trim();
2698
- const message = formData.get('message').trim();
2699
-
2700
- if (!to || !message) {
2701
- // Close modal temporarily to show alert, then reopen
2702
- modal.classList.remove('show');
2703
- await this.alertMethod('Please fill in the recipient and message fields.', 'Validation Error', null, 'OK');
2704
- modal.classList.add('show');
2705
- // Re-focus the appropriate field
2706
- const fieldToFocus = !to ? form.querySelector('input[name="to"]') : form.querySelector('textarea[name="message"]');
2707
- setTimeout(() => fieldToFocus.focus(), 100);
3585
+ // Save the composed message as a draft instead of sending it
3586
+ const saveDraftButton = modal.querySelector('.ee-compose-save-draft');
3587
+ saveDraftButton.addEventListener('click', async () => {
3588
+ const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Could not save the draft', false, (...args) =>
3589
+ this.saveDraft(...args)
3590
+ );
3591
+ if (!response) {
2708
3592
  return;
2709
3593
  }
3594
+ this.notify('Draft saved to the Drafts folder.');
3595
+ // Refresh the list when the user is looking at the Drafts folder
3596
+ if (!this._destroyed && response.path && this.currentFolder === response.path) {
3597
+ this._fireAndForget(this.loadMessages(this.currentFolder));
3598
+ }
3599
+ });
2710
3600
 
2711
- // Disable send button and show loading state
2712
- const originalText = sendButton.textContent;
2713
- sendButton.disabled = true;
2714
- sendButton.textContent = 'Sending...';
2715
-
2716
- try {
2717
- await this.sendMessage(to, subject, message);
2718
- // Close modal before showing success alert
2719
- closeModal();
2720
- await this.alertMethod('Email sent successfully!', 'Success', null, 'OK');
2721
- } catch (error) {
2722
- console.error('Failed to send email:', error);
2723
- // Close modal before showing error alert
2724
- modal.classList.remove('show');
2725
- const errorMessage = this._formatSendError(error);
2726
- await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
2727
-
2728
- // Reopen modal with preserved values after error alert
2729
- modal.classList.add('show');
2730
- // Re-focus the To field to allow user to continue editing
2731
- const toField = form.querySelector('input[name="to"]');
2732
- setTimeout(() => toField.focus(), 100);
2733
- } finally {
2734
- // Re-enable send button
2735
- sendButton.disabled = false;
2736
- sendButton.textContent = originalText;
3601
+ // Send email
3602
+ const sendButton = modal.querySelector('.ee-compose-send');
3603
+ sendButton.addEventListener('click', async () => {
3604
+ const response = await this._runComposeAction(sendButton, 'Sending...', 'Could not send the message', true, (...args) => this.sendMessage(...args));
3605
+ if (response) {
3606
+ // Submitting only queues the message; delivery happens afterwards and can still fail
3607
+ this.notify('Message queued for delivery.');
2737
3608
  }
2738
3609
  });
2739
3610
 
2740
3611
  // Handle Enter key in form (Ctrl+Enter to send)
2741
3612
  form.addEventListener('keydown', e => {
2742
- if (e.key === 'Enter' && e.ctrlKey) {
3613
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
2743
3614
  e.preventDefault();
2744
3615
  sendButton.click();
2745
3616
  }
@@ -2756,26 +3627,24 @@ export class EmailEngineClient {
2756
3627
  return;
2757
3628
  }
2758
3629
 
3630
+ const sidebarCompose = this.container.querySelector('.ee-sidebar-compose');
2759
3631
  const updateButtonPosition = () => {
2760
3632
  const containerRect = this.container.getBoundingClientRect();
2761
3633
  const margin = 20; // Desired margin from edges
2762
-
2763
- // A hidden container (display: none) reports a zero-size rect; positioning
2764
- // against it would push the fixed-position button off-screen. Hide the button
2765
- // instead and let the ResizeObserver below restore it once the container is
2766
- // shown - hosts often create the client inside a container that is only made
2767
- // visible afterwards.
2768
- 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)) {
2769
3643
  composeButton.style.display = 'none';
2770
3644
  return;
2771
3645
  }
2772
3646
  composeButton.style.display = '';
2773
3647
 
2774
- // A labelled pill on roomy layouts, a round icon button where width is
2775
- // short and the button would cover too much of the single pane
2776
- composeButton.classList.toggle('ee-compose-compact', containerRect.width < NARROW_WIDTH);
2777
- const buttonSize = composeButton.offsetWidth || 56;
2778
-
2779
3648
  // Calculate the ideal position (bottom-right of container with margin)
2780
3649
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
2781
3650
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -2868,6 +3737,13 @@ export class EmailEngineClient {
2868
3737
  // paint their own loading states from this point on.
2869
3738
  this._setPaneHtml('.ee-message-list', this._messageListPlaceholder());
2870
3739
 
3740
+ // A deep-linked message loads alongside the folders, not after them. Only the first load
3741
+ // follows the link: a Retry after a folder failure starts from the inbox as usual. A
3742
+ // message that fails has already put its error in the viewer.
3743
+ const messageId = this.initialMessage;
3744
+ this.initialMessage = null;
3745
+ const message = messageId ? this.loadMessage(messageId).catch(() => null) : Promise.resolve(null);
3746
+
2871
3747
  return this.loadFolders()
2872
3748
  .catch(error => {
2873
3749
  // loadFolders reports into the sidebar, but the message list is the
@@ -2876,21 +3752,39 @@ export class EmailEngineClient {
2876
3752
  this._renderPaneError('.ee-message-list', 'Folders unavailable', error, () => this._loadInitialView());
2877
3753
  throw error;
2878
3754
  })
2879
- .then(() => {
2880
- const inbox =
2881
- this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
2882
- this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
2883
- this.folders[0];
2884
- if (inbox) {
2885
- return this.loadMessages(inbox.path);
2886
- }
2887
- })
3755
+ .then(async () => this._listFolderOf(await message))
2888
3756
  .catch(error => {
2889
3757
  // Both loadFolders and loadMessages have already rendered a panel
2890
3758
  console.error('Failed to load the initial view:', error);
2891
3759
  });
2892
3760
  }
2893
3761
 
3762
+ _inboxFolder() {
3763
+ return (
3764
+ this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
3765
+ this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
3766
+ this.folders[0]
3767
+ );
3768
+ }
3769
+
3770
+ // Lists the folder holding a message, or the inbox when there is no message or it reports no
3771
+ // folder (Gmail API accounts) or one that is not listed
3772
+ _listFolderOf(message) {
3773
+ const folder = (message && message.path && this.folders.find(f => f.path === message.path)) || this._inboxFolder();
3774
+ if (folder && !this._destroyed) {
3775
+ return this.loadMessages(folder.path);
3776
+ }
3777
+ }
3778
+
3779
+ // Opens one message by its EmailEngine ID and lists the folder holding it. A message that
3780
+ // cannot be loaded leaves its error in the viewer and the inbox in the list, so the reader
3781
+ // still has somewhere to go.
3782
+ async openMessage(messageId) {
3783
+ const [message] = await Promise.all([this.loadMessage(messageId).catch(() => null), this.folders.length ? null : this.loadFolders()]);
3784
+ await this._listFolderOf(message);
3785
+ return message;
3786
+ }
3787
+
2894
3788
  _updateActivity() {
2895
3789
  this.lastActivity = Date.now();
2896
3790
  }
@@ -2940,12 +3834,14 @@ export class EmailEngineClient {
2940
3834
 
2941
3835
  // Update UI. The compose button and modal are siblings of .ee-client, so
2942
3836
  // they carry the class themselves.
2943
- 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));
2944
3840
 
2945
3841
  // Update toggle button icon
2946
- const icon = this.container.querySelector('.ee-dark-mode-icon');
2947
- if (icon) {
2948
- icon.textContent = this.darkMode ? '☀️' : '🌙';
3842
+ const toggleIcon = this.container.querySelector('.ee-dark-mode-icon');
3843
+ if (toggleIcon) {
3844
+ toggleIcon.innerHTML = icon(this.darkMode ? 'sun' : 'moon', 14);
2949
3845
  }
2950
3846
  }
2951
3847
 
@@ -2969,6 +3865,9 @@ export class EmailEngineClient {
2969
3865
  this.keepAliveTimer = null;
2970
3866
  }
2971
3867
 
3868
+ clearTimeout(this._toastTimer);
3869
+ clearTimeout(this._otpCopyTimer);
3870
+
2972
3871
  // Remove the compose button's window scroll/resize listeners
2973
3872
  if (this._composeButtonCleanup) {
2974
3873
  this._composeButtonCleanup();