OpenPGP first look (#53)

This commit is contained in:
RainLoop Team 2014-01-28 01:34:54 +04:00
parent 74991b16d9
commit 098a04eab6
15 changed files with 175 additions and 20 deletions

View file

@ -103,6 +103,11 @@ class Message
*/
private $sPlain;
/**
* @var string
*/
private $sPlainRaw;
/**
* @var string
*/
@ -158,6 +163,11 @@ class Message
*/
private $iThreadsLen;
/**
* @var string
*/
private $sPgpSignature;
/**
* @access private
*/
@ -191,6 +201,7 @@ class Message
$this->oBcc = null;
$this->sPlain = '';
$this->sPlainRaw = '';
$this->sHtml = '';
$this->oAttachments = null;
@ -208,6 +219,8 @@ class Message
$this->iThreadsLen = 0;
$this->iParentThread = 0;
$this->sPgpSignature = '';
return $this;
}
@ -227,6 +240,14 @@ class Message
return $this->sPlain;
}
/**
* @return string
*/
public function PlainRaw()
{
return $this->sPlainRaw;
}
/**
* @return string
*/
@ -235,6 +256,14 @@ class Message
return $this->sHtml;
}
/**
* @return string
*/
public function PgpSignature()
{
return $this->sPgpSignature;
}
/**
* @param string $sHtml
*
@ -527,8 +556,6 @@ class Message
$oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
}
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : array();
$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
$sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
@ -704,6 +731,7 @@ class Message
$this->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, '');
}
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
if (\is_array($aTextParts) && 0 < \count($aTextParts))
{
if (0 === \strlen($sCharset))
@ -749,9 +777,43 @@ class Message
else
{
$this->sPlain = \implode("\n", $sPlainParts);
$this->sPlainRaw = $this->sPlain;
}
unset($sHtmlParts, $sPlainParts);
$aMatch = array();
if (\preg_match('/-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0]))
{
$this->sPgpSignature = $aMatch[0];
$this->sPlain = \trim($this->sPlain);
}
$aMatch = array();
if (!empty($this->sPgpSignature) &&
\preg_match('/-----BEGIN PGP SIGNED MESSAGE-----(.+)-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) &&
!empty($aMatch[0]) && isset($aMatch[1]))
{
$this->sPlain = \str_replace($aMatch[0], $aMatch[1], $this->sPlain);
$this->sPlain = \trim(\preg_replace('/^Hash: [^\s]+/i', '', \trim($this->sPlain)));
}
unset($sHtmlParts, $sPlainParts, $aMatch);
}
if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) &&
'application/pgp-signature' === \strtolower($oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::PROTOCOL
)))
{
$aPgpSignatureParts = $oBodyStructure ? $oBodyStructure->SearchByContentType('application/pgp-signature') : null;
if (\is_array($aPgpSignatureParts) && 0 < \count($aPgpSignatureParts) && isset($aPgpSignatureParts[0]))
{
$sPgpSignatureText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$aPgpSignatureParts[0]->PartID().']');
if (\is_string($sPgpSignatureText) && 0 < \strlen($sPgpSignatureText) && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE'))
{
$this->sPgpSignature = \trim($sPgpSignatureText);
}
}
}
if ($oBodyStructure)