33'use strict' ;
44
55import { Backend , FcUuidAuth } from '../../../../js/common/api/backend.js' ;
6- import { BaseMailFormatter } from './base-mail-formatter.js' ;
7- import { ComposerResetBtnTrigger } from '../compose-err-module.js' ;
86import { Mime , SendableMsgBody } from '../../../../js/common/core/mime.js' ;
97import { NewMsgData , PubkeyResult } from '../compose-types.js' ;
108import { Str , Value } from '../../../../js/common/core/common.js' ;
9+
10+ import { AcctStore } from '../../../../js/common/platform/store/acct-store.js' ;
1111import { ApiErr } from '../../../../js/common/api/error/api-error.js' ;
1212import { Att } from '../../../../js/common/core/att.js' ;
13+ import { BaseMailFormatter } from './base-mail-formatter.js' ;
1314import { Buf } from '../../../../js/common/core/buf.js' ;
1415import { Catch } from '../../../../js/common/platform/catch.js' ;
16+ import { ComposerResetBtnTrigger } from '../compose-err-module.js' ;
17+ import { ContactStore } from '../../../../js/common/platform/store/contact-store.js' ;
1518import { Lang } from '../../../../js/common/lang.js' ;
1619import { PgpKey } from '../../../../js/common/core/pgp-key.js' ;
1720import { PgpMsg } from '../../../../js/common/core/pgp-msg.js' ;
@@ -20,8 +23,6 @@ import { Settings } from '../../../../js/common/settings.js';
2023import { Ui } from '../../../../js/common/browser/ui.js' ;
2124import { Xss } from '../../../../js/common/platform/xss.js' ;
2225import { opgp } from '../../../../js/common/core/pgp.js' ;
23- import { ContactStore } from '../../../../js/common/platform/store/contact-store.js' ;
24- import { AcctStore } from '../../../../js/common/platform/store/acct-store.js' ;
2526
2627export class EncryptedMsgMailFormatter extends BaseMailFormatter {
2728
@@ -43,7 +44,7 @@ export class EncryptedMsgMailFormatter extends BaseMailFormatter {
4344 const authInfo = await AcctStore . authInfo ( this . acctEmail ) ;
4445 const msgBodyWithReplyToken = await this . getPwdMsgSendableBodyWithOnlineReplyMsgToken ( authInfo , newMsg ) ;
4546 const pgpMimeWithAtts = await Mime . encode ( msgBodyWithReplyToken , { Subject : newMsg . subject } , await this . view . attsModule . attach . collectAtts ( ) ) ;
46- const pwdEncryptedWithAtts = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeWithAtts ) , newMsg . pwd , [ ] ) ; // encrypted only for pwd, not signed
47+ const { buffer : pwdEncryptedWithAtts } = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeWithAtts ) , newMsg . pwd , [ ] ) ; // encrypted only for pwd, not signed
4748 const { short, admin_code } = await Backend . messageUpload (
4849 authInfo . uuid ? authInfo : undefined ,
4950 pwdEncryptedWithAtts ,
@@ -57,23 +58,24 @@ export class EncryptedMsgMailFormatter extends BaseMailFormatter {
5758 // encoded as: PGP/MIME-like structure but with attachments as external files due to email size limit (encrypted for pubkeys only)
5859 const msgBody = this . richtext ? { 'text/plain' : newMsg . plaintext , 'text/html' : newMsg . plainhtml } : { 'text/plain' : newMsg . plaintext } ;
5960 const pgpMimeNoAtts = await Mime . encode ( msgBody , { Subject : newMsg . subject } , [ ] ) ; // no atts, attached to email separately
60- const pubEncryptedNoAtts = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeNoAtts ) , undefined , pubs , signingPrv ) ; // encrypted only for pubs
61+ const { buffer : pubEncryptedNoAtts } = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeNoAtts ) , undefined , pubs , signingPrv ) ; // encrypted only for pubs
6162 const atts = this . createPgpMimeAtts ( pubEncryptedNoAtts ) . concat ( await this . view . attsModule . attach . collectEncryptAtts ( pubs . map ( p => p . pubkey ) ) ) ; // encrypted only for pubs
6263 const emailIntroAndLinkBody = await this . formatPwdEncryptedMsgBodyLink ( short ) ;
6364 return await SendableMsg . create ( this . acctEmail , { ...this . headers ( newMsg ) , body : emailIntroAndLinkBody , atts, isDraft : this . isDraft } ) ;
6465 }
6566
6667 private sendableSimpleTextMsg = async ( newMsg : NewMsgData , pubs : PubkeyResult [ ] , signingPrv ?: OpenPGP . key . Key ) => {
6768 const atts = this . isDraft ? [ ] : await this . view . attsModule . attach . collectEncryptAtts ( pubs . map ( p => p . pubkey ) ) ;
68- const encrypted = await this . encryptDataArmor ( Buf . fromUtfStr ( newMsg . plaintext ) , undefined , pubs , signingPrv ) ;
69+ const { buffer : encrypted , rawHeaders } = await this . encryptDataArmor ( Buf . fromUtfStr ( newMsg . plaintext ) , undefined , pubs , signingPrv ) ;
70+ console . log ( rawHeaders ) ;
6971 const encryptedBody = { 'text/plain' : encrypted . toString ( ) } ;
70- return await SendableMsg . create ( this . acctEmail , { ...this . headers ( newMsg ) , body : encryptedBody , atts, isDraft : this . isDraft } ) ;
72+ return await SendableMsg . create ( this . acctEmail , { ...this . headers ( newMsg ) , body : encryptedBody , atts, isDraft : this . isDraft , rawHeaders } ) ;
7173 }
7274
7375 private sendableRichTextMsg = async ( newMsg : NewMsgData , pubs : PubkeyResult [ ] , signingPrv ?: OpenPGP . key . Key ) => {
7476 const plainAtts = this . isDraft ? [ ] : await this . view . attsModule . attach . collectAtts ( ) ;
7577 const pgpMimeToEncrypt = await Mime . encode ( { 'text/plain' : newMsg . plaintext , 'text/html' : newMsg . plainhtml } , { Subject : newMsg . subject } , plainAtts ) ;
76- const encrypted = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeToEncrypt ) , undefined , pubs , signingPrv ) ;
78+ const { buffer : encrypted } = await this . encryptDataArmor ( Buf . fromUtfStr ( pgpMimeToEncrypt ) , undefined , pubs , signingPrv ) ;
7779 const atts = this . createPgpMimeAtts ( encrypted ) ;
7880 return await SendableMsg . create ( this . acctEmail , { ...this . headers ( newMsg ) , body : { } , atts, type : 'pgpMimeEncrypted' , isDraft : this . isDraft } ) ;
7981 }
@@ -85,10 +87,11 @@ export class EncryptedMsgMailFormatter extends BaseMailFormatter {
8587 return atts ;
8688 }
8789
88- private encryptDataArmor = async ( data : Buf , pwd : string | undefined , pubs : PubkeyResult [ ] , signingPrv ?: OpenPGP . key . Key ) : Promise < Uint8Array > => {
89- const encryptAsOfDate = await this . encryptMsgAsOfDateIfSomeAreExpiredAndUserConfirmedModal ( pubs ) ;
90+ private encryptDataArmor = async ( data : Buf , pwd : string | undefined , pubs : PubkeyResult [ ] , signingPrv ?: OpenPGP . key . Key ) : Promise < { buffer : Uint8Array , rawHeaders : { [ key : string ] : string } } > => {
91+ // IMPORTANT
92+ const encryptAsOfDate = await this . encryptMsgAsOfDateIfSomeAreExpiredAndUserConfirmedModal ( [ ] ) ;
9093 const r = await PgpMsg . encrypt ( { pubkeys : pubs . map ( p => p . pubkey ) , signingPrv, pwd, data, armor : true , date : encryptAsOfDate } ) as OpenPGP . EncryptArmorResult ;
91- return Buf . fromUtfStr ( r . data ) ;
94+ return { buffer : Buf . fromUtfStr ( r . data ) , rawHeaders : r . headers || { } } ;
9295 }
9396
9497 private getPwdMsgSendableBodyWithOnlineReplyMsgToken = async ( authInfo : FcUuidAuth , newMsgData : NewMsgData ) : Promise < SendableMsgBody > => {
0 commit comments