@postalsys/ee-client 1.7.0 → 1.7.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.
- package/README.md +5 -0
- package/index.js +248 -102
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,6 +218,11 @@ When a `container` is provided the client builds a full webmail interface:
|
|
|
218
218
|
- Quoted thread history collapsed behind a "Show quoted text" control
|
|
219
219
|
- Compose modal (floating button) for sending plain-text mail, with a Save Draft option that stores the message in the Drafts folder instead of sending it
|
|
220
220
|
- Dark mode toggle with the preference persisted to `localStorage`
|
|
221
|
+
- Failed requests replace the affected pane's placeholder with an error panel and a Retry button
|
|
222
|
+
|
|
223
|
+
### Failed requests
|
|
224
|
+
|
|
225
|
+
When a request behind a pane fails, that pane shows why instead of sitting on its "Loading..." placeholder. The reason is the message EmailEngine returned - for example "Requested account is not yet initialized" for an account that has not connected yet, or "Requested mailbox folder was not found" - and a Retry button re-runs the request. If the server could not be reached at all, the panel says so and names the configured `apiUrl`. The underlying promise still rejects, so callers driving the client programmatically can handle the error themselves.
|
|
221
226
|
|
|
222
227
|
### Quoted thread history
|
|
223
228
|
|
package/index.js
CHANGED
|
@@ -66,23 +66,13 @@ export class EmailEngineClient {
|
|
|
66
66
|
this._startKeepAliveTimer();
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// Resolves the platform fetch (native in browsers and modern Node, node-fetch as
|
|
70
|
+
// an optional fallback on older Node) and normalizes transport failures, so both
|
|
71
|
+
// HTTP entry points - apiRequest and _fetchBlob - fail in the same shape.
|
|
72
|
+
async _fetch(url, options) {
|
|
73
|
+
// Any request counts as activity for the keep-alive timer
|
|
71
74
|
this._updateActivity();
|
|
72
75
|
|
|
73
|
-
const url = `${this.apiUrl}${endpoint}`;
|
|
74
|
-
const options = {
|
|
75
|
-
method: method,
|
|
76
|
-
headers: {
|
|
77
|
-
'Content-Type': 'application/json',
|
|
78
|
-
...this._authHeaders()
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
if (data) {
|
|
83
|
-
options.body = JSON.stringify(data);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
76
|
let fetchFn = globalThis.fetch;
|
|
87
77
|
if (!fetchFn) {
|
|
88
78
|
// Native fetch is missing (older Node.js). Fall back to node-fetch.
|
|
@@ -102,26 +92,63 @@ export class EmailEngineClient {
|
|
|
102
92
|
);
|
|
103
93
|
}
|
|
104
94
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
95
|
+
try {
|
|
96
|
+
return await fetchFn(url, options);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
// Mark transport level failures - an unreachable server, DNS/TLS
|
|
99
|
+
// problems, a blocked CORS preflight - so callers can tell them apart
|
|
100
|
+
// from an API error that carries a server message.
|
|
101
|
+
const error = new Error(`Could not reach the EmailEngine server at ${this.apiUrl}`);
|
|
102
|
+
error.isNetworkError = true;
|
|
103
|
+
error.cause = err;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Turns a non-ok response into an Error carrying the server's own explanation.
|
|
109
|
+
// EmailEngine answers with Boom payloads - { statusCode, error, message, code,
|
|
110
|
+
// fields } - which _errorMessage() knows how to read.
|
|
111
|
+
async _responseError(response) {
|
|
112
|
+
let details;
|
|
113
|
+
try {
|
|
114
|
+
details = await response.json();
|
|
115
|
+
} catch (parseError) {
|
|
116
|
+
// Not a JSON body - the status line is all there is to go on
|
|
117
|
+
details = { message: response.statusText };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const error = new Error(`API request failed: ${response.statusText}`);
|
|
121
|
+
error.statusCode = response.status;
|
|
122
|
+
error.details = details;
|
|
123
|
+
return error;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async apiRequest(method, endpoint, data = null) {
|
|
127
|
+
const options = {
|
|
128
|
+
method: method,
|
|
129
|
+
headers: {
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
...this._authHeaders()
|
|
113
132
|
}
|
|
133
|
+
};
|
|
114
134
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
135
|
+
if (data) {
|
|
136
|
+
options.body = JSON.stringify(data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const response = await this._fetch(`${this.apiUrl}${endpoint}`, options);
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw await this._responseError(response);
|
|
119
142
|
}
|
|
120
143
|
|
|
121
144
|
return await response.json();
|
|
122
145
|
}
|
|
123
146
|
|
|
124
147
|
async loadFolders() {
|
|
148
|
+
// Reset the pane to its loading state so a retry after a failure does not
|
|
149
|
+
// keep showing the previous error while the new request is in flight.
|
|
150
|
+
this._setPaneHtml('.ee-folder-tree', '<div class="ee-loading">Loading folders...</div>');
|
|
151
|
+
|
|
125
152
|
try {
|
|
126
153
|
const data = await this.apiRequest('GET', `/v1/account/${this.account}/mailboxes`);
|
|
127
154
|
this.folders = data.mailboxes || [];
|
|
@@ -132,17 +159,13 @@ export class EmailEngineClient {
|
|
|
132
159
|
return this.folders;
|
|
133
160
|
} catch (error) {
|
|
134
161
|
console.error('Failed to load folders:', error);
|
|
162
|
+
this._renderPaneError('.ee-folder-tree', 'Folders unavailable', error, () => this._loadInitialView());
|
|
135
163
|
throw error;
|
|
136
164
|
}
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
async loadMessages(path, cursor = null) {
|
|
140
|
-
|
|
141
|
-
const messageList = this.container.querySelector('.ee-message-list');
|
|
142
|
-
if (messageList) {
|
|
143
|
-
messageList.innerHTML = '<div class="ee-loading">Loading messages...</div>';
|
|
144
|
-
}
|
|
145
|
-
}
|
|
168
|
+
this._setPaneHtml('.ee-message-list', '<div class="ee-loading">Loading messages...</div>');
|
|
146
169
|
|
|
147
170
|
try {
|
|
148
171
|
const params = new URLSearchParams({ path: path, pageSize: this.pageSize });
|
|
@@ -172,23 +195,15 @@ export class EmailEngineClient {
|
|
|
172
195
|
};
|
|
173
196
|
} catch (error) {
|
|
174
197
|
console.error('Failed to load messages:', error);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
messageList.innerHTML = '<div class="ee-error">Failed to load messages</div>';
|
|
179
|
-
}
|
|
180
|
-
}
|
|
198
|
+
this._renderPaneError('.ee-message-list', 'Messages unavailable', error, () =>
|
|
199
|
+
this._fireAndForget(this.loadMessages(path, cursor))
|
|
200
|
+
);
|
|
181
201
|
throw error;
|
|
182
202
|
}
|
|
183
203
|
}
|
|
184
204
|
|
|
185
205
|
async loadMessage(messageId) {
|
|
186
|
-
|
|
187
|
-
const viewer = this.container.querySelector('.ee-message-viewer');
|
|
188
|
-
if (viewer) {
|
|
189
|
-
viewer.innerHTML = '<div class="ee-loading">Loading message...</div>';
|
|
190
|
-
}
|
|
191
|
-
}
|
|
206
|
+
this._setPaneHtml('.ee-message-viewer', '<div class="ee-loading">Loading message...</div>');
|
|
192
207
|
|
|
193
208
|
try {
|
|
194
209
|
const params = new URLSearchParams({
|
|
@@ -224,12 +239,9 @@ export class EmailEngineClient {
|
|
|
224
239
|
return this.currentMessage;
|
|
225
240
|
} catch (error) {
|
|
226
241
|
console.error('Failed to load message:', error);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
viewer.innerHTML = '<div class="ee-error">Failed to load message</div>';
|
|
231
|
-
}
|
|
232
|
-
}
|
|
242
|
+
this._renderPaneError('.ee-message-viewer', 'Message unavailable', error, () =>
|
|
243
|
+
this._fireAndForget(this.loadMessage(messageId))
|
|
244
|
+
);
|
|
233
245
|
throw error;
|
|
234
246
|
}
|
|
235
247
|
}
|
|
@@ -337,8 +349,6 @@ export class EmailEngineClient {
|
|
|
337
349
|
return response;
|
|
338
350
|
} catch (error) {
|
|
339
351
|
console.error('Failed to send message:', error);
|
|
340
|
-
// Try to parse detailed error information
|
|
341
|
-
this._parseApiError(error);
|
|
342
352
|
throw error;
|
|
343
353
|
}
|
|
344
354
|
}
|
|
@@ -380,7 +390,6 @@ export class EmailEngineClient {
|
|
|
380
390
|
return response;
|
|
381
391
|
} catch (error) {
|
|
382
392
|
console.error('Failed to save draft:', error);
|
|
383
|
-
this._parseApiError(error);
|
|
384
393
|
throw error;
|
|
385
394
|
}
|
|
386
395
|
}
|
|
@@ -395,7 +404,6 @@ export class EmailEngineClient {
|
|
|
395
404
|
return response;
|
|
396
405
|
} catch (error) {
|
|
397
406
|
console.error('Failed to submit draft:', error);
|
|
398
|
-
this._parseApiError(error);
|
|
399
407
|
throw error;
|
|
400
408
|
}
|
|
401
409
|
}
|
|
@@ -414,23 +422,21 @@ export class EmailEngineClient {
|
|
|
414
422
|
return !!(folder && folder.specialUse === '\\Drafts');
|
|
415
423
|
}
|
|
416
424
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
} catch (parseError) {
|
|
425
|
-
// If parsing fails, just use the original error
|
|
426
|
-
console.error('Failed to parse error details:', parseError);
|
|
425
|
+
// Best-effort human readable reason for a failed request. EmailEngine returns
|
|
426
|
+
// Boom style payloads - { statusCode, error, message, code, fields } - so the
|
|
427
|
+
// `message` field usually carries the actual cause, e.g. "Requested account is
|
|
428
|
+
// not yet initialized" when the account has not connected yet.
|
|
429
|
+
_errorMessage(error, fallback = 'Unexpected error') {
|
|
430
|
+
if (!error) {
|
|
431
|
+
return fallback;
|
|
427
432
|
}
|
|
428
|
-
}
|
|
429
433
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
+
const details = error.details;
|
|
435
|
+
const detailsMessage = details && typeof details.message === 'string' ? details.message : '';
|
|
436
|
+
|
|
437
|
+
// Validation failures list the offending fields
|
|
438
|
+
if (details && Array.isArray(details.fields)) {
|
|
439
|
+
const fieldErrors = details.fields
|
|
434
440
|
// Keep only entries that carry a usable message string.
|
|
435
441
|
.filter(field => field && typeof field.message === 'string')
|
|
436
442
|
// Map technical field names to user-friendly ones. Each replace
|
|
@@ -443,18 +449,100 @@ export class EmailEngineClient {
|
|
|
443
449
|
.replace(/"text"/g, 'message')
|
|
444
450
|
);
|
|
445
451
|
|
|
446
|
-
const mainMessage =
|
|
452
|
+
const mainMessage = detailsMessage || fallback;
|
|
447
453
|
if (fieldErrors.length > 0) {
|
|
448
454
|
return `${mainMessage}:\n\n• ${fieldErrors.join('\n• ')}`;
|
|
449
455
|
}
|
|
450
456
|
return mainMessage;
|
|
451
457
|
}
|
|
452
458
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
459
|
+
if (detailsMessage) {
|
|
460
|
+
return detailsMessage;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
if (error.statusCode) {
|
|
464
|
+
return `The server responded with status ${error.statusCode}`;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return error.message || fallback;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
_formatSendError(error) {
|
|
471
|
+
return this._errorMessage(error, 'Failed to send email. Please check your input and try again.');
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Writes markup into one of the client's panes when the UI exists and is still
|
|
475
|
+
// alive, and hands the pane back so callers can wire up what they rendered.
|
|
476
|
+
_setPaneHtml(selector, html) {
|
|
477
|
+
if (typeof document === 'undefined' || !this.container || this._destroyed) {
|
|
478
|
+
return null;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const pane = this.container.querySelector(selector);
|
|
482
|
+
if (pane) {
|
|
483
|
+
pane.innerHTML = html;
|
|
484
|
+
}
|
|
485
|
+
return pane;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// Replaces a pane's contents with an error panel explaining why its data is
|
|
489
|
+
// missing, optionally with a Retry button. Without this a failed request
|
|
490
|
+
// leaves the pane stuck on its "Loading..." placeholder forever, with the
|
|
491
|
+
// only trace of the failure in the developer console.
|
|
492
|
+
_renderPaneError(selector, title, error, retry = null) {
|
|
493
|
+
const detail = this._errorMessage(error, '');
|
|
494
|
+
const pane = this._setPaneHtml(
|
|
495
|
+
selector,
|
|
496
|
+
`
|
|
497
|
+
<div class="ee-error">
|
|
498
|
+
<div class="ee-error-title">${this.escapeHtml(title)}</div>
|
|
499
|
+
${detail ? `<div class="ee-error-detail">${this.escapeHtml(detail)}</div>` : ''}
|
|
500
|
+
${retry ? '<button type="button" class="ee-button ee-error-retry">Retry</button>' : ''}
|
|
501
|
+
</div>
|
|
502
|
+
`
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
if (pane && retry) {
|
|
506
|
+
const retryButton = pane.querySelector('.ee-error-retry');
|
|
507
|
+
if (retryButton) {
|
|
508
|
+
retryButton.addEventListener('click', () => {
|
|
509
|
+
if (this._destroyed) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
// Disable while the request is in flight so an impatient second
|
|
513
|
+
// click can not fan out a duplicate round trip. A failed retry
|
|
514
|
+
// re-renders the panel with a fresh button.
|
|
515
|
+
retryButton.disabled = true;
|
|
516
|
+
retry();
|
|
517
|
+
});
|
|
518
|
+
}
|
|
456
519
|
}
|
|
457
|
-
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Loads started from a DOM handler render their own error panel, so the user
|
|
523
|
+
// has already been told. Swallow the rejection rather than letting it surface
|
|
524
|
+
// as an unhandled rejection in hosts with a global error reporter.
|
|
525
|
+
_fireAndForget(promise) {
|
|
526
|
+
promise.catch(() => {});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// Message actions (flag, delete, move) have no pane of their own to report into:
|
|
530
|
+
// when one fails the message simply stays put, which is indistinguishable from
|
|
531
|
+
// nothing having happened. Say so instead.
|
|
532
|
+
_alertActionFailed(error, fallback) {
|
|
533
|
+
console.error(`${fallback}:`, error);
|
|
534
|
+
return this.alertMethod(this._errorMessage(error, fallback), 'Error', null, 'OK');
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// The message list before any folder is opened. Shared with createLayout so the
|
|
538
|
+
// pane header markup lives in one place.
|
|
539
|
+
_messageListPlaceholder() {
|
|
540
|
+
return `
|
|
541
|
+
<div class="ee-pane-header">
|
|
542
|
+
<span class="ee-pane-title">Messages</span>
|
|
543
|
+
</div>
|
|
544
|
+
<div class="ee-empty-state">Select a folder</div>
|
|
545
|
+
`;
|
|
458
546
|
}
|
|
459
547
|
|
|
460
548
|
formatDate(dateStr) {
|
|
@@ -508,15 +596,17 @@ export class EmailEngineClient {
|
|
|
508
596
|
}
|
|
509
597
|
|
|
510
598
|
// Authenticated GET for binary payloads (attachments, message source).
|
|
511
|
-
// apiRequest is not reused here - it always parses the body as JSON
|
|
599
|
+
// apiRequest is not reused here - it always parses the body as JSON - but the
|
|
600
|
+
// same _fetch/_responseError pair is, so a failed download reports the same
|
|
601
|
+
// reason as any other request.
|
|
512
602
|
async _fetchBlob(endpoint) {
|
|
513
|
-
const response = await
|
|
603
|
+
const response = await this._fetch(`${this.apiUrl}${endpoint}`, {
|
|
514
604
|
headers: this._authHeaders(),
|
|
515
605
|
credentials: 'include'
|
|
516
606
|
});
|
|
517
607
|
|
|
518
608
|
if (!response.ok) {
|
|
519
|
-
throw
|
|
609
|
+
throw await this._responseError(response);
|
|
520
610
|
}
|
|
521
611
|
|
|
522
612
|
return response;
|
|
@@ -541,7 +631,12 @@ export class EmailEngineClient {
|
|
|
541
631
|
this._saveBlob(blob, filename);
|
|
542
632
|
} catch (error) {
|
|
543
633
|
console.error('Failed to download attachment:', error);
|
|
544
|
-
this.alertMethod(
|
|
634
|
+
this.alertMethod(
|
|
635
|
+
this._errorMessage(error, 'Failed to download attachment. Please try again.'),
|
|
636
|
+
'Download Error',
|
|
637
|
+
null,
|
|
638
|
+
'OK'
|
|
639
|
+
);
|
|
545
640
|
}
|
|
546
641
|
}
|
|
547
642
|
|
|
@@ -561,7 +656,12 @@ export class EmailEngineClient {
|
|
|
561
656
|
this._saveBlob(blob, filename);
|
|
562
657
|
} catch (error) {
|
|
563
658
|
console.error('Failed to download original message:', error);
|
|
564
|
-
this.alertMethod(
|
|
659
|
+
this.alertMethod(
|
|
660
|
+
this._errorMessage(error, 'Failed to download original message. Please try again.'),
|
|
661
|
+
'Download Error',
|
|
662
|
+
null,
|
|
663
|
+
'OK'
|
|
664
|
+
);
|
|
565
665
|
}
|
|
566
666
|
}
|
|
567
667
|
|
|
@@ -926,6 +1026,25 @@ export class EmailEngineClient {
|
|
|
926
1026
|
border: 1px solid #fcc;
|
|
927
1027
|
border-radius: 4px;
|
|
928
1028
|
margin: 16px;
|
|
1029
|
+
/* Panes can be as narrow as the 200px sidebar and server
|
|
1030
|
+
messages are arbitrary text, so break anywhere rather than
|
|
1031
|
+
letting a long word push the layout wider. */
|
|
1032
|
+
overflow-wrap: anywhere;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
.ee-error-title {
|
|
1036
|
+
font-weight: 500;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
.ee-error-detail {
|
|
1040
|
+
margin-top: 6px;
|
|
1041
|
+
font-size: 12px;
|
|
1042
|
+
/* Field level API errors arrive as a newline separated list */
|
|
1043
|
+
white-space: pre-line;
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
.ee-error-retry {
|
|
1047
|
+
margin-top: 10px;
|
|
929
1048
|
}
|
|
930
1049
|
|
|
931
1050
|
.ee-flag {
|
|
@@ -1362,11 +1481,16 @@ export class EmailEngineClient {
|
|
|
1362
1481
|
}
|
|
1363
1482
|
|
|
1364
1483
|
.ee-dark-mode .ee-loading,
|
|
1365
|
-
.ee-dark-mode .ee-empty-state
|
|
1366
|
-
.ee-dark-mode .ee-error {
|
|
1484
|
+
.ee-dark-mode .ee-empty-state {
|
|
1367
1485
|
color: #999;
|
|
1368
1486
|
}
|
|
1369
1487
|
|
|
1488
|
+
.ee-dark-mode .ee-error {
|
|
1489
|
+
background: #3a2222;
|
|
1490
|
+
border-color: #5c3030;
|
|
1491
|
+
color: #f0a5a5;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1370
1494
|
.ee-dark-mode .ee-pagination {
|
|
1371
1495
|
background: #252525;
|
|
1372
1496
|
border-color: #333;
|
|
@@ -1560,7 +1684,7 @@ export class EmailEngineClient {
|
|
|
1560
1684
|
folderTree.querySelectorAll('.ee-folder-item').forEach(item => {
|
|
1561
1685
|
item.addEventListener('click', () => {
|
|
1562
1686
|
const path = item.getAttribute('data-path');
|
|
1563
|
-
this.loadMessages(path);
|
|
1687
|
+
this._fireAndForget(this.loadMessages(path));
|
|
1564
1688
|
});
|
|
1565
1689
|
});
|
|
1566
1690
|
}
|
|
@@ -1636,19 +1760,19 @@ export class EmailEngineClient {
|
|
|
1636
1760
|
messageList.querySelectorAll('.ee-message-item').forEach(item => {
|
|
1637
1761
|
item.addEventListener('click', () => {
|
|
1638
1762
|
const messageId = item.getAttribute('data-id');
|
|
1639
|
-
this.loadMessage(messageId);
|
|
1763
|
+
this._fireAndForget(this.loadMessage(messageId));
|
|
1640
1764
|
});
|
|
1641
1765
|
});
|
|
1642
1766
|
|
|
1643
1767
|
messageList.querySelectorAll('[data-action="prev-page"]').forEach(btn => {
|
|
1644
1768
|
btn.addEventListener('click', () => {
|
|
1645
|
-
this.loadMessages(this.currentFolder, this.prevPageCursor);
|
|
1769
|
+
this._fireAndForget(this.loadMessages(this.currentFolder, this.prevPageCursor));
|
|
1646
1770
|
});
|
|
1647
1771
|
});
|
|
1648
1772
|
|
|
1649
1773
|
messageList.querySelectorAll('[data-action="next-page"]').forEach(btn => {
|
|
1650
1774
|
btn.addEventListener('click', () => {
|
|
1651
|
-
this.loadMessages(this.currentFolder, this.nextPageCursor);
|
|
1775
|
+
this._fireAndForget(this.loadMessages(this.currentFolder, this.nextPageCursor));
|
|
1652
1776
|
});
|
|
1653
1777
|
});
|
|
1654
1778
|
|
|
@@ -1660,7 +1784,7 @@ export class EmailEngineClient {
|
|
|
1660
1784
|
if (typeof window !== 'undefined' && window.localStorage) {
|
|
1661
1785
|
localStorage.setItem('ee-client-page-size', this.pageSize.toString());
|
|
1662
1786
|
}
|
|
1663
|
-
this.loadMessages(this.currentFolder);
|
|
1787
|
+
this._fireAndForget(this.loadMessages(this.currentFolder));
|
|
1664
1788
|
});
|
|
1665
1789
|
}
|
|
1666
1790
|
}
|
|
@@ -1797,7 +1921,9 @@ export class EmailEngineClient {
|
|
|
1797
1921
|
|
|
1798
1922
|
viewer.querySelector('[data-action="toggle-read"]').addEventListener('click', () => {
|
|
1799
1923
|
const currentlyUnseen = msg.unseen;
|
|
1800
|
-
this.markAsRead(msg.id, currentlyUnseen)
|
|
1924
|
+
this.markAsRead(msg.id, currentlyUnseen).catch(error =>
|
|
1925
|
+
this._alertActionFailed(error, 'Failed to update the message flags')
|
|
1926
|
+
);
|
|
1801
1927
|
});
|
|
1802
1928
|
|
|
1803
1929
|
viewer.querySelector('[data-action="delete"]').addEventListener('click', async () => {
|
|
@@ -1808,7 +1934,9 @@ export class EmailEngineClient {
|
|
|
1808
1934
|
'Delete'
|
|
1809
1935
|
);
|
|
1810
1936
|
if (result) {
|
|
1811
|
-
this.deleteMessage(msg.id)
|
|
1937
|
+
this.deleteMessage(msg.id).catch(error =>
|
|
1938
|
+
this._alertActionFailed(error, 'Failed to delete the message')
|
|
1939
|
+
);
|
|
1812
1940
|
}
|
|
1813
1941
|
});
|
|
1814
1942
|
|
|
@@ -1819,7 +1947,12 @@ export class EmailEngineClient {
|
|
|
1819
1947
|
viewer.querySelector('[data-action="move"]').addEventListener('change', e => {
|
|
1820
1948
|
const targetPath = e.target.value;
|
|
1821
1949
|
if (targetPath) {
|
|
1822
|
-
this.moveMessage(msg.id, targetPath)
|
|
1950
|
+
this.moveMessage(msg.id, targetPath).catch(error => {
|
|
1951
|
+
// The message did not move, so the select must not keep showing
|
|
1952
|
+
// the target folder as though it had
|
|
1953
|
+
e.target.value = '';
|
|
1954
|
+
this._alertActionFailed(error, 'Failed to move the message');
|
|
1955
|
+
});
|
|
1823
1956
|
}
|
|
1824
1957
|
});
|
|
1825
1958
|
|
|
@@ -1872,16 +2005,9 @@ export class EmailEngineClient {
|
|
|
1872
2005
|
<div class="ee-pane-header">
|
|
1873
2006
|
<span class="ee-pane-title">Folders</span>
|
|
1874
2007
|
</div>
|
|
1875
|
-
<div class="ee-folder-tree">
|
|
1876
|
-
<div class="ee-loading">Loading folders...</div>
|
|
1877
|
-
</div>
|
|
1878
|
-
</div>
|
|
1879
|
-
<div class="ee-message-list">
|
|
1880
|
-
<div class="ee-pane-header">
|
|
1881
|
-
<span class="ee-pane-title">Messages</span>
|
|
1882
|
-
</div>
|
|
1883
|
-
<div class="ee-empty-state">Select a folder</div>
|
|
2008
|
+
<div class="ee-folder-tree"></div>
|
|
1884
2009
|
</div>
|
|
2010
|
+
<div class="ee-message-list">${this._messageListPlaceholder()}</div>
|
|
1885
2011
|
<div class="ee-message-viewer">
|
|
1886
2012
|
<div class="ee-empty-state">Select a message to view</div>
|
|
1887
2013
|
</div>
|
|
@@ -2182,18 +2308,38 @@ export class EmailEngineClient {
|
|
|
2182
2308
|
toggleBtn.addEventListener('click', () => this.toggleDarkMode());
|
|
2183
2309
|
}
|
|
2184
2310
|
|
|
2185
|
-
this.
|
|
2311
|
+
this._loadInitialView();
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
// Load the folder list and open the account's inbox. Used on startup and by
|
|
2315
|
+
// the Retry button that loadFolders renders when the request fails; both
|
|
2316
|
+
// failure paths already put an error panel in the UI, so the rejection is
|
|
2317
|
+
// logged and swallowed here rather than surfacing as an unhandled rejection.
|
|
2318
|
+
_loadInitialView() {
|
|
2319
|
+
// Drop whatever a previous attempt left here; loadFolders and loadMessages
|
|
2320
|
+
// paint their own loading states from this point on.
|
|
2321
|
+
this._setPaneHtml('.ee-message-list', this._messageListPlaceholder());
|
|
2322
|
+
|
|
2323
|
+
return this.loadFolders()
|
|
2324
|
+
.catch(error => {
|
|
2325
|
+
// loadFolders reports into the sidebar, but the message list is the
|
|
2326
|
+
// larger pane and would still read "Select a folder" - a folder the
|
|
2327
|
+
// sidebar can no longer offer. Say what happened there too.
|
|
2328
|
+
this._renderPaneError('.ee-message-list', 'Folders unavailable', error, () => this._loadInitialView());
|
|
2329
|
+
throw error;
|
|
2330
|
+
})
|
|
2186
2331
|
.then(() => {
|
|
2187
2332
|
const inbox =
|
|
2188
2333
|
this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
|
|
2189
2334
|
this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
|
|
2190
2335
|
this.folders[0];
|
|
2191
2336
|
if (inbox) {
|
|
2192
|
-
this.loadMessages(inbox.path);
|
|
2337
|
+
return this.loadMessages(inbox.path);
|
|
2193
2338
|
}
|
|
2194
2339
|
})
|
|
2195
2340
|
.catch(error => {
|
|
2196
|
-
|
|
2341
|
+
// Both loadFolders and loadMessages have already rendered a panel
|
|
2342
|
+
console.error('Failed to load the initial view:', error);
|
|
2197
2343
|
});
|
|
2198
2344
|
}
|
|
2199
2345
|
|