@@ -19,6 +19,7 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
1919 public reinsertReplyBox : ( replyMsgId : string ) => void ;
2020 public scrollToReplyBox : ( replyMsgId : string ) => void ;
2121 public scrollToCursorInReplyBox : ( replyMsgId : string , cursorOffsetTop : number ) => void ;
22+ private acctEmail : string ;
2223 private emailBodyFromThunderbirdMail : string ;
2324 private thunderbirdEmailSelector = $ ( 'div.moz-text-plain' ) ;
2425
@@ -32,12 +33,13 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
3233 if ( ! messagePart ) {
3334 return ;
3435 } else {
35- const acctEmail = await BrowserMsg . send . bg . await . thunderbirdGetCurrentUser ( ) ;
36- const parsedPubs = ( await ContactStore . getOneWithAllPubkeys ( undefined , String ( acctEmail ) ) ) ?. sortedPubkeys ?? [ ] ;
36+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37+ this . acctEmail = ( await BrowserMsg . send . bg . await . thunderbirdGetCurrentUser ( ) ) ! ;
38+ const parsedPubs = ( await ContactStore . getOneWithAllPubkeys ( undefined , this . acctEmail ) ) ?. sortedPubkeys ?? [ ] ;
3739 const signerKeys = parsedPubs . map ( key => KeyUtil . armor ( key . pubkey ) ) ;
3840 if ( this . isPublicKeyEncryptedMsg ( ) ) {
3941 const result = await MsgUtil . decryptMessage ( {
40- kisWithPp : await KeyStore . getAllWithOptionalPassPhrase ( String ( acctEmail ) ) ,
42+ kisWithPp : await KeyStore . getAllWithOptionalPassPhrase ( this . acctEmail ) ,
4143 encryptedData : this . emailBodyFromThunderbirdMail ,
4244 verificationPubs : signerKeys ,
4345 } ) ;
@@ -70,6 +72,15 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
7072 const pgpBlock = this . generatePgpBlockTemplate ( decryptionErrorMsg , 'not signed' , this . emailBodyFromThunderbirdMail ) ;
7173 $ ( 'body' ) . html ( pgpBlock ) ; // xss-sanitized
7274 }
75+ if ( ! attachments . length ) {
76+ return ;
77+ } else {
78+ for ( const attachment of attachments ) {
79+ const generatedPgpTemplate = this . generatePgpAttachmentTemplate ( attachment ) ;
80+ $ ( '.pgp_attachments_block' ) . append ( generatedPgpTemplate ) ; // xss-sanitized
81+ // todo: detached signed message via https://github.com/FlowCrypt/flowcrypt-browser/issues/5668
82+ }
83+ }
7384 } else if ( this . isCleartextMsg ( ) ) {
7485 const message = await openpgp . readCleartextMessage ( { cleartextMessage : this . emailBodyFromThunderbirdMail } ) ;
7586 const result = await OpenPGPKey . verify ( message , await ContactStore . getPubkeyInfos ( undefined , signerKeys ) ) ;
@@ -85,15 +96,6 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
8596 $ ( 'body' ) . html ( pgpBlock ) ; // xss-sanitized
8697 }
8798 }
88- if ( ! attachments . length ) {
89- return ;
90- } else {
91- for ( const attachment of attachments ) {
92- const generatedPgpTemplate = this . generatePgpAttachmentTemplate ( attachment ) ;
93- $ ( '.pgp_attachments_block' ) . append ( generatedPgpTemplate ) ; // xss-sanitized
94- // todo: detached signed message via https://github.com/FlowCrypt/flowcrypt-browser/issues/5668
95- }
96- }
9799 }
98100 } ;
99101
@@ -129,7 +131,25 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
129131 } ;
130132
131133 private downloadThunderbirdAttachmentHandler = async ( attachment : messenger . messages . MessageAttachment ) => {
132- await BrowserMsg . send . bg . await . thunderbirdAttachmentDownload ( { attachment } ) ;
134+ const flowCryptAttachment = await BrowserMsg . send . bg . await . thunderbirdGetDownloadableAttachment ( { attachment } ) ;
135+ if ( flowCryptAttachment ) {
136+ const result = await MsgUtil . decryptMessage ( {
137+ kisWithPp : await KeyStore . getAllWithOptionalPassPhrase ( this . acctEmail ) ,
138+ encryptedData : this . emailBodyFromThunderbirdMail ,
139+ verificationPubs : [ ] , // todo: #4158 signature verification of attachments
140+ } ) ;
141+ if ( result . success && result . content ) {
142+ console . log ( 'debug: download me' ) ;
143+ // todo - create separate background message for download prompt and file download
144+ // const fileUrl = URL.createObjectURL(rawAttachment);
145+ // await browser.downloads.download({
146+ // url: fileUrl,
147+ // filename: r.attachment.name,
148+ // saveAs: true,
149+ // });
150+ // URL.revokeObjectURL(fileUrl);
151+ }
152+ }
133153 } ;
134154
135155 private isCleartextMsg = ( ) : boolean => {
0 commit comments