Skip to content

Commit ced4a3a

Browse files
committed
Added (rudimentary) support for the vnd.dovecot.pgp-encrypt sieve filter.
1 parent dfeeac1 commit ced4a3a

File tree

7 files changed

+216
-3
lines changed

7 files changed

+216
-3
lines changed

src/common/libSieve/extensions/extensions.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,6 @@ import "./notify/widgets/SieveNotifyUI.mjs";
5656

5757
// vnd.dovecot.pipe - pipe
5858
import "./pipe/widgets/SievePipeUI.mjs";
59+
60+
// vnd.dovecot.pgp-encrypt - pgp_encrypt
61+
import "./pgpencrypt/widgets/SievePgpEncryptUI.mjs";
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* The contents of this file are licensed. You may obtain a copy of
3+
* the license at https://github.com/thsmi/sieve/ or request it via
4+
* email from the author.
5+
*
6+
* Do not remove or change this comment.
7+
*
8+
* The initial author of the code is:
9+
* kaivol <github@kavol.de>
10+
*
11+
*/
12+
13+
import { SieveGrammar } from "./../../../toolkit/logic/GenericElements.mjs";
14+
15+
// :keys
16+
SieveGrammar.addTag({
17+
node: "action/pgpencrypt/keys",
18+
type: "action/pgpencrypt/",
19+
20+
token: ":keys",
21+
22+
properties: [{
23+
id: "parameters",
24+
25+
elements: [{
26+
id: "keys",
27+
type: "string",
28+
29+
value: '""'
30+
}]
31+
}]
32+
});
33+
34+
// Usage: pgp_encrypt :keys <key: string>
35+
SieveGrammar.addAction({
36+
node: "action/pgpencrypt",
37+
type: "action",
38+
39+
token: "pgp_encrypt",
40+
41+
requires: "vnd.dovecot.pgp-encrypt",
42+
43+
properties: [{
44+
id: "tags",
45+
optional: true,
46+
47+
elements: [{
48+
id: "keys",
49+
type: "action/pgpencrypt/keys"
50+
}]
51+
}]
52+
});
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div>
2+
<ul id="template-tabs">
3+
<li class="nav-item">
4+
<a data-i18n="pgpencrypt.tab.home" class="nav-link active" data-bs-toggle="tab" href="#sieve-widget-pgpencrypt" role="tab"></a>
5+
</li>
6+
<li class="nav-item">
7+
<a data-i18n="pgpencrypt.tab.help" class="nav-link" data-bs-toggle="tab" href="#sieve-widget-help" role="tab"></a>
8+
</li>
9+
</ul>
10+
11+
<div id="template-content">
12+
<div class="tab-content m-2">
13+
<div class="tab-pane fade show active" id="sieve-widget-pgpencrypt" role="tabpanel">
14+
15+
<div class="mb-3">
16+
<label data-i18n="pgpencrypt.key.label" class="form-label"></label>
17+
<textarea id="sivPgpKey"
18+
class="form-control col-lg-8"
19+
style="height: 300px"
20+
required="required"></textarea>
21+
</div>
22+
</div>
23+
<div style="white-space: pre-line" class="tab-pane fade form-text" id="sieve-widget-help" role="tabpanel" data-i18n="pgpencrypt.help"></div>
24+
</div>
25+
</div>
26+
</div>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* The contents of this file are licensed. You may obtain a copy of
3+
* the license at https://github.com/thsmi/sieve/ or request it via
4+
* email from the author.
5+
*
6+
* Do not remove or change this comment.
7+
*
8+
* The initial author of the code is:
9+
* kaivol <github@kavol.de>
10+
*
11+
*/
12+
13+
/* global net */
14+
15+
const suite = net.tschmid.yautt.test;
16+
17+
if (!suite)
18+
throw new Error("Could not initialize test suite");
19+
20+
suite.description("pgpencrypt Unit Tests...");
21+
22+
suite.add("pgpencrypt Snippet I", () => {
23+
24+
const script = ''
25+
+ 'require "vnd.dovecot.pgp-encrypt";\r\n'
26+
+ 'if true {\r\n'
27+
+ ' pgp_encrypt :keys text:\r\n'
28+
+ 'ABCDEF\r\n'
29+
+ '.\r\n'
30+
+ ';\r\n'
31+
+ '}\r\n';
32+
33+
suite.expectValidScript(script, ["vnd.dovecot.pgp-encrypt"]);
34+
});
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* The contents of this file are licensed. You may obtain a copy of
3+
* the license at https://github.com/thsmi/sieve/ or request it via
4+
* email from the author.
5+
*
6+
* Do not remove or change this comment.
7+
*
8+
* The initial author of the code is:
9+
* kaivol <github@kavol.de>
10+
*
11+
*/
12+
13+
import "./../logic/SievePgpEncrypt.mjs";
14+
15+
import { SieveDesigner } from "./../../../toolkit/SieveDesigner.mjs";
16+
17+
import {
18+
SieveActionDialogBoxUI
19+
} from "./../../../toolkit/widgets/Boxes.mjs";
20+
21+
import { SieveTemplate } from "./../../../toolkit/utils/SieveTemplate.mjs";
22+
import { SieveI18n } from "../../../toolkit/utils/SieveI18n.mjs";
23+
24+
/**
25+
* Provides an abstract UI for the pgpencrypt action.
26+
*/
27+
class SievePgpEncryptUI extends SieveActionDialogBoxUI {
28+
29+
/**
30+
* @inheritdoc
31+
*/
32+
getTemplate() {
33+
return "./extensions/pgpencrypt/templates/SievePgpEncryptActionUI.html";
34+
}
35+
36+
/**
37+
* Gets the currently set key.
38+
*
39+
* @returns {string}
40+
* the element's key
41+
*/
42+
keys(key) {
43+
return this.getSieve().getElement("keys").getElement("keys").value(key);
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
onSave() {
50+
const key = document.querySelector("#sivPgpKey").value;
51+
this.keys(key);
52+
this.getSieve().enable("keys", key.length > 0);
53+
// should check if the given key is a valid PGP key
54+
return true;
55+
}
56+
57+
/**
58+
* @inheritdoc
59+
*/
60+
onLoad() {
61+
document.querySelector("#sivPgpKey").value = this.keys();
62+
}
63+
64+
/**
65+
* @inheritdoc
66+
*/
67+
getSummary() {
68+
const msg = SieveI18n.getInstance().getString("pgpencrypt.summary").replace("${address}", `
69+
<pre
70+
style="-webkit-line-clamp: 4;
71+
-webkit-box-orient: vertical;
72+
display: -webkit-box;
73+
overflow: hidden;"
74+
class="sivPgpKey"
75+
></pre>
76+
`);
77+
78+
const elm = (new SieveTemplate()).convert(`<div>${msg}</div>`);
79+
elm.querySelector(".sivPgpKey").textContent = this.keys();
80+
return elm;
81+
}
82+
}
83+
84+
SieveDesigner.register("action/pgpencrypt", SievePgpEncryptUI);

src/common/libSieve/i18n/en-US.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,12 @@
675675
"notifymethodcapability.maybe" : "maybe",
676676
"notifymethodcapability.maybe.text" : "The Sieve interpreter can't determine if the entity identified by the notification-uri is online or not",
677677
"notifymethodcapability.help" :"The notify_method_capability test retrieves the notification capability for given method and matches it to the given values.\n\nThe capability parameter is case insensitive. Currently only a single capability \"online\" is defined. But Sieve Notifications extensions may add aditional capabilities.\n\nThe \"online\" capabilities result is either \"yes\", \"no\" or \"maybe\". And describes the likelyness for a successfull delivery.\n\nNote that even after a \"yes\", there is no guarantee when and if the notification is received. Transport errors, recipient policy, etc. can prevent that.",
678-
"notifymethodcapability.summary" :"Check the notification capabilities."
679-
680-
}
678+
"notifymethodcapability.summary" :"Check the notification capabilities.",
679+
680+
"pgpencrypt.tab.home": "PGP encryption",
681+
"pgpencrypt.tab.help": "Help",
682+
"pgpencrypt.key.label": "Encryption key: ",
683+
"pgpencrypt.key.placeholder": "Enter key",
684+
"pgpencrypt.help": "Encrypts incoming mails with the given PGP key.",
685+
"pgpencrypt.summary" : "Encrypt mails with the following key:${address}"
686+
}

tests/tests/tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@
236236
]
237237
});
238238

239+
tests.set("pgpencrypt", {
240+
script: "${workspace}/libSieve/extensions/pgpencrypt/tests/SievePgpEncryptTest.mjs",
241+
extend: "rfc5228",
242+
require: [
243+
"${workspace}/libSieve/extensions/pgpencrypt/logic/SievePgpEncrypt.mjs"
244+
]
245+
});
246+
239247
tests.set("examples-fastmail", {
240248
script: "${workspace}/libSieve/tests/SieveFastMailTest.mjs",
241249
extend: "rfc5228",

0 commit comments

Comments
 (0)