Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for vnd.dovecot.pgp-encrypt #658

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/libSieve/extensions/extensions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ import "./notify/widgets/SieveNotifyUI.mjs";

// vnd.dovecot.pipe - pipe
import "./pipe/widgets/SievePipeUI.mjs";

// vnd.dovecot.pgp-encrypt - pgp_encrypt
import "./pgpencrypt/widgets/SievePgpEncryptUI.mjs";
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 <github@kavol.de>
*
*/

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"
}]
}]
});
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>
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 <github@kavol.de>
*
*/

/* 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"]);
});
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 <github@kavol.de>
*
*/

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);
12 changes: 9 additions & 3 deletions src/common/libSieve/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,12 @@
"notifymethodcapability.maybe" : "maybe",
"notifymethodcapability.maybe.text" : "The Sieve interpreter can't determine if the entity identified by the notification-uri is online or not",
"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.",
"notifymethodcapability.summary" :"Check the notification capabilities."

}
"notifymethodcapability.summary" :"Check the notification capabilities.",

"pgpencrypt.tab.home": "PGP encryption",
"pgpencrypt.tab.help": "Help",
"pgpencrypt.key.label": "Encryption key: ",
"pgpencrypt.key.placeholder": "Enter key",
"pgpencrypt.help": "Encrypts incoming mails with the given PGP key.",
"pgpencrypt.summary" : "Encrypt mails with the following key:${address}"
}
8 changes: 8 additions & 0 deletions tests/tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@
]
});

tests.set("pgpencrypt", {
script: "${workspace}/libSieve/extensions/pgpencrypt/tests/SievePgpEncryptTest.mjs",
extend: "rfc5228",
require: [
"${workspace}/libSieve/extensions/pgpencrypt/logic/SievePgpEncrypt.mjs"
]
});

tests.set("examples-fastmail", {
script: "${workspace}/libSieve/tests/SieveFastMailTest.mjs",
extend: "rfc5228",
Expand Down