Compare commits
5 Commits
c327ba6e04
...
master
Author | SHA1 | Date | |
---|---|---|---|
88b805b221
|
|||
7980094d32
|
|||
bc998fbfa0
|
|||
900c2733e5 | |||
0f99446c92 |
18
exceptions/MDMailerEncryptionFailedException.php
Normal file
18
exceptions/MDMailerEncryptionFailedException.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Exception to be thrown
|
||||
*/
|
||||
final class MDMailerEncryptionFailedException extends Exception {
|
||||
/**
|
||||
* Error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function errorMessage() {
|
||||
//error message
|
||||
return 'GPG encryption failed';
|
||||
|
||||
}
|
||||
}
|
@ -10,29 +10,29 @@ declare(strict_types = 1);
|
||||
*/
|
||||
final class MDMailFormat {
|
||||
|
||||
const ACCENT_COLOR_MAIN = "#0280ee";
|
||||
const ACCENT_COLOR_SEC = "#0d5dc8";
|
||||
const CSS_H1 = "margin: .5em 0 .8em 0; padding: 0 0 .5em 0; font-size: 1.3em; font-weight: bold; border-bottom: 1px solid #D6D6D6;";
|
||||
const CSS_H2 = "margin: .3em 0 .5em 0; padding: 0 0 0 0; font-size: 1.1em; font-weight: bold;";
|
||||
const CSS_P = "margin: 0 0 0 0; padding: .4em 0 .6em 0; font-style: normal;";
|
||||
const CSS_FOOTER = "margin-top: .5em; padding-top: .5em; border-top: .1em solid #D6D6D6;";
|
||||
const CSS_UL = "margin: 1em 0; padding: 0 0 0 1em; list-style: square;";
|
||||
const CSS_OL = "margin: 1em 0; padding: 0 0 0 1em;";
|
||||
const CSS_HR = "margin: 1em 0; border-width: 0 0 0 0; border-top: 1px solid #D6D6D6;";
|
||||
const CSS_A_NORMAL = "text-decoration: none;";
|
||||
const CSS_A_FOOTER = "text-decoration: none; font-size: .95em;";
|
||||
const CSS_A_FOOTER_HOVER = "color: " . self::ACCENT_COLOR_SEC . " !important;";
|
||||
const CSS_A_BUTTONLIKE = 'display: inline-block; width: auto;
|
||||
private const ACCENT_COLOR_MAIN = "#0280ee";
|
||||
private const ACCENT_COLOR_SEC = "#0d5dc8";
|
||||
private const CSS_H1 = "margin: .5em 0 .8em 0; padding: 0 0 .5em 0; font-size: 1.3em; font-weight: bold; border-bottom: 1px solid #D6D6D6;";
|
||||
private const CSS_H2 = "margin: .3em 0 .5em 0; padding: 0 0 0 0; font-size: 1.1em; font-weight: bold;";
|
||||
private const CSS_P = "margin: 0 0 0 0; padding: .4em 0 .6em 0; font-style: normal;";
|
||||
private const CSS_FOOTER = "margin-top: .5em; padding-top: .5em; border-top: .1em solid #D6D6D6;";
|
||||
private const CSS_UL = "margin: 1em 0; padding: 0 0 0 1em; list-style: square;";
|
||||
private const CSS_OL = "margin: 1em 0; padding: 0 0 0 1em;";
|
||||
private const CSS_HR = "margin: 1em 0; border-width: 0 0 0 0; border-top: 1px solid #D6D6D6;";
|
||||
private const CSS_A_NORMAL = "text-decoration: none;";
|
||||
private const CSS_A_FOOTER = "text-decoration: none; font-size: .95em;";
|
||||
private const CSS_A_FOOTER_HOVER = "color: " . self::ACCENT_COLOR_SEC . " !important;";
|
||||
private const CSS_A_BUTTONLIKE = 'display: inline-block; width: auto;
|
||||
margin: .5em 0; padding: .6em .8em;
|
||||
text-decoration: none;
|
||||
font-size: inherit; font-weight: bold;
|
||||
border-radius: .2em; transition: border .2s;
|
||||
background: ' . self::ACCENT_COLOR_MAIN . ' !important; color: #FFF !important;
|
||||
transition: background .4s;';
|
||||
const CSS_A_BUTTONLIKE_HOVER = 'background: ' . self::ACCENT_COLOR_SEC . ' !important;';
|
||||
private const CSS_A_BUTTONLIKE_HOVER = 'background: ' . self::ACCENT_COLOR_SEC . ' !important;';
|
||||
|
||||
const CSS_LOGO = "height: 1.5em; margin-right: .4em; vertical-align: middle;";
|
||||
const CSS_H1_SPAN = "vertical-align: middle;";
|
||||
private const CSS_LOGO = "height: 1.5em; margin-right: .4em; vertical-align: middle;";
|
||||
private const CSS_H1_SPAN = "vertical-align: middle;";
|
||||
|
||||
/** @var string */
|
||||
private string $_msg_html = "";
|
||||
|
@ -21,6 +21,10 @@ final class MDMailerHelper {
|
||||
* @return string
|
||||
*/
|
||||
public static function pgp_encrypt(string $to, string $msg):string {
|
||||
// Skip encryption if PGP_ENC_KEY is null
|
||||
if (MD_CONF_EMAIL::PGP_ENC_KEY === null) {
|
||||
return $msg;
|
||||
}
|
||||
|
||||
$gpg = new gnupg();
|
||||
$gpg->seterrormode(GNUPG_ERROR_EXCEPTION);
|
||||
@ -39,11 +43,16 @@ final class MDMailerHelper {
|
||||
}
|
||||
|
||||
if ($gpg->addsignkey(MD_CONF_EMAIL::PGP_ENC_KEY) === false) {
|
||||
throw new \Exception("Cannot set private key for GPG encryption");
|
||||
throw new \MDMailerEncryptionFailedException("Cannot set private key for GPG encryption");
|
||||
}
|
||||
|
||||
if (empty($msg = $gpg->encrypt($msg))) {
|
||||
throw new \Exception("Failed to sign and encrypt the message");
|
||||
try {
|
||||
if (empty($msg = $gpg->encrypt($msg))) {
|
||||
throw new \MDMailerEncryptionFailedException("Failed to sign and encrypt the message");
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
throw new MDMailerEncryptionFailedException("Failed to sign and encrypt the message to " . $to);
|
||||
}
|
||||
|
||||
return $msg;
|
||||
|
Reference in New Issue
Block a user