From 22d7384b99088e83b50345a6db3a87e75f3a60c9 Mon Sep 17 00:00:00 2001
From: "Kamil Mankowski (kam193)"
Date: Wed, 11 Jan 2023 21:27:49 +0100
Subject: [PATCH] Fixed trying to sync removed accounts
Fix #5
---
signature-extension/background.js | 36 ++++++++++++++++++++----------
signature-extension/changelog.html | 7 ++++++
signature-extension/manifest.json | 2 +-
3 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/signature-extension/background.js b/signature-extension/background.js
index ab54867..325eca1 100644
--- a/signature-extension/background.js
+++ b/signature-extension/background.js
@@ -42,14 +42,16 @@ function refreshAccessTokenWithErrorCatching(refreshToken) {
},
});
return new Promise((resolve, reject) => {
- fetch(refreshRequest).then((response) => {
- if (response.status != 200) {
- reject("Cannot refresh access token");
- }
- response.json().then((json) => {
- resolve(json.access_token);
- });
- }).catch((error) => reject(error));
+ fetch(refreshRequest)
+ .then((response) => {
+ if (response.status != 200) {
+ reject("Cannot refresh access token");
+ }
+ response.json().then((json) => {
+ resolve(json.access_token);
+ });
+ })
+ .catch((error) => reject(error));
});
}
@@ -58,7 +60,7 @@ async function getUserSendAs(syncable) {
try {
let token = await refreshAccessTokenWithErrorCatching(syncable.refreshToken);
let settings = await makeRequest(token, dataUrl);
-
+
let sendAs = [];
settings.sendAs.forEach((alias) => {
sendAs.push({
@@ -111,6 +113,12 @@ async function syncAccounts() {
continue;
}
try {
+ let account = await browser.accounts.get(account_id, false);
+ if (account === null) {
+ console.warn(`The account ${account_id} doesn't exist anymore. Skipping sync...`);
+ continue;
+ }
+
let gmailSendAs = await getUserSendAs(syncable);
let aliasesByEmail = {};
gmailSendAs.forEach((alias) => {
@@ -119,8 +127,12 @@ async function syncAccounts() {
await ensureDefaultIdentitySyncable(syncable);
let identities = syncable.identitiesSyncable || {};
- Object.values(identities).forEach((identity) => {
- if (identity.gmailSendAsEmail != NONE_EMAIL) {
+
+ for (const identity of Object.values(identities)) {
+ let thunderbirdIdentity = await browser.identities.get(identity.identityId);
+ if (thunderbirdIdentity === null) {
+ console.warn(`The identity ${account_id} doesn't exist anymore. Skipping sync...`);
+ } else if (identity.gmailSendAsEmail != NONE_EMAIL) {
let alias = aliasesByEmail[identity.gmailSendAsEmail];
if (alias) {
console.log(
@@ -133,7 +145,7 @@ async function syncAccounts() {
console.error(error);
}
}
- });
+ }
// After trying sync all identities, throw last error if any
if (error) throw error;
diff --git a/signature-extension/changelog.html b/signature-extension/changelog.html
index 6d53127..b5aadc9 100644
--- a/signature-extension/changelog.html
+++ b/signature-extension/changelog.html
@@ -15,6 +15,13 @@ Welcome in the new version of Signature sync for Gmail!
only on first use and major changes, but you can always access it in add-on's preferences.
+ Version 3.1.0
+
+ -
+ Fixing trying to sync already removed from Thunderbird accounts or identities.
+
+
+
Version 3.0.0
-
diff --git a/signature-extension/manifest.json b/signature-extension/manifest.json
index e55a047..e1f6a69 100644
--- a/signature-extension/manifest.json
+++ b/signature-extension/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Signature sync for Gmail",
- "version": "3.0.0",
+ "version": "3.1.0",
"author": "Kamil MaĆkowski",
"description": "Sync your signatures with Gmail accounts",
"homepage_url": "https://thbrd-signature.kam193.eu/",