@@ -31,25 +31,27 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
3131 public handleThunderbirdMessageParsing = async ( ) => {
3232 const emailBodyToParse = $ ( 'div.moz-text-plain' ) . text ( ) . trim ( ) || $ ( 'div.moz-text-html' ) . text ( ) . trim ( ) ;
3333 if ( Catch . isThunderbirdMail ( ) ) {
34- const pgpRegex = / - - - - - B E G I N P G P M E S S A G E - - - - - ( .* ?) - - - - - E N D P G P M E S S A G E - - - - - / s;
35- const pgpRegexMatch = new RegExp ( pgpRegex ) . exec ( emailBodyToParse ) ;
3634 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3735 this . acctEmail = ( await BrowserMsg . send . bg . await . thunderbirdGetCurrentUser ( ) ) ! ;
3836 const parsedPubs = ( await ContactStore . getOneWithAllPubkeys ( undefined , this . acctEmail ) ) ?. sortedPubkeys ?? [ ] ;
3937 const signerKeys = parsedPubs . map ( key => KeyUtil . armor ( key . pubkey ) ) ;
40- if ( pgpRegexMatch && this . resemblesAsciiArmoredMsg ( pgpRegexMatch [ 0 ] ) ) {
38+ if ( this . resemblesAsciiArmoredMsg ( emailBodyToParse ) ) {
4139 await this . messageDecrypt ( signerKeys , this . emailBodyFromThunderbirdMail ) ;
4240 } else if ( this . resemblesSignedMsg ( emailBodyToParse ) ) {
4341 await this . messageVerify ( signerKeys ) ;
4442 }
4543 const fcAttachments = await BrowserMsg . send . bg . await . thunderbirdGetDownloadableAttachment ( ) ;
46- for ( const fcAttachment of fcAttachments ) {
47- await this . attachmentUiRenderer ( fcAttachment , signerKeys , emailBodyToParse ) ;
44+ if ( fcAttachments . length ) {
45+ for ( const fcAttachment of fcAttachments ) {
46+ await this . attachmentUiRenderer ( fcAttachment , signerKeys , emailBodyToParse ) ;
47+ }
4848 }
49+ $ ( 'body' ) . show ( ) ;
4950 }
5051 } ;
5152
5253 private messageDecrypt = async ( verificationPubs : string [ ] , encryptedData : string | Buf ) => {
54+ $ ( 'body' ) . hide ( ) ;
5355 const result = await MsgUtil . decryptMessage ( {
5456 kisWithPp : await KeyStore . getAllWithOptionalPassPhrase ( this . acctEmail ) ,
5557 encryptedData,
@@ -87,6 +89,7 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
8789 } ;
8890
8991 private messageVerify = async ( verificationPubs : string [ ] , detachedSignatureParams ?: { plaintext : string ; sigText : string } ) => {
92+ $ ( 'body' ) . hide ( ) ;
9093 let result : VerifyRes ;
9194 if ( ! detachedSignatureParams ) {
9295 const message = await openpgp . readCleartextMessage ( { cleartextMessage : this . emailBodyFromThunderbirdMail } ) ;
@@ -188,7 +191,12 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
188191 } ;
189192
190193 private resemblesAsciiArmoredMsg = ( body : string ) : boolean => {
191- this . emailBodyFromThunderbirdMail = body ;
192- return body . startsWith ( PgpArmor . ARMOR_HEADER_DICT . encryptedMsg . begin ) && body . endsWith ( PgpArmor . ARMOR_HEADER_DICT . encryptedMsg . end as string ) ;
194+ const pgpRegex = / - - - - - B E G I N P G P M E S S A G E - - - - - ( .* ?) - - - - - E N D P G P M E S S A G E - - - - - / s;
195+ const pgpRegexMatch = new RegExp ( pgpRegex ) . exec ( body ) ;
196+ if ( pgpRegexMatch ?. [ 0 ] ) {
197+ this . emailBodyFromThunderbirdMail = pgpRegexMatch [ 0 ] ;
198+ return true ;
199+ }
200+ return false ;
193201 } ;
194202}
0 commit comments