@postalsys/ee-client 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +33 -7
  2. package/index.d.ts +79 -2
  3. package/index.js +1318 -333
  4. package/package.json +8 -4
package/index.js CHANGED
@@ -65,6 +65,114 @@ const MESSAGE_BODY_STYLES = `
65
65
  }
66
66
  `;
67
67
 
68
+ // Inline SVG icons (24x24 grid, stroked with currentColor so they follow the button's text
69
+ // colour in both themes). Static markup only, nothing here is built from message data.
70
+ const ICON_PATHS = {
71
+ back: '<path d="m15 18-6-6 6-6"/>',
72
+ next: '<path d="m9 18 6-6-6-6"/>',
73
+ chevronDown: '<path d="m6 9 6 6 6-6"/>',
74
+ mail: '<rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>',
75
+ mailOpen:
76
+ '<path d="M21.2 8.4c.5.38.8.97.8 1.6v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V10a2 2 0 0 1 .8-1.6l8-6a2 2 0 0 1 2.4 0l8 6Z"/><path d="m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10"/>',
77
+ trash: '<path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/>',
78
+ 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
+ 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
+ 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"/>',
82
+ reply: '<polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/>',
83
+ 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"/>',
84
+ forward: '<polyline points="15 17 20 12 15 7"/><path d="M4 18v-2a4 4 0 0 1 4-4h12"/>',
85
+ 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"/>',
86
+ close: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
87
+ 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"/>',
88
+ moon: '<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"/>'
89
+ };
90
+
91
+ // Default cap on the files attached in the compose form, in bytes. They travel base64 encoded
92
+ // inside one JSON request, which grows them by a third, and most providers refuse a message
93
+ // much larger than this anyway. Hosts that know their limit pass maxAttachmentSize.
94
+ const DEFAULT_MAX_ATTACHMENT_SIZE = 25 * 1024 * 1024;
95
+
96
+ // What a compose form address has to look like before it is sent. Deliberately loose: the
97
+ // server validates properly, this only catches a name typed without its address.
98
+ const ADDRESS_PATTERN = /^[^\s@<>",;]+@[^\s@<>",;]+$/;
99
+
100
+ // Splits an address field on commas and semicolons that are not inside a quoted name or an
101
+ // angle-bracketed address, so "Doe, John" <john@example.com> stays one entry.
102
+ function splitAddressField(value) {
103
+ const parts = [];
104
+ let current = '';
105
+ let quoted = false;
106
+ let bracketed = false;
107
+ for (let i = 0; i < value.length; i++) {
108
+ const chr = value[i];
109
+ if (chr === '\\' && quoted && i + 1 < value.length) {
110
+ current += chr + value[++i];
111
+ continue;
112
+ }
113
+ if (chr === '"' && !bracketed) {
114
+ quoted = !quoted;
115
+ } else if (chr === '<' && !quoted) {
116
+ bracketed = true;
117
+ } else if (chr === '>' && !quoted) {
118
+ bracketed = false;
119
+ } else if ((chr === ',' || chr === ';') && !quoted && !bracketed) {
120
+ parts.push(current);
121
+ current = '';
122
+ continue;
123
+ }
124
+ current += chr;
125
+ }
126
+ parts.push(current);
127
+ return parts.map(part => part.trim()).filter(Boolean);
128
+ }
129
+
130
+ function parseAddressEntry(entry) {
131
+ const match = entry.match(/^(.*)<([^>]*)>$/);
132
+ if (!match) {
133
+ return { address: entry };
134
+ }
135
+ let name = match[1].trim();
136
+ if (name.length > 1 && name.startsWith('"') && name.endsWith('"')) {
137
+ name = name.slice(1, -1).replace(/\\(.)/g, '$1');
138
+ }
139
+ const address = match[2].trim();
140
+ return name ? { name, address } : { address };
141
+ }
142
+
143
+ // Adds "Re: " or "Fwd: " unless the subject already starts with that prefix, so a long
144
+ // thread does not read "Re: Re: Re:"
145
+ function prefixSubject(subject, prefix) {
146
+ const value = (subject || '').trim();
147
+ const pattern = prefix === 'Re' ? /^re\s*:/i : /^fwd?\s*:/i;
148
+ return pattern.test(value) ? value : `${prefix}: ${value}`.trim();
149
+ }
150
+
151
+ // Address entries that carry an address, from a list, a single entry or a bare address string.
152
+ // The server can return name-only entries and a single object where a list is expected.
153
+ function addressEntries(value) {
154
+ return (Array.isArray(value) ? value : value ? [value] : [])
155
+ .map(entry => (typeof entry === 'string' ? { address: entry } : entry))
156
+ .filter(entry => entry && typeof entry.address === 'string' && entry.address);
157
+ }
158
+
159
+ // Compose form titles, by mode
160
+ const COMPOSE_TITLES = {
161
+ new: 'New Message',
162
+ reply: 'Reply',
163
+ 'reply-all': 'Reply All',
164
+ forward: 'Forward'
165
+ };
166
+
167
+ // Below this container width the UI shows one pane at a time and the compose button
168
+ // drops its label. Shared by the stylesheet's container query and the compose button
169
+ // sizing, which cannot use the query because the button is not inside .ee-client.
170
+ const NARROW_WIDTH = 700;
171
+
172
+ function icon(name, size = 16) {
173
+ return `<svg class="ee-icon" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${ICON_PATHS[name]}</svg>`;
174
+ }
175
+
68
176
  export class EmailEngineClient {
69
177
  constructor(options = {}) {
70
178
  this.apiUrl = options.apiUrl || 'http://127.0.0.1:3000';
@@ -87,6 +195,14 @@ export class EmailEngineClient {
87
195
 
88
196
  this.currentFolder = null;
89
197
  this.currentMessage = null;
198
+ // A message to open on startup instead of the inbox listing (a deep link). Its folder
199
+ // is listed next to it, so the reader lands where the message lives.
200
+ this.initialMessage = typeof options.message === 'string' && options.message ? options.message : null;
201
+ // Told whenever the open folder or message changes, so a host page can keep its address
202
+ // bar in step (see _notifyNavigate)
203
+ this.onNavigate = typeof options.onNavigate === 'function' ? options.onNavigate : null;
204
+ const maxAttachmentSize = Number(options.maxAttachmentSize);
205
+ this.maxAttachmentSize = maxAttachmentSize > 0 ? maxAttachmentSize : DEFAULT_MAX_ATTACHMENT_SIZE;
90
206
  this.folders = [];
91
207
  this.messages = [];
92
208
  this.nextPageCursor = null;
@@ -241,8 +357,10 @@ export class EmailEngineClient {
241
357
  }
242
358
  }
243
359
 
360
+ // Loads and renders one page of a folder's message list. The open message stays open: it is
361
+ // the folder click (openFolder()) that closes it, while paging and refreshes keep it.
244
362
  async loadMessages(path, cursor = null) {
245
- this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
363
+ this._setPaneHtml('.ee-message-list', `${this._messageListHeader(path)}<div class="ee-loading">Loading messages...</div>`);
246
364
 
247
365
  try {
248
366
  const params = new URLSearchParams({ path, pageSize: this.pageSize });
@@ -256,15 +374,13 @@ export class EmailEngineClient {
256
374
  this.nextPageCursor = data.nextPageCursor || null;
257
375
  this.prevPageCursor = data.prevPageCursor || null;
258
376
 
259
- // Clear active email selection when folder changes
260
- this.currentMessage = null;
261
-
262
377
  if (this.container) {
263
378
  this.renderMessageList();
264
379
  this.renderFolderList(); // Re-render to update active state
265
- this.renderMessage(); // Clear message viewer
266
380
  }
267
381
 
382
+ this._notifyNavigate();
383
+
268
384
  return {
269
385
  messages: this.messages,
270
386
  nextPageCursor: this.nextPageCursor,
@@ -272,13 +388,28 @@ export class EmailEngineClient {
272
388
  };
273
389
  } catch (error) {
274
390
  console.error('Failed to load messages:', error);
275
- this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () => this._fireAndForget(this.loadMessages(path, cursor)));
391
+ this._renderPaneError(
392
+ '.ee-message-list',
393
+ 'Messages unavailable',
394
+ error,
395
+ () => this._fireAndForget(this.loadMessages(path, cursor)),
396
+ this._messageListHeader(path)
397
+ );
276
398
  throw error;
277
399
  }
278
400
  }
279
401
 
402
+ // Switches to another folder: closes the open message and lists the folder
403
+ openFolder(path) {
404
+ this.currentMessage = null;
405
+ this.renderMessage();
406
+ this._setView('list');
407
+ return this.loadMessages(path);
408
+ }
409
+
280
410
  async loadMessage(messageId) {
281
- this._setPaneHtml('.ee-message-viewer', '<div class="ee-loading">Loading message...</div>');
411
+ this._setView('message');
412
+ this._setPaneHtml('.ee-message-viewer', `${this._messageToolbar()}<div class="ee-loading">Loading message...</div>`);
282
413
 
283
414
  try {
284
415
  const params = new URLSearchParams({
@@ -289,6 +420,7 @@ export class EmailEngineClient {
289
420
  this.currentMessage = data;
290
421
 
291
422
  this.currentMessage.unseen = false;
423
+ this._notifyNavigate();
292
424
 
293
425
  const msg = this.messages.find(m => m.id === messageId);
294
426
  if (msg) {
@@ -314,7 +446,13 @@ export class EmailEngineClient {
314
446
  return this.currentMessage;
315
447
  } catch (error) {
316
448
  console.error('Failed to load message:', error);
317
- this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () => this._fireAndForget(this.loadMessage(messageId)));
449
+ this._renderPaneError(
450
+ '.ee-message-viewer',
451
+ 'Message unavailable',
452
+ error,
453
+ () => this._fireAndForget(this.loadMessage(messageId)),
454
+ this._messageToolbar()
455
+ );
318
456
  throw error;
319
457
  }
320
458
  }
@@ -347,21 +485,28 @@ export class EmailEngineClient {
347
485
  }
348
486
  }
349
487
 
350
- async deleteMessage(messageId) {
351
- try {
352
- await this.apiRequest('DELETE', this._messagePath(messageId));
488
+ // Takes a message that left the folder (deleted or moved) off the list, and out of the
489
+ // viewer when it was the open one
490
+ _dropMessage(messageId) {
491
+ this.messages = this.messages.filter(m => m.id !== messageId);
492
+ if (this.container) {
493
+ this.renderMessageList();
494
+ }
353
495
 
354
- this.messages = this.messages.filter(m => m.id !== messageId);
496
+ if (this.currentMessage && this.currentMessage.id === messageId) {
497
+ this.currentMessage = null;
355
498
  if (this.container) {
356
- this.renderMessageList();
499
+ this.renderMessage();
357
500
  }
501
+ this._notifyNavigate();
502
+ }
503
+ }
358
504
 
359
- if (this.currentMessage && this.currentMessage.id === messageId) {
360
- this.currentMessage = null;
361
- if (this.container) {
362
- this.renderMessage();
363
- }
364
- }
505
+ async deleteMessage(messageId) {
506
+ try {
507
+ await this.apiRequest('DELETE', this._messagePath(messageId));
508
+
509
+ this._dropMessage(messageId);
365
510
 
366
511
  return true;
367
512
  } catch (error) {
@@ -376,17 +521,7 @@ export class EmailEngineClient {
376
521
  path: targetPath
377
522
  });
378
523
 
379
- this.messages = this.messages.filter(m => m.id !== messageId);
380
- if (this.container) {
381
- this.renderMessageList();
382
- }
383
-
384
- if (this.currentMessage && this.currentMessage.id === messageId) {
385
- this.currentMessage = null;
386
- if (this.container) {
387
- this.renderMessage();
388
- }
389
- }
524
+ this._dropMessage(messageId);
390
525
 
391
526
  return true;
392
527
  } catch (error) {
@@ -395,10 +530,6 @@ export class EmailEngineClient {
395
530
  }
396
531
  }
397
532
 
398
- _normalizeRecipients(to) {
399
- return Array.isArray(to) ? to.map(addr => (typeof addr === 'string' ? { address: addr } : addr)) : [typeof to === 'string' ? { address: to } : to];
400
- }
401
-
402
533
  // Account details (name, email address) fetched once and cached for the lifetime
403
534
  // of the instance; used as the From identity of saved drafts.
404
535
  async _getAccountInfo() {
@@ -408,13 +539,35 @@ export class EmailEngineClient {
408
539
  return this._accountInfo;
409
540
  }
410
541
 
411
- async sendMessage(to, subject, text) {
542
+ // The address and content fields shared by a submission and a draft upload. Empty recipient
543
+ // lists are left out rather than sent as [].
544
+ _messagePayload(to, subject, text, { cc, bcc, attachments, reference } = {}) {
545
+ const data = { subject, text };
546
+ for (const [key, value] of [
547
+ ['to', to],
548
+ ['cc', cc],
549
+ ['bcc', bcc]
550
+ ]) {
551
+ const list = addressEntries(value);
552
+ if (list.length) {
553
+ data[key] = list;
554
+ }
555
+ }
556
+ if (Array.isArray(attachments) && attachments.length) {
557
+ data.attachments = attachments.map(({ filename, contentType, content }) => ({ filename, contentType, content }));
558
+ }
559
+ if (reference) {
560
+ data.reference = reference;
561
+ }
562
+ return data;
563
+ }
564
+
565
+ // options: { cc, bcc, attachments: [{ filename, contentType, content (base64) }], reference }.
566
+ // reference is EmailEngine's submit reference block ({ message, action, inline,
567
+ // forwardAttachments }); with it the server adds the threading headers and the quote.
568
+ async sendMessage(to, subject, text, options = {}) {
412
569
  try {
413
- const messageData = {
414
- to: this._normalizeRecipients(to),
415
- subject,
416
- text
417
- };
570
+ const messageData = this._messagePayload(to, subject, text, options);
418
571
 
419
572
  const response = await this.apiRequest('POST', `${this._accountPath()}/submit`, messageData);
420
573
  return response;
@@ -424,7 +577,7 @@ export class EmailEngineClient {
424
577
  }
425
578
  }
426
579
 
427
- async saveDraft(to, subject, text) {
580
+ async saveDraft(to, subject, text, options = {}) {
428
581
  try {
429
582
  if (!this.folders.length) {
430
583
  await this.loadFolders();
@@ -437,15 +590,9 @@ export class EmailEngineClient {
437
590
  const messageData = {
438
591
  path: draftsFolder.path,
439
592
  flags: ['\\Draft'],
440
- subject,
441
- text
593
+ ...this._messagePayload(to, subject, text, options)
442
594
  };
443
595
 
444
- const recipients = to ? this._normalizeRecipients(to) : [];
445
- if (recipients.length) {
446
- messageData.to = recipients;
447
- }
448
-
449
596
  // The upload endpoint does not add a From header on its own, but the draft
450
597
  // needs one to be deliverable later - use the account's own identity.
451
598
  try {
@@ -465,6 +612,82 @@ export class EmailEngineClient {
465
612
  }
466
613
  }
467
614
 
615
+ // Parses a typed address field ("Name <a@example.com>, b@example.com") into address entries
616
+ parseAddressList(value) {
617
+ return splitAddressField(String(value || '')).map(parseAddressEntry);
618
+ }
619
+
620
+ // The reverse of parseAddressList, for filling a compose field
621
+ formatAddressList(list) {
622
+ return addressEntries(list)
623
+ .map(entry => {
624
+ if (!entry.name) {
625
+ return entry.address;
626
+ }
627
+ const name = /[",;<>@\\]/.test(entry.name) ? `"${entry.name.replace(/(["\\])/g, '\\$1')}"` : entry.name;
628
+ return `${name} <${entry.address}>`;
629
+ })
630
+ .join(', ');
631
+ }
632
+
633
+ // Recipients, subject and submit reference for a reply, reply-all or forward of msg, as the
634
+ // compose form shows them. ownAddress (the account's) is left out of the recipients.
635
+ //
636
+ // Reply-all is resolved here rather than by the server: EmailEngine's reply-all merges the
637
+ // original recipients into whatever is sent, so one the user removed from the form would be
638
+ // put back. It goes out as a reply with every recipient spelled out instead, which the server
639
+ // leaves alone, and what the form shows is what is sent.
640
+ prepareResponse(msg, action, ownAddress = null) {
641
+ if (action === 'forward') {
642
+ return { to: [], cc: [], subject: prefixSubject(msg.subject, 'Fwd'), reference: { message: msg.id, action: 'forward', inline: true } };
643
+ }
644
+
645
+ const own = typeof ownAddress === 'string' ? ownAddress.toLowerCase() : '';
646
+ const seen = new Set(own ? [own] : []);
647
+ const take = list =>
648
+ addressEntries(list)
649
+ .filter(entry => {
650
+ const key = entry.address.toLowerCase();
651
+ if (seen.has(key)) {
652
+ return false;
653
+ }
654
+ seen.add(key);
655
+ return true;
656
+ })
657
+ .map(entry => (entry.name ? { name: entry.name, address: entry.address } : { address: entry.address }));
658
+
659
+ // Answer the address the message nominates, otherwise its sender - or, for a message the
660
+ // account sent itself (Sent folder), the people it went to. The account's own address is
661
+ // never an answer, so a Reply-To naming the account falls through to the next candidate.
662
+ const fromSelf = !!own && addressEntries(msg.from).some(entry => entry.address.toLowerCase() === own);
663
+ let to = [];
664
+ for (const candidate of [msg.replyTo, fromSelf ? msg.to : msg.from]) {
665
+ to = take(candidate);
666
+ if (to.length) {
667
+ break;
668
+ }
669
+ }
670
+ if (!to.length) {
671
+ // A message from the account to itself: answer it anyway
672
+ to = addressEntries(msg.from).map(entry => ({ ...entry }));
673
+ }
674
+ const cc = action === 'reply-all' ? take(addressEntries(msg.to).concat(addressEntries(msg.cc))) : [];
675
+
676
+ return { to, cc, subject: prefixSubject(msg.subject, 'Re'), reference: { message: msg.id, action: 'reply', inline: true } };
677
+ }
678
+
679
+ // Tells the host which folder and message are open. A host error must not break the client.
680
+ _notifyNavigate() {
681
+ if (!this.onNavigate || this._destroyed) {
682
+ return;
683
+ }
684
+ try {
685
+ this.onNavigate({ path: this.currentFolder, messageId: this.currentMessage ? this.currentMessage.id : null });
686
+ } catch (error) {
687
+ console.error('onNavigate handler failed:', error);
688
+ }
689
+ }
690
+
468
691
  async submitDraft(messageId, options = null) {
469
692
  try {
470
693
  const response = await this.apiRequest('POST', this._messagePath(messageId, '/submit'), options);
@@ -511,7 +734,7 @@ export class EmailEngineClient {
511
734
  // are needed - and to[N] for any index is handled, not just to[0].
512
735
  .map(field =>
513
736
  field.message
514
- .replace(/to\[\d+\]\.address|"address"/g, 'email address')
737
+ .replace(/(?:to|cc|bcc)\[\d+\]\.address|"address"/g, 'email address')
515
738
  .replace(/"subject"/g, 'subject')
516
739
  .replace(/"text"/g, 'message')
517
740
  );
@@ -556,11 +779,12 @@ export class EmailEngineClient {
556
779
  // missing, optionally with a Retry button. Without this a failed request
557
780
  // leaves the pane stuck on its "Loading..." placeholder forever, with the
558
781
  // only trace of the failure in the developer console.
559
- _renderPaneError(selector, title, error, retry = null) {
782
+ _renderPaneError(selector, title, error, retry = null, header = '') {
560
783
  const detail = this._errorMessage(error, '');
561
784
  const pane = this._setPaneHtml(
562
785
  selector,
563
786
  `
787
+ ${header}
564
788
  <div class="ee-error">
565
789
  <div class="ee-error-title">${this.escapeHtml(title)}</div>
566
790
  ${detail ? `<div class="ee-error-detail">${this.escapeHtml(detail)}</div>` : ''}
@@ -604,14 +828,54 @@ export class EmailEngineClient {
604
828
  // The message list before any folder is opened. Shared with createLayout so the
605
829
  // pane header markup lives in one place.
606
830
  _messageListPlaceholder() {
831
+ return `${this._messageListHeader(null)}<div class="ee-empty-state">Select a folder</div>`;
832
+ }
833
+
834
+ // Header for every state of the message list pane, titled with the folder
835
+ // being shown. In the single-pane layout its back button leads to the folders.
836
+ _messageListHeader(path, controls = '') {
837
+ const folder = path && this.folders.find(f => f.path === path);
607
838
  return `
608
839
  <div class="ee-pane-header">
609
- <span class="ee-pane-title">Messages</span>
840
+ <div class="ee-pane-heading">
841
+ ${this._iconButton('show-folders', 'back', 'Folders', 'ee-nav-button')}
842
+ <span class="ee-pane-title">${this.escapeHtml(folder ? folder.name : 'Messages')}</span>
843
+ </div>
844
+ ${controls}
845
+ </div>
846
+ `;
847
+ }
848
+
849
+ // The viewer's toolbar row. It stays up in the loading, empty and error states
850
+ // too, so the header band runs unbroken across the panes and the single-pane
851
+ // layout always has its way back to the list.
852
+ _messageToolbar(actions = '') {
853
+ return `
854
+ <div class="ee-message-actions">
855
+ ${this._iconButton('back-to-list', 'back', 'Back to messages', 'ee-nav-button')}
856
+ ${actions}
610
857
  </div>
611
- <div class="ee-empty-state">Select a folder</div>
612
858
  `;
613
859
  }
614
860
 
861
+ _messageViewerPlaceholder() {
862
+ return `${this._messageToolbar()}<div class="ee-empty-state">Select a message to view</div>`;
863
+ }
864
+
865
+ // Which pane the single-pane (narrow) layout shows: folders, list or message.
866
+ // Wider layouts show all three and ignore it.
867
+ _getView() {
868
+ const client = this.container && this.container.querySelector('.ee-client');
869
+ return client ? client.dataset.view : null;
870
+ }
871
+
872
+ _setView(view) {
873
+ const client = this.container && this.container.querySelector('.ee-client');
874
+ if (client) {
875
+ client.dataset.view = view;
876
+ }
877
+ }
878
+
615
879
  formatDate(dateStr) {
616
880
  const date = new Date(dateStr);
617
881
  const now = new Date();
@@ -830,6 +1094,9 @@ export class EmailEngineClient {
830
1094
  background: #fff;
831
1095
  border: 1px solid #ddd;
832
1096
  position: relative;
1097
+ /* Layout breakpoints follow the widget's own width, not the viewport:
1098
+ hosts embed it in pages of any shape */
1099
+ container: ee-client / inline-size;
833
1100
  }
834
1101
 
835
1102
  .ee-client * {
@@ -837,7 +1104,8 @@ export class EmailEngineClient {
837
1104
  }
838
1105
 
839
1106
  .ee-sidebar {
840
- width: 200px;
1107
+ width: clamp(160px, 18%, 220px);
1108
+ flex-shrink: 0;
841
1109
  background: #ffffff;
842
1110
  border-right: 1px solid #ddd;
843
1111
  display: flex;
@@ -917,7 +1185,8 @@ export class EmailEngineClient {
917
1185
  }
918
1186
 
919
1187
  .ee-message-list {
920
- width: 350px;
1188
+ width: clamp(260px, 32%, 380px);
1189
+ flex-shrink: 0;
921
1190
  border-right: 1px solid #ddd;
922
1191
  background: #ffffff;
923
1192
  display: flex;
@@ -986,57 +1255,157 @@ export class EmailEngineClient {
986
1255
  }
987
1256
 
988
1257
  .ee-attachment-indicator {
989
- display: inline-block;
1258
+ display: inline-flex;
1259
+ align-items: center;
1260
+ white-space: nowrap;
1261
+ flex-shrink: 0;
990
1262
  font-size: 11px;
991
1263
  color: #666;
992
1264
  margin-left: 8px;
993
1265
  }
994
1266
 
995
- .ee-attachment-indicator::before {
996
- content: "📎 ";
1267
+ .ee-attachment-indicator .ee-icon {
1268
+ margin-right: 2px;
1269
+ }
1270
+
1271
+ /* Replied / forwarded markers, from the message flags (see _responseMarkers) */
1272
+ .ee-response-marker {
1273
+ display: inline-flex;
1274
+ align-items: center;
1275
+ gap: 4px;
1276
+ color: #666;
1277
+ margin-right: 6px;
1278
+ flex-shrink: 0;
1279
+ }
1280
+
1281
+ .ee-message-title-markers {
1282
+ display: flex;
1283
+ gap: 4px;
1284
+ margin: -8px 0 12px;
1285
+ font-size: 12px;
1286
+ }
1287
+
1288
+ .ee-message-title-markers:empty {
1289
+ display: none;
1290
+ }
1291
+
1292
+ .ee-dark-mode .ee-response-marker {
1293
+ color: #999;
997
1294
  }
998
1295
 
999
1296
  .ee-message-viewer {
1000
1297
  flex: 1;
1298
+ min-width: 0;
1001
1299
  display: flex;
1002
1300
  flex-direction: column;
1003
1301
  overflow: hidden;
1302
+ container: ee-viewer / inline-size;
1004
1303
  }
1005
1304
 
1006
1305
  .ee-message-actions {
1007
- padding: 10px 16px;
1306
+ padding: 0 12px;
1008
1307
  background: #e9ecef;
1009
1308
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
1010
1309
  border-bottom: 2px solid #dee2e6;
1011
1310
  display: flex;
1012
- gap: 8px;
1311
+ gap: 6px;
1013
1312
  height: 44px;
1014
1313
  align-items: center;
1015
1314
  flex-shrink: 0;
1016
1315
  box-sizing: border-box;
1017
1316
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1317
+ overflow-x: auto;
1318
+ scrollbar-width: none;
1018
1319
  }
1019
1320
 
1020
1321
  .ee-button {
1021
- padding: 4px 10px;
1022
- border: 1px solid #ddd;
1322
+ display: inline-flex;
1323
+ align-items: center;
1324
+ justify-content: center;
1325
+ gap: 6px;
1326
+ flex-shrink: 0;
1327
+ padding: 0 10px;
1328
+ border: 1px solid #d0d4d9;
1023
1329
  background: white;
1024
- border-radius: 4px;
1330
+ color: #333;
1331
+ border-radius: 6px;
1025
1332
  cursor: pointer;
1026
- font-size: 12px;
1027
- height: 24px;
1333
+ font-family: inherit;
1334
+ font-size: 13px;
1335
+ font-weight: 500;
1336
+ height: 30px;
1028
1337
  line-height: 1;
1338
+ white-space: nowrap;
1029
1339
  box-sizing: border-box;
1030
1340
  }
1031
1341
 
1032
- select.ee-button {
1033
- padding: 3px 10px;
1034
- height: 24px;
1035
- }
1036
-
1037
1342
  .ee-button:hover:not(:disabled) {
1038
1343
  background: #f0f0f0;
1039
1344
  }
1345
+
1346
+ .ee-button:focus-visible,
1347
+ .ee-move-button:focus-within,
1348
+ .ee-compose-button:focus-visible {
1349
+ outline: 2px solid #4d9fff;
1350
+ outline-offset: 1px;
1351
+ }
1352
+
1353
+ .ee-icon {
1354
+ flex-shrink: 0;
1355
+ }
1356
+
1357
+ .ee-icon-button {
1358
+ width: 30px;
1359
+ padding: 0;
1360
+ }
1361
+
1362
+ .ee-nav-button {
1363
+ display: none;
1364
+ }
1365
+
1366
+ /* Borderless, so a back arrow beside the title does not read as one
1367
+ of the pagination arrows */
1368
+ .ee-client .ee-button.ee-nav-button {
1369
+ background: transparent;
1370
+ border-color: transparent;
1371
+ margin-left: -6px;
1372
+ }
1373
+
1374
+ .ee-toolbar-spacer {
1375
+ flex: 1;
1376
+ }
1377
+
1378
+ .ee-button-primary {
1379
+ background: #007bff;
1380
+ border-color: #007bff;
1381
+ color: white;
1382
+ }
1383
+
1384
+ .ee-button-primary:hover:not(:disabled) {
1385
+ background: #0069d9;
1386
+ }
1387
+
1388
+ .ee-button-danger:hover:not(:disabled) {
1389
+ background: #fdecea;
1390
+ border-color: #f1b0ab;
1391
+ color: #c62828;
1392
+ }
1393
+
1394
+ .ee-move-button {
1395
+ position: relative;
1396
+ }
1397
+
1398
+ /* The native select covers the whole button, invisibly, so a click
1399
+ anywhere on it opens the platform folder picker */
1400
+ .ee-move-select {
1401
+ position: absolute;
1402
+ inset: 0;
1403
+ width: 100%;
1404
+ height: 100%;
1405
+ opacity: 0;
1406
+ cursor: pointer;
1407
+ font-size: 14px;
1408
+ }
1040
1409
 
1041
1410
  .ee-button:disabled {
1042
1411
  background: #e9ecef;
@@ -1047,18 +1416,35 @@ export class EmailEngineClient {
1047
1416
 
1048
1417
  .ee-message-content {
1049
1418
  flex: 1;
1050
- padding: 16px;
1419
+ /* The bottom padding lets the end of the message scroll clear of
1420
+ the floating compose button */
1421
+ padding: 20px 20px 88px;
1051
1422
  overflow-y: auto;
1052
1423
  }
1424
+
1425
+ .ee-message-title {
1426
+ margin: 0 0 12px;
1427
+ font-size: 20px;
1428
+ font-weight: 600;
1429
+ line-height: 1.3;
1430
+ overflow-wrap: anywhere;
1431
+ }
1053
1432
 
1054
1433
  .ee-message-meta {
1434
+ display: grid;
1435
+ grid-template-columns: auto minmax(0, 1fr);
1436
+ gap: 2px 12px;
1055
1437
  margin-bottom: 16px;
1056
1438
  padding-bottom: 16px;
1057
1439
  border-bottom: 1px solid #e0e0e0;
1058
1440
  }
1059
1441
 
1060
1442
  .ee-message-meta-row {
1061
- margin-bottom: 4px;
1443
+ display: contents;
1444
+ }
1445
+
1446
+ .ee-message-meta-value {
1447
+ overflow-wrap: anywhere;
1062
1448
  }
1063
1449
 
1064
1450
  .ee-otp {
@@ -1138,8 +1524,6 @@ export class EmailEngineClient {
1138
1524
  }
1139
1525
 
1140
1526
  .ee-message-meta-label {
1141
- display: inline-block;
1142
- width: 60px;
1143
1527
  color: #666;
1144
1528
  font-weight: 500;
1145
1529
  }
@@ -1173,8 +1557,9 @@ export class EmailEngineClient {
1173
1557
  }
1174
1558
 
1175
1559
  .ee-attachment-icon {
1560
+ display: flex;
1176
1561
  margin-right: 8px;
1177
- font-size: 18px;
1562
+ color: #666;
1178
1563
  }
1179
1564
 
1180
1565
  .ee-attachment-info {
@@ -1249,7 +1634,8 @@ export class EmailEngineClient {
1249
1634
  }
1250
1635
 
1251
1636
  .ee-pane-header {
1252
- padding: 10px 16px;
1637
+ gap: 8px;
1638
+ padding: 0 12px 0 16px;
1253
1639
  background: #e9ecef;
1254
1640
  background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
1255
1641
  border-bottom: 2px solid #dee2e6;
@@ -1262,10 +1648,20 @@ export class EmailEngineClient {
1262
1648
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
1263
1649
  }
1264
1650
 
1651
+ .ee-pane-heading {
1652
+ display: flex;
1653
+ align-items: center;
1654
+ gap: 6px;
1655
+ min-width: 0;
1656
+ }
1657
+
1265
1658
  .ee-pane-title {
1266
- font-weight: 500;
1659
+ font-weight: 600;
1267
1660
  font-size: 14px;
1268
1661
  color: #333;
1662
+ overflow: hidden;
1663
+ text-overflow: ellipsis;
1664
+ white-space: nowrap;
1269
1665
  }
1270
1666
 
1271
1667
  .ee-folder-tree {
@@ -1275,15 +1671,16 @@ export class EmailEngineClient {
1275
1671
 
1276
1672
  .ee-pagination-controls {
1277
1673
  display: flex;
1278
- gap: 8px;
1674
+ gap: 6px;
1279
1675
  align-items: center;
1676
+ flex-shrink: 0;
1280
1677
  }
1281
1678
 
1282
1679
  .ee-page-size-selector {
1283
1680
  display: flex;
1284
- gap: 4px;
1681
+ gap: 6px;
1285
1682
  align-items: center;
1286
- margin-left: auto;
1683
+ margin-left: 4px;
1287
1684
  }
1288
1685
 
1289
1686
  .ee-page-size-label {
@@ -1292,73 +1689,124 @@ export class EmailEngineClient {
1292
1689
  }
1293
1690
 
1294
1691
  .ee-page-size-select {
1295
- font-size: 11px;
1296
- padding: 2px 4px;
1297
- border: 1px solid #ddd;
1298
- border-radius: 3px;
1299
- background: white;
1300
- cursor: pointer;
1301
- height: 22px;
1302
- }
1303
-
1304
- .ee-pagination-btn {
1305
- font-size: 11px;
1306
- padding: 3px 8px;
1307
- height: 22px;
1308
- line-height: 1;
1692
+ padding: 0 4px;
1309
1693
  }
1310
1694
 
1311
1695
  .ee-message-items {
1312
1696
  flex: 1;
1313
1697
  overflow-y: auto;
1698
+ padding-bottom: 88px;
1314
1699
  }
1315
1700
 
1316
1701
  .ee-compose-button {
1317
1702
  position: fixed;
1318
1703
  bottom: 20px;
1319
1704
  right: 20px;
1320
- width: 56px;
1321
- height: 56px;
1705
+ display: inline-flex;
1706
+ align-items: center;
1707
+ gap: 10px;
1708
+ height: 52px;
1709
+ padding: 0 22px 0 18px;
1322
1710
  background: #007bff;
1323
1711
  border: none;
1324
- border-radius: 50%;
1712
+ border-radius: 16px;
1325
1713
  color: white;
1326
- font-size: 24px;
1714
+ font-family: var(--ee-font, inherit);
1715
+ font-size: 15px;
1716
+ font-weight: 600;
1327
1717
  cursor: pointer;
1328
1718
  box-shadow: 0 4px 12px rgba(0,123,255,0.3);
1329
1719
  z-index: 1000;
1330
- transition: all 0.2s ease;
1720
+ transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
1331
1721
  }
1332
1722
 
1333
1723
  .ee-compose-button:hover {
1334
1724
  background: #0056b3;
1335
- transform: scale(1.05);
1725
+ transform: translateY(-1px);
1336
1726
  box-shadow: 0 6px 16px rgba(0,123,255,0.4);
1337
1727
  }
1338
-
1339
- .ee-compose-modal {
1340
- display: none;
1341
- position: fixed;
1342
- top: 0;
1343
- left: 0;
1344
- width: 100%;
1345
- height: 100%;
1346
- background: rgba(0, 0, 0, 0.5);
1347
- z-index: 2000;
1348
- }
1349
-
1350
- .ee-compose-modal.show {
1351
- display: flex;
1352
- align-items: center;
1728
+
1729
+ .ee-compose-button.ee-compose-compact {
1730
+ width: 56px;
1731
+ height: 56px;
1732
+ padding: 0;
1353
1733
  justify-content: center;
1734
+ border-radius: 50%;
1354
1735
  }
1355
-
1356
- .ee-compose-dialog {
1357
- background: white;
1358
- border-radius: 8px;
1359
- width: 90%;
1736
+
1737
+ .ee-compose-compact .ee-compose-button-label {
1738
+ display: none;
1739
+ }
1740
+
1741
+ /* Medium widths: the viewer is too narrow for labelled buttons, so the
1742
+ 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 {
1745
+ display: none;
1746
+ }
1747
+
1748
+ .ee-message-actions .ee-button:not(.ee-keep-label) {
1749
+ width: 30px;
1750
+ padding: 0;
1751
+ }
1752
+
1753
+ .ee-message-actions .ee-move-button {
1754
+ width: 44px;
1755
+ gap: 2px;
1756
+ }
1757
+ }
1758
+
1759
+ /* Narrow widths: one pane at a time, in the order a phone mail app uses
1760
+ (folders, list, message), with back buttons in the pane headers. The
1761
+ shown pane follows data-view on .ee-client. */
1762
+ @container ee-client (max-width: ${NARROW_WIDTH - 1}px) {
1763
+ .ee-sidebar,
1764
+ .ee-message-list,
1765
+ .ee-message-viewer {
1766
+ display: none;
1767
+ width: 100%;
1768
+ flex: 1;
1769
+ border-right: 0;
1770
+ }
1771
+
1772
+ .ee-client[data-view="folders"] .ee-sidebar,
1773
+ .ee-client[data-view="list"] .ee-message-list,
1774
+ .ee-client[data-view="message"] .ee-message-viewer {
1775
+ display: flex;
1776
+ }
1777
+
1778
+ .ee-nav-button {
1779
+ display: inline-flex;
1780
+ }
1781
+
1782
+ .ee-message-content {
1783
+ padding: 16px 16px 88px;
1784
+ }
1785
+ }
1786
+
1787
+ .ee-compose-modal {
1788
+ display: none;
1789
+ position: fixed;
1790
+ top: 0;
1791
+ left: 0;
1792
+ width: 100%;
1793
+ height: 100%;
1794
+ background: rgba(0, 0, 0, 0.5);
1795
+ z-index: 2000;
1796
+ }
1797
+
1798
+ .ee-compose-modal.show {
1799
+ display: flex;
1800
+ align-items: center;
1801
+ justify-content: center;
1802
+ }
1803
+
1804
+ .ee-compose-dialog {
1805
+ background: white;
1806
+ border-radius: 8px;
1807
+ width: 90%;
1360
1808
  max-width: 600px;
1361
- max-height: 80vh;
1809
+ max-height: 90vh;
1362
1810
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
1363
1811
  display: flex;
1364
1812
  flex-direction: column;
@@ -1382,7 +1830,6 @@ export class EmailEngineClient {
1382
1830
  .ee-compose-close {
1383
1831
  background: none;
1384
1832
  border: none;
1385
- font-size: 24px;
1386
1833
  color: #666;
1387
1834
  cursor: pointer;
1388
1835
  padding: 0;
@@ -1439,7 +1886,7 @@ export class EmailEngineClient {
1439
1886
  font-size: 14px;
1440
1887
  font-family: inherit;
1441
1888
  resize: vertical;
1442
- min-height: 200px;
1889
+ min-height: 160px;
1443
1890
  }
1444
1891
 
1445
1892
  .ee-compose-textarea:focus {
@@ -1515,24 +1962,159 @@ export class EmailEngineClient {
1515
1962
  opacity: 0.6;
1516
1963
  }
1517
1964
 
1518
- /* Dark mode toggle button */
1965
+ /* Parts of the compose form that come and go (Cc/Bcc, the forward checkbox, the
1966
+ quote) use the hidden attribute, which a display rule would otherwise override */
1967
+ .ee-compose-modal [hidden] {
1968
+ display: none !important;
1969
+ }
1970
+
1971
+ .ee-compose-label-row {
1972
+ display: flex;
1973
+ justify-content: space-between;
1974
+ align-items: baseline;
1975
+ }
1976
+
1977
+ .ee-compose-link {
1978
+ background: none;
1979
+ border: none;
1980
+ padding: 0;
1981
+ font: inherit;
1982
+ font-size: 13px;
1983
+ color: #007bff;
1984
+ cursor: pointer;
1985
+ }
1986
+
1987
+ .ee-compose-link:hover {
1988
+ text-decoration: underline;
1989
+ }
1990
+
1991
+ .ee-compose-files {
1992
+ display: flex;
1993
+ flex-direction: column;
1994
+ gap: 8px;
1995
+ }
1996
+
1997
+ .ee-compose-files-row {
1998
+ display: flex;
1999
+ flex-wrap: wrap;
2000
+ align-items: center;
2001
+ gap: 8px 16px;
2002
+ }
2003
+
2004
+ .ee-compose-attach {
2005
+ display: inline-flex;
2006
+ align-items: center;
2007
+ gap: 6px;
2008
+ background: transparent;
2009
+ border: 1px solid #ddd;
2010
+ border-radius: 4px;
2011
+ padding: 6px 12px;
2012
+ font: inherit;
2013
+ font-size: 13px;
2014
+ color: inherit;
2015
+ cursor: pointer;
2016
+ }
2017
+
2018
+ .ee-compose-attach:hover {
2019
+ background: #f0f0f0;
2020
+ }
2021
+
2022
+ .ee-compose-forward-attachments {
2023
+ display: inline-flex;
2024
+ align-items: center;
2025
+ gap: 6px;
2026
+ font-size: 13px;
2027
+ cursor: pointer;
2028
+ }
2029
+
2030
+ .ee-compose-chips {
2031
+ display: flex;
2032
+ flex-wrap: wrap;
2033
+ gap: 6px;
2034
+ }
2035
+
2036
+ .ee-compose-chips:empty {
2037
+ display: none;
2038
+ }
2039
+
2040
+ .ee-compose-chip {
2041
+ display: inline-flex;
2042
+ align-items: center;
2043
+ gap: 6px;
2044
+ max-width: 100%;
2045
+ padding: 4px 4px 4px 10px;
2046
+ border: 1px solid #ddd;
2047
+ border-radius: 16px;
2048
+ background: #f8f9fa;
2049
+ font-size: 13px;
2050
+ }
2051
+
2052
+ .ee-compose-chip-name {
2053
+ overflow: hidden;
2054
+ text-overflow: ellipsis;
2055
+ white-space: nowrap;
2056
+ min-width: 0;
2057
+ }
2058
+
2059
+ .ee-compose-chip-size {
2060
+ color: #666;
2061
+ flex-shrink: 0;
2062
+ }
2063
+
2064
+ .ee-compose-chip-remove {
2065
+ display: inline-flex;
2066
+ align-items: center;
2067
+ justify-content: center;
2068
+ width: 22px;
2069
+ height: 22px;
2070
+ padding: 0;
2071
+ border: none;
2072
+ border-radius: 50%;
2073
+ background: transparent;
2074
+ color: #666;
2075
+ cursor: pointer;
2076
+ flex-shrink: 0;
2077
+ }
2078
+
2079
+ .ee-compose-chip-remove:hover {
2080
+ background: #e0e0e0;
2081
+ }
2082
+
2083
+ .ee-compose-quote {
2084
+ display: flex;
2085
+ flex-direction: column;
2086
+ gap: 6px;
2087
+ }
2088
+
2089
+ .ee-compose-quote-label {
2090
+ font-size: 13px;
2091
+ color: #666;
2092
+ }
2093
+
2094
+ .ee-compose-quote-frame {
2095
+ max-height: 220px;
2096
+ overflow: auto;
2097
+ padding: 8px 12px;
2098
+ border-left: 3px solid #ddd;
2099
+ background: #fafafa;
2100
+ border-radius: 0 4px 4px 0;
2101
+ }
2102
+
2103
+ /* Dark mode toggle button, in the Folders pane header */
1519
2104
  .ee-dark-mode-toggle {
1520
- position: absolute;
1521
- top: 8px;
1522
- right: 16px;
1523
2105
  background: #f8f9fa;
1524
2106
  border: 1px solid #dee2e6;
1525
- border-radius: 3px;
1526
- padding: 6px 10px;
1527
- font-size: 12px;
2107
+ border-radius: 6px;
2108
+ padding: 0;
2109
+ width: 30px;
2110
+ height: 30px;
2111
+ flex-shrink: 0;
1528
2112
  cursor: pointer;
1529
- z-index: 100;
1530
2113
  transition: all 0.2s ease;
1531
2114
  display: flex;
1532
2115
  align-items: center;
1533
2116
  justify-content: center;
1534
2117
  color: #495057;
1535
- font-weight: 500;
1536
2118
  }
1537
2119
 
1538
2120
  .ee-dark-mode-toggle:hover {
@@ -1541,8 +2123,7 @@ export class EmailEngineClient {
1541
2123
  }
1542
2124
 
1543
2125
  .ee-dark-mode-icon {
1544
- font-size: 14px;
1545
- line-height: 1;
2126
+ display: flex;
1546
2127
  }
1547
2128
 
1548
2129
  /* Dark mode styles */
@@ -1645,6 +2226,27 @@ export class EmailEngineClient {
1645
2226
  border-color: #555;
1646
2227
  }
1647
2228
 
2229
+ .ee-dark-mode .ee-button-primary,
2230
+ .ee-dark-mode .ee-button-primary:hover:not(:disabled) {
2231
+ background: #0056b3;
2232
+ border-color: #0056b3;
2233
+ color: white;
2234
+ }
2235
+
2236
+ .ee-dark-mode .ee-button-danger:hover:not(:disabled) {
2237
+ background: #4a2323;
2238
+ border-color: #7a3434;
2239
+ color: #f0a5a5;
2240
+ }
2241
+
2242
+ .ee-dark-mode .ee-message-meta {
2243
+ border-color: #333;
2244
+ }
2245
+
2246
+ .ee-dark-mode .ee-message-meta-label {
2247
+ color: #999;
2248
+ }
2249
+
1648
2250
  .ee-dark-mode .ee-button:disabled {
1649
2251
  background: #222;
1650
2252
  color: #666;
@@ -1662,10 +2264,18 @@ export class EmailEngineClient {
1662
2264
  }
1663
2265
 
1664
2266
  .ee-dark-mode .ee-attachments {
1665
- background: #252525;
1666
2267
  border-color: #333;
1667
2268
  }
1668
2269
 
2270
+ .ee-dark-mode .ee-attachments-title,
2271
+ .ee-dark-mode .ee-attachment-name {
2272
+ color: #e0e0e0;
2273
+ }
2274
+
2275
+ .ee-dark-mode .ee-attachment-size {
2276
+ color: #999;
2277
+ }
2278
+
1669
2279
  .ee-dark-mode .ee-attachment-item {
1670
2280
  background: #2a2a2a;
1671
2281
  border-color: #333;
@@ -1716,19 +2326,30 @@ export class EmailEngineClient {
1716
2326
  border-color: #333;
1717
2327
  }
1718
2328
 
1719
- .ee-dark-mode .ee-compose-button {
2329
+ /* The compose button and modal sit beside .ee-client, not inside it, so
2330
+ setDarkMode puts the ee-dark-mode class on them directly */
2331
+ .ee-compose-button.ee-dark-mode {
1720
2332
  background: #0056b3;
2333
+ color: white;
2334
+ }
2335
+
2336
+ .ee-compose-button.ee-dark-mode:hover {
2337
+ background: #004a99;
1721
2338
  }
1722
2339
 
1723
- .ee-dark-mode .ee-compose-modal {
2340
+ .ee-compose-modal.ee-dark-mode {
1724
2341
  background: rgba(0, 0, 0, 0.7);
1725
2342
  }
1726
2343
 
1727
- .ee-dark-mode .ee-compose-content {
2344
+ .ee-dark-mode .ee-compose-dialog {
1728
2345
  background: #202020;
1729
2346
  color: #e0e0e0;
1730
2347
  }
1731
2348
 
2349
+ .ee-dark-mode .ee-compose-label {
2350
+ color: #ccc;
2351
+ }
2352
+
1732
2353
  .ee-dark-mode .ee-compose-header {
1733
2354
  background: linear-gradient(to bottom, #2a2a2a, #252525);
1734
2355
  border-color: #333;
@@ -1776,6 +2397,35 @@ export class EmailEngineClient {
1776
2397
  background: #66b2ff;
1777
2398
  color: #1a1a1a;
1778
2399
  }
2400
+
2401
+ .ee-dark-mode .ee-compose-link {
2402
+ color: #66b2ff;
2403
+ }
2404
+
2405
+ .ee-dark-mode .ee-compose-attach {
2406
+ border-color: #444;
2407
+ }
2408
+
2409
+ .ee-dark-mode .ee-compose-attach:hover,
2410
+ .ee-dark-mode .ee-compose-chip-remove:hover {
2411
+ background: #333;
2412
+ }
2413
+
2414
+ .ee-dark-mode .ee-compose-chip {
2415
+ background: #2a2a2a;
2416
+ border-color: #444;
2417
+ }
2418
+
2419
+ .ee-dark-mode .ee-compose-chip-size,
2420
+ .ee-dark-mode .ee-compose-chip-remove,
2421
+ .ee-dark-mode .ee-compose-quote-label {
2422
+ color: #999;
2423
+ }
2424
+
2425
+ .ee-dark-mode .ee-compose-quote-frame {
2426
+ background: #1a1a1a;
2427
+ border-color: #444;
2428
+ }
1779
2429
  `);
1780
2430
  document.head.appendChild(style);
1781
2431
  this._styleElement = style;
@@ -1904,7 +2554,7 @@ export class EmailEngineClient {
1904
2554
  folderTree.querySelectorAll('.ee-folder-item').forEach(item => {
1905
2555
  item.addEventListener('click', () => {
1906
2556
  const path = item.getAttribute('data-path');
1907
- this._fireAndForget(this.loadMessages(path));
2557
+ this._fireAndForget(this.openFolder(path));
1908
2558
  });
1909
2559
  });
1910
2560
  }
@@ -1920,41 +2570,39 @@ export class EmailEngineClient {
1920
2570
  }
1921
2571
 
1922
2572
  if (!this.messages.length) {
1923
- messageList.innerHTML = `
1924
- <div class="ee-pane-header">
1925
- <span class="ee-pane-title">Messages</span>
1926
- </div>
1927
- <div class="ee-empty-state">No messages</div>
1928
- `;
2573
+ messageList.innerHTML = `${this._messageListHeader(this.currentFolder)}<div class="ee-empty-state">No messages</div>`;
1929
2574
  return;
1930
2575
  }
1931
2576
 
1932
2577
  const hasPagination = this.nextPageCursor || this.prevPageCursor;
1933
2578
 
1934
- const html = `
1935
- <div class="ee-pane-header">
1936
- <span class="ee-pane-title">Messages</span>
2579
+ // Both arrows stay in place once there is more than one page, the unavailable
2580
+ // one disabled, so the controls do not shift under the pointer between pages
2581
+ const controls = `
1937
2582
  <div class="ee-pagination-controls">
1938
2583
  ${
1939
2584
  hasPagination
1940
2585
  ? `
1941
- ${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
1942
- ${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
2586
+ ${this._iconButton('prev-page', 'back', 'Previous page', '', !this.prevPageCursor)}
2587
+ ${this._iconButton('next-page', 'next', 'Next page', '', !this.nextPageCursor)}
1943
2588
  `
1944
2589
  : ''
1945
2590
  }
1946
- <div class="ee-page-size-selector">
1947
- <span class="ee-page-size-label">Show:</span>
1948
- <select class="ee-page-size-select" data-action="page-size">
2591
+ <label class="ee-page-size-selector" title="Messages per page">
2592
+ <span class="ee-page-size-label">Show</span>
2593
+ <select class="ee-button ee-page-size-select" data-action="page-size">
1949
2594
  <option value="10" ${this.pageSize === 10 ? 'selected' : ''}>10</option>
1950
2595
  <option value="20" ${this.pageSize === 20 ? 'selected' : ''}>20</option>
1951
2596
  <option value="30" ${this.pageSize === 30 ? 'selected' : ''}>30</option>
1952
2597
  <option value="50" ${this.pageSize === 50 ? 'selected' : ''}>50</option>
1953
2598
  <option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100</option>
1954
2599
  </select>
1955
- </div>
2600
+ </label>
1956
2601
  </div>
1957
- </div>
2602
+ `;
2603
+
2604
+ const html = `
2605
+ ${this._messageListHeader(this.currentFolder, controls)}
1958
2606
  <div class="ee-message-items">
1959
2607
  ${this.messages
1960
2608
  .map(
@@ -1965,8 +2613,9 @@ export class EmailEngineClient {
1965
2613
  <span class="ee-message-date">${this.formatDate(msg.date)}</span>
1966
2614
  </div>
1967
2615
  <div class="ee-message-subject">
2616
+ ${this._responseMarkers(msg)}
1968
2617
  <span class="ee-message-subject-text">${this.escapeHtml(msg.subject || '(no subject)')}</span>
1969
- ${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator">${msg.attachments.length}</span>` : ''}
2618
+ ${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator" title="Attachments">${icon('paperclip', 12)}${msg.attachments.length}</span>` : ''}
1970
2619
  </div>
1971
2620
  <div class="ee-message-preview">${this.escapeHtml(msg.intro || '')}</div>
1972
2621
  </div>
@@ -2020,57 +2669,74 @@ export class EmailEngineClient {
2020
2669
  }
2021
2670
 
2022
2671
  if (!this.currentMessage) {
2023
- viewer.innerHTML = '<div class="ee-empty-state">Select a message to view</div>';
2672
+ viewer.innerHTML = this._messageViewerPlaceholder();
2673
+ // Nothing left to show in the single-pane layout (the message was deleted
2674
+ // or moved), so return to the list it came from
2675
+ if (this._getView() === 'message') {
2676
+ this._setView('list');
2677
+ }
2024
2678
  return;
2025
2679
  }
2026
2680
 
2027
2681
  const msg = this.currentMessage;
2028
2682
  const isUnseen = msg.unseen;
2029
2683
  const isDraft = this._isDraftMessage(msg);
2684
+ // Labels drop to icons when the viewer is narrow (see the ee-viewer container
2685
+ // query); aria-label and title carry the full name either way. The move control
2686
+ // is a native select laid invisibly over a button so it looks like the rest of
2687
+ // the toolbar while keeping the platform's own folder picker.
2688
+ const respond = isDraft
2689
+ ? ''
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')}`;
2693
+ const actions = `
2694
+ ${isDraft ? this._toolbarButton('send-draft', 'send', 'Send draft', 'Send this draft now', 'ee-button-primary ee-keep-label') : respond}
2695
+ ${this._toolbarButton('toggle-read', isUnseen ? 'mailOpen' : 'mail', isUnseen ? 'Mark read' : 'Mark unread', isUnseen ? 'Mark as read' : 'Mark as unread')}
2696
+ <span class="ee-button ee-move-button" title="Move to folder">
2697
+ ${icon('move')}<span class="ee-button-label">Move</span>${icon('chevronDown', 12)}
2698
+ <select class="ee-move-select" data-action="move" aria-label="Move to folder">
2699
+ <option value="">Move to...</option>
2700
+ ${this.buildFolderTree()
2701
+ .map(({ folder, depth }) => {
2702
+ const indent = ' '.repeat(depth);
2703
+ const prefix = depth > 0 ? '└ ' : '';
2704
+ return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
2705
+ })
2706
+ .join('')}
2707
+ </select>
2708
+ </span>
2709
+ ${this._toolbarButton('delete', 'trash', 'Delete', 'Delete', 'ee-button-danger')}
2710
+ <span class="ee-toolbar-spacer"></span>
2711
+ ${this._toolbarButton('download-original', 'download', 'Download', 'Download the original message (.eml)')}
2712
+ `;
2030
2713
  const html = `
2031
- <div class="ee-message-actions">
2032
- ${isDraft ? '<button class="ee-button" data-action="send-draft">Send Draft</button>' : ''}
2033
- <button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
2034
- <button class="ee-button" data-action="delete">Delete</button>
2035
- <button class="ee-button" data-action="download-original">Download Original</button>
2036
- <select class="ee-button" data-action="move">
2037
- <option value="">Move to...</option>
2038
- ${this.buildFolderTree()
2039
- .map(({ folder, depth }) => {
2040
- const indent = ' '.repeat(depth);
2041
- const prefix = depth > 0 ? '└ ' : '';
2042
- return `<option value="${this.escapeHtml(folder.path)}" ${folder.path === this.currentFolder ? 'disabled' : ''}>${indent}${prefix}${this.escapeHtml(folder.name)}</option>`;
2043
- })
2044
- .join('')}
2045
- </select>
2046
- </div>
2714
+ ${this._messageToolbar(actions)}
2047
2715
  <div class="ee-message-content">
2716
+ <h2 class="ee-message-title">${this.escapeHtml(msg.subject || '(no subject)')}</h2>
2717
+ <div class="ee-message-title-markers">${this._responseMarkers(msg, true)}</div>
2048
2718
  <div class="ee-message-meta">
2049
2719
  <div class="ee-message-meta-row">
2050
- <span class="ee-message-meta-label">From:</span>
2051
- ${msg.from ? `${this.escapeHtml(msg.from.name || '')} &lt;${this.escapeHtml(msg.from.address)}&gt;` : 'Unknown'}
2720
+ <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>
2052
2722
  </div>
2053
2723
  <div class="ee-message-meta-row">
2054
- <span class="ee-message-meta-label">To:</span>
2055
- ${msg.to ? msg.to.map(t => `${this.escapeHtml(t.name || '')} &lt;${this.escapeHtml(t.address)}&gt;`).join(', ') : ''}
2724
+ <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>
2056
2726
  </div>
2057
2727
  ${
2058
2728
  msg.cc && msg.cc.length
2059
2729
  ? `
2060
2730
  <div class="ee-message-meta-row">
2061
- <span class="ee-message-meta-label">Cc:</span>
2062
- ${msg.cc.map(c => `${this.escapeHtml(c.name || '')} &lt;${this.escapeHtml(c.address)}&gt;`).join(', ')}
2731
+ <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>
2063
2733
  </div>
2064
2734
  `
2065
2735
  : ''
2066
2736
  }
2067
2737
  <div class="ee-message-meta-row">
2068
- <span class="ee-message-meta-label">Date:</span>
2069
- ${new Date(msg.date).toLocaleString()}
2070
- </div>
2071
- <div class="ee-message-meta-row">
2072
- <span class="ee-message-meta-label">Subject:</span>
2073
- ${this.escapeHtml(msg.subject || '(no subject)')}
2738
+ <span class="ee-message-meta-label">Date</span>
2739
+ <span class="ee-message-meta-value">${this.escapeHtml(new Date(msg.date).toLocaleString())}</span>
2074
2740
  </div>
2075
2741
  </div>
2076
2742
  ${this.renderOtpBox(msg.otp)}
@@ -2084,7 +2750,7 @@ export class EmailEngineClient {
2084
2750
  .map(
2085
2751
  att => `
2086
2752
  <div class="ee-attachment-item" data-attachment-id="${this.escapeHtml(att.id)}">
2087
- <div class="ee-attachment-icon">📎</div>
2753
+ <div class="ee-attachment-icon">${icon('paperclip', 18)}</div>
2088
2754
  <div class="ee-attachment-info">
2089
2755
  <div class="ee-attachment-name">${this.escapeHtml(att.filename || 'Unnamed attachment')}</div>
2090
2756
  ${att.size ? `<div class="ee-attachment-size">${this.formatFileSize(att.size)}</div>` : ''}
@@ -2117,9 +2783,11 @@ export class EmailEngineClient {
2117
2783
  return;
2118
2784
  }
2119
2785
 
2120
- const originalText = sendDraftButton.textContent;
2786
+ // Only the label changes, the icon stays
2787
+ const label = sendDraftButton.querySelector('.ee-button-label');
2788
+ const originalText = label.textContent;
2121
2789
  sendDraftButton.disabled = true;
2122
- sendDraftButton.textContent = 'Sending...';
2790
+ label.textContent = 'Sending...';
2123
2791
 
2124
2792
  try {
2125
2793
  await this.submitDraft(msg.id);
@@ -2127,18 +2795,24 @@ export class EmailEngineClient {
2127
2795
  // Refresh the folder view - the provider removes the draft once it is sent,
2128
2796
  // immediately for Gmail and MS Graph, after SMTP delivery for IMAP accounts.
2129
2797
  if (!this._destroyed && this.currentFolder) {
2130
- await this.loadMessages(this.currentFolder);
2798
+ await this.openFolder(this.currentFolder);
2131
2799
  }
2132
2800
  } catch (error) {
2133
2801
  console.error('Failed to send draft:', error);
2134
2802
  const errorMessage = this._formatSendError(error);
2135
2803
  await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
2136
2804
  sendDraftButton.disabled = false;
2137
- sendDraftButton.textContent = originalText;
2805
+ label.textContent = originalText;
2138
2806
  }
2139
2807
  });
2140
2808
  }
2141
2809
 
2810
+ viewer.querySelectorAll('[data-action="reply"], [data-action="reply-all"], [data-action="forward"]').forEach(button => {
2811
+ button.addEventListener('click', () => {
2812
+ this._respond(msg.id, button.dataset.action).catch(error => this._alertActionFailed(error, 'Failed to open the compose form'));
2813
+ });
2814
+ });
2815
+
2142
2816
  viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
2143
2817
  const currentlyUnseen = msg.unseen;
2144
2818
  this.markAsRead(msg.id, currentlyUnseen).catch(error => this._alertActionFailed(error, 'Failed to update the message flags'));
@@ -2199,6 +2873,37 @@ export class EmailEngineClient {
2199
2873
  // Message content scrolling is now handled in loadMessage method
2200
2874
  }
2201
2875
 
2876
+ // Replied / forwarded markers from the flags the server sets on the original once a reply or
2877
+ // forward has been delivered (IMAP accounts; Gmail API and MS Graph report neither flag).
2878
+ // labelled shows the words next to the icons, otherwise they are the accessible name only.
2879
+ //
2880
+ // EmailEngine adds \Answered to a forwarded message as well as $Forwarded, so one marker is
2881
+ // shown: Forwarded when that flag is set, Replied otherwise.
2882
+ _responseMarkers(msg, labelled = false) {
2883
+ const flags = Array.isArray(msg.flags) ? msg.flags : [];
2884
+ const marker = flags.includes('$Forwarded')
2885
+ ? { icon: 'forward', label: 'Forwarded' }
2886
+ : flags.includes('\\Answered')
2887
+ ? { icon: 'reply', label: 'Replied' }
2888
+ : null;
2889
+ if (!marker) {
2890
+ return '';
2891
+ }
2892
+ return labelled
2893
+ ? `<span class="ee-response-marker">${icon(marker.icon, 12)}<span>${marker.label}</span></span>`
2894
+ : `<span class="ee-response-marker" role="img" aria-label="${marker.label}" title="${marker.label}">${icon(marker.icon, 12)}</span>`;
2895
+ }
2896
+
2897
+ // An icon-only button. Static arguments only, never message data.
2898
+ _iconButton(action, iconName, label, extraClass = '', disabled = false) {
2899
+ return `<button type="button" class="ee-button ee-icon-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${label}"${disabled ? ' disabled' : ''}>${icon(iconName)}</button>`;
2900
+ }
2901
+
2902
+ // A message toolbar button. Static arguments only, never message data.
2903
+ _toolbarButton(action, iconName, label, title, extraClass = '') {
2904
+ return `<button type="button" class="ee-button ${extraClass}" data-action="${action}" aria-label="${label}" title="${title}">${icon(iconName)}<span class="ee-button-label">${label}</span></button>`;
2905
+ }
2906
+
2202
2907
  // The message body goes into a shadow root on its container. Sanitised message HTML still
2203
2908
  // carries class and id attributes, and in the host document those would pick up the host's
2204
2909
  // own stylesheet (a utility class like "fixed inset-0" could cover the whole page) or collide
@@ -2248,44 +2953,68 @@ export class EmailEngineClient {
2248
2953
  }
2249
2954
 
2250
2955
  this.container.innerHTML = `
2251
- <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}">
2252
- ${
2253
- this.showDarkModeToggle
2254
- ? `<button class="ee-dark-mode-toggle" title="Toggle dark mode">
2255
- <span class="ee-dark-mode-icon">${this.darkMode ? '☀️' : '🌙'}</span>
2256
- </button>`
2257
- : ''
2258
- }
2956
+ <div class="ee-client${this.darkMode ? ' ee-dark-mode' : ''}" data-view="list">
2259
2957
  <div class="ee-sidebar">
2260
2958
  <div class="ee-pane-header">
2261
2959
  <span class="ee-pane-title">Folders</span>
2960
+ ${
2961
+ this.showDarkModeToggle
2962
+ ? `<button type="button" class="ee-dark-mode-toggle" title="Toggle dark mode" aria-label="Toggle dark mode">
2963
+ <span class="ee-dark-mode-icon">${icon(this.darkMode ? 'sun' : 'moon', 14)}</span>
2964
+ </button>`
2965
+ : ''
2966
+ }
2262
2967
  </div>
2263
2968
  <div class="ee-folder-tree"></div>
2264
2969
  </div>
2265
2970
  <div class="ee-message-list">${this._messageListPlaceholder()}</div>
2266
- <div class="ee-message-viewer">
2267
- <div class="ee-empty-state">Select a message to view</div>
2268
- </div>
2971
+ <div class="ee-message-viewer">${this._messageViewerPlaceholder()}</div>
2269
2972
  </div>
2270
- <button class="ee-compose-button" title="Compose Email">✉</button>
2271
- <div class="ee-compose-modal">
2272
- <div class="ee-compose-dialog">
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>
2974
+ <div class="ee-compose-modal${this.darkMode ? ' ee-dark-mode' : ''}">
2975
+ <div class="ee-compose-dialog" role="dialog" aria-modal="true" aria-label="Compose">
2273
2976
  <div class="ee-compose-header">
2274
- <h3 class="ee-compose-title">Compose Email</h3>
2275
- <button class="ee-compose-close">×</button>
2977
+ <h3 class="ee-compose-title">${COMPOSE_TITLES.new}</h3>
2978
+ <button type="button" class="ee-compose-close" aria-label="Close" title="Close">${icon('close', 18)}</button>
2276
2979
  </div>
2277
2980
  <form class="ee-compose-form">
2278
2981
  <div class="ee-compose-field">
2279
- <label class="ee-compose-label">To:</label>
2280
- <input type="email" class="ee-compose-input" name="to" placeholder="recipient@example.com" required>
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">
2987
+ </div>
2988
+ <div class="ee-compose-field" data-field="cc" hidden>
2989
+ <label class="ee-compose-label" for="${this._composeId('cc')}">Cc:</label>
2990
+ <input type="text" class="ee-compose-input" id="${this._composeId('cc')}" name="cc" autocomplete="off" spellcheck="false">
2991
+ </div>
2992
+ <div class="ee-compose-field" data-field="bcc" hidden>
2993
+ <label class="ee-compose-label" for="${this._composeId('bcc')}">Bcc:</label>
2994
+ <input type="text" class="ee-compose-input" id="${this._composeId('bcc')}" name="bcc" autocomplete="off" spellcheck="false">
2281
2995
  </div>
2282
2996
  <div class="ee-compose-field">
2283
- <label class="ee-compose-label">Subject:</label>
2284
- <input type="text" class="ee-compose-input" name="subject" placeholder="Enter subject">
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">
2285
2999
  </div>
2286
3000
  <div class="ee-compose-field">
2287
- <label class="ee-compose-label">Message:</label>
2288
- <textarea class="ee-compose-textarea" name="message" placeholder="Type your message here..." required></textarea>
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>
3003
+ </div>
3004
+ <div class="ee-compose-files">
3005
+ <div class="ee-compose-chips"></div>
3006
+ <div class="ee-compose-files-row">
3007
+ <button type="button" class="ee-compose-attach" data-action="attach">${icon('paperclip', 14)}<span>Attach files</span></button>
3008
+ <input type="file" class="ee-compose-file-input" multiple hidden>
3009
+ <label class="ee-compose-forward-attachments" hidden>
3010
+ <input type="checkbox" name="forwardAttachments" checked>
3011
+ <span class="ee-compose-forward-attachments-label"></span>
3012
+ </label>
3013
+ </div>
3014
+ </div>
3015
+ <div class="ee-compose-quote" hidden>
3016
+ <div class="ee-compose-quote-label"></div>
3017
+ <div class="ee-compose-quote-frame"></div>
2289
3018
  </div>
2290
3019
  </form>
2291
3020
  <div class="ee-compose-actions">
@@ -2297,6 +3026,15 @@ export class EmailEngineClient {
2297
3026
  </div>
2298
3027
  `;
2299
3028
 
3029
+ // Pane navigation in the single-pane layout, delegated because the panes
3030
+ // re-render their headers on every load
3031
+ this.container.querySelector('.ee-client').addEventListener('click', e => {
3032
+ const nav = e.target.closest('[data-action="show-folders"], [data-action="back-to-list"]');
3033
+ if (nav) {
3034
+ this._setView(nav.dataset.action === 'show-folders' ? 'folders' : 'list');
3035
+ }
3036
+ });
3037
+
2300
3038
  // Wire up compose modal events
2301
3039
  this.setupComposeModal();
2302
3040
 
@@ -2304,142 +3042,366 @@ export class EmailEngineClient {
2304
3042
  this.positionComposeButton();
2305
3043
  }
2306
3044
 
3045
+ // Unique element ids for the compose form labels, so two clients on one page do not share them
3046
+ _composeId(field) {
3047
+ if (!this._composeIdPrefix) {
3048
+ EmailEngineClient._composeCounter = (EmailEngineClient._composeCounter || 0) + 1;
3049
+ this._composeIdPrefix = `ee-compose-${EmailEngineClient._composeCounter}`;
3050
+ }
3051
+ return `${this._composeIdPrefix}-${field}`;
3052
+ }
3053
+
3054
+ // Opens a blank compose form, optionally prefilled: { to, cc, bcc, subject, text }. The
3055
+ // address fields take a string or address entries.
3056
+ compose(prefill = {}) {
3057
+ this._openCompose({ mode: 'new', ...prefill });
3058
+ }
3059
+
3060
+ // Opens the compose form as a reply to a message (the open one when messageId is omitted)
3061
+ reply(messageId = null, { all = false } = {}) {
3062
+ return this._respond(messageId, all ? 'reply-all' : 'reply');
3063
+ }
3064
+
3065
+ // Opens the compose form to forward a message (the open one when messageId is omitted)
3066
+ forward(messageId = null) {
3067
+ return this._respond(messageId, 'forward');
3068
+ }
3069
+
3070
+ async _respond(messageId, action) {
3071
+ const id = messageId || (this.currentMessage && this.currentMessage.id);
3072
+ if (!id) {
3073
+ throw new Error('No message to respond to');
3074
+ }
3075
+
3076
+ const [msg, ownAddress] = await Promise.all([
3077
+ this.currentMessage && this.currentMessage.id === id ? this.currentMessage : this.apiRequest('GET', this._messagePath(id, '?webSafeHtml=true')),
3078
+ // Without it the account's own address may stay among the reply-all recipients
3079
+ this._getAccountInfo().then(
3080
+ info => info && info.email,
3081
+ () => null
3082
+ )
3083
+ ]);
3084
+
3085
+ this._openCompose({ mode: action, original: msg, ...this.prepareResponse(msg, action, ownAddress) });
3086
+ }
3087
+
3088
+ _openCompose({ mode = 'new', to, cc, bcc, subject, text, reference = null, original = null } = {}) {
3089
+ const els = this._compose && this._compose.els;
3090
+ if (!els) {
3091
+ throw new Error('The compose form needs the client UI (a container)');
3092
+ }
3093
+ this._resetCompose();
3094
+ this._compose.reference = reference;
3095
+
3096
+ const asField = value => (typeof value === 'string' ? value : this.formatAddressList(value));
3097
+ const { form } = els;
3098
+ form.elements.to.value = asField(to);
3099
+ form.elements.cc.value = asField(cc);
3100
+ form.elements.bcc.value = asField(bcc);
3101
+ form.elements.subject.value = subject || '';
3102
+ form.elements.message.value = text || '';
3103
+ this._showCopyFields({ cc: !!form.elements.cc.value, bcc: !!form.elements.bcc.value });
3104
+
3105
+ els.title.textContent = COMPOSE_TITLES[mode] || COMPOSE_TITLES.new;
3106
+
3107
+ // The server carries the original's attachments over on request (all or none)
3108
+ const originalAttachments = original && mode === 'forward' ? (original.attachments || []).filter(att => !att.inline && !att.embedded) : [];
3109
+ els.forwardAttachments.hidden = !originalAttachments.length;
3110
+ els.forwardAttachments.querySelector('.ee-compose-forward-attachments-label').textContent =
3111
+ `Include the original attachments (${originalAttachments.length})`;
3112
+
3113
+ if (original && reference && reference.inline) {
3114
+ this._renderComposeQuote(original, mode);
3115
+ }
3116
+
3117
+ els.modal.classList.add('show');
3118
+ const focusTarget = form.elements.to.value ? form.elements.message : form.elements.to;
3119
+ setTimeout(() => {
3120
+ focusTarget.focus();
3121
+ if (focusTarget === form.elements.message) {
3122
+ focusTarget.setSelectionRange(0, 0);
3123
+ }
3124
+ }, 100);
3125
+ }
3126
+
3127
+ // A read-only copy of the message being answered, under the textarea. The quote that is sent
3128
+ // is built by the server from the stored original; this shows what it will contain.
3129
+ _renderComposeQuote(original, mode) {
3130
+ const { quote } = this._compose.els;
3131
+ const from = addressEntries(original.from)[0];
3132
+ const sender = from ? from.name || from.address : 'the sender';
3133
+ quote.querySelector('.ee-compose-quote-label').textContent =
3134
+ mode === 'forward' ? 'The forwarded message is added below your text:' : `${sender}'s message is quoted below your reply:`;
3135
+ // A shadow root cannot be attached twice, so each quote gets a fresh host
3136
+ const host = document.createElement('div');
3137
+ quote.querySelector('.ee-compose-quote-frame').replaceChildren(host);
3138
+ this._labelCollapsedThreads(this._renderMessageBody(host, original));
3139
+ quote.hidden = false;
3140
+ }
3141
+
3142
+ // Shows the Cc and Bcc fields named true and hides the rest; the link offers whichever is hidden
3143
+ _showCopyFields(show) {
3144
+ const { form } = this._compose.els;
3145
+ const hidden = [];
3146
+ for (const key of ['cc', 'bcc']) {
3147
+ form.querySelector(`[data-field="${key}"]`).hidden = !show[key];
3148
+ if (!show[key]) {
3149
+ hidden.push(key === 'cc' ? 'Cc' : 'Bcc');
3150
+ }
3151
+ }
3152
+ const link = form.querySelector('[data-action="show-cc"]');
3153
+ link.hidden = !hidden.length;
3154
+ link.textContent = hidden.join(' / ');
3155
+ }
3156
+
3157
+ // Empties the form and starts a new compose state; the element references are kept
3158
+ _resetCompose() {
3159
+ const { els } = this._compose;
3160
+ els.form.reset();
3161
+ els.chips.replaceChildren();
3162
+ els.fileInput.value = '';
3163
+ els.forwardAttachments.hidden = true;
3164
+ els.quote.hidden = true;
3165
+ els.quote.querySelector('.ee-compose-quote-frame').replaceChildren();
3166
+ this._compose = { els, reference: null, files: [] };
3167
+ this._showCopyFields({ cc: false, bcc: false });
3168
+ }
3169
+
3170
+ _closeCompose() {
3171
+ if (this._compose && this._compose.els) {
3172
+ this._compose.els.modal.classList.remove('show');
3173
+ this._resetCompose();
3174
+ }
3175
+ }
3176
+
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);
3190
+ }
3191
+ }
3192
+
3193
+ _renderComposeChips() {
3194
+ this._compose.els.chips.innerHTML = this._compose.files
3195
+ .map(
3196
+ (file, index) => `
3197
+ <span class="ee-compose-chip">
3198
+ ${icon('paperclip', 12)}
3199
+ <span class="ee-compose-chip-name">${this.escapeHtml(file.name)}</span>
3200
+ <span class="ee-compose-chip-size">${this.formatFileSize(file.size)}</span>
3201
+ <button type="button" class="ee-compose-chip-remove" data-index="${index}" aria-label="Remove ${this.escapeHtml(file.name)}" title="Remove">${icon('close', 12)}</button>
3202
+ </span>`
3203
+ )
3204
+ .join('');
3205
+ }
3206
+
3207
+ _readFileAsBase64(file) {
3208
+ return new Promise((resolve, reject) => {
3209
+ const reader = new FileReader();
3210
+ reader.onload = () => {
3211
+ const result = String(reader.result || '');
3212
+ resolve(result.slice(result.indexOf(',') + 1));
3213
+ };
3214
+ reader.onerror = () => reject(reader.error || new Error(`Could not read ${file.name}`));
3215
+ reader.readAsDataURL(file);
3216
+ });
3217
+ }
3218
+
3219
+ // Takes picked files into the form within the size limit. They are kept as File objects and
3220
+ // read only when the message is sent, so a removed file is never read at all.
3221
+ async _addComposeFiles(files) {
3222
+ let total = this._compose.files.reduce((sum, file) => sum + file.size, 0);
3223
+ const skipped = [];
3224
+ for (const file of files) {
3225
+ if (total + file.size > this.maxAttachmentSize) {
3226
+ skipped.push(file.name);
3227
+ continue;
3228
+ }
3229
+ total += file.size;
3230
+ this._compose.files.push(file);
3231
+ }
3232
+ this._renderComposeChips();
3233
+ 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
+ );
3238
+ }
3239
+ }
3240
+
3241
+ _readComposeAttachments(files) {
3242
+ return Promise.all(
3243
+ files.map(async file => ({
3244
+ filename: file.name,
3245
+ contentType: file.type || 'application/octet-stream',
3246
+ content: await this._readFileAsBase64(file)
3247
+ }))
3248
+ );
3249
+ }
3250
+
3251
+ // The form as a submission: parsed recipients, the text, the reference and the picked files,
3252
+ // plus the first reason it cannot go out as asked (null when it can). requireMessage applies
3253
+ // the send rules: a recipient, and some text unless the message is a forward.
3254
+ _readComposeForm(requireMessage) {
3255
+ const { form } = this._compose.els;
3256
+ const fields = {};
3257
+ const invalid = [];
3258
+ for (const key of ['to', 'cc', 'bcc']) {
3259
+ fields[key] = this.parseAddressList(form.elements[key].value);
3260
+ invalid.push(...fields[key].filter(entry => !ADDRESS_PATTERN.test(entry.address)).map(entry => entry.address || entry.name));
3261
+ }
3262
+
3263
+ let reference = this._compose.reference;
3264
+ const isForward = !!reference && reference.action === 'forward';
3265
+ if (isForward) {
3266
+ reference = { ...reference, forwardAttachments: form.elements.forwardAttachments.checked };
3267
+ }
3268
+
3269
+ const draft = {
3270
+ to: fields.to,
3271
+ subject: form.elements.subject.value.trim(),
3272
+ text: form.elements.message.value,
3273
+ files: this._compose.files,
3274
+ options: { cc: fields.cc, bcc: fields.bcc, reference }
3275
+ };
3276
+
3277
+ const empty = !fields.to.length && !fields.cc.length && !fields.bcc.length && !draft.subject && !draft.text.trim() && !draft.files.length && !reference;
3278
+ if (requireMessage && !fields.to.length) {
3279
+ draft.problem = { message: 'Add at least one recipient.', field: 'to' };
3280
+ } else if (!requireMessage && empty) {
3281
+ draft.problem = { message: 'Nothing to save - fill in at least one field first.', field: 'to' };
3282
+ } else if (invalid.length) {
3283
+ draft.problem = { message: `Not a valid email address: ${invalid.join(', ')}`, field: 'to' };
3284
+ } else if (requireMessage && !draft.text.trim() && !isForward) {
3285
+ // A forward can go without a note of its own; anything else needs some text
3286
+ draft.problem = { message: 'Write a message before sending.', field: 'message' };
3287
+ }
3288
+ return draft;
3289
+ }
3290
+
3291
+ // Runs a compose request with its button showing progress. The form is checked first, the
3292
+ // picked files are read, and on success the form closes and the result is returned; on any
3293
+ // failure the reason is shown over the form, kept as it was, and the result is null.
3294
+ async _runComposeAction(button, busyText, errorTitle, requireMessage, submit) {
3295
+ const draft = this._readComposeForm(requireMessage);
3296
+ if (draft.problem) {
3297
+ await this._composeAlert(draft.problem.message, 'Validation Error', draft.problem.field);
3298
+ return null;
3299
+ }
3300
+
3301
+ const originalText = button.textContent;
3302
+ button.disabled = true;
3303
+ button.textContent = busyText;
3304
+ try {
3305
+ const attachments = await this._readComposeAttachments(draft.files);
3306
+ const result = await submit(draft.to, draft.subject, draft.text, { ...draft.options, attachments });
3307
+ this._closeCompose();
3308
+ return result || {};
3309
+ } catch (error) {
3310
+ console.error(`${errorTitle}:`, error);
3311
+ await this._composeAlert(this._formatSendError(error), errorTitle, 'to');
3312
+ return null;
3313
+ } finally {
3314
+ button.disabled = false;
3315
+ button.textContent = originalText;
3316
+ }
3317
+ }
3318
+
2307
3319
  setupComposeModal() {
2308
3320
  if (typeof document === 'undefined' || !this.container) {
2309
3321
  return;
2310
3322
  }
2311
3323
 
2312
- const composeButton = this.container.querySelector('.ee-compose-button');
2313
3324
  const modal = this.container.querySelector('.ee-compose-modal');
2314
- const closeButton = this.container.querySelector('.ee-compose-close');
2315
- const cancelButton = this.container.querySelector('.ee-compose-cancel');
2316
- const saveDraftButton = this.container.querySelector('.ee-compose-save-draft');
2317
- const sendButton = this.container.querySelector('.ee-compose-send');
2318
- const form = this.container.querySelector('.ee-compose-form');
2319
-
2320
- // Open modal
2321
- composeButton.addEventListener('click', () => {
2322
- modal.classList.add('show');
2323
- // Focus the To field
2324
- const toField = form.querySelector('input[name="to"]');
2325
- setTimeout(() => toField.focus(), 100);
2326
- });
2327
-
2328
- // Close modal handlers
2329
- const closeModal = () => {
2330
- modal.classList.remove('show');
2331
- form.reset();
3325
+ const els = {
3326
+ modal,
3327
+ form: modal.querySelector('.ee-compose-form'),
3328
+ title: modal.querySelector('.ee-compose-title'),
3329
+ chips: modal.querySelector('.ee-compose-chips'),
3330
+ fileInput: modal.querySelector('.ee-compose-file-input'),
3331
+ forwardAttachments: modal.querySelector('.ee-compose-forward-attachments'),
3332
+ quote: modal.querySelector('.ee-compose-quote')
2332
3333
  };
3334
+ const { form, fileInput, chips } = els;
3335
+ this._compose = { els, reference: null, files: [] };
3336
+
3337
+ this.container.querySelector('.ee-compose-button').addEventListener('click', () => this.compose());
2333
3338
 
2334
- closeButton.addEventListener('click', closeModal);
2335
- cancelButton.addEventListener('click', closeModal);
3339
+ const closeCompose = () => this._closeCompose();
3340
+ modal.querySelector('.ee-compose-close').addEventListener('click', closeCompose);
3341
+ modal.querySelector('.ee-compose-cancel').addEventListener('click', closeCompose);
2336
3342
 
2337
3343
  // Close on backdrop click
2338
3344
  modal.addEventListener('click', e => {
2339
3345
  if (e.target === modal) {
2340
- closeModal();
3346
+ closeCompose();
2341
3347
  }
2342
3348
  });
2343
3349
 
2344
3350
  // Close on Escape key
2345
3351
  this._composeKeydownHandler = e => {
2346
3352
  if (e.key === 'Escape' && modal.classList.contains('show')) {
2347
- closeModal();
3353
+ closeCompose();
2348
3354
  }
2349
3355
  };
2350
3356
  document.addEventListener('keydown', this._composeKeydownHandler);
2351
3357
 
3358
+ form.querySelector('[data-action="show-cc"]').addEventListener('click', () => {
3359
+ const ccShown = !form.querySelector('[data-field="cc"]').hidden;
3360
+ this._showCopyFields({ cc: true, bcc: true });
3361
+ (ccShown ? form.elements.bcc : form.elements.cc).focus();
3362
+ });
3363
+
3364
+ form.querySelector('[data-action="attach"]').addEventListener('click', () => fileInput.click());
3365
+ fileInput.addEventListener('change', () => {
3366
+ const files = Array.from(fileInput.files || []);
3367
+ fileInput.value = '';
3368
+ this._fireAndForget(this._addComposeFiles(files));
3369
+ });
3370
+ chips.addEventListener('click', e => {
3371
+ const remove = e.target.closest('.ee-compose-chip-remove');
3372
+ if (remove) {
3373
+ this._compose.files.splice(Number(remove.dataset.index), 1);
3374
+ this._renderComposeChips();
3375
+ }
3376
+ });
3377
+
2352
3378
  // Save the composed message as a draft instead of sending it
3379
+ const saveDraftButton = modal.querySelector('.ee-compose-save-draft');
2353
3380
  saveDraftButton.addEventListener('click', async () => {
2354
- const formData = new FormData(form);
2355
- const to = formData.get('to').trim();
2356
- const subject = formData.get('subject').trim();
2357
- const message = formData.get('message').trim();
2358
-
2359
- if (!to && !subject && !message) {
2360
- modal.classList.remove('show');
2361
- await this.alertMethod('Nothing to save - fill in at least one field first.', 'Validation Error', null, 'OK');
2362
- modal.classList.add('show');
2363
- setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
3381
+ const response = await this._runComposeAction(saveDraftButton, 'Saving...', 'Save Error', false, (...args) => this.saveDraft(...args));
3382
+ if (!response) {
2364
3383
  return;
2365
3384
  }
2366
-
2367
- const originalText = saveDraftButton.textContent;
2368
- saveDraftButton.disabled = true;
2369
- saveDraftButton.textContent = 'Saving...';
2370
-
2371
- try {
2372
- const response = await this.saveDraft(to || null, subject, message);
2373
- closeModal();
2374
- await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
2375
- // Refresh the list when the user is looking at the Drafts folder
2376
- if (!this._destroyed && response && response.path && this.currentFolder === response.path) {
2377
- await this.loadMessages(this.currentFolder);
2378
- }
2379
- } catch (error) {
2380
- console.error('Failed to save draft:', error);
2381
- // Close modal before showing error alert, then reopen with preserved values
2382
- modal.classList.remove('show');
2383
- const errorMessage = this._formatSendError(error);
2384
- await this.alertMethod(errorMessage, 'Save Error', null, 'OK');
2385
- modal.classList.add('show');
2386
- setTimeout(() => form.querySelector('input[name="to"]').focus(), 100);
2387
- } finally {
2388
- saveDraftButton.disabled = false;
2389
- saveDraftButton.textContent = originalText;
3385
+ await this.alertMethod('Draft saved to the Drafts folder.', 'Success', null, 'OK');
3386
+ // Refresh the list when the user is looking at the Drafts folder
3387
+ if (!this._destroyed && response.path && this.currentFolder === response.path) {
3388
+ this._fireAndForget(this.loadMessages(this.currentFolder));
2390
3389
  }
2391
3390
  });
2392
3391
 
2393
3392
  // Send email
3393
+ const sendButton = modal.querySelector('.ee-compose-send');
2394
3394
  sendButton.addEventListener('click', async () => {
2395
- const formData = new FormData(form);
2396
- const to = formData.get('to').trim();
2397
- const subject = formData.get('subject').trim();
2398
- const message = formData.get('message').trim();
2399
-
2400
- if (!to || !message) {
2401
- // Close modal temporarily to show alert, then reopen
2402
- modal.classList.remove('show');
2403
- await this.alertMethod('Please fill in the recipient and message fields.', 'Validation Error', null, 'OK');
2404
- modal.classList.add('show');
2405
- // Re-focus the appropriate field
2406
- const fieldToFocus = !to ? form.querySelector('input[name="to"]') : form.querySelector('textarea[name="message"]');
2407
- setTimeout(() => fieldToFocus.focus(), 100);
2408
- return;
2409
- }
2410
-
2411
- // Disable send button and show loading state
2412
- const originalText = sendButton.textContent;
2413
- sendButton.disabled = true;
2414
- sendButton.textContent = 'Sending...';
2415
-
2416
- try {
2417
- await this.sendMessage(to, subject, message);
2418
- // Close modal before showing success alert
2419
- closeModal();
2420
- await this.alertMethod('Email sent successfully!', 'Success', null, 'OK');
2421
- } catch (error) {
2422
- console.error('Failed to send email:', error);
2423
- // Close modal before showing error alert
2424
- modal.classList.remove('show');
2425
- const errorMessage = this._formatSendError(error);
2426
- await this.alertMethod(errorMessage, 'Send Error', null, 'OK');
2427
-
2428
- // Reopen modal with preserved values after error alert
2429
- modal.classList.add('show');
2430
- // Re-focus the To field to allow user to continue editing
2431
- const toField = form.querySelector('input[name="to"]');
2432
- setTimeout(() => toField.focus(), 100);
2433
- } finally {
2434
- // Re-enable send button
2435
- sendButton.disabled = false;
2436
- sendButton.textContent = originalText;
3395
+ const response = await this._runComposeAction(sendButton, 'Sending...', 'Send Error', true, (...args) => this.sendMessage(...args));
3396
+ if (response) {
3397
+ // Submitting only queues the message; delivery happens afterwards and can still fail
3398
+ await this.alertMethod('Message queued for delivery.', 'Queued', null, 'OK');
2437
3399
  }
2438
3400
  });
2439
3401
 
2440
3402
  // Handle Enter key in form (Ctrl+Enter to send)
2441
3403
  form.addEventListener('keydown', e => {
2442
- if (e.key === 'Enter' && e.ctrlKey) {
3404
+ if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
2443
3405
  e.preventDefault();
2444
3406
  sendButton.click();
2445
3407
  }
@@ -2458,7 +3420,6 @@ export class EmailEngineClient {
2458
3420
 
2459
3421
  const updateButtonPosition = () => {
2460
3422
  const containerRect = this.container.getBoundingClientRect();
2461
- const buttonSize = 56; // Button width/height
2462
3423
  const margin = 20; // Desired margin from edges
2463
3424
 
2464
3425
  // A hidden container (display: none) reports a zero-size rect; positioning
@@ -2472,6 +3433,11 @@ export class EmailEngineClient {
2472
3433
  }
2473
3434
  composeButton.style.display = '';
2474
3435
 
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
+
2475
3441
  // Calculate the ideal position (bottom-right of container with margin)
2476
3442
  const idealBottom = window.innerHeight - containerRect.bottom + margin;
2477
3443
  const idealRight = window.innerWidth - containerRect.right + margin;
@@ -2564,6 +3530,13 @@ export class EmailEngineClient {
2564
3530
  // paint their own loading states from this point on.
2565
3531
  this._setPaneHtml('.ee-message-list', this._messageListPlaceholder());
2566
3532
 
3533
+ // A deep-linked message loads alongside the folders, not after them. Only the first load
3534
+ // follows the link: a Retry after a folder failure starts from the inbox as usual. A
3535
+ // message that fails has already put its error in the viewer.
3536
+ const messageId = this.initialMessage;
3537
+ this.initialMessage = null;
3538
+ const message = messageId ? this.loadMessage(messageId).catch(() => null) : Promise.resolve(null);
3539
+
2567
3540
  return this.loadFolders()
2568
3541
  .catch(error => {
2569
3542
  // loadFolders reports into the sidebar, but the message list is the
@@ -2572,21 +3545,39 @@ export class EmailEngineClient {
2572
3545
  this._renderPaneError('.ee-message-list', 'Folders unavailable', error, () => this._loadInitialView());
2573
3546
  throw error;
2574
3547
  })
2575
- .then(() => {
2576
- const inbox =
2577
- this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
2578
- this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
2579
- this.folders[0];
2580
- if (inbox) {
2581
- return this.loadMessages(inbox.path);
2582
- }
2583
- })
3548
+ .then(async () => this._listFolderOf(await message))
2584
3549
  .catch(error => {
2585
3550
  // Both loadFolders and loadMessages have already rendered a panel
2586
3551
  console.error('Failed to load the initial view:', error);
2587
3552
  });
2588
3553
  }
2589
3554
 
3555
+ _inboxFolder() {
3556
+ return (
3557
+ this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
3558
+ this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
3559
+ this.folders[0]
3560
+ );
3561
+ }
3562
+
3563
+ // Lists the folder holding a message, or the inbox when there is no message or it reports no
3564
+ // folder (Gmail API accounts) or one that is not listed
3565
+ _listFolderOf(message) {
3566
+ const folder = (message && message.path && this.folders.find(f => f.path === message.path)) || this._inboxFolder();
3567
+ if (folder && !this._destroyed) {
3568
+ return this.loadMessages(folder.path);
3569
+ }
3570
+ }
3571
+
3572
+ // Opens one message by its EmailEngine ID and lists the folder holding it. A message that
3573
+ // cannot be loaded leaves its error in the viewer and the inbox in the list, so the reader
3574
+ // still has somewhere to go.
3575
+ async openMessage(messageId) {
3576
+ const [message] = await Promise.all([this.loadMessage(messageId).catch(() => null), this.folders.length ? null : this.loadFolders()]);
3577
+ await this._listFolderOf(message);
3578
+ return message;
3579
+ }
3580
+
2590
3581
  _updateActivity() {
2591
3582
  this.lastActivity = Date.now();
2592
3583
  }
@@ -2634,20 +3625,14 @@ export class EmailEngineClient {
2634
3625
  return;
2635
3626
  }
2636
3627
 
2637
- // Update UI
2638
- const client = this.container.querySelector('.ee-client');
2639
- if (client) {
2640
- if (this.darkMode) {
2641
- client.classList.add('ee-dark-mode');
2642
- } else {
2643
- client.classList.remove('ee-dark-mode');
2644
- }
2645
- }
3628
+ // Update UI. The compose button and modal are siblings of .ee-client, so
3629
+ // 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));
2646
3631
 
2647
3632
  // Update toggle button icon
2648
- const icon = this.container.querySelector('.ee-dark-mode-icon');
2649
- if (icon) {
2650
- icon.textContent = this.darkMode ? '☀️' : '🌙';
3633
+ const toggleIcon = this.container.querySelector('.ee-dark-mode-icon');
3634
+ if (toggleIcon) {
3635
+ toggleIcon.innerHTML = icon(this.darkMode ? 'sun' : 'moon', 14);
2651
3636
  }
2652
3637
  }
2653
3638