Skip to content

Commit

Permalink
Fix support for Conversations add-on in Thunderbird 115 and later (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Oct 22, 2023
1 parent 0bf905c commit 8ce2309
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ All notable changes to this project will be documented in this file.
- Don't save DKIM results that contain a temporary error.
- Show proper error message if parsing of a message failed.

### Fixes

- Fixed support for Thunderbird Conversations add-on in Thunderbird 115 and later (#395).

### Other

- Added Polish translation (by dMbski) (#392).
Expand Down
8 changes: 4 additions & 4 deletions content/background.mjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
///<reference path="../experiments/dkimHeader.d.ts" />
/* eslint-env webextensions */

import * as Conversations from "../modules/conversation.mjs.js";
import KeyStore, { KeyDb } from "../modules/dkim/keyStore.mjs.js";
import SignRules, { initSignRulesProxy } from "../modules/dkim/signRules.mjs.js";
import { migrateKeyStore, migratePrefs, migrateSignRulesUser } from "../modules/migration.mjs.js";
import AuthVerifier from "../modules/authVerifier.mjs.js";
import Logging from "../modules/logging.mjs.js";
import MsgParser from "../modules/msgParser.mjs.js";
import prefs from "../modules/preferences.mjs.js";
import verifyMessageForConversation from "../modules/conversation.mjs.js";

const log = Logging.getLogger("background");

Expand Down Expand Up @@ -156,7 +156,7 @@ browser.messageDisplay.onMessageDisplayed.addListener(async (tab, message) => {
}
try {
await isInitialized;
if (tab.url?.startsWith("chrome://conversations/")) {
if (await Conversations.isConversationView(tab)) {
// Conversation view is handled in onMessagesDisplayed
return;
}
Expand Down Expand Up @@ -201,9 +201,9 @@ browser.messageDisplay.onMessageDisplayed.addListener(async (tab, message) => {
browser.messageDisplay.onMessagesDisplayed.addListener(async (tab, messages) => {
try {
await isInitialized;
if (tab.url?.startsWith("chrome://conversations/")) {
if (await Conversations.isConversationView(tab)) {
for (const message of messages) {
await verifyMessageForConversation(message);
await Conversations.verifyMessage(message);
}
}
// Normal Thunderbird view ("classic") is handled in onMessageDisplayed
Expand Down
1 change: 1 addition & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"accountsRead",
"downloads",
"messagesRead",
"management",
"notifications",
"storage",
"tabs"
Expand Down
36 changes: 31 additions & 5 deletions modules/conversation.mjs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Push the authentication result to the Conversation add-on.
* Push the authentication result to the Conversations add-on.
*
* Copyright (c) 2021-2023 Philippe Lieser
*
Expand Down Expand Up @@ -35,7 +35,7 @@ const log = Logging.getLogger("Conversation");
let port = null;

/**
* Add a pill in Conversation.
* Add a pill in Conversations.
*
* @param {number} msgId
* @param {Severity|undefined} severity
Expand All @@ -57,7 +57,7 @@ function addPill(msgId, severity, icon, message, tooltip) {
if (!port) {
port = browser.runtime.connect("gconversation@xulforum.org");
port.onDisconnect.addListener((p) => {
log.debug("Port to Conversation was disconnected", p.error);
log.debug("Port to Conversations was disconnected", p.error);
port = null;
});
}
Expand All @@ -67,12 +67,38 @@ function addPill(msgId, severity, icon, message, tooltip) {
const verifier = new AuthVerifier();

/**
* Verify a message and display the result in Conversation.
* Detect if a Tab shows message in Conversations message view style.
*
* @param {browser.tabs.Tab} tab
* @returns {Promise<boolean>}
*/
export async function isConversationView(tab) {
if (tab.url?.startsWith("chrome://conversations/")) {
// TB < 115
return true;
}
// Messages opened in Thunderbirds main 3pane tab have type "mail",
// and are shown in Conversations message view style (if Conversations add-on is installed).
// Single messages opened in a tab or windows have type "messageDisplay",
// and are always shown in Thunderbird's normal message view style.
if (tab.type === "mail") {
try {
const conversationsInfo = await browser.management.get("gconversation@xulforum.org");
return conversationsInfo.enabled;
} catch (error) {
// Conversations not installed
}
}
return false;
}

/**
* Verify a message and display the result in Conversations.
*
* @param {browser.messages.MessageHeader} MessageHeader
* @returns {Promise<void>}
*/
export default async function verifyMessage(MessageHeader) {
export async function verifyMessage(MessageHeader) {
const res = await verifier.verify(MessageHeader);
if (!res.dkim[0]) {
throw new Error("Result does not contain a DKIM result.");
Expand Down

0 comments on commit 8ce2309

Please sign in to comment.