antispam filter added the addressbook skip option. see #748
This commit is contained in:
parent
e6d6a095ac
commit
7ae4aa1899
6 changed files with 93 additions and 3 deletions
|
|
@ -1448,6 +1448,26 @@
|
||||||
"message": "The sender is in the email address antispam skip list.",
|
"message": "The sender is in the email address antispam skip list.",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"prefs_OptionText_spamfilter_skip_addressbook": {
|
||||||
|
"message": "Skip address books addresses",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"prefs_OptionText_spamfilter_skip_addressbook_Info": {
|
||||||
|
"message": "If checked, emails from senders in your address books will not be sent to the AI for spam filtering.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"spamfilter_skip_addressbook_explanation": {
|
||||||
|
"message": "The sender is a contact in the address book.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"addressbook_permission_denied": {
|
||||||
|
"message": "Address book permission was denied. Please enable the feature again to grant permission.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
|
"addressbook_permission_error": {
|
||||||
|
"message": "Error requesting address book permission. Please try again.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"SpamReport_Title": {
|
"SpamReport_Title": {
|
||||||
"message": "Spam Filter Reports",
|
"message": "Spam Filter Reports",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
"messagesTagsList"
|
"messagesTagsList"
|
||||||
],
|
],
|
||||||
"optional_permissions": [
|
"optional_permissions": [
|
||||||
|
"addressBooks",
|
||||||
"clipboardRead",
|
"clipboardRead",
|
||||||
"messagesTags",
|
"messagesTags",
|
||||||
"messagesUpdate",
|
"messagesUpdate",
|
||||||
|
|
|
||||||
|
|
@ -805,11 +805,13 @@ async function _generateSpamReportForMessage(headerMessageId, options = {}) {
|
||||||
body_text = msg_text.text.replace(/\s+/g, ' ').trim();
|
body_text = msg_text.text.replace(/\s+/g, ' ').trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(">>>>>>>>>>>>>> options.skip_addresses: " + JSON.stringify(options.skip_addresses));
|
|
||||||
|
// Extract sender email for skip checks
|
||||||
|
let senderEmail = (message.author.match(/[\w.-]+@[\w.-]+\.\w+/) || [''])[0].toLowerCase();
|
||||||
|
|
||||||
// Check if sender is in the skip addresses list
|
// Check if sender is in the skip addresses list
|
||||||
let skip_addresses = options.skip_addresses || (await browser.storage.sync.get({spamfilter_skip_addresses: prefs_default.spamfilter_skip_addresses})).spamfilter_skip_addresses;
|
let skip_addresses = options.skip_addresses || (await browser.storage.sync.get({spamfilter_skip_addresses: prefs_default.spamfilter_skip_addresses})).spamfilter_skip_addresses;
|
||||||
if (skip_addresses.length > 0) {
|
if (skip_addresses.length > 0) {
|
||||||
let senderEmail = (message.author.match(/[\w.-]+@[\w.-]+\.\w+/) || [''])[0].toLowerCase();
|
|
||||||
if (senderEmail && skip_addresses.includes(senderEmail)) {
|
if (senderEmail && skip_addresses.includes(senderEmail)) {
|
||||||
taLog.log("Sender " + senderEmail + " is in the skip addresses list, skipping spam filter.");
|
taLog.log("Sender " + senderEmail + " is in the skip addresses list, skipping spam filter.");
|
||||||
let report_data = {};
|
let report_data = {};
|
||||||
|
|
@ -828,6 +830,43 @@ console.log(">>>>>>>>>>>>>> options.skip_addresses: " + JSON.stringify(options.s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if sender is in any address book
|
||||||
|
let skip_addressbook = options.skip_addressbook !== undefined
|
||||||
|
? options.skip_addressbook
|
||||||
|
: (await browser.storage.sync.get({spamfilter_skip_addressbook: prefs_default.spamfilter_skip_addressbook})).spamfilter_skip_addressbook;
|
||||||
|
if (skip_addressbook && senderEmail) {
|
||||||
|
try {
|
||||||
|
let hasPermission = await browser.permissions.contains({ permissions: ["addressBooks"] });
|
||||||
|
if (hasPermission) {
|
||||||
|
let matchingContacts = await browser.contacts.quickSearch({ searchString: senderEmail });
|
||||||
|
let isInAddressBook = matchingContacts.some(contact => {
|
||||||
|
let props = contact.properties;
|
||||||
|
return (props.PrimaryEmail && props.PrimaryEmail.toLowerCase() === senderEmail) ||
|
||||||
|
(props.SecondEmail && props.SecondEmail.toLowerCase() === senderEmail);
|
||||||
|
});
|
||||||
|
if (isInAddressBook) {
|
||||||
|
taLog.log("Sender " + senderEmail + " is in the address book, skipping spam filter.");
|
||||||
|
let report_data = {};
|
||||||
|
report_data.report_date = new Date();
|
||||||
|
report_data.headerMessageId = headerMessageId;
|
||||||
|
report_data.spamValue = 0;
|
||||||
|
report_data.explanation = browser.i18n.getMessage('spamfilter_skip_addressbook_explanation');
|
||||||
|
report_data.subject = curr_fullMessage.headers.subject;
|
||||||
|
report_data.from = curr_fullMessage.headers.from;
|
||||||
|
report_data.message_date = new Date(message.date);
|
||||||
|
report_data.moved = false;
|
||||||
|
report_data.SpamThreshold = prefs.spamfilter_threshold || prefs_init.spamfilter_threshold;
|
||||||
|
spamReport.saveReportData(report_data, headerMessageId);
|
||||||
|
await updateSpamPanel(headerMessageId, "showSpamReport", report_data);
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
taLog.error("Error checking address book for sender: " + err);
|
||||||
|
// Fail open — continue with normal spam check
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let curr_prompt_spamfilter = await getSpamFilterPrompt();
|
let curr_prompt_spamfilter = await getSpamFilterPrompt();
|
||||||
let chatgpt_lang = await taPromptUtils.getDefaultLang(curr_prompt_spamfilter);
|
let chatgpt_lang = await taPromptUtils.getDefaultLang(curr_prompt_spamfilter);
|
||||||
let specialFullPrompt_spamfilter = await taPromptUtils.preparePrompt({
|
let specialFullPrompt_spamfilter = await taPromptUtils.preparePrompt({
|
||||||
|
|
@ -1673,11 +1712,13 @@ async function processEmails(args) {
|
||||||
add_tags_auto_uselist_list: prefs_default.add_tags_auto_uselist_list,
|
add_tags_auto_uselist_list: prefs_default.add_tags_auto_uselist_list,
|
||||||
spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts,
|
spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts,
|
||||||
spamfilter_skip_addresses: prefs_default.spamfilter_skip_addresses,
|
spamfilter_skip_addresses: prefs_default.spamfilter_skip_addresses,
|
||||||
|
spamfilter_skip_addressbook: prefs_default.spamfilter_skip_addressbook,
|
||||||
...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type']),
|
...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type']),
|
||||||
do_debug: prefs_default.do_debug,
|
do_debug: prefs_default.do_debug,
|
||||||
});
|
});
|
||||||
// console.log(">>>>>>>>>>>>>>>> prefs_aats: " + JSON.stringify(prefs_aats));
|
// console.log(">>>>>>>>>>>>>>>> prefs_aats: " + JSON.stringify(prefs_aats));
|
||||||
let spamfilter_skip_addresses = prefs_aats.spamfilter_skip_addresses;
|
let spamfilter_skip_addresses = prefs_aats.spamfilter_skip_addresses;
|
||||||
|
let spamfilter_skip_addressbook = prefs_aats.spamfilter_skip_addressbook;
|
||||||
|
|
||||||
for await (let message of messages) {
|
for await (let message of messages) {
|
||||||
let curr_fullMessage = null;
|
let curr_fullMessage = null;
|
||||||
|
|
@ -1755,7 +1796,8 @@ async function processEmails(args) {
|
||||||
messageData: { message, fullMessage: curr_fullMessage, body_text, msg_text },
|
messageData: { message, fullMessage: curr_fullMessage, body_text, msg_text },
|
||||||
prefs: prefs_aats,
|
prefs: prefs_aats,
|
||||||
autoMove: true,
|
autoMove: true,
|
||||||
skip_addresses: spamfilter_skip_addresses
|
skip_addresses: spamfilter_skip_addresses,
|
||||||
|
skip_addressbook: spamfilter_skip_addressbook
|
||||||
});
|
});
|
||||||
if (!result.success) continue;
|
if (!result.success) continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,7 @@ export const prefs_default = {
|
||||||
spamfilter_threshold: 70,
|
spamfilter_threshold: 70,
|
||||||
spamfilter_enabled_accounts: [],
|
spamfilter_enabled_accounts: [],
|
||||||
spamfilter_skip_addresses: [],
|
spamfilter_skip_addresses: [],
|
||||||
|
spamfilter_skip_addressbook: false,
|
||||||
summarize: false,
|
summarize: false,
|
||||||
summarize_auto: 1, // 0: disabled, 1: manual button, 2: automatic on message open, 3: generate on email receive
|
summarize_auto: 1, // 0: disabled, 1: manual button, 2: automatic on message open, 3: generate on email receive
|
||||||
summarize_display_mode: 'inline', // 'inline' or 'webchat'
|
summarize_display_mode: 'inline', // 'inline' or 'webchat'
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@
|
||||||
<br>__MSG_SpamFilter_skip_addresses_infoline2__</span>
|
<br>__MSG_SpamFilter_skip_addresses_infoline2__</span>
|
||||||
<br><textarea id="spamfilter_skip_addresses" rows="7"></textarea>
|
<br><textarea id="spamfilter_skip_addresses" rows="7"></textarea>
|
||||||
<div class="btn_div"><button id="btn_save_skip_addresses" disabled>__MSG_save__</button></div>
|
<div class="btn_div"><button id="btn_save_skip_addresses" disabled>__MSG_save__</button></div>
|
||||||
|
<br><label><input type="checkbox" id="spamfilter_skip_addressbook" name="spamfilter_skip_addressbook" /> <span class="opt_title">__MSG_prefs_OptionText_spamfilter_skip_addressbook__</span><br>__MSG_prefs_OptionText_spamfilter_skip_addressbook_Info__</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="spamfitler_reports_container">
|
<div id="spamfitler_reports_container">
|
||||||
<div><span class="section_title">__MSG_SpamReport_Title__</span></div>
|
<div><span class="section_title">__MSG_SpamReport_Title__</span></div>
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,31 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
document.getElementById('skip_addresses_unsaved').classList.add('hidden');
|
document.getElementById('skip_addresses_unsaved').classList.add('hidden');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Address book skip option
|
||||||
|
let skip_addressbook_checkbox = document.getElementById('spamfilter_skip_addressbook');
|
||||||
|
let prefs_skip_ab = await browser.storage.sync.get({ spamfilter_skip_addressbook: prefs_default.spamfilter_skip_addressbook });
|
||||||
|
skip_addressbook_checkbox.checked = prefs_skip_ab.spamfilter_skip_addressbook;
|
||||||
|
|
||||||
|
skip_addressbook_checkbox.addEventListener('change', async (event) => {
|
||||||
|
if (event.target.checked) {
|
||||||
|
try {
|
||||||
|
const granted = await browser.permissions.request({ permissions: ["addressBooks"] });
|
||||||
|
if (granted) {
|
||||||
|
await browser.storage.sync.set({ spamfilter_skip_addressbook: true });
|
||||||
|
} else {
|
||||||
|
event.target.checked = false;
|
||||||
|
alert(browser.i18n.getMessage("addressbook_permission_denied"));
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
taLog.error("Error requesting addressBooks permission:", err);
|
||||||
|
event.target.checked = false;
|
||||||
|
alert(browser.i18n.getMessage("addressbook_permission_error"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await browser.storage.sync.set({ spamfilter_skip_addressbook: false });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Accounts manager
|
//Accounts manager
|
||||||
let accounts = await getAccountsList();
|
let accounts = await getAccountsList();
|
||||||
const accountsContainer = document.getElementById('account_selector_checkboxes');
|
const accountsContainer = document.getElementById('account_selector_checkboxes');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue