diff --git a/src/background.js b/src/background.js index c4b65f0..22813fd 100644 --- a/src/background.js +++ b/src/background.js @@ -9,6 +9,8 @@ let removeOnClassify = true; // Standardwert true const maxTokenCount = 10000; // Maximale Anzahl der Tokens in der Datenbank. let tagKeyToNameMap = {}; // Mapping von Tag-Key zu Tag-Name let tagNameToKeyMap = {}; // Mapping von Tag-Name zu Tag-Key +const lastCheckTimestamps = {}; // Stores the last check timestamp for each folder to optimize performance (in milliseconds) + // translate-Funktion zur Nutzung von i18n function trans(messageName, placeholders = []) { @@ -188,6 +190,14 @@ function initialize() { } }); + // Sheduler for updateUsageData + messenger.alarms.create("updateUsageDataAlarm", { periodInMinutes: 10 }); + messenger.alarms.onAlarm.addListener((alarm) => { + if (alarm.name === "updateUsageDataAlarm") { + updateUsageData(); + } + }); + }) .catch((error) => { console.error("Error during initialization:", error); @@ -441,9 +451,14 @@ function getMessageTags(messageId) { * @param {object} folder - Information about the displayed folder. */ +/** + * Handles the display of a folder and checks for new emails. + * @param {Object} tab - The mail tab object. + * @param {Object} folder - The folder object. + */ async function onFolderDisplayed(tab, folder) { - updateUsageData(); - + const CHECK_INTERVAL = 5 * 60 * 1000; // 5 minutes + console.debug("onFolderDisplayed") if (folder && folder.accountId && folder.path) { const accountId = folder.accountId; @@ -456,6 +471,16 @@ async function onFolderDisplayed(tab, folder) { try { const folderKey = `${accountId}:${folder.path}`; + // To optimize performance, skip the check if the last one occurred recently. + const now = Date.now(); + // Check the last time this folder was processed + const lastCheck = lastCheckTimestamps[folderKey] || 0; + if (now - lastCheck < CHECK_INTERVAL) { + return; + } + // Update the last check timestamp + lastCheckTimestamps[folderKey] = now; + // Load the last processed date for this folder from storage let result = await messenger.storage.local.get("folderLastProcessed"); let folderLastProcessed = result.folderLastProcessed || {}; @@ -553,6 +578,8 @@ async function onFolderDisplayed(tab, folder) { + + // learnTagFromMail Funktion function learnTagFromMail(messageId, tagName, isPositive) { console.log(`Training with message ID: ${messageId} and tag: ${tagName}`); diff --git a/src/bayes.js b/src/bayes.js index 3457255..1d6fce4 100644 --- a/src/bayes.js +++ b/src/bayes.js @@ -135,7 +135,7 @@ function calculateBayesProbability(tokens, data, returnTokenContributions = fals const probability = Math.exp(logProbPositive - logSumExp); // Normalisierte positive Wahrscheinlichkeit - console.log("Calculated probability:", probability); + console.debug("Calculated probability:", probability); // Rückgabe der Token-Beiträge, falls aktiviert if (returnTokenContributions) { diff --git a/src/donation_handler.js b/src/donation_handler.js index 3c662cf..c988016 100644 --- a/src/donation_handler.js +++ b/src/donation_handler.js @@ -49,7 +49,6 @@ async function verifyDonationCode(cryptedemail, code) { * Wenn die Checksum nicht mit der berechneten übereinstimmt, wird der usage_counter auf 30 gesetzt. */ async function updateUsageData() { - console.debug(`updateUsageData`); const currentData = await messenger.storage.local.get(['donation_handler']); const donationHandler = currentData.donation_handler || {}; @@ -58,7 +57,7 @@ async function updateUsageData() { const shortHash = await short_sha256(donationHandler.donation_mail); const isValid = await verifyDonationCode(shortHash, donationHandler.donation_key); if (isValid) { - console.debug("Gültiger donation_key. updateUsageData."); + console.debug("Valid donation_key found."); return; } } @@ -89,6 +88,7 @@ async function updateUsageData() { // Wenn die Checksum korrekt ist, prüfe, ob ein neuer Tag begonnen hat if (today != lastCheckDate) { + console.debug(`updateUsageData (new day)`); const newUsageCounter = (donationHandler.usage_counter || 0) + 1; const newLastCheckDate = today; diff --git a/src/manifest.json b/src/manifest.json index 5b9facc..0eeb790 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "PrioMailbox", - "version": "1.3.1", + "version": "1.3.3", "default_locale": "en", "description": "PrioMailbox organizes your emails in Thunderbird with intelligent, trainable tags. Important messages are highlighted, while unimportant ones are hidden.", "icons": { @@ -23,7 +23,8 @@ "menus", "notifications", "accountsRead", - "accountsFolders" + "accountsFolders", + "alarms" ], "browser_action": { "default_popup": "popup/popup.html", diff --git a/src/utils.js b/src/utils.js index 708044b..32c36b6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -105,11 +105,6 @@ function calculateKnownTokenTypesPercentage(tokens, tokenList) { const knownUnigramsPercentage = totalUnigrams > 0 ? (knownUnigrams / totalUnigrams) * 100 : 0; const knownBigramsPercentage = totalBigrams > 0 ? (knownBigrams / totalBigrams) * 100 : 0; - // Log the results for debugging - console.log(`Known unigrams: ${knownUnigramsPercentage.toFixed(2)}% (Known: ${knownUnigrams}, Total: ${totalUnigrams})`); - console.log(`Known bigrams: ${knownBigramsPercentage.toFixed(2)}% (Known: ${knownBigrams}, Total: ${totalBigrams})`); - - // Return the percentages return { knownUnigramsPercentage, knownBigramsPercentage