Added: MailSo\Mime\Part::IsPgpSigned()/IsPgpSignature()

Drop: MailSo\Mime\Enumerations\Constants
This commit is contained in:
the-djmaze 2022-01-26 14:43:31 +01:00
parent 8dc949f15c
commit 5ed4498e4f
9 changed files with 35 additions and 44 deletions

View file

@ -158,8 +158,8 @@ class Binary
{
$rFilter = \stream_filter_append($rStream, $sUtilsDecodeOrEncodeFunctionName,
\STREAM_FILTER_READ, array(
'line-length' => \MailSo\Mime\Enumerations\Constants::LINE_LENGTH,
'line-break-chars' => \MailSo\Mime\Enumerations\Constants::CRLF
'line-length' => 74,
'line-break-chars' => "\r\n"
));
return \is_resource($rFilter) ? $rStream : false;
}

View file

@ -189,13 +189,12 @@ class BodyStructure
&& 'application/pgp-signature' === \strtolower(\trim($this->aBodyParams['protocol']))
// The multipart/signed body MUST consist of exactly two parts.
&& 2 === \count($this->aSubParts)
&& $this->aSubParts[1]->IsPgpSignature();
&& $this->aSubParts[1]->IsPgpSignature();
}
public function IsPgpSignature() : bool
{
return \in_array($this->sContentType,
array('application/pgp-signature', 'application/pkcs7-signature'));
return \in_array($this->sContentType, ['application/pgp-signature', 'application/pkcs7-signature']);
}
public function IsAttachBodyPart() : bool

View file

@ -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;
}

View file

@ -150,7 +150,7 @@ class Header
private function wordWrapHelper(string $sValue, string $sGlue = "\r\n ") : string
{
return \trim(substr(wordwrap($this->NameWithDelimitrom().$sValue,
Enumerations\Constants::LINE_LENGTH, $sGlue
74, $sGlue
), \strlen($this->NameWithDelimitrom())));
}
@ -168,8 +168,8 @@ class Header
'scheme' => \MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
'input-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'output-charset' => \MailSo\Base\Enumerations\Charset::UTF_8,
'line-length' => Enumerations\Constants::LINE_LENGTH,
'line-break-chars' => Enumerations\Constants::CRLF
'line-length' => 74,
'line-break-chars' => "\r\n"
);
return \iconv_mime_encode($this->Name(), $sResult, $aPreferences);

View file

@ -307,6 +307,6 @@ class HeaderCollection extends \MailSo\Base\Collection
foreach ($this as $oHeader) {
$aResult[] = $oHeader->EncodedValue();
}
return \implode(Enumerations\Constants::CRLF, $aResult);
return \implode("\r\n", $aResult);
}
}

View file

@ -325,7 +325,7 @@ class Message
{
$this->aAlternativeParts[] = array(
$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,
array()
);

View file

@ -163,6 +163,22 @@ class Part
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
{
$rStreamHandle = \file_exists($sFileName) ? \fopen($sFileName, 'rb') : false;
@ -524,13 +540,11 @@ class Part
$aSubStreams = array(
$this->Headers->ToEncodedString().
Enumerations\Constants::CRLF.
Enumerations\Constants::CRLF,
$this->Headers->ToEncodedString() . "\r\n\r\n",
null === $this->Body ? '' : $this->Body,
Enumerations\Constants::CRLF
"\r\n"
);
if (0 < $this->SubParts->Count())
@ -538,7 +552,7 @@ class Part
$sBoundary = $this->HeaderBoundary();
if (\strlen($sBoundary))
{
$aSubStreams[] = '--'.$sBoundary.Enumerations\Constants::CRLF;
$aSubStreams[] = "--{$sBoundary}\r\n";
$rSubPartsStream = $this->SubParts->ToStream($sBoundary);
if (\is_resource($rSubPartsStream))
@ -546,8 +560,7 @@ class Part
$aSubStreams[] = $rSubPartsStream;
}
$aSubStreams[] = Enumerations\Constants::CRLF.
'--'.$sBoundary.'--'.Enumerations\Constants::CRLF;
$aSubStreams[] = "\r\n--{$sBoundary}--\r\n";
}
}

View file

@ -36,8 +36,7 @@ class PartCollection extends \MailSo\Base\Collection
{
if (\count($aResult))
{
$aResult[] = Enumerations\Constants::CRLF.
'--'.$sBoundary.Enumerations\Constants::CRLF;
$aResult[] = "\r\n--{$sBoundary}\r\n";
}
$aResult[] = $oPart->ToStream();

View file

@ -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);
}