@postalsys/ee-client 1.0.0 → 1.0.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/index.cjs +362 -45
- package/index.js +362 -45
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -12,6 +12,11 @@ class EmailEngineClient {
|
|
|
12
12
|
this.nextPageCursor = null;
|
|
13
13
|
this.prevPageCursor = null;
|
|
14
14
|
|
|
15
|
+
// Get page size from localStorage or options or default
|
|
16
|
+
const savedPageSize =
|
|
17
|
+
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
18
|
+
this.pageSize = savedPageSize ? parseInt(savedPageSize) : options.pageSize || 20;
|
|
19
|
+
|
|
15
20
|
if (this.container) {
|
|
16
21
|
this.init();
|
|
17
22
|
}
|
|
@@ -81,7 +86,7 @@ class EmailEngineClient {
|
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
try {
|
|
84
|
-
const params = new URLSearchParams({ path: path, pageSize:
|
|
89
|
+
const params = new URLSearchParams({ path: path, pageSize: this.pageSize });
|
|
85
90
|
if (cursor) {
|
|
86
91
|
params.set('cursor', cursor);
|
|
87
92
|
}
|
|
@@ -94,6 +99,7 @@ class EmailEngineClient {
|
|
|
94
99
|
|
|
95
100
|
if (this.container) {
|
|
96
101
|
this.renderMessageList();
|
|
102
|
+
this.renderFolderList(); // Re-render to update active state
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
return {
|
|
@@ -246,6 +252,99 @@ class EmailEngineClient {
|
|
|
246
252
|
}
|
|
247
253
|
}
|
|
248
254
|
|
|
255
|
+
formatFileSize(bytes) {
|
|
256
|
+
if (!bytes) {
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
260
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
261
|
+
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async downloadAttachment(attachmentId, suggestedFilename = null) {
|
|
265
|
+
try {
|
|
266
|
+
const headers = {};
|
|
267
|
+
if (this.accessToken) {
|
|
268
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const response = await fetch(`${this.apiUrl}/v1/account/${this.account}/attachment/${attachmentId}`, {
|
|
272
|
+
headers,
|
|
273
|
+
credentials: 'include'
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (!response.ok) {
|
|
277
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Get filename from Content-Disposition header if available
|
|
281
|
+
const contentDisposition = response.headers.get('content-disposition');
|
|
282
|
+
let filename = suggestedFilename || 'attachment';
|
|
283
|
+
if (contentDisposition) {
|
|
284
|
+
const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
285
|
+
if (filenameMatch && filenameMatch[1]) {
|
|
286
|
+
filename = filenameMatch[1].replace(/['"]/g, '');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Get the attachment data
|
|
291
|
+
const blob = await response.blob();
|
|
292
|
+
|
|
293
|
+
// Create a download link
|
|
294
|
+
const url = window.URL.createObjectURL(blob);
|
|
295
|
+
const a = document.createElement('a');
|
|
296
|
+
a.href = url;
|
|
297
|
+
a.download = filename;
|
|
298
|
+
document.body.appendChild(a);
|
|
299
|
+
a.click();
|
|
300
|
+
document.body.removeChild(a);
|
|
301
|
+
window.URL.revokeObjectURL(url);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.error('Failed to download attachment:', error);
|
|
304
|
+
alert('Failed to download attachment');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async downloadOriginalMessage(messageId, subject = null) {
|
|
309
|
+
try {
|
|
310
|
+
const headers = {};
|
|
311
|
+
if (this.accessToken) {
|
|
312
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const response = await fetch(`${this.apiUrl}/v1/account/${this.account}/message/${messageId}/source`, {
|
|
316
|
+
headers,
|
|
317
|
+
credentials: 'include'
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
if (!response.ok) {
|
|
321
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Get the email data
|
|
325
|
+
const blob = await response.blob();
|
|
326
|
+
|
|
327
|
+
// Create filename based on subject and date
|
|
328
|
+
const now = new Date();
|
|
329
|
+
const dateStr = now.toISOString().split('T')[0];
|
|
330
|
+
const safeSubject = subject ? subject.replace(/[^a-z0-9]/gi, '_').substring(0, 50) : 'email';
|
|
331
|
+
const filename = `${dateStr}_${safeSubject}.eml`;
|
|
332
|
+
|
|
333
|
+
// Create a download link
|
|
334
|
+
const url = window.URL.createObjectURL(blob);
|
|
335
|
+
const a = document.createElement('a');
|
|
336
|
+
a.href = url;
|
|
337
|
+
a.download = filename;
|
|
338
|
+
document.body.appendChild(a);
|
|
339
|
+
a.click();
|
|
340
|
+
document.body.removeChild(a);
|
|
341
|
+
window.URL.revokeObjectURL(url);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
console.error('Failed to download original message:', error);
|
|
344
|
+
alert('Failed to download original message');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
249
348
|
createStyles() {
|
|
250
349
|
if (typeof document === 'undefined') {
|
|
251
350
|
return;
|
|
@@ -271,9 +370,10 @@ class EmailEngineClient {
|
|
|
271
370
|
|
|
272
371
|
.ee-sidebar {
|
|
273
372
|
width: 200px;
|
|
274
|
-
background: #
|
|
373
|
+
background: #ffffff;
|
|
275
374
|
border-right: 1px solid #ddd;
|
|
276
|
-
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
277
377
|
}
|
|
278
378
|
|
|
279
379
|
.ee-folder-list {
|
|
@@ -285,6 +385,7 @@ class EmailEngineClient {
|
|
|
285
385
|
.ee-folder-item {
|
|
286
386
|
cursor: pointer;
|
|
287
387
|
border-bottom: 1px solid #e0e0e0;
|
|
388
|
+
position: relative;
|
|
288
389
|
}
|
|
289
390
|
|
|
290
391
|
.ee-folder-item:hover {
|
|
@@ -296,6 +397,16 @@ class EmailEngineClient {
|
|
|
296
397
|
color: white;
|
|
297
398
|
}
|
|
298
399
|
|
|
400
|
+
.ee-folder-item.active::before {
|
|
401
|
+
content: '';
|
|
402
|
+
position: absolute;
|
|
403
|
+
left: 0;
|
|
404
|
+
top: 0;
|
|
405
|
+
bottom: 0;
|
|
406
|
+
width: 3px;
|
|
407
|
+
background: #0056b3;
|
|
408
|
+
}
|
|
409
|
+
|
|
299
410
|
.ee-folder-content {
|
|
300
411
|
padding: 8px 16px 8px 0px;
|
|
301
412
|
display: flex;
|
|
@@ -340,7 +451,9 @@ class EmailEngineClient {
|
|
|
340
451
|
.ee-message-list {
|
|
341
452
|
width: 350px;
|
|
342
453
|
border-right: 1px solid #ddd;
|
|
343
|
-
|
|
454
|
+
background: #ffffff;
|
|
455
|
+
display: flex;
|
|
456
|
+
flex-direction: column;
|
|
344
457
|
}
|
|
345
458
|
|
|
346
459
|
.ee-message-item {
|
|
@@ -382,10 +495,17 @@ class EmailEngineClient {
|
|
|
382
495
|
}
|
|
383
496
|
|
|
384
497
|
.ee-message-subject {
|
|
498
|
+
display: flex;
|
|
499
|
+
align-items: center;
|
|
500
|
+
margin-bottom: 2px;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.ee-message-subject-text {
|
|
385
504
|
overflow: hidden;
|
|
386
505
|
text-overflow: ellipsis;
|
|
387
506
|
white-space: nowrap;
|
|
388
|
-
|
|
507
|
+
flex: 1;
|
|
508
|
+
min-width: 0;
|
|
389
509
|
}
|
|
390
510
|
|
|
391
511
|
.ee-message-preview {
|
|
@@ -397,6 +517,17 @@ class EmailEngineClient {
|
|
|
397
517
|
font-weight: normal;
|
|
398
518
|
}
|
|
399
519
|
|
|
520
|
+
.ee-attachment-indicator {
|
|
521
|
+
display: inline-block;
|
|
522
|
+
font-size: 11px;
|
|
523
|
+
color: #666;
|
|
524
|
+
margin-left: 8px;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.ee-attachment-indicator::before {
|
|
528
|
+
content: "📎 ";
|
|
529
|
+
}
|
|
530
|
+
|
|
400
531
|
.ee-message-viewer {
|
|
401
532
|
flex: 1;
|
|
402
533
|
display: flex;
|
|
@@ -405,20 +536,34 @@ class EmailEngineClient {
|
|
|
405
536
|
}
|
|
406
537
|
|
|
407
538
|
.ee-message-actions {
|
|
408
|
-
padding:
|
|
409
|
-
background: #
|
|
410
|
-
|
|
539
|
+
padding: 10px 16px;
|
|
540
|
+
background: #e9ecef;
|
|
541
|
+
background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
|
|
542
|
+
border-bottom: 2px solid #dee2e6;
|
|
411
543
|
display: flex;
|
|
412
544
|
gap: 8px;
|
|
545
|
+
height: 44px;
|
|
546
|
+
align-items: center;
|
|
547
|
+
flex-shrink: 0;
|
|
548
|
+
box-sizing: border-box;
|
|
549
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
413
550
|
}
|
|
414
551
|
|
|
415
552
|
.ee-button {
|
|
416
|
-
padding:
|
|
553
|
+
padding: 4px 10px;
|
|
417
554
|
border: 1px solid #ddd;
|
|
418
555
|
background: white;
|
|
419
556
|
border-radius: 4px;
|
|
420
557
|
cursor: pointer;
|
|
421
|
-
font-size:
|
|
558
|
+
font-size: 12px;
|
|
559
|
+
height: 24px;
|
|
560
|
+
line-height: 1;
|
|
561
|
+
box-sizing: border-box;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
select.ee-button {
|
|
565
|
+
padding: 3px 10px;
|
|
566
|
+
height: 24px;
|
|
422
567
|
}
|
|
423
568
|
|
|
424
569
|
.ee-button:hover:not(:disabled) {
|
|
@@ -464,6 +609,53 @@ class EmailEngineClient {
|
|
|
464
609
|
height: auto;
|
|
465
610
|
}
|
|
466
611
|
|
|
612
|
+
.ee-attachments {
|
|
613
|
+
margin-top: 16px;
|
|
614
|
+
padding-top: 16px;
|
|
615
|
+
border-top: 1px solid #e0e0e0;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.ee-attachments-title {
|
|
619
|
+
font-weight: 500;
|
|
620
|
+
margin-bottom: 8px;
|
|
621
|
+
color: #333;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.ee-attachment-item {
|
|
625
|
+
display: flex;
|
|
626
|
+
align-items: center;
|
|
627
|
+
padding: 8px;
|
|
628
|
+
margin-bottom: 4px;
|
|
629
|
+
background: #f8f8f8;
|
|
630
|
+
border: 1px solid #e0e0e0;
|
|
631
|
+
border-radius: 4px;
|
|
632
|
+
cursor: pointer;
|
|
633
|
+
transition: background 0.2s;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
.ee-attachment-item:hover {
|
|
637
|
+
background: #f0f0f0;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
.ee-attachment-icon {
|
|
641
|
+
margin-right: 8px;
|
|
642
|
+
font-size: 18px;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
.ee-attachment-info {
|
|
646
|
+
flex: 1;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
.ee-attachment-name {
|
|
650
|
+
font-weight: 500;
|
|
651
|
+
color: #333;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
.ee-attachment-size {
|
|
655
|
+
font-size: 12px;
|
|
656
|
+
color: #666;
|
|
657
|
+
}
|
|
658
|
+
|
|
467
659
|
.ee-empty-state {
|
|
468
660
|
display: flex;
|
|
469
661
|
align-items: center;
|
|
@@ -502,19 +694,64 @@ class EmailEngineClient {
|
|
|
502
694
|
background: #2196F3;
|
|
503
695
|
}
|
|
504
696
|
|
|
505
|
-
.ee-
|
|
506
|
-
padding:
|
|
507
|
-
background: #
|
|
508
|
-
|
|
509
|
-
border-bottom:
|
|
697
|
+
.ee-pane-header {
|
|
698
|
+
padding: 10px 16px;
|
|
699
|
+
background: #e9ecef;
|
|
700
|
+
background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
|
|
701
|
+
border-bottom: 2px solid #dee2e6;
|
|
510
702
|
display: flex;
|
|
511
703
|
justify-content: space-between;
|
|
512
704
|
align-items: center;
|
|
705
|
+
height: 44px;
|
|
706
|
+
flex-shrink: 0;
|
|
707
|
+
box-sizing: border-box;
|
|
708
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.ee-pane-title {
|
|
712
|
+
font-weight: 500;
|
|
713
|
+
font-size: 14px;
|
|
714
|
+
color: #333;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
.ee-folder-tree {
|
|
718
|
+
flex: 1;
|
|
719
|
+
overflow-y: auto;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
.ee-pagination-controls {
|
|
723
|
+
display: flex;
|
|
724
|
+
gap: 8px;
|
|
725
|
+
align-items: center;
|
|
513
726
|
}
|
|
514
727
|
|
|
515
|
-
.ee-
|
|
728
|
+
.ee-page-size-selector {
|
|
729
|
+
display: flex;
|
|
730
|
+
gap: 4px;
|
|
731
|
+
align-items: center;
|
|
732
|
+
margin-left: auto;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.ee-page-size-label {
|
|
516
736
|
font-size: 12px;
|
|
517
|
-
|
|
737
|
+
color: #666;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
.ee-page-size-select {
|
|
741
|
+
font-size: 11px;
|
|
742
|
+
padding: 2px 4px;
|
|
743
|
+
border: 1px solid #ddd;
|
|
744
|
+
border-radius: 3px;
|
|
745
|
+
background: white;
|
|
746
|
+
cursor: pointer;
|
|
747
|
+
height: 22px;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
.ee-pagination-btn {
|
|
751
|
+
font-size: 11px;
|
|
752
|
+
padding: 3px 8px;
|
|
753
|
+
height: 22px;
|
|
754
|
+
line-height: 1;
|
|
518
755
|
}
|
|
519
756
|
|
|
520
757
|
.ee-message-items {
|
|
@@ -600,8 +837,8 @@ class EmailEngineClient {
|
|
|
600
837
|
return;
|
|
601
838
|
}
|
|
602
839
|
|
|
603
|
-
const
|
|
604
|
-
if (!
|
|
840
|
+
const folderTree = this.container.querySelector('.ee-folder-tree');
|
|
841
|
+
if (!folderTree) {
|
|
605
842
|
return;
|
|
606
843
|
}
|
|
607
844
|
|
|
@@ -628,9 +865,9 @@ class EmailEngineClient {
|
|
|
628
865
|
.join('')}
|
|
629
866
|
</ul>
|
|
630
867
|
`;
|
|
631
|
-
|
|
868
|
+
folderTree.innerHTML = html;
|
|
632
869
|
|
|
633
|
-
|
|
870
|
+
folderTree.querySelectorAll('.ee-folder-item').forEach(item => {
|
|
634
871
|
item.addEventListener('click', () => {
|
|
635
872
|
const path = item.getAttribute('data-path');
|
|
636
873
|
this.loadMessages(path);
|
|
@@ -649,22 +886,41 @@ class EmailEngineClient {
|
|
|
649
886
|
}
|
|
650
887
|
|
|
651
888
|
if (!this.messages.length) {
|
|
652
|
-
messageList.innerHTML =
|
|
889
|
+
messageList.innerHTML = `
|
|
890
|
+
<div class="ee-pane-header">
|
|
891
|
+
<span class="ee-pane-title">Messages</span>
|
|
892
|
+
</div>
|
|
893
|
+
<div class="ee-empty-state">No messages</div>
|
|
894
|
+
`;
|
|
653
895
|
return;
|
|
654
896
|
}
|
|
655
897
|
|
|
656
|
-
const
|
|
657
|
-
this.nextPageCursor || this.prevPageCursor
|
|
658
|
-
? `
|
|
659
|
-
<div class="ee-pagination">
|
|
660
|
-
${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
|
|
661
|
-
${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
|
|
662
|
-
</div>
|
|
663
|
-
`
|
|
664
|
-
: '';
|
|
898
|
+
const hasPagination = this.nextPageCursor || this.prevPageCursor;
|
|
665
899
|
|
|
666
900
|
const html = `
|
|
667
|
-
|
|
901
|
+
<div class="ee-pane-header">
|
|
902
|
+
<span class="ee-pane-title">Messages</span>
|
|
903
|
+
<div class="ee-pagination-controls">
|
|
904
|
+
${
|
|
905
|
+
hasPagination
|
|
906
|
+
? `
|
|
907
|
+
${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
|
|
908
|
+
${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
|
|
909
|
+
`
|
|
910
|
+
: ''
|
|
911
|
+
}
|
|
912
|
+
<div class="ee-page-size-selector">
|
|
913
|
+
<span class="ee-page-size-label">Show:</span>
|
|
914
|
+
<select class="ee-page-size-select" data-action="page-size">
|
|
915
|
+
<option value="10" ${this.pageSize === 10 ? 'selected' : ''}>10</option>
|
|
916
|
+
<option value="20" ${this.pageSize === 20 ? 'selected' : ''}>20</option>
|
|
917
|
+
<option value="30" ${this.pageSize === 30 ? 'selected' : ''}>30</option>
|
|
918
|
+
<option value="50" ${this.pageSize === 50 ? 'selected' : ''}>50</option>
|
|
919
|
+
<option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100</option>
|
|
920
|
+
</select>
|
|
921
|
+
</div>
|
|
922
|
+
</div>
|
|
923
|
+
</div>
|
|
668
924
|
<div class="ee-message-items">
|
|
669
925
|
${this.messages
|
|
670
926
|
.map(
|
|
@@ -674,14 +930,16 @@ class EmailEngineClient {
|
|
|
674
930
|
<span class="ee-message-from">${msg.from ? msg.from.name || msg.from.address : 'Unknown'}</span>
|
|
675
931
|
<span class="ee-message-date">${this.formatDate(msg.date)}</span>
|
|
676
932
|
</div>
|
|
677
|
-
<div class="ee-message-subject"
|
|
933
|
+
<div class="ee-message-subject">
|
|
934
|
+
<span class="ee-message-subject-text">${msg.subject || '(no subject)'}</span>
|
|
935
|
+
${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator">${msg.attachments.length}</span>` : ''}
|
|
936
|
+
</div>
|
|
678
937
|
<div class="ee-message-preview">${msg.intro || ''}</div>
|
|
679
938
|
</div>
|
|
680
939
|
`
|
|
681
940
|
)
|
|
682
941
|
.join('')}
|
|
683
942
|
</div>
|
|
684
|
-
${paginationHtml}
|
|
685
943
|
`;
|
|
686
944
|
messageList.innerHTML = html;
|
|
687
945
|
|
|
@@ -703,6 +961,18 @@ class EmailEngineClient {
|
|
|
703
961
|
this.loadMessages(this.currentFolder, this.nextPageCursor);
|
|
704
962
|
});
|
|
705
963
|
});
|
|
964
|
+
|
|
965
|
+
const pageSizeSelect = messageList.querySelector('[data-action="page-size"]');
|
|
966
|
+
if (pageSizeSelect) {
|
|
967
|
+
pageSizeSelect.addEventListener('change', e => {
|
|
968
|
+
this.pageSize = parseInt(e.target.value);
|
|
969
|
+
// Save to localStorage
|
|
970
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
971
|
+
localStorage.setItem('ee-client-page-size', this.pageSize.toString());
|
|
972
|
+
}
|
|
973
|
+
this.loadMessages(this.currentFolder);
|
|
974
|
+
});
|
|
975
|
+
}
|
|
706
976
|
}
|
|
707
977
|
|
|
708
978
|
renderMessage() {
|
|
@@ -726,6 +996,7 @@ class EmailEngineClient {
|
|
|
726
996
|
<div class="ee-message-actions">
|
|
727
997
|
<button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
|
|
728
998
|
<button class="ee-button" data-action="delete">Delete</button>
|
|
999
|
+
<button class="ee-button" data-action="download-original">Download Original</button>
|
|
729
1000
|
<select class="ee-button" data-action="move">
|
|
730
1001
|
<option value="">Move to...</option>
|
|
731
1002
|
${this.buildFolderTree()
|
|
@@ -770,6 +1041,28 @@ class EmailEngineClient {
|
|
|
770
1041
|
<div class="ee-message-body">
|
|
771
1042
|
${msg.text && msg.text.html ? msg.text.html : msg.text && msg.text.plain ? `<pre>${msg.text.plain}</pre>` : ''}
|
|
772
1043
|
</div>
|
|
1044
|
+
${
|
|
1045
|
+
msg.attachments && msg.attachments.length > 0
|
|
1046
|
+
? `
|
|
1047
|
+
<div class="ee-attachments">
|
|
1048
|
+
<div class="ee-attachments-title">Attachments (${msg.attachments.length})</div>
|
|
1049
|
+
${msg.attachments
|
|
1050
|
+
.map(
|
|
1051
|
+
att => `
|
|
1052
|
+
<div class="ee-attachment-item" data-attachment-id="${att.id}">
|
|
1053
|
+
<div class="ee-attachment-icon">📎</div>
|
|
1054
|
+
<div class="ee-attachment-info">
|
|
1055
|
+
<div class="ee-attachment-name">${att.filename || 'Unnamed attachment'}</div>
|
|
1056
|
+
${att.size ? `<div class="ee-attachment-size">${this.formatFileSize(att.size)}</div>` : ''}
|
|
1057
|
+
</div>
|
|
1058
|
+
</div>
|
|
1059
|
+
`
|
|
1060
|
+
)
|
|
1061
|
+
.join('')}
|
|
1062
|
+
</div>
|
|
1063
|
+
`
|
|
1064
|
+
: ''
|
|
1065
|
+
}
|
|
773
1066
|
</div>
|
|
774
1067
|
`;
|
|
775
1068
|
viewer.innerHTML = html;
|
|
@@ -785,12 +1078,25 @@ class EmailEngineClient {
|
|
|
785
1078
|
}
|
|
786
1079
|
});
|
|
787
1080
|
|
|
1081
|
+
viewer.querySelector('[data-action="download-original"]').addEventListener('click', () => {
|
|
1082
|
+
this.downloadOriginalMessage(msg.id, msg.subject);
|
|
1083
|
+
});
|
|
1084
|
+
|
|
788
1085
|
viewer.querySelector('[data-action="move"]').addEventListener('change', e => {
|
|
789
1086
|
const targetPath = e.target.value;
|
|
790
1087
|
if (targetPath) {
|
|
791
1088
|
this.moveMessage(msg.id, targetPath);
|
|
792
1089
|
}
|
|
793
1090
|
});
|
|
1091
|
+
|
|
1092
|
+
// Add click handlers for attachments
|
|
1093
|
+
viewer.querySelectorAll('.ee-attachment-item').forEach(item => {
|
|
1094
|
+
item.addEventListener('click', () => {
|
|
1095
|
+
const attachmentId = item.getAttribute('data-attachment-id');
|
|
1096
|
+
const attachment = msg.attachments.find(a => a.id === attachmentId);
|
|
1097
|
+
this.downloadAttachment(attachmentId, attachment ? attachment.filename : null);
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
794
1100
|
}
|
|
795
1101
|
|
|
796
1102
|
createLayout() {
|
|
@@ -801,9 +1107,17 @@ class EmailEngineClient {
|
|
|
801
1107
|
this.container.innerHTML = `
|
|
802
1108
|
<div class="ee-client">
|
|
803
1109
|
<div class="ee-sidebar">
|
|
804
|
-
<div class="ee-
|
|
1110
|
+
<div class="ee-pane-header">
|
|
1111
|
+
<span class="ee-pane-title">Folders</span>
|
|
1112
|
+
</div>
|
|
1113
|
+
<div class="ee-folder-tree">
|
|
1114
|
+
<div class="ee-loading">Loading folders...</div>
|
|
1115
|
+
</div>
|
|
805
1116
|
</div>
|
|
806
1117
|
<div class="ee-message-list">
|
|
1118
|
+
<div class="ee-pane-header">
|
|
1119
|
+
<span class="ee-pane-title">Messages</span>
|
|
1120
|
+
</div>
|
|
807
1121
|
<div class="ee-empty-state">Select a folder</div>
|
|
808
1122
|
</div>
|
|
809
1123
|
<div class="ee-message-viewer">
|
|
@@ -821,16 +1135,19 @@ class EmailEngineClient {
|
|
|
821
1135
|
|
|
822
1136
|
this.createStyles();
|
|
823
1137
|
this.createLayout();
|
|
824
|
-
this.loadFolders()
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1138
|
+
this.loadFolders()
|
|
1139
|
+
.then(() => {
|
|
1140
|
+
const inbox =
|
|
1141
|
+
this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
|
|
1142
|
+
this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
|
|
1143
|
+
this.folders[0];
|
|
1144
|
+
if (inbox) {
|
|
1145
|
+
this.loadMessages(inbox.path);
|
|
1146
|
+
}
|
|
1147
|
+
})
|
|
1148
|
+
.catch(error => {
|
|
1149
|
+
console.error('Failed to auto-select inbox:', error);
|
|
1150
|
+
});
|
|
834
1151
|
}
|
|
835
1152
|
}
|
|
836
1153
|
|
package/index.js
CHANGED
|
@@ -12,6 +12,11 @@ export class EmailEngineClient {
|
|
|
12
12
|
this.nextPageCursor = null;
|
|
13
13
|
this.prevPageCursor = null;
|
|
14
14
|
|
|
15
|
+
// Get page size from localStorage or options or default
|
|
16
|
+
const savedPageSize =
|
|
17
|
+
typeof window !== 'undefined' && window.localStorage ? localStorage.getItem('ee-client-page-size') : null;
|
|
18
|
+
this.pageSize = savedPageSize ? parseInt(savedPageSize) : options.pageSize || 20;
|
|
19
|
+
|
|
15
20
|
if (this.container) {
|
|
16
21
|
this.init();
|
|
17
22
|
}
|
|
@@ -81,7 +86,7 @@ export class EmailEngineClient {
|
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
try {
|
|
84
|
-
const params = new URLSearchParams({ path: path, pageSize:
|
|
89
|
+
const params = new URLSearchParams({ path: path, pageSize: this.pageSize });
|
|
85
90
|
if (cursor) {
|
|
86
91
|
params.set('cursor', cursor);
|
|
87
92
|
}
|
|
@@ -94,6 +99,7 @@ export class EmailEngineClient {
|
|
|
94
99
|
|
|
95
100
|
if (this.container) {
|
|
96
101
|
this.renderMessageList();
|
|
102
|
+
this.renderFolderList(); // Re-render to update active state
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
return {
|
|
@@ -246,6 +252,99 @@ export class EmailEngineClient {
|
|
|
246
252
|
}
|
|
247
253
|
}
|
|
248
254
|
|
|
255
|
+
formatFileSize(bytes) {
|
|
256
|
+
if (!bytes) {
|
|
257
|
+
return '';
|
|
258
|
+
}
|
|
259
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
260
|
+
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
261
|
+
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
async downloadAttachment(attachmentId, suggestedFilename = null) {
|
|
265
|
+
try {
|
|
266
|
+
const headers = {};
|
|
267
|
+
if (this.accessToken) {
|
|
268
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const response = await fetch(`${this.apiUrl}/v1/account/${this.account}/attachment/${attachmentId}`, {
|
|
272
|
+
headers,
|
|
273
|
+
credentials: 'include'
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (!response.ok) {
|
|
277
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Get filename from Content-Disposition header if available
|
|
281
|
+
const contentDisposition = response.headers.get('content-disposition');
|
|
282
|
+
let filename = suggestedFilename || 'attachment';
|
|
283
|
+
if (contentDisposition) {
|
|
284
|
+
const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
|
|
285
|
+
if (filenameMatch && filenameMatch[1]) {
|
|
286
|
+
filename = filenameMatch[1].replace(/['"]/g, '');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Get the attachment data
|
|
291
|
+
const blob = await response.blob();
|
|
292
|
+
|
|
293
|
+
// Create a download link
|
|
294
|
+
const url = window.URL.createObjectURL(blob);
|
|
295
|
+
const a = document.createElement('a');
|
|
296
|
+
a.href = url;
|
|
297
|
+
a.download = filename;
|
|
298
|
+
document.body.appendChild(a);
|
|
299
|
+
a.click();
|
|
300
|
+
document.body.removeChild(a);
|
|
301
|
+
window.URL.revokeObjectURL(url);
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.error('Failed to download attachment:', error);
|
|
304
|
+
alert('Failed to download attachment');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async downloadOriginalMessage(messageId, subject = null) {
|
|
309
|
+
try {
|
|
310
|
+
const headers = {};
|
|
311
|
+
if (this.accessToken) {
|
|
312
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const response = await fetch(`${this.apiUrl}/v1/account/${this.account}/message/${messageId}/source`, {
|
|
316
|
+
headers,
|
|
317
|
+
credentials: 'include'
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
if (!response.ok) {
|
|
321
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Get the email data
|
|
325
|
+
const blob = await response.blob();
|
|
326
|
+
|
|
327
|
+
// Create filename based on subject and date
|
|
328
|
+
const now = new Date();
|
|
329
|
+
const dateStr = now.toISOString().split('T')[0];
|
|
330
|
+
const safeSubject = subject ? subject.replace(/[^a-z0-9]/gi, '_').substring(0, 50) : 'email';
|
|
331
|
+
const filename = `${dateStr}_${safeSubject}.eml`;
|
|
332
|
+
|
|
333
|
+
// Create a download link
|
|
334
|
+
const url = window.URL.createObjectURL(blob);
|
|
335
|
+
const a = document.createElement('a');
|
|
336
|
+
a.href = url;
|
|
337
|
+
a.download = filename;
|
|
338
|
+
document.body.appendChild(a);
|
|
339
|
+
a.click();
|
|
340
|
+
document.body.removeChild(a);
|
|
341
|
+
window.URL.revokeObjectURL(url);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
console.error('Failed to download original message:', error);
|
|
344
|
+
alert('Failed to download original message');
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
249
348
|
createStyles() {
|
|
250
349
|
if (typeof document === 'undefined') {
|
|
251
350
|
return;
|
|
@@ -271,9 +370,10 @@ export class EmailEngineClient {
|
|
|
271
370
|
|
|
272
371
|
.ee-sidebar {
|
|
273
372
|
width: 200px;
|
|
274
|
-
background: #
|
|
373
|
+
background: #ffffff;
|
|
275
374
|
border-right: 1px solid #ddd;
|
|
276
|
-
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
277
377
|
}
|
|
278
378
|
|
|
279
379
|
.ee-folder-list {
|
|
@@ -285,6 +385,7 @@ export class EmailEngineClient {
|
|
|
285
385
|
.ee-folder-item {
|
|
286
386
|
cursor: pointer;
|
|
287
387
|
border-bottom: 1px solid #e0e0e0;
|
|
388
|
+
position: relative;
|
|
288
389
|
}
|
|
289
390
|
|
|
290
391
|
.ee-folder-item:hover {
|
|
@@ -296,6 +397,16 @@ export class EmailEngineClient {
|
|
|
296
397
|
color: white;
|
|
297
398
|
}
|
|
298
399
|
|
|
400
|
+
.ee-folder-item.active::before {
|
|
401
|
+
content: '';
|
|
402
|
+
position: absolute;
|
|
403
|
+
left: 0;
|
|
404
|
+
top: 0;
|
|
405
|
+
bottom: 0;
|
|
406
|
+
width: 3px;
|
|
407
|
+
background: #0056b3;
|
|
408
|
+
}
|
|
409
|
+
|
|
299
410
|
.ee-folder-content {
|
|
300
411
|
padding: 8px 16px 8px 0px;
|
|
301
412
|
display: flex;
|
|
@@ -340,7 +451,9 @@ export class EmailEngineClient {
|
|
|
340
451
|
.ee-message-list {
|
|
341
452
|
width: 350px;
|
|
342
453
|
border-right: 1px solid #ddd;
|
|
343
|
-
|
|
454
|
+
background: #ffffff;
|
|
455
|
+
display: flex;
|
|
456
|
+
flex-direction: column;
|
|
344
457
|
}
|
|
345
458
|
|
|
346
459
|
.ee-message-item {
|
|
@@ -382,10 +495,17 @@ export class EmailEngineClient {
|
|
|
382
495
|
}
|
|
383
496
|
|
|
384
497
|
.ee-message-subject {
|
|
498
|
+
display: flex;
|
|
499
|
+
align-items: center;
|
|
500
|
+
margin-bottom: 2px;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
.ee-message-subject-text {
|
|
385
504
|
overflow: hidden;
|
|
386
505
|
text-overflow: ellipsis;
|
|
387
506
|
white-space: nowrap;
|
|
388
|
-
|
|
507
|
+
flex: 1;
|
|
508
|
+
min-width: 0;
|
|
389
509
|
}
|
|
390
510
|
|
|
391
511
|
.ee-message-preview {
|
|
@@ -397,6 +517,17 @@ export class EmailEngineClient {
|
|
|
397
517
|
font-weight: normal;
|
|
398
518
|
}
|
|
399
519
|
|
|
520
|
+
.ee-attachment-indicator {
|
|
521
|
+
display: inline-block;
|
|
522
|
+
font-size: 11px;
|
|
523
|
+
color: #666;
|
|
524
|
+
margin-left: 8px;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
.ee-attachment-indicator::before {
|
|
528
|
+
content: "📎 ";
|
|
529
|
+
}
|
|
530
|
+
|
|
400
531
|
.ee-message-viewer {
|
|
401
532
|
flex: 1;
|
|
402
533
|
display: flex;
|
|
@@ -405,20 +536,34 @@ export class EmailEngineClient {
|
|
|
405
536
|
}
|
|
406
537
|
|
|
407
538
|
.ee-message-actions {
|
|
408
|
-
padding:
|
|
409
|
-
background: #
|
|
410
|
-
|
|
539
|
+
padding: 10px 16px;
|
|
540
|
+
background: #e9ecef;
|
|
541
|
+
background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
|
|
542
|
+
border-bottom: 2px solid #dee2e6;
|
|
411
543
|
display: flex;
|
|
412
544
|
gap: 8px;
|
|
545
|
+
height: 44px;
|
|
546
|
+
align-items: center;
|
|
547
|
+
flex-shrink: 0;
|
|
548
|
+
box-sizing: border-box;
|
|
549
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
413
550
|
}
|
|
414
551
|
|
|
415
552
|
.ee-button {
|
|
416
|
-
padding:
|
|
553
|
+
padding: 4px 10px;
|
|
417
554
|
border: 1px solid #ddd;
|
|
418
555
|
background: white;
|
|
419
556
|
border-radius: 4px;
|
|
420
557
|
cursor: pointer;
|
|
421
|
-
font-size:
|
|
558
|
+
font-size: 12px;
|
|
559
|
+
height: 24px;
|
|
560
|
+
line-height: 1;
|
|
561
|
+
box-sizing: border-box;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
select.ee-button {
|
|
565
|
+
padding: 3px 10px;
|
|
566
|
+
height: 24px;
|
|
422
567
|
}
|
|
423
568
|
|
|
424
569
|
.ee-button:hover:not(:disabled) {
|
|
@@ -464,6 +609,53 @@ export class EmailEngineClient {
|
|
|
464
609
|
height: auto;
|
|
465
610
|
}
|
|
466
611
|
|
|
612
|
+
.ee-attachments {
|
|
613
|
+
margin-top: 16px;
|
|
614
|
+
padding-top: 16px;
|
|
615
|
+
border-top: 1px solid #e0e0e0;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
.ee-attachments-title {
|
|
619
|
+
font-weight: 500;
|
|
620
|
+
margin-bottom: 8px;
|
|
621
|
+
color: #333;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.ee-attachment-item {
|
|
625
|
+
display: flex;
|
|
626
|
+
align-items: center;
|
|
627
|
+
padding: 8px;
|
|
628
|
+
margin-bottom: 4px;
|
|
629
|
+
background: #f8f8f8;
|
|
630
|
+
border: 1px solid #e0e0e0;
|
|
631
|
+
border-radius: 4px;
|
|
632
|
+
cursor: pointer;
|
|
633
|
+
transition: background 0.2s;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
.ee-attachment-item:hover {
|
|
637
|
+
background: #f0f0f0;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
.ee-attachment-icon {
|
|
641
|
+
margin-right: 8px;
|
|
642
|
+
font-size: 18px;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
.ee-attachment-info {
|
|
646
|
+
flex: 1;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
.ee-attachment-name {
|
|
650
|
+
font-weight: 500;
|
|
651
|
+
color: #333;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
.ee-attachment-size {
|
|
655
|
+
font-size: 12px;
|
|
656
|
+
color: #666;
|
|
657
|
+
}
|
|
658
|
+
|
|
467
659
|
.ee-empty-state {
|
|
468
660
|
display: flex;
|
|
469
661
|
align-items: center;
|
|
@@ -502,19 +694,64 @@ export class EmailEngineClient {
|
|
|
502
694
|
background: #2196F3;
|
|
503
695
|
}
|
|
504
696
|
|
|
505
|
-
.ee-
|
|
506
|
-
padding:
|
|
507
|
-
background: #
|
|
508
|
-
|
|
509
|
-
border-bottom:
|
|
697
|
+
.ee-pane-header {
|
|
698
|
+
padding: 10px 16px;
|
|
699
|
+
background: #e9ecef;
|
|
700
|
+
background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
|
|
701
|
+
border-bottom: 2px solid #dee2e6;
|
|
510
702
|
display: flex;
|
|
511
703
|
justify-content: space-between;
|
|
512
704
|
align-items: center;
|
|
705
|
+
height: 44px;
|
|
706
|
+
flex-shrink: 0;
|
|
707
|
+
box-sizing: border-box;
|
|
708
|
+
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
.ee-pane-title {
|
|
712
|
+
font-weight: 500;
|
|
713
|
+
font-size: 14px;
|
|
714
|
+
color: #333;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
.ee-folder-tree {
|
|
718
|
+
flex: 1;
|
|
719
|
+
overflow-y: auto;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
.ee-pagination-controls {
|
|
723
|
+
display: flex;
|
|
724
|
+
gap: 8px;
|
|
725
|
+
align-items: center;
|
|
513
726
|
}
|
|
514
727
|
|
|
515
|
-
.ee-
|
|
728
|
+
.ee-page-size-selector {
|
|
729
|
+
display: flex;
|
|
730
|
+
gap: 4px;
|
|
731
|
+
align-items: center;
|
|
732
|
+
margin-left: auto;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
.ee-page-size-label {
|
|
516
736
|
font-size: 12px;
|
|
517
|
-
|
|
737
|
+
color: #666;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
.ee-page-size-select {
|
|
741
|
+
font-size: 11px;
|
|
742
|
+
padding: 2px 4px;
|
|
743
|
+
border: 1px solid #ddd;
|
|
744
|
+
border-radius: 3px;
|
|
745
|
+
background: white;
|
|
746
|
+
cursor: pointer;
|
|
747
|
+
height: 22px;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
.ee-pagination-btn {
|
|
751
|
+
font-size: 11px;
|
|
752
|
+
padding: 3px 8px;
|
|
753
|
+
height: 22px;
|
|
754
|
+
line-height: 1;
|
|
518
755
|
}
|
|
519
756
|
|
|
520
757
|
.ee-message-items {
|
|
@@ -600,8 +837,8 @@ export class EmailEngineClient {
|
|
|
600
837
|
return;
|
|
601
838
|
}
|
|
602
839
|
|
|
603
|
-
const
|
|
604
|
-
if (!
|
|
840
|
+
const folderTree = this.container.querySelector('.ee-folder-tree');
|
|
841
|
+
if (!folderTree) {
|
|
605
842
|
return;
|
|
606
843
|
}
|
|
607
844
|
|
|
@@ -628,9 +865,9 @@ export class EmailEngineClient {
|
|
|
628
865
|
.join('')}
|
|
629
866
|
</ul>
|
|
630
867
|
`;
|
|
631
|
-
|
|
868
|
+
folderTree.innerHTML = html;
|
|
632
869
|
|
|
633
|
-
|
|
870
|
+
folderTree.querySelectorAll('.ee-folder-item').forEach(item => {
|
|
634
871
|
item.addEventListener('click', () => {
|
|
635
872
|
const path = item.getAttribute('data-path');
|
|
636
873
|
this.loadMessages(path);
|
|
@@ -649,22 +886,41 @@ export class EmailEngineClient {
|
|
|
649
886
|
}
|
|
650
887
|
|
|
651
888
|
if (!this.messages.length) {
|
|
652
|
-
messageList.innerHTML =
|
|
889
|
+
messageList.innerHTML = `
|
|
890
|
+
<div class="ee-pane-header">
|
|
891
|
+
<span class="ee-pane-title">Messages</span>
|
|
892
|
+
</div>
|
|
893
|
+
<div class="ee-empty-state">No messages</div>
|
|
894
|
+
`;
|
|
653
895
|
return;
|
|
654
896
|
}
|
|
655
897
|
|
|
656
|
-
const
|
|
657
|
-
this.nextPageCursor || this.prevPageCursor
|
|
658
|
-
? `
|
|
659
|
-
<div class="ee-pagination">
|
|
660
|
-
${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
|
|
661
|
-
${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
|
|
662
|
-
</div>
|
|
663
|
-
`
|
|
664
|
-
: '';
|
|
898
|
+
const hasPagination = this.nextPageCursor || this.prevPageCursor;
|
|
665
899
|
|
|
666
900
|
const html = `
|
|
667
|
-
|
|
901
|
+
<div class="ee-pane-header">
|
|
902
|
+
<span class="ee-pane-title">Messages</span>
|
|
903
|
+
<div class="ee-pagination-controls">
|
|
904
|
+
${
|
|
905
|
+
hasPagination
|
|
906
|
+
? `
|
|
907
|
+
${this.prevPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="prev-page">← Previous</button>` : ''}
|
|
908
|
+
${this.nextPageCursor ? `<button class="ee-button ee-pagination-btn" data-action="next-page">Next →</button>` : ''}
|
|
909
|
+
`
|
|
910
|
+
: ''
|
|
911
|
+
}
|
|
912
|
+
<div class="ee-page-size-selector">
|
|
913
|
+
<span class="ee-page-size-label">Show:</span>
|
|
914
|
+
<select class="ee-page-size-select" data-action="page-size">
|
|
915
|
+
<option value="10" ${this.pageSize === 10 ? 'selected' : ''}>10</option>
|
|
916
|
+
<option value="20" ${this.pageSize === 20 ? 'selected' : ''}>20</option>
|
|
917
|
+
<option value="30" ${this.pageSize === 30 ? 'selected' : ''}>30</option>
|
|
918
|
+
<option value="50" ${this.pageSize === 50 ? 'selected' : ''}>50</option>
|
|
919
|
+
<option value="100" ${this.pageSize === 100 ? 'selected' : ''}>100</option>
|
|
920
|
+
</select>
|
|
921
|
+
</div>
|
|
922
|
+
</div>
|
|
923
|
+
</div>
|
|
668
924
|
<div class="ee-message-items">
|
|
669
925
|
${this.messages
|
|
670
926
|
.map(
|
|
@@ -674,14 +930,16 @@ export class EmailEngineClient {
|
|
|
674
930
|
<span class="ee-message-from">${msg.from ? msg.from.name || msg.from.address : 'Unknown'}</span>
|
|
675
931
|
<span class="ee-message-date">${this.formatDate(msg.date)}</span>
|
|
676
932
|
</div>
|
|
677
|
-
<div class="ee-message-subject"
|
|
933
|
+
<div class="ee-message-subject">
|
|
934
|
+
<span class="ee-message-subject-text">${msg.subject || '(no subject)'}</span>
|
|
935
|
+
${msg.attachments && msg.attachments.length > 0 ? `<span class="ee-attachment-indicator">${msg.attachments.length}</span>` : ''}
|
|
936
|
+
</div>
|
|
678
937
|
<div class="ee-message-preview">${msg.intro || ''}</div>
|
|
679
938
|
</div>
|
|
680
939
|
`
|
|
681
940
|
)
|
|
682
941
|
.join('')}
|
|
683
942
|
</div>
|
|
684
|
-
${paginationHtml}
|
|
685
943
|
`;
|
|
686
944
|
messageList.innerHTML = html;
|
|
687
945
|
|
|
@@ -703,6 +961,18 @@ export class EmailEngineClient {
|
|
|
703
961
|
this.loadMessages(this.currentFolder, this.nextPageCursor);
|
|
704
962
|
});
|
|
705
963
|
});
|
|
964
|
+
|
|
965
|
+
const pageSizeSelect = messageList.querySelector('[data-action="page-size"]');
|
|
966
|
+
if (pageSizeSelect) {
|
|
967
|
+
pageSizeSelect.addEventListener('change', e => {
|
|
968
|
+
this.pageSize = parseInt(e.target.value);
|
|
969
|
+
// Save to localStorage
|
|
970
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
971
|
+
localStorage.setItem('ee-client-page-size', this.pageSize.toString());
|
|
972
|
+
}
|
|
973
|
+
this.loadMessages(this.currentFolder);
|
|
974
|
+
});
|
|
975
|
+
}
|
|
706
976
|
}
|
|
707
977
|
|
|
708
978
|
renderMessage() {
|
|
@@ -726,6 +996,7 @@ export class EmailEngineClient {
|
|
|
726
996
|
<div class="ee-message-actions">
|
|
727
997
|
<button class="ee-button" data-action="toggle-read">Mark as ${isUnseen ? 'seen' : 'unseen'}</button>
|
|
728
998
|
<button class="ee-button" data-action="delete">Delete</button>
|
|
999
|
+
<button class="ee-button" data-action="download-original">Download Original</button>
|
|
729
1000
|
<select class="ee-button" data-action="move">
|
|
730
1001
|
<option value="">Move to...</option>
|
|
731
1002
|
${this.buildFolderTree()
|
|
@@ -770,6 +1041,28 @@ export class EmailEngineClient {
|
|
|
770
1041
|
<div class="ee-message-body">
|
|
771
1042
|
${msg.text && msg.text.html ? msg.text.html : msg.text && msg.text.plain ? `<pre>${msg.text.plain}</pre>` : ''}
|
|
772
1043
|
</div>
|
|
1044
|
+
${
|
|
1045
|
+
msg.attachments && msg.attachments.length > 0
|
|
1046
|
+
? `
|
|
1047
|
+
<div class="ee-attachments">
|
|
1048
|
+
<div class="ee-attachments-title">Attachments (${msg.attachments.length})</div>
|
|
1049
|
+
${msg.attachments
|
|
1050
|
+
.map(
|
|
1051
|
+
att => `
|
|
1052
|
+
<div class="ee-attachment-item" data-attachment-id="${att.id}">
|
|
1053
|
+
<div class="ee-attachment-icon">📎</div>
|
|
1054
|
+
<div class="ee-attachment-info">
|
|
1055
|
+
<div class="ee-attachment-name">${att.filename || 'Unnamed attachment'}</div>
|
|
1056
|
+
${att.size ? `<div class="ee-attachment-size">${this.formatFileSize(att.size)}</div>` : ''}
|
|
1057
|
+
</div>
|
|
1058
|
+
</div>
|
|
1059
|
+
`
|
|
1060
|
+
)
|
|
1061
|
+
.join('')}
|
|
1062
|
+
</div>
|
|
1063
|
+
`
|
|
1064
|
+
: ''
|
|
1065
|
+
}
|
|
773
1066
|
</div>
|
|
774
1067
|
`;
|
|
775
1068
|
viewer.innerHTML = html;
|
|
@@ -785,12 +1078,25 @@ export class EmailEngineClient {
|
|
|
785
1078
|
}
|
|
786
1079
|
});
|
|
787
1080
|
|
|
1081
|
+
viewer.querySelector('[data-action="download-original"]').addEventListener('click', () => {
|
|
1082
|
+
this.downloadOriginalMessage(msg.id, msg.subject);
|
|
1083
|
+
});
|
|
1084
|
+
|
|
788
1085
|
viewer.querySelector('[data-action="move"]').addEventListener('change', e => {
|
|
789
1086
|
const targetPath = e.target.value;
|
|
790
1087
|
if (targetPath) {
|
|
791
1088
|
this.moveMessage(msg.id, targetPath);
|
|
792
1089
|
}
|
|
793
1090
|
});
|
|
1091
|
+
|
|
1092
|
+
// Add click handlers for attachments
|
|
1093
|
+
viewer.querySelectorAll('.ee-attachment-item').forEach(item => {
|
|
1094
|
+
item.addEventListener('click', () => {
|
|
1095
|
+
const attachmentId = item.getAttribute('data-attachment-id');
|
|
1096
|
+
const attachment = msg.attachments.find(a => a.id === attachmentId);
|
|
1097
|
+
this.downloadAttachment(attachmentId, attachment ? attachment.filename : null);
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
794
1100
|
}
|
|
795
1101
|
|
|
796
1102
|
createLayout() {
|
|
@@ -801,9 +1107,17 @@ export class EmailEngineClient {
|
|
|
801
1107
|
this.container.innerHTML = `
|
|
802
1108
|
<div class="ee-client">
|
|
803
1109
|
<div class="ee-sidebar">
|
|
804
|
-
<div class="ee-
|
|
1110
|
+
<div class="ee-pane-header">
|
|
1111
|
+
<span class="ee-pane-title">Folders</span>
|
|
1112
|
+
</div>
|
|
1113
|
+
<div class="ee-folder-tree">
|
|
1114
|
+
<div class="ee-loading">Loading folders...</div>
|
|
1115
|
+
</div>
|
|
805
1116
|
</div>
|
|
806
1117
|
<div class="ee-message-list">
|
|
1118
|
+
<div class="ee-pane-header">
|
|
1119
|
+
<span class="ee-pane-title">Messages</span>
|
|
1120
|
+
</div>
|
|
807
1121
|
<div class="ee-empty-state">Select a folder</div>
|
|
808
1122
|
</div>
|
|
809
1123
|
<div class="ee-message-viewer">
|
|
@@ -821,16 +1135,19 @@ export class EmailEngineClient {
|
|
|
821
1135
|
|
|
822
1136
|
this.createStyles();
|
|
823
1137
|
this.createLayout();
|
|
824
|
-
this.loadFolders()
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1138
|
+
this.loadFolders()
|
|
1139
|
+
.then(() => {
|
|
1140
|
+
const inbox =
|
|
1141
|
+
this.folders.find(f => f.specialUse && f.specialUse.includes('\\Inbox')) ||
|
|
1142
|
+
this.folders.find(f => f.name.toLowerCase() === 'inbox') ||
|
|
1143
|
+
this.folders[0];
|
|
1144
|
+
if (inbox) {
|
|
1145
|
+
this.loadMessages(inbox.path);
|
|
1146
|
+
}
|
|
1147
|
+
})
|
|
1148
|
+
.catch(error => {
|
|
1149
|
+
console.error('Failed to auto-select inbox:', error);
|
|
1150
|
+
});
|
|
834
1151
|
}
|
|
835
1152
|
}
|
|
836
1153
|
|