mailcow/data/web/js/presets/sieveMailbox.js
tinect 79053742ca Add better preset management (#3119)
* add rspamd-presets

* add sieveMailbox-presets

* adding new translations
2019-11-11 10:38:56 +01:00

32 lines
1.3 KiB
JavaScript

var sieveMailboxPresets = [
{
description: lang.sieve_preset_1,
codeValue: 'if header :contains "x-attached"\n [".exe",".bat",".js",".com",".cmd",".ini",".dll",".bas",".cpl",".drv",".inf",".sys",".pif",".doc",".docx"] {\n discard;\n stop;\n}'
},
{
description: lang.sieve_preset_2,
codeValue: 'require ["envelope", "imap4flags"];\nif envelope "from" "mark@me-read.com"\n{\n setflag "\\\\seen";\n}'
}
];
var sieve_presetsElem = document.getElementById("sieve_presets");
if (sieve_presetsElem && sieveMailboxPresets) {
sieve_presetsElem.innerHTML = '';
sieveMailboxPresets.forEach(function (item, index) {
var elemID = 'sieve_preset_' + index;
sieve_presetsElem.innerHTML += '<li><a href="#" class="small" id="' + elemID + '">' + lang.insert_preset.replace('%s', item.description) + '</a></li>';
/*
we need to define 0-timeout here, to prevent dom not be ready.
*/
setTimeout(function () {
document.getElementById(elemID).addEventListener('click', function (e) {
e.preventDefault();
document.querySelector('form[data-id=add_filter] #script_desc').value = item.description;
document.querySelector('form[data-id=add_filter] #script_data').value = item.codeValue;
return true;
});
}, 0)
});
}