11import { Component , Prop , h } from '@stencil/core' ;
22import translate from '../../global/translations' ;
33import { Languages } from '../date-picker/date.types' ;
4+ import { EmailAttachment } from '../../util/email' ;
5+ import { formatBytes } from '../../util/format-bytes' ;
46
57/**
68 * This is a private component, used to render `.eml` files inside
@@ -63,6 +65,12 @@ export class EmailViewer {
6365 @Prop ( )
6466 public bodyText ?: string ;
6567
68+ /**
69+ * List of non-inline attachments.
70+ */
71+ @Prop ( )
72+ public attachments ?: EmailAttachment [ ] ;
73+
6674 /**
6775 * Optional URL to render as a final fallback using an `<object type="text/plain">`.
6876 */
@@ -112,6 +120,7 @@ export class EmailViewer {
112120 this . getTranslation ( 'file-viewer.email.date' ) ,
113121 this . date
114122 ) }
123+ { this . renderAttachments ( ) }
115124 </ div >
116125 ) ;
117126 }
@@ -156,8 +165,8 @@ export class EmailViewer {
156165 return (
157166 < dl class = { `headers ${ type } ` } >
158167 < dt > { label } </ dt >
159- { values . map ( ( v ) => (
160- < dd > { v } </ dd >
168+ { values . map ( ( headerValue , index ) => (
169+ < dd key = { ` ${ type } - ${ index } ` } > { headerValue } </ dd >
161170 ) ) }
162171 </ dl >
163172 ) ;
@@ -170,13 +179,52 @@ export class EmailViewer {
170179 if ( type === 'to' || type === 'cc' ) {
171180 return value
172181 . split ( ',' )
173- . map ( ( v ) => v . trim ( ) )
182+ . map ( ( valuePart ) => valuePart . trim ( ) )
174183 . filter ( Boolean ) ;
175184 }
176185
177186 return [ value ] ;
178187 }
179188
189+ private renderAttachments ( ) {
190+ if ( ! this . attachments || this . attachments . length === 0 ) {
191+ return ;
192+ }
193+
194+ const label = this . getTranslation ( 'file-viewer.email.attachments' ) ;
195+
196+ return (
197+ < div class = "attachments" >
198+ < span > { label } </ span >
199+ < ul >
200+ { this . attachments . map ( ( attachment , index ) => (
201+ < li key = { `attachment-${ index } ` } >
202+ < span class = "attachment-filename" >
203+ { attachment . filename ?. trim ( ) ||
204+ this . getTranslation (
205+ 'file-viewer.email.attachment.unnamed'
206+ ) }
207+ </ span >
208+ < span class = "attachment-mime-type" >
209+ { attachment . mimeType ?. trim ( ) }
210+ </ span >
211+ { this . renderSizeBadge ( attachment . size ) }
212+ </ li >
213+ ) ) }
214+ </ ul >
215+ </ div >
216+ ) ;
217+ }
218+
219+ private renderSizeBadge ( size : number ) {
220+ if ( typeof size !== 'number' ) {
221+ return ;
222+ }
223+ return (
224+ < limel-badge class = "attachment-size" label = { formatBytes ( size ) } />
225+ ) ;
226+ }
227+
180228 private getTranslation ( key : string ) {
181229 return translate . get ( key , this . language ) ;
182230 }
0 commit comments