Fix secure Mail addon

This commit is contained in:
nupplaPhil 2020-01-31 19:32:16 +01:00
parent 360e58e6e3
commit 7603b23799
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90

View file

@ -116,6 +116,8 @@ function securemail_settings_post(App &$a, array &$b)
*/ */
function securemail_emailer_send_prepare(App &$a, IEmail &$email) function securemail_emailer_send_prepare(App &$a, IEmail &$email)
{ {
DI::logger()->warning('start securemail', ['email' => $email]);
if (empty($email->getRecipientUid())) { if (empty($email->getRecipientUid())) {
return; return;
} }
@ -124,6 +126,7 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email)
$enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable'); $enable_checked = DI::pConfig()->get($uid, 'securemail', 'enable');
if (!$enable_checked) { if (!$enable_checked) {
DI::logger()->warning('No check!!', ['email' => $email]);
return; return;
} }
@ -133,12 +136,17 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email)
$marker = empty($matches[1]) ? 'MESSAGE' : $matches[1]; $marker = empty($matches[1]) ? 'MESSAGE' : $matches[1];
$public_key = OpenPGP::unarmor($public_key_ascii, $marker); $public_key = OpenPGP::unarmor($public_key_ascii, $marker);
DI::logger()->warning('public key', ['public_key' => $public_key]);
$key = OpenPGP_Message::parse($public_key); $key = OpenPGP_Message::parse($public_key);
$data = new OpenPGP_LiteralDataPacket($email->getMessage(true), [ $data = new OpenPGP_LiteralDataPacket($email->getMessage(true), [
'format' => 'u', 'format' => 'u',
'filename' => 'encrypted.gpg' 'filename' => 'encrypted.gpg'
]); ]);
DI::logger()->warning('data', ['data' => $data]);
try { try {
$encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data])); $encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message([$data]));
$armored_encrypted = wordwrap( $armored_encrypted = wordwrap(
@ -148,10 +156,10 @@ function securemail_emailer_send_prepare(App &$a, IEmail &$email)
true true
); );
$email = Friendica\Object\EMail::createFromPrototype($email, [ $email = $email->withMessage($armored_encrypted, null);
'textVersion' => $armored_encrypted,
'htmlVersion' => null, DI::logger()->warning('End securemail', ['email' => $email]);
]);
} catch (Exception $e) { } catch (Exception $e) {
DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]); DI::logger()->warning('Encryption failed.', ['email' => $email, 'exception' => $e]);
} }