Add spam filter account selection and management features. see #326
This commit is contained in:
parent
73c11f8b28
commit
617a1467d7
6 changed files with 106 additions and 23 deletions
|
|
@ -1362,5 +1362,9 @@
|
|||
"AccountSelector_AutoTags_infoline": {
|
||||
"message": "Each change is saved immediately.",
|
||||
"description": ""
|
||||
},
|
||||
"AccountSelector_Spamfilter": {
|
||||
"message": "Choose the accounts where the spam filter is enabled",
|
||||
"description": ""
|
||||
}
|
||||
}
|
||||
|
|
@ -845,6 +845,9 @@ const newEmailListener = (folder, messagesList) => {
|
|||
|
||||
async function processEmails(messages, addTagsAuto, spamFilter) {
|
||||
taWorkingStatus.startWorking();
|
||||
|
||||
let prefs_aats = await browser.storage.sync.get({ add_tags_maxnum: prefs_default.add_tags_maxnum, connection_type: prefs_default.connection_type, add_tags_force_lang: prefs_default.add_tags_force_lang, default_chatgpt_lang: prefs_default.default_chatgpt_lang, add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_enabled_accounts: prefs_default.add_tags_enabled_accounts, spamfilter_enabled_accounts: prefs_default.spamfilter_enabled_accounts });
|
||||
|
||||
for await (let message of messages) {
|
||||
let curr_fullMessage = null;
|
||||
let msg_text = null;
|
||||
|
|
@ -857,10 +860,9 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
|
|||
}
|
||||
|
||||
if (addTagsAuto) {
|
||||
let prefs_aat = await browser.storage.sync.get({ add_tags_maxnum: prefs_default.add_tags_maxnum, connection_type: prefs_default.connection_type, add_tags_force_lang: prefs_default.add_tags_force_lang, default_chatgpt_lang: prefs_default.default_chatgpt_lang, add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, add_tags_enabled_accounts: prefs_default.add_tags_enabled_accounts });
|
||||
if(prefs_aat.add_tags_enabled_accounts.length > 0){
|
||||
if(prefs_aats.add_tags_enabled_accounts.length > 0){
|
||||
let accountId = message.folder.accountId;
|
||||
if(!prefs_aat.add_tags_enabled_accounts.includes(accountId)){
|
||||
if(!prefs_aats.add_tags_enabled_accounts.includes(accountId)){
|
||||
taLog.log("Account " + accountId + " not enabled for add_tags, skipping...");
|
||||
continue;
|
||||
}
|
||||
|
|
@ -886,6 +888,13 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
|
|||
}
|
||||
|
||||
if (spamFilter) {
|
||||
if(prefs_aats.spamfilter_enabled_accounts.length > 0){
|
||||
let accountId = message.folder.accountId;
|
||||
if(!prefs_aats.spamfilter_enabled_accounts.includes(accountId)){
|
||||
taLog.log("Account " + accountId + " not enabled for spamfilter, skipping...");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let curr_prompt_spamfilter = await getSpamFilterPrompt();
|
||||
let chatgpt_lang = await taPromptUtils.getDefaultLang(curr_prompt_spamfilter);
|
||||
let specialFullPrompt_spamfilter = await taPromptUtils.preparePrompt(curr_prompt_spamfilter, message, chatgpt_lang, '', body_text, curr_fullMessage.headers.subject, msg_text, '', '');
|
||||
|
|
|
|||
|
|
@ -59,4 +59,5 @@ export const prefs_default = {
|
|||
spamfilter: false,
|
||||
spamfilter_threshold: 70,
|
||||
spamfilter_context_menu: true,
|
||||
spamfilter_enabled_accounts: [],
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
#spamfilter_prompt_container{
|
||||
#spamfilter_container, #account_selector_container, #spamfitler_reports_container{
|
||||
width: 90%;
|
||||
margin: 20px auto;
|
||||
}
|
||||
|
|
@ -7,6 +7,19 @@
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
#account_selector_container{
|
||||
margin-top: 40px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
|
||||
#account_selector_checkboxes{
|
||||
padding: 10px;
|
||||
border: 1px solid gray;
|
||||
width: 24em;
|
||||
margin-bottom: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.infoline{
|
||||
font-size: 0.8em;
|
||||
font-style: italic;
|
||||
|
|
|
|||
|
|
@ -44,24 +44,33 @@
|
|||
<div id="spamfilter_info_additional_statements"></div>
|
||||
<div class="btn_div"><button id="btn_reset_prompt" disabled>__MSG_reset_default__</button><button id="btn_save_prompt" disabled>__MSG_save__</button></div>
|
||||
</div>
|
||||
<h2>__MSG_SpamReport_Title__</h2>
|
||||
<table id="report_data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Message_ID</th>
|
||||
<th>__MSG_Date__</th>
|
||||
<th>__MSG_From__</th>
|
||||
<th>__MSG_Subject__</th>
|
||||
<th>__MSG_Spam_Value__</th>
|
||||
<th>__MSG_Moved_to_Spam__</th>
|
||||
<th>__MSG_Explanation__</th>
|
||||
<th>__MSG_Report_Date__</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="report_data_body">
|
||||
<!-- Rows will be inserted dynamically -->
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="account_selector_container">
|
||||
<div id="account_selector_info"><span class="section_title">__MSG_AccountSelector_Spamfilter__</span>
|
||||
<br><span class="infoline">__MSG_AccountSelector_AutoTags_infoline__</span></div>
|
||||
<div id="account_selector_checkboxes"></div>
|
||||
<button type="button" id="accounts_select_all">Select All</button>
|
||||
<button type="button" id="accounts_deselect_all">Deselect All</button>
|
||||
</div>
|
||||
<div id="spamfitler_reports_container">
|
||||
<h2>__MSG_SpamReport_Title__</h2>
|
||||
<table id="report_data">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Message_ID</th>
|
||||
<th>__MSG_Date__</th>
|
||||
<th>__MSG_From__</th>
|
||||
<th>__MSG_Subject__</th>
|
||||
<th>__MSG_Spam_Value__</th>
|
||||
<th>__MSG_Moved_to_Spam__</th>
|
||||
<th>__MSG_Explanation__</th>
|
||||
<th>__MSG_Report_Date__</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="report_data_body">
|
||||
<!-- Rows will be inserted dynamically -->
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script src="mzta-spamfilter.js" type="module"></script>
|
||||
<script src="../../js/mzta-i18n.js"></script>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { getSpecialPrompts, setSpecialPrompts } from "../../js/mzta-prompts.js";
|
|||
import { getPlaceholders } from "../../js/mzta-placeholders.js";
|
||||
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
|
||||
import { taSpamReport } from '../../js/mzta-spamreport.js';
|
||||
import { getAccountsList } from "../../js/mzta-utils.js";
|
||||
|
||||
let autocompleteSuggestions = [];
|
||||
let taLog = new taLogger("mzta-spamfilter-page",true);
|
||||
|
|
@ -80,7 +81,53 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
autocompleteSuggestions = (await getPlaceholders(true)).filter(p => !(p.id === 'additional_text')).map(p => ({command: '{%'+p.id+'%}', type: p.type}));
|
||||
textareaAutocomplete(spamfilter_textarea, autocompleteSuggestions, 1); // type_value = 1, only when reading an email
|
||||
|
||||
loadSpamReport()
|
||||
//Accounts manager
|
||||
let accounts = await getAccountsList();
|
||||
const accountsContainer = document.getElementById('account_selector_checkboxes');
|
||||
accounts.forEach(account => {
|
||||
const accountLabel = document.createElement('label');
|
||||
const accountCheckbox = document.createElement('input');
|
||||
accountCheckbox.type = 'checkbox';
|
||||
accountCheckbox.classList.add('accountCheckbox');
|
||||
accountCheckbox.value = account.id;
|
||||
accountLabel.appendChild(accountCheckbox);
|
||||
accountLabel.appendChild(document.createTextNode(account.name));
|
||||
accountsContainer.appendChild(accountLabel);
|
||||
accountsContainer.appendChild(document.createElement('br'));
|
||||
});
|
||||
|
||||
let prefs_spamfilter = await browser.storage.sync.get({ spamfilter_enabled_accounts: [] });
|
||||
let spamfilter_enabled_accounts = prefs_spamfilter.spamfilter_enabled_accounts;
|
||||
document.querySelectorAll('.accountCheckbox').forEach(checkbox => {
|
||||
if (spamfilter_enabled_accounts.length === 0 || spamfilter_enabled_accounts.includes(checkbox.value)) {
|
||||
checkbox.checked = true;
|
||||
} else {
|
||||
checkbox.checked = false;
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('.accountCheckbox').forEach(checkbox => {
|
||||
checkbox.addEventListener('change', () => {
|
||||
let selectedAccounts = Array.from(document.querySelectorAll('.accountCheckbox:checked')).map(checkbox => checkbox.value);
|
||||
if (selectedAccounts.length === document.querySelectorAll('.accountCheckbox').length) {
|
||||
browser.storage.sync.set({ spamfilter_enabled_accounts: [] });
|
||||
} else {
|
||||
browser.storage.sync.set({ spamfilter_enabled_accounts: selectedAccounts });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('accounts_select_all').addEventListener('click', () => {
|
||||
let checkboxes = document.querySelectorAll('.accountCheckbox');
|
||||
checkboxes.forEach(checkbox => checkbox.checked = true);
|
||||
});
|
||||
|
||||
document.getElementById('accounts_deselect_all').addEventListener('click', () => {
|
||||
let checkboxes = document.querySelectorAll('.accountCheckbox');
|
||||
checkboxes.forEach(checkbox => checkbox.checked = false);
|
||||
});
|
||||
|
||||
loadSpamReport();
|
||||
});
|
||||
|
||||
function check_spamfilter_threshold(event) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue