-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added (rudimentary) support for the vnd.dovecot.pgp-encrypt sieve fil…
…ter.
- Loading branch information
Showing
7 changed files
with
216 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/common/libSieve/extensions/pgpencrypt/logic/SievePgpEncrypt.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* The contents of this file are licensed. You may obtain a copy of | ||
* the license at https://github.com/thsmi/sieve/ or request it via | ||
* email from the author. | ||
* | ||
* Do not remove or change this comment. | ||
* | ||
* The initial author of the code is: | ||
* kaivol <[email protected]> | ||
* | ||
*/ | ||
|
||
import { SieveGrammar } from "./../../../toolkit/logic/GenericElements.mjs"; | ||
|
||
// :keys | ||
SieveGrammar.addTag({ | ||
node: "action/pgpencrypt/keys", | ||
type: "action/pgpencrypt/", | ||
|
||
token: ":keys", | ||
|
||
properties: [{ | ||
id: "parameters", | ||
|
||
elements: [{ | ||
id: "keys", | ||
type: "string", | ||
|
||
value: '""' | ||
}] | ||
}] | ||
}); | ||
|
||
// Usage: pgp_encrypt :keys <key: string> | ||
SieveGrammar.addAction({ | ||
node: "action/pgpencrypt", | ||
type: "action", | ||
|
||
token: "pgp_encrypt", | ||
|
||
requires: "vnd.dovecot.pgp-encrypt", | ||
|
||
properties: [{ | ||
id: "tags", | ||
optional: true, | ||
|
||
elements: [{ | ||
id: "keys", | ||
type: "action/pgpencrypt/keys" | ||
}] | ||
}] | ||
}); |
26 changes: 26 additions & 0 deletions
26
src/common/libSieve/extensions/pgpencrypt/templates/SievePgpEncryptActionUI.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<div> | ||
<ul id="template-tabs"> | ||
<li class="nav-item"> | ||
<a data-i18n="pgpencrypt.tab.home" class="nav-link active" data-bs-toggle="tab" href="#sieve-widget-pgpencrypt" role="tab"></a> | ||
</li> | ||
<li class="nav-item"> | ||
<a data-i18n="pgpencrypt.tab.help" class="nav-link" data-bs-toggle="tab" href="#sieve-widget-help" role="tab"></a> | ||
</li> | ||
</ul> | ||
|
||
<div id="template-content"> | ||
<div class="tab-content m-2"> | ||
<div class="tab-pane fade show active" id="sieve-widget-pgpencrypt" role="tabpanel"> | ||
|
||
<div class="mb-3"> | ||
<label data-i18n="pgpencrypt.key.label" class="form-label"></label> | ||
<textarea id="sivPgpKey" | ||
class="form-control col-lg-8" | ||
style="height: 300px" | ||
required="required"></textarea> | ||
</div> | ||
</div> | ||
<div style="white-space: pre-line" class="tab-pane fade form-text" id="sieve-widget-help" role="tabpanel" data-i18n="pgpencrypt.help"></div> | ||
</div> | ||
</div> | ||
</div> |
34 changes: 34 additions & 0 deletions
34
src/common/libSieve/extensions/pgpencrypt/tests/SievePgpEncryptTest.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* The contents of this file are licensed. You may obtain a copy of | ||
* the license at https://github.com/thsmi/sieve/ or request it via | ||
* email from the author. | ||
* | ||
* Do not remove or change this comment. | ||
* | ||
* The initial author of the code is: | ||
* kaivol <[email protected]> | ||
* | ||
*/ | ||
|
||
/* global net */ | ||
|
||
const suite = net.tschmid.yautt.test; | ||
|
||
if (!suite) | ||
throw new Error("Could not initialize test suite"); | ||
|
||
suite.description("pgpencrypt Unit Tests..."); | ||
|
||
suite.add("pgpencrypt Snippet I", () => { | ||
|
||
const script = '' | ||
+ 'require "vnd.dovecot.pgp-encrypt";\r\n' | ||
+ 'if true {\r\n' | ||
+ ' pgp_encrypt :keys text:\r\n' | ||
+ 'ABCDEF\r\n' | ||
+ '.\r\n' | ||
+ ';\r\n' | ||
+ '}\r\n'; | ||
|
||
suite.expectValidScript(script, ["vnd.dovecot.pgp-encrypt"]); | ||
}); |
84 changes: 84 additions & 0 deletions
84
src/common/libSieve/extensions/pgpencrypt/widgets/SievePgpEncryptUI.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* The contents of this file are licensed. You may obtain a copy of | ||
* the license at https://github.com/thsmi/sieve/ or request it via | ||
* email from the author. | ||
* | ||
* Do not remove or change this comment. | ||
* | ||
* The initial author of the code is: | ||
* kaivol <[email protected]> | ||
* | ||
*/ | ||
|
||
import "./../logic/SievePgpEncrypt.mjs"; | ||
|
||
import { SieveDesigner } from "./../../../toolkit/SieveDesigner.mjs"; | ||
|
||
import { | ||
SieveActionDialogBoxUI | ||
} from "./../../../toolkit/widgets/Boxes.mjs"; | ||
|
||
import { SieveTemplate } from "./../../../toolkit/utils/SieveTemplate.mjs"; | ||
import { SieveI18n } from "../../../toolkit/utils/SieveI18n.mjs"; | ||
|
||
/** | ||
* Provides an abstract UI for the pgpencrypt action. | ||
*/ | ||
class SievePgpEncryptUI extends SieveActionDialogBoxUI { | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getTemplate() { | ||
return "./extensions/pgpencrypt/templates/SievePgpEncryptActionUI.html"; | ||
} | ||
|
||
/** | ||
* Gets the currently set key. | ||
* | ||
* @returns {string} | ||
* the element's key | ||
*/ | ||
keys(key) { | ||
return this.getSieve().getElement("keys").getElement("keys").value(key); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
onSave() { | ||
const key = document.querySelector("#sivPgpKey").value; | ||
this.keys(key); | ||
this.getSieve().enable("keys", key.length > 0); | ||
// should check if the given key is a valid PGP key | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
onLoad() { | ||
document.querySelector("#sivPgpKey").value = this.keys(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getSummary() { | ||
const msg = SieveI18n.getInstance().getString("pgpencrypt.summary").replace("${address}", ` | ||
<pre | ||
style="-webkit-line-clamp: 4; | ||
-webkit-box-orient: vertical; | ||
display: -webkit-box; | ||
overflow: hidden;" | ||
class="sivPgpKey" | ||
></pre> | ||
`); | ||
|
||
const elm = (new SieveTemplate()).convert(`<div>${msg}</div>`); | ||
elm.querySelector(".sivPgpKey").textContent = this.keys(); | ||
return elm; | ||
} | ||
} | ||
|
||
SieveDesigner.register("action/pgpencrypt", SievePgpEncryptUI); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters