mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-09-20 15:45:55 +08:00
Added: MailSo\Mime\Part::IsPgpSigned()/IsPgpSignature()
Drop: MailSo\Mime\Enumerations\Constants
This commit is contained in:
parent
8dc949f15c
commit
5ed4498e4f
|
@ -158,8 +158,8 @@ class Binary
|
||||||
{
|
{
|
||||||
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName,
|
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName,
|
||||||
\STREAM_FILTER_READ, array(
|
\STREAM_FILTER_READ, array(
|
||||||
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
|
'line-length' => 74,
|
||||||
'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF
|
'line-break-chars' => "\r\n"
|
||||||
));
|
));
|
||||||
return \is_resource($rFilter) ? $rStream : false;
|
return \is_resource($rFilter) ? $rStream : false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,13 +189,12 @@ class BodyStructure
|
||||||
&& 'application/pgp-signature' === \strtolower(\trim($this->aBodyParams['protocol']))
|
&& 'application/pgp-signature' === \strtolower(\trim($this->aBodyParams['protocol']))
|
||||||
// The multipart/signed body MUST consist of exactly two parts.
|
// The multipart/signed body MUST consist of exactly two parts.
|
||||||
&& 2 === \count($this->aSubParts)
|
&& 2 === \count($this->aSubParts)
|
||||||
&& $this->aSubParts[1]->IsPgpSignature();
|
&& $this->aSubParts[1]->IsPgpSignature();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsPgpSignature() : bool
|
public function IsPgpSignature() : bool
|
||||||
{
|
{
|
||||||
return \in_array($this->sContentType,
|
return \in_array($this->sContentType, ['application/pgp-signature', 'application/pkcs7-signature']);
|
||||||
array('application/pgp-signature', 'application/pkcs7-signature'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsAttachBodyPart() : bool
|
public function IsAttachBodyPart() : bool
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of MailSo.
|
|
||||||
*
|
|
||||||
* (c) 2014 Usenko Timur
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace MailSo\Mime\Enumerations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @category MailSo
|
|
||||||
* @package Mime
|
|
||||||
* @subpackage Enumerations
|
|
||||||
*/
|
|
||||||
abstract class Constants
|
|
||||||
{
|
|
||||||
const TAB = "\t";
|
|
||||||
const CRLF = "\r\n";
|
|
||||||
|
|
||||||
const LINE_LENGTH = 74;
|
|
||||||
}
|
|
|
@ -150,7 +150,7 @@ class Header
|
||||||
private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string
|
private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string
|
||||||
{
|
{
|
||||||
return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue,
|
return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue,
|
||||||
Enumerations\Constants::LINE_LENGTH, $sGlue
|
74, $sGlue
|
||||||
), \strlen($this->NameWithDelimitrom())));
|
), \strlen($this->NameWithDelimitrom())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +168,8 @@ class Header
|
||||||
'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
|
'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
|
||||||
'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
|
'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
|
||||||
'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
|
'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
|
||||||
'line-length' => Enumerations\Constants::LINE_LENGTH,
|
'line-length' => 74,
|
||||||
'line-break-chars' => Enumerations\Constants::CRLF
|
'line-break-chars' => "\r\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
return \iconv_mime_encode($this->Name(), $sResult, $aPreferences);
|
return \iconv_mime_encode($this->Name(), $sResult, $aPreferences);
|
||||||
|
|
|
@ -307,6 +307,6 @@ class HeaderCollection extends \MailSo\Base\Collection
|
||||||
foreach ($this as $oHeader) {
|
foreach ($this as $oHeader) {
|
||||||
$aResult[] = $oHeader->EncodedValue();
|
$aResult[] = $oHeader->EncodedValue();
|
||||||
}
|
}
|
||||||
return \implode(Enumerations\Constants::CRLF, $aResult);
|
return \implode("\r\n", $aResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ class Message
|
||||||
{
|
{
|
||||||
$this->aAlternativeParts[] = array(
|
$this->aAlternativeParts[] = array(
|
||||||
$sContentType,
|
$sContentType,
|
||||||
\preg_replace('/\\r?\\n/', Enumerations\Constants::CRLF, \trim($sData)),
|
\preg_replace('/\\r?\\n/', "\r\n", \trim($sData)),
|
||||||
\MailSo\Base\Enumerations\Encoding::QUOTED_PRINTABLE_LOWER,
|
\MailSo\Base\Enumerations\Encoding::QUOTED_PRINTABLE_LOWER,
|
||||||
array()
|
array()
|
||||||
);
|
);
|
||||||
|
|
|
@ -163,6 +163,22 @@ class Part
|
||||||
return $sResult;
|
return $sResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function IsPgpSigned() : bool
|
||||||
|
{
|
||||||
|
// https://datatracker.ietf.org/doc/html/rfc3156#section-5
|
||||||
|
$header = $this->Headers->GetByName(Enumerations\Header::CONTENT_TYPE);
|
||||||
|
return $header
|
||||||
|
&& \preg_match('#multipart/signed.+protocol=["\']?application/pgp-signature#si', $header->FullValue())
|
||||||
|
// The multipart/signed body MUST consist of exactly two parts.
|
||||||
|
&& 2 === \count($this->SubParts)
|
||||||
|
&& $this->SubParts[1]->IsPgpSignature();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function IsPgpSignature() : bool
|
||||||
|
{
|
||||||
|
return \in_array($this->ContentType(), array('application/pgp-signature', 'application/pkcs7-signature'));
|
||||||
|
}
|
||||||
|
|
||||||
public static function FromFile(string $sFileName) : ?self
|
public static function FromFile(string $sFileName) : ?self
|
||||||
{
|
{
|
||||||
$rStreamHandle = \file_exists($sFileName) ? \fopen($sFileName, 'rb') : false;
|
$rStreamHandle = \file_exists($sFileName) ? \fopen($sFileName, 'rb') : false;
|
||||||
|
@ -524,13 +540,11 @@ class Part
|
||||||
|
|
||||||
$aSubStreams = array(
|
$aSubStreams = array(
|
||||||
|
|
||||||
$this->Headers->ToEncodedString().
|
$this->Headers->ToEncodedString() . "\r\n\r\n",
|
||||||
Enumerations\Constants::CRLF.
|
|
||||||
Enumerations\Constants::CRLF,
|
|
||||||
|
|
||||||
null === $this->Body ? '' : $this->Body,
|
null === $this->Body ? '' : $this->Body,
|
||||||
|
|
||||||
Enumerations\Constants::CRLF
|
"\r\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (0 < $this->SubParts->Count())
|
if (0 < $this->SubParts->Count())
|
||||||
|
@ -538,7 +552,7 @@ class Part
|
||||||
$sBoundary = $this->HeaderBoundary();
|
$sBoundary = $this->HeaderBoundary();
|
||||||
if (\strlen($sBoundary))
|
if (\strlen($sBoundary))
|
||||||
{
|
{
|
||||||
$aSubStreams[] = '--'.$sBoundary.Enumerations\Constants::CRLF;
|
$aSubStreams[] = "--{$sBoundary}\r\n";
|
||||||
|
|
||||||
$rSubPartsStream = $this->SubParts->ToStream($sBoundary);
|
$rSubPartsStream = $this->SubParts->ToStream($sBoundary);
|
||||||
if (\is_resource($rSubPartsStream))
|
if (\is_resource($rSubPartsStream))
|
||||||
|
@ -546,8 +560,7 @@ class Part
|
||||||
$aSubStreams[] = $rSubPartsStream;
|
$aSubStreams[] = $rSubPartsStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
$aSubStreams[] = Enumerations\Constants::CRLF.
|
$aSubStreams[] = "\r\n--{$sBoundary}--\r\n";
|
||||||
'--'.$sBoundary.'--'.Enumerations\Constants::CRLF;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@ class PartCollection extends \MailSo\Base\Collection
|
||||||
{
|
{
|
||||||
if (\count($aResult))
|
if (\count($aResult))
|
||||||
{
|
{
|
||||||
$aResult[] = Enumerations\Constants::CRLF.
|
$aResult[] = "\r\n--{$sBoundary}\r\n";
|
||||||
'--'.$sBoundary.Enumerations\Constants::CRLF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$aResult[] = $oPart->ToStream();
|
$aResult[] = $oPart->ToStream();
|
||||||
|
|
|
@ -84,6 +84,11 @@ trait Pgp
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($oPart->IsPgpSigned()) {
|
||||||
|
// $GPG->verifyStream($oPart->SubParts[0]->Body, \stream_get_contents($oPart->SubParts[1]->Body));
|
||||||
|
$oPart = $oPart->SubParts[0];
|
||||||
|
}
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, $oPart);
|
return $this->DefaultResponse(__FUNCTION__, $oPart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue