X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=securemail%2Fsecuremail.php;h=115ba47290e2cb2f6d7ed948edb726b33220ce8b;hb=7eb7706a2420f5ee2c2d8d84d1693b101fd80c1e;hp=e25e96695c05b5cc6864aa5a23a6a5fd4869d9b2;hpb=49254a8307f80cfe3ebd165ca556c3acb893b7c6;p=friendica-addons.git diff --git a/securemail/securemail.php b/securemail/securemail.php index e25e9669..115ba472 100644 --- a/securemail/securemail.php +++ b/securemail/securemail.php @@ -6,12 +6,13 @@ * Author: Fabio Comuni */ -use Friendica\Addon\securemail\SecureTestEMail; +use Friendica\Addon\securemail\SecureTestEmail; use Friendica\App; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Renderer; use Friendica\DI; +use Friendica\Object\EMail\IEmail; require_once __DIR__ . '/vendor/autoload.php'; @@ -89,7 +90,7 @@ function securemail_settings_post(App &$a, array &$b) if ($_POST['securemail-submit'] == DI::l10n()->t('Save and send test')) { - $res = DI::emailer()->send(new SecureTestEMail(DI::app(), DI::config(), DI::pConfig(), DI::baseUrl())); + $res = DI::emailer()->send(new SecureTestEmail(DI::app(), DI::config(), DI::pConfig(), DI::baseUrl())); // revert to saved value DI::pConfig()->set(local_user(), 'securemail', 'enable', $enable); @@ -109,20 +110,21 @@ function securemail_settings_post(App &$a, array &$b) * @link https://github.com/friendica/friendica/blob/develop/doc/Addons.md#emailer_send_prepare 'emailer_send_prepare' hook * * @param App $a App instance - * @param array $b hook data + * @param IEmail $email Email * * @see App */ -function securemail_emailer_send_prepare(App &$a, array &$b) +function securemail_emailer_send_prepare(App &$a, IEmail &$email) { - if (empty($b['uid'])) { + if (empty($email->getRecipientUid())) { return; } - $uid = $b['uid']; + $uid = $email->getRecipientUid(); $enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable'); if (!$enable_checked) { + DI::logger()->debug('No securemail enabled.'); return; } @@ -134,18 +136,23 @@ function securemail_emailer_send_prepare(App &$a, array &$b) $key = OpenPGP_Message::parse($public_key); - $data = new OpenPGP_LiteralDataPacket($b['textVersion'], [ + $data = new OpenPGP_LiteralDataPacket($email->getMessage(true), [ 'format' => 'u', 'filename' => 'encrypted.gpg' ]); - $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); - $armored_encrypted = wordwrap( - OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'), - 64, - "\n", - true - ); - - $b['textVersion'] = $armored_encrypted; - $b['htmlVersion'] = null; + + try { + $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); + $armored_encrypted = wordwrap( + OpenPGP::enarmor($encrypted->to_bytes(), 'PGP MESSAGE'), + 64, + "\n", + true + ); + + $email = $email->withMessage($armored_encrypted, null); + + } catch (Exception $e) { + DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]); + } }