Skip to content

Commit aee96fc

Browse files
committed
Improved compatibility with Thunderbird 128
1 parent d6b7873 commit aee96fc

File tree

4 files changed

+56
-101
lines changed

4 files changed

+56
-101
lines changed

src/_locales/de/messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"message": "🔍 E-Mail-Infos"
77
},
88
"classifyMenu": {
9-
"message": "📄 Klassifiziere E-Mail"
9+
"message": "📄 Klassifiziere E-Mail(s)"
1010
},
1111
"trainTagMenu": {
1212
"message": "Trainiere: $1"

src/_locales/en/messages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"message": "🔍 Email Info"
77
},
88
"classifyMenu": {
9-
"message": "📄 Classify Email"
9+
"message": "📄 Classify Email(s)"
1010
},
1111
"trainTagMenu": {
1212
"message": "Train: $1"

src/background.js

+52-98
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ function trans(messageName, placeholders = []) {
2222
return message;
2323
}
2424

25+
console.log("Available functions in messenger.messages:", Object.keys(messenger.messages));
26+
2527

2628
function initialize() {
2729
console.log("Initializing...");
@@ -332,13 +334,16 @@ function selectMessage(messageId) {
332334
}
333335

334336
function getMessageTags(messageId) {
335-
return messenger.messages.get(messageId).then((message) => message.tags || []);
337+
return messenger.messages.get(messageId).then((message) => {
338+
console.log(`Retrieved tags for message ${messageId}:`, message.tags);
339+
return message.tags || [];
340+
});
336341
}
337342

343+
344+
// learnTagFromMail Funktion
338345
function learnTagFromMail(messageId, tagName, isPositive) {
339-
console.log(
340-
`Training with message ID: ${messageId} and tag: ${tagName}`
341-
);
346+
console.log(`Training with message ID: ${messageId} and tag: ${tagName}`);
342347

343348
const tagKey = tagNameToKeyMap[tagName];
344349

@@ -350,8 +355,7 @@ function learnTagFromMail(messageId, tagName, isPositive) {
350355
messenger.storage.local
351356
.get(["bayesData", "tagOnTraining"])
352357
.then((result) => {
353-
const tagOnTraining =
354-
result.tagOnTraining !== undefined ? result.tagOnTraining : true;
358+
const tagOnTraining = result.tagOnTraining !== undefined ? result.tagOnTraining : true;
355359
bayesData = result.bayesData || {};
356360

357361
bayesData[tagName] = bayesData[tagName] || {
@@ -378,16 +382,10 @@ function learnTagFromMail(messageId, tagName, isPositive) {
378382

379383
const uniqueTokens = Object.keys(tokenCounts);
380384

381-
const probabilityData = calculateBayesProbability(
382-
tokens,
383-
bayesData[tagName]
384-
);
385+
const probabilityData = calculateBayesProbability(tokens, bayesData[tagName]);
385386
const probabilityBefore = probabilityData.probability;
386387

387-
const knownTokenData = getKnownTokenPercentage(
388-
tokens,
389-
bayesData[tagName].tokenList
390-
);
388+
const knownTokenData = getKnownTokenPercentage(tokens, bayesData[tagName].tokenList);
391389

392390
if (knownTokenData.knownPercentage === 100) {
393391
console.log("Aborting: mail already trained (all tokens known).");
@@ -399,18 +397,14 @@ function learnTagFromMail(messageId, tagName, isPositive) {
399397
probabilityBefore > 0.9999 &&
400398
knownTokenData.knownPercentage >= 90
401399
) {
402-
console.log(
403-
"Overfitting stop: Probability already > 99.99% and over 90% tokens known."
404-
);
400+
console.log("Overfitting stop: Probability already > 99.99% and over 90% tokens known.");
405401
return;
406402
} else if (
407403
!isPositive &&
408404
probabilityBefore < 0.0001 &&
409405
knownTokenData.knownPercentage >= 90
410406
) {
411-
console.log(
412-
"Overfitting stop: Probability already < 0.01% and over 90% tokens known."
413-
);
407+
console.log("Overfitting stop: Probability already < 0.01% and over 90% tokens known.");
414408
return;
415409
}
416410

@@ -431,8 +425,7 @@ function learnTagFromMail(messageId, tagName, isPositive) {
431425
bayesData[tagName].tokenList[token][5] += 1; // negativeTrainCount
432426
}
433427

434-
bayesData[tagName].tokenList[token][6] =
435-
bayesData[tagName].trainingCount;
428+
bayesData[tagName].tokenList[token][6] = bayesData[tagName].trainingCount;
436429
});
437430

438431
uniqueTokens.forEach((token) => {
@@ -455,63 +448,34 @@ function learnTagFromMail(messageId, tagName, isPositive) {
455448
if (tagOnTraining) {
456449
getMessageTags(messageId)
457450
.then((currentTags) => {
451+
let updatedTags;
458452
if (isPositive) {
459-
const updatedTags = Array.from(
460-
new Set([...currentTags, tagKey])
461-
);
462-
messenger.messages
463-
.update(messageId, {
464-
tags: updatedTags,
465-
})
466-
.then(() => {
467-
console.log(`Tag "${tagName}" added to the email.`);
468-
})
469-
.catch((error) => {
470-
console.error(`Error adding tag "${tagName}":`, error);
471-
});
453+
updatedTags = Array.from(new Set([...currentTags, tagKey]));
472454
} else {
473-
const updatedTags = currentTags.filter(
474-
(key) => key !== tagKey
475-
);
476-
messenger.messages
477-
.update(messageId, {
478-
tags: updatedTags,
479-
})
480-
.then(() => {
481-
console.log(`Tag "${tagName}" removed from the email.`);
482-
})
483-
.catch((error) => {
484-
console.error(
485-
`Error removing tag "${tagName}":`,
486-
error
487-
);
488-
});
455+
updatedTags = currentTags.filter((key) => key !== tagKey);
489456
}
457+
458+
messenger.messages
459+
.update(messageId, { tags: updatedTags })
460+
.then(() => {
461+
console.log(`Tag "${tagName}" ${isPositive ? "added to" : "removed from"} the email.`);
462+
})
463+
.catch((error) => {
464+
console.error(`Error updating tag "${tagName}":`, error);
465+
});
490466
})
491467
.catch((error) => {
492-
console.error(
493-
`Error retrieving tags for message ${messageId}:`,
494-
error
495-
);
468+
console.error(`Error retrieving tags for message ${messageId}:`, error);
496469
});
497470
}
498471

499472
messenger.storage.local
500473
.set({ bayesData })
501474
.then(() => {
502-
const probabilityAfter = calculateBayesProbability(
503-
tokens,
504-
bayesData[tagName]
505-
).probability;
506-
const trainingResult = isPositive
507-
? `as ${tagName}`
508-
: `as NOT ${tagName}`;
475+
const probabilityAfter = calculateBayesProbability(tokens, bayesData[tagName]).probability;
476+
const trainingResult = isPositive ? `als ${tagName}` : `als NICHT ${tagName}`;
509477
console.log(
510-
`Mail trained ${trainingResult}. (Before -> After Training: ${(
511-
probabilityBefore * 100
512-
).toFixed(2)}% -> ${(
513-
probabilityAfter * 100
514-
).toFixed(2)}%)`
478+
`Mail wurde ${trainingResult} trainiert. (Vorher -> Nachher: ${(probabilityBefore * 100).toFixed(2)}% -> ${(probabilityAfter * 100).toFixed(2)}%)`
515479
);
516480
})
517481
.catch((error) => {
@@ -527,6 +491,11 @@ function learnTagFromMail(messageId, tagName, isPositive) {
527491
});
528492
}
529493

494+
495+
496+
497+
498+
// classifyEmail Funktion
530499
function classifyEmail(messageId) {
531500
console.log(`Classifying message with ID: ${messageId}`);
532501
getEmailContent(messageId)
@@ -538,14 +507,9 @@ function classifyEmail(messageId) {
538507
selectedTags.forEach((tagName) => {
539508
const tagKey = tagNameToKeyMap[tagName];
540509
if (tagKey && bayesData[tagName]) {
541-
const probabilityData = calculateBayesProbability(
542-
tokens,
543-
bayesData[tagName]
544-
);
510+
const probabilityData = calculateBayesProbability(tokens, bayesData[tagName]);
545511
const probability = probabilityData.probability;
546-
console.log(
547-
`Probability for ${tagName}: ${(probability * 100).toFixed(2)}%`
548-
);
512+
console.log(`Probability for ${tagName}: ${(probability * 100).toFixed(2)}%`);
549513

550514
if (probability >= threshold) {
551515
tagsToAdd.push(tagKey);
@@ -571,15 +535,11 @@ function classifyEmail(messageId) {
571535
.update(messageId, { tags: updatedTags })
572536
.then(() => {
573537
if (tagsToAdd.length > 0) {
574-
const addedTagNames = tagsToAdd.map(
575-
(key) => tagKeyToNameMap[key]
576-
);
538+
const addedTagNames = tagsToAdd.map((key) => tagKeyToNameMap[key]);
577539
console.log("Tags added:", addedTagNames);
578540
}
579541
if (tagsToRemove.length > 0) {
580-
const removedTagNames = tagsToRemove.map(
581-
(key) => tagKeyToNameMap[key]
582-
);
542+
const removedTagNames = tagsToRemove.map((key) => tagKeyToNameMap[key]);
583543
console.log("Tags removed:", removedTagNames);
584544
}
585545
})
@@ -591,17 +551,16 @@ function classifyEmail(messageId) {
591551
}
592552
})
593553
.catch((error) => {
594-
console.error(
595-
`Error retrieving tags for message ${messageId}:`,
596-
error
597-
);
554+
console.error(`Error retrieving tags for message ${messageId}:`, error);
598555
});
599556
})
600557
.catch((error) => {
601558
console.error("Error classifying email:", error);
602559
});
603560
}
604561

562+
563+
605564
function classifyNewEmail(messageId) {
606565
getEmailContent(messageId)
607566
.then((content) => {
@@ -611,14 +570,9 @@ function classifyNewEmail(messageId) {
611570
selectedTags.forEach((tagName) => {
612571
const tagKey = tagNameToKeyMap[tagName];
613572
if (tagKey && bayesData[tagName]) {
614-
const probabilityData = calculateBayesProbability(
615-
tokens,
616-
bayesData[tagName]
617-
);
573+
const probabilityData = calculateBayesProbability(tokens, bayesData[tagName]);
618574
const probability = probabilityData.probability;
619-
console.log(
620-
`Probability for ${tagName}: ${(probability * 100).toFixed(2)}%`
621-
);
575+
console.log(`Probability for ${tagName}: ${(probability * 100).toFixed(2)}%`);
622576

623577
if (probability >= threshold) {
624578
tagsToAdd.push(tagKey);
@@ -629,9 +583,7 @@ function classifyNewEmail(messageId) {
629583
if (tagsToAdd.length > 0) {
630584
getMessageTags(messageId)
631585
.then((currentTags) => {
632-
const updatedTags = Array.from(
633-
new Set([...currentTags, ...tagsToAdd])
634-
);
586+
const updatedTags = Array.from(new Set([...currentTags, ...tagsToAdd]));
635587
messenger.messages
636588
.update(messageId, { tags: updatedTags })
637589
.then(() => {
@@ -645,10 +597,7 @@ function classifyNewEmail(messageId) {
645597
});
646598
})
647599
.catch((error) => {
648-
console.error(
649-
`Error retrieving tags for message ${messageId}:`,
650-
error
651-
);
600+
console.error(`Error retrieving tags for message ${messageId}:`, error);
652601
});
653602
} else {
654603
console.log("No tags added.");
@@ -659,6 +608,11 @@ function classifyNewEmail(messageId) {
659608
});
660609
}
661610

611+
612+
613+
614+
615+
662616
function onNewMailReceived(folder, messages) {
663617
const accountId = folder.accountId;
664618
if (selectedAccounts.includes(accountId)) {

src/manifest.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "PrioMailbox",
4-
"version": "0.11.8",
4+
"version": "0.11.9",
55
"default_locale": "en",
66
"description": "PrioMailbox organizes your emails in Thunderbird with intelligent, trainable tags. Important messages are highlighted, while unimportant ones are hidden.",
77
"icons": {
@@ -18,6 +18,7 @@
1818
"permissions": [
1919
"messagesModify",
2020
"messagesRead",
21+
"messagesUpdate",
2122
"storage",
2223
"menus",
2324
"notifications",

0 commit comments

Comments
 (0)