diff --git a/dev/Model/Message.js b/dev/Model/Message.js index eac31f777..0767fc072 100644 --- a/dev/Model/Message.js +++ b/dev/Model/Message.js @@ -24,6 +24,8 @@ import { LanguageStore } from 'Stores/Language'; import Remote from 'Remote/User/Fetch'; +import { MimeToMessage } from 'Mime/Utils'; + const msgHtml = msg => cleanHtml(msg.html(), msg.attachments(), '#rl-msg-' + msg.hash), @@ -196,6 +198,11 @@ export class MessageModel extends AbstractModel { return options; } }); + + this.smimeSigned.subscribe(value => { + value?.body && MimeToMessage(value.body, this); + value?.body && this.smimeVerified(value.verified); + }); } get requestHash() { diff --git a/dev/View/User/MailBox/MessageView.js b/dev/View/User/MailBox/MessageView.js index c2e9654c2..551915799 100644 --- a/dev/View/User/MailBox/MessageView.js +++ b/dev/View/User/MailBox/MessageView.js @@ -671,7 +671,7 @@ export class MailMessageView extends AbstractViewRight { message.html() ? message.viewHtml() : message.viewPlain(); response.Result.body = null; } - message.smimeVerified(response.Result); + message.smimeVerified(response.Result.success); } }); } diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php index 2febf7c7b..69293d6bc 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Imap/Commands/Messages.php @@ -132,6 +132,26 @@ trait Messages return $aReturn; } + public function FetchMessagePart(int $iUid, string $sPartId) : string + { + if ('TEXT' === $sPartId) { + $oFetchResponse = $this->Fetch([ + FetchType::BODY_PEEK.'['.$sPartId.']', + FetchType::BODY_HEADER_PEEK + ], $iUid, true)[0]; + $sHeader = $oFetchResponse->GetFetchValue(FetchType::BODY_HEADER); + } else { + $oFetchResponse = $this->Fetch([ + FetchType::BODY_PEEK.'['.$sPartId.']', + // An empty section specification refers to the entire message, including the header. + // But Dovecot does not return it with BODY.PEEK[1], so we also use BODY.PEEK[1.MIME]. + FetchType::BODY_PEEK.'['.$sPartId.'.MIME]' + ], $iUid, true)[0]; + $sHeader = $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.'.MIME]'); + } + return $sHeader . $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.']'); + } + /** * Appends message to specified folder * diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php index 38ee6d9e0..1ac9cc2ed 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php @@ -171,6 +171,16 @@ class MailClient $aFetchResponse = $this->oImapClient->Fetch($aFetchItems, $iIndex, $bIndexIsUid); if (\count($aFetchResponse)) { $oMessage = Message::fromFetchResponse($sFolderName, $aFetchResponse[0], $oBodyStructure); + // S/MIME opaque signed. Verify it, so we have the raw mime body to show + if ($oMessage->smimeSigned && !$oMessage->smimeSigned['detached']) { + $sBody = $this->oImapClient->FetchMessagePart( + $oMessage->Uid, + $oMessage->smimeSigned['partId'] + ); + $result = (new \SnappyMail\SMime\OpenSSL(''))->verify($sBody, null, true); + $oMessage->smimeSigned['body'] = $result['body']; + $oMessage->smimeSigned['verified'] = true; + } } return $oMessage; diff --git a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php index 13b098013..3578fdd2e 100644 --- a/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php +++ b/snappymail/v/0.0.0/app/libraries/MailSo/Mail/Message.php @@ -69,7 +69,7 @@ class Message implements \JsonSerializable private ?array $pgpSigned = null; private ?array $pgpEncrypted = null; - private ?array $smimeSigned = null; + public ?array $smimeSigned = null; private ?array $smimeEncrypted = null; private ?\MailSo\Mime\EmailCollection diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/SMime.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/SMime.php index 5aed83217..96263411b 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/SMime.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/SMime.php @@ -118,32 +118,12 @@ trait SMime $sPartId = $this->GetActionParam('partId', ''); $bDetached = !empty($this->GetActionParam('detached', 0)); if (!$sBody && $sPartId) { - $sFolderName = $this->GetActionParam('folder', ''); $iUid = (int) $this->GetActionParam('uid', 0); - $sMicAlg = $this->GetActionParam('micAlg', ''); - +// $sMicAlg = $this->GetActionParam('micAlg', ''); $this->initMailClientConnection(); $oImapClient = $this->ImapClient(); - $oImapClient->FolderExamine($sFolderName); - - if ('TEXT' === $sPartId) { - $oFetchResponse = $oImapClient->Fetch([ - FetchType::BODY_PEEK.'['.$sPartId.']', - // An empty section specification refers to the entire message, including the header. - // But Dovecot does not return it with BODY.PEEK[1], so we also use BODY.PEEK[1.MIME]. - FetchType::BODY_HEADER_PEEK - ], $iUid, true)[0]; - $sBody = $oFetchResponse->GetFetchValue(FetchType::BODY_HEADER); - } else { - $oFetchResponse = $oImapClient->Fetch([ - FetchType::BODY_PEEK.'['.$sPartId.']', - // An empty section specification refers to the entire message, including the header. - // But Dovecot does not return it with BODY.PEEK[1], so we also use BODY.PEEK[1.MIME]. - FetchType::BODY_PEEK.'['.$sPartId.'.MIME]' - ], $iUid, true)[0]; - $sBody = $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.'.MIME]'); - } - $sBody .= $oFetchResponse->GetFetchValue(FetchType::BODY.'['.$sPartId.']'); + $oImapClient->FolderExamine($this->GetActionParam('folder', '')); + $sBody = $oImapClient->FetchMessagePart($iUid, $sPartId); } $result = $this->SMIME()->verify($sBody, null, !$bDetached); @@ -151,7 +131,7 @@ trait SMime // Import the certificates automatically $sBody = $this->GetActionParam('sigPart', ''); $sPartId = $this->GetActionParam('sigPartId', '') ?: $sPartId; - if (!$sBody && $sPartId) { + if (!$sBody && $sPartId && $oImapClient) { $sBody = $oImapClient->Fetch( [FetchType::BODY_PEEK.'['.$sPartId.']'], $iUid, diff --git a/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html b/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html index 97d0022e7..53e17a085 100644 --- a/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html +++ b/snappymail/v/0.0.0/app/templates/Views/User/MailMessageView.html @@ -312,7 +312,7 @@
-
+