Skip to content

Commit 0bdd951

Browse files
committed
simplified detection for ASCII armored data
1 parent 79e807d commit 0bdd951

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

extension/js/content_scripts/webmail/thunderbird/thunderbird-element-replacer.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
2020
public scrollToReplyBox: (replyMsgId: string) => void;
2121
public scrollToCursorInReplyBox: (replyMsgId: string, cursorOffsetTop: number) => void;
2222
private emailBodyFromThunderbirdMail: string;
23+
private thunderbirdEmailSelector = $('div.moz-text-plain');
2324

2425
public getIntervalFunctions = (): IntervalFunction[] => {
2526
return [{ interval: 2000, handler: () => this.replaceThunderbirdMsgPane() }];
@@ -34,7 +35,7 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
3435
const acctEmail = await BrowserMsg.send.bg.await.thunderbirdGetCurrentUser();
3536
const parsedPubs = (await ContactStore.getOneWithAllPubkeys(undefined, String(acctEmail)))?.sortedPubkeys ?? [];
3637
const signerKeys = parsedPubs.map(key => KeyUtil.armor(key.pubkey));
37-
if (this.isPublicKeyEncryptedMsg(messagePart)) {
38+
if (this.isPublicKeyEncryptedMsg()) {
3839
const result = await MsgUtil.decryptMessage({
3940
kisWithPp: await KeyStore.getAllWithOptionalPassPhrase(String(acctEmail)),
4041
encryptedData: this.emailBodyFromThunderbirdMail,
@@ -69,7 +70,7 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
6970
const pgpBlock = this.generatePgpBlockTemplate(decryptionErrorMsg, 'not signed', this.emailBodyFromThunderbirdMail);
7071
$('body').html(pgpBlock); // xss-sanitized
7172
}
72-
} else if (this.isCleartextMsg(messagePart)) {
73+
} else if (this.isCleartextMsg()) {
7374
const message = await openpgp.readCleartextMessage({ cleartextMessage: this.emailBodyFromThunderbirdMail });
7475
const result = await OpenPGPKey.verify(message, await ContactStore.getPubkeyInfos(undefined, signerKeys));
7576
let verificationStatus = '';
@@ -120,16 +121,9 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
120121
`;
121122
};
122123

123-
private isCleartextMsg = (messagePart: messenger.messages.MessagePart): boolean => {
124-
return (
125-
(messagePart.headers &&
126-
'openpgp' in messagePart.headers &&
127-
messagePart.parts &&
128-
messagePart.parts[0]?.parts?.length === 1 &&
129-
messagePart.parts[0].parts[0].contentType === 'text/plain' &&
130-
this.resemblesCleartextMsg(messagePart.parts[0].parts[0].body?.trim() || '')) ||
131-
false
132-
);
124+
private isCleartextMsg = (): boolean => {
125+
const emailBody = this.thunderbirdEmailSelector.text().trim();
126+
return this.resemblesCleartextMsg(emailBody);
133127
};
134128

135129
private resemblesCleartextMsg = (body: string) => {
@@ -141,22 +135,9 @@ export class ThunderbirdElementReplacer extends WebmailElementReplacer {
141135
);
142136
};
143137

144-
private isPublicKeyEncryptedMsg = (messagePart: messenger.messages.MessagePart): boolean => {
145-
if (messagePart.headers && 'openpgp' in messagePart.headers && messagePart.parts) {
146-
return (
147-
(messagePart.parts[0]?.parts?.length === 2 &&
148-
messagePart.parts[0]?.parts[1].contentType === 'application/pgp-encrypted' &&
149-
this.resemblesAsciiArmoredMsg(messagePart.parts[0]?.parts[0].body?.trim() || '')) ||
150-
(messagePart.parts[0]?.parts?.length === 1 &&
151-
messagePart.parts[0]?.contentType === 'multipart/mixed' &&
152-
this.resemblesAsciiArmoredMsg(messagePart.parts[0]?.parts[0].body?.trim() || '')) ||
153-
(messagePart.parts.length === 1 &&
154-
messagePart.parts[0]?.contentType === 'text/plain' &&
155-
this.resemblesAsciiArmoredMsg(messagePart.parts[0]?.body?.trim() || '')) ||
156-
false
157-
);
158-
}
159-
return false;
138+
private isPublicKeyEncryptedMsg = (): boolean => {
139+
const emailBody = this.thunderbirdEmailSelector.text().trim();
140+
return this.resemblesAsciiArmoredMsg(emailBody);
160141
};
161142

162143
private resemblesAsciiArmoredMsg = (body: string): boolean => {

extension/js/content_scripts/webmail/thunderbird/thunderbird-webmail-startup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ThunderbirdWebmailStartup {
1919

2020
private start = async () => {
2121
this.replacer = new ThunderbirdElementReplacer();
22-
this.replacer.runIntervalFunctionsPeriodically();
22+
await this.replacer.replaceThunderbirdMsgPane();
2323
// todo: show notification using Thunderbird Notification as contentscript notification or such does not work.
2424
// await notifications.showInitial(acctEmail);
2525
// notifications.show(

0 commit comments

Comments
 (0)