Skip to content

Commit

Permalink
#89 added send OpenPGP.js signed HTML message
Browse files Browse the repository at this point in the history
  • Loading branch information
the-djmaze committed Feb 7, 2022
1 parent 0cf63da commit 051e78d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions dev/Styles/User/Compose.less
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
td:first-child {
padding: 0 10px 0 0;
text-align: right;
white-space: nowrap;
width: 4em;
}

Expand Down
22 changes: 13 additions & 9 deletions dev/View/Popup/Compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,18 +407,15 @@ class ComposePopupView extends AbstractViewPopup {
params.Encrypted = draft
? await this.mailvelope.createDraft()
: await this.mailvelope.encrypt(recipients);
} else if (encrypt) {
if ('openpgp' != encrypt) {
throw 'Encryption with ' + encrypt + ' not yet implemented';
}
if (sign && 'openpgp' != sign[0]) {
throw 'Signing with ' + sign[0] + ' not yet implemented';
}
} else if (encrypt || sign) {
let data = new MimePart;
data.headers['Content-Type'] = 'text/'+(TextIsHtml?'html':'plain')+'; charset="utf-8"';
data.headers['Content-Transfer-Encoding'] = 'base64';
data.body = base64_encode(Text);
if (TextIsHtml && sign && sign[1]) {
if (sign && sign[1]) {
if ('openpgp' != sign[0]) {
throw 'Signing with ' + sign[0] + ' not yet implemented';
}
let signed = new MimePart;
signed.headers['Content-Type'] =
'multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"';
Expand All @@ -431,7 +428,14 @@ class ComposePopupView extends AbstractViewPopup {
signed.children.push(signature);
data = signed;
}
params.Encrypted = await OpenPGPUserStore.encrypt(data.toString(), recipients);
if (encrypt) {
if ('openpgp' != encrypt) {
throw 'Encryption with ' + encrypt + ' not yet implemented';
}
params.Encrypted = await OpenPGPUserStore.encrypt(data.toString(), recipients);
} else {
params.Signed = data.toString();
}
} else {
params.Html = TextIsHtml ? Text : '';
params.Text = TextIsHtml ? '' : Text;
Expand Down
19 changes: 19 additions & 0 deletions snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ private function buildMessage(Account $oAccount, bool $bWithDraftInfo = true) :
$aFoundCids = array();
$aFoundDataURL = array();
$aFoundContentLocationUrls = array();
$oPart;

if ($sHtml = $this->GetActionParam('Html', '')) {
$oPart = new MimePart;
Expand Down Expand Up @@ -1142,6 +1143,23 @@ private function buildMessage(Account $oAccount, bool $bWithDraftInfo = true) :
unset($sHtml);
unset($sPlain);

} else if ($sSigned = $this->GetActionParam('Signed', '')) {
$aSigned = \explode("\r\n\r\n", $sSigned, 2);
$sBoundary = \preg_replace('/^.+boundary="([^"]+)".+$/Dsi', '$1', $aSigned[0]);

$oPart = new MimePart;
$oPart->Headers->AddByName(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
'multipart/signed; ' . (new \MailSo\Mime\ParameterCollection)->Add(
new \MailSo\Mime\Parameter(\MailSo\Mime\Enumerations\Parameter::BOUNDARY, $sBoundary)
)->ToString() . '; protocol="application/pgp-signature"'
);
$oPart->Body = \str_replace("--{$sBoundary}--", '', $aSigned[1]);
$oMessage->SubParts->append($oPart);

unset($oAlternativePart);
unset($sSigned);

} else if ($sEncrypted = $this->GetActionParam('Encrypted', '')) {
$oPart = new MimePart;
$oPart->Headers->AddByName(
Expand Down Expand Up @@ -1207,6 +1225,7 @@ private function buildMessage(Account $oAccount, bool $bWithDraftInfo = true) :
unset($sSignature);
unset($sPlain);
}
unset($oPart);

$aAttachments = $this->GetActionParam('Attachments', null);
if (\is_array($aAttachments))
Expand Down

0 comments on commit 051e78d

Please sign in to comment.