Use union and mixed type declaration

This commit is contained in:
the-djmaze 2026-10-27 17:35:08 +01:00
parent 08bc097dd4
commit 03151d72a0
67 changed files with 773 additions and 963 deletions

View file

@ -25,10 +25,7 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
} }
} }
/** public function append(mixed $mItem, bool $bToTop = false): void
* @param mixed $mItem
*/
public function append($mItem, bool $bToTop = false) : void
{ {
if ($bToTop) { if ($bToTop) {
$array = $this->getArrayCopy(); $array = $this->getArrayCopy();
@ -39,18 +36,18 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
} }
} }
public function keys() : array public function keys(): array
{ {
return \array_keys($this->getArrayCopy()); return \array_keys($this->getArrayCopy());
} }
public function Add($mItem, bool $bToTop = false) : self public function Add($mItem, bool $bToTop = false): self
{ {
$this->append($mItem, $bToTop); $this->append($mItem, $bToTop);
return $this; return $this;
} }
public function Clear() : void public function Clear(): void
{ {
$this->exchangeArray([]); $this->exchangeArray([]);
} }
@ -64,14 +61,14 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
return $callable($this->getArrayCopy(), ...$arguments); return $callable($this->getArrayCopy(), ...$arguments);
} }
*/ */
public function Slice(int $offset, ?int $length = null, bool $preserve_keys = false) public function Slice(int $offset, ?int $length = null, bool $preserve_keys = false)/*: static*/
{ {
return new static( return new static(
\array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys) \array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys)
); );
} }
public function Crop(?int $length = null, int $offset = 0, bool $preserve_keys = false) public function Crop(?int $length = null, int $offset = 0, bool $preserve_keys = false): self
{ {
$this->exchangeArray( $this->exchangeArray(
\array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys) \array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys)
@ -79,8 +76,8 @@ abstract class Collection extends \ArrayObject implements \JsonSerializable
return $this; return $this;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aNames = \explode('\\', \get_class($this)); $aNames = \explode('\\', \get_class($this));
return array( return array(

View file

@ -40,27 +40,27 @@ class BodyStructure implements \JsonSerializable
*/ */
private array $aSubParts; private array $aSubParts;
public function Charset() : string public function Charset(): string
{ {
return $this->sCharset; return $this->sCharset;
} }
public function ContentTransferEncoding() : string public function ContentTransferEncoding(): string
{ {
return $this->sContentTransferEncoding; return $this->sContentTransferEncoding;
} }
public function ContentType() : string public function ContentType(): string
{ {
return $this->sContentType; return $this->sContentType;
} }
public function PartID() : string public function PartID(): string
{ {
return $this->sPartID; return $this->sPartID;
} }
public function FileName(bool $bCalculateOnEmpty = false) : string public function FileName(bool $bCalculateOnEmpty = false): string
{ {
$sFileName = \trim($this->sFileName); $sFileName = \trim($this->sFileName);
if (\strlen($sFileName) || !$bCalculateOnEmpty) { if (\strlen($sFileName) || !$bCalculateOnEmpty) {
@ -90,7 +90,7 @@ class BodyStructure implements \JsonSerializable
return ($this->isInline() ? 'inline' : 'part' ) . $sIdx; return ($this->isInline() ? 'inline' : 'part' ) . $sIdx;
} }
public function EstimatedSize() : int public function EstimatedSize(): int
{ {
$fCoefficient = 1; $fCoefficient = 1;
switch ($this->sContentTransferEncoding) switch ($this->sContentTransferEncoding)
@ -106,17 +106,17 @@ class BodyStructure implements \JsonSerializable
return (int) ($this->iSize * $fCoefficient); return (int) ($this->iSize * $fCoefficient);
} }
public function SubParts() : array public function SubParts(): array
{ {
return $this->aSubParts; return $this->aSubParts;
} }
public function isInline() : bool public function isInline(): bool
{ {
return 'inline' === $this->sDisposition || \strlen($this->sContentID); return 'inline' === $this->sDisposition || \strlen($this->sContentID);
} }
public function isText() : bool public function isText(): bool
{ {
return 'text/html' === $this->sContentType return 'text/html' === $this->sContentType
|| 'text/plain' === $this->sContentType || 'text/plain' === $this->sContentType
@ -125,7 +125,7 @@ class BodyStructure implements \JsonSerializable
} }
// https://datatracker.ietf.org/doc/html/rfc3156#section-4 // https://datatracker.ietf.org/doc/html/rfc3156#section-4
public function isPgpEncrypted() : bool public function isPgpEncrypted(): bool
{ {
return 'multipart/encrypted' === $this->sContentType return 'multipart/encrypted' === $this->sContentType
&& !empty($this->aContentTypeParams['protocol']) && !empty($this->aContentTypeParams['protocol'])
@ -138,7 +138,7 @@ class BodyStructure implements \JsonSerializable
} }
// https://datatracker.ietf.org/doc/html/rfc3156#section-5 // https://datatracker.ietf.org/doc/html/rfc3156#section-5
public function isPgpSigned() : bool public function isPgpSigned(): bool
{ {
return 'multipart/signed' === $this->sContentType return 'multipart/signed' === $this->sContentType
&& !empty($this->aContentTypeParams['protocol']) && !empty($this->aContentTypeParams['protocol'])
@ -149,7 +149,7 @@ class BodyStructure implements \JsonSerializable
} }
// https://datatracker.ietf.org/doc/html/rfc2633#section-3.3 // https://datatracker.ietf.org/doc/html/rfc2633#section-3.3
public function isSMimeEncrypted() : bool public function isSMimeEncrypted(): bool
{ {
$type = \strtolower(\trim($this->aContentTypeParams['smime-type'] ?? '')); $type = \strtolower(\trim($this->aContentTypeParams['smime-type'] ?? ''));
return ContentType::isPkcs7Mime($this->sContentType) return ContentType::isPkcs7Mime($this->sContentType)
@ -158,7 +158,7 @@ class BodyStructure implements \JsonSerializable
} }
// https://www.rfc-editor.org/rfc/rfc8551.html#section-3.5 // https://www.rfc-editor.org/rfc/rfc8551.html#section-3.5
public function isSMimeSigned() : bool public function isSMimeSigned(): bool
{ {
return ('multipart/signed' === $this->sContentType return ('multipart/signed' === $this->sContentType
&& !empty($this->aContentTypeParams['protocol']) && !empty($this->aContentTypeParams['protocol'])
@ -172,7 +172,7 @@ class BodyStructure implements \JsonSerializable
); );
} }
protected function IsAttachment(/*BodyStructure*/ $oParent) : bool protected function IsAttachment(/*BodyStructure*/ $oParent): bool
{ {
// return 'application/pgp-encrypted' !== $this->sContentType // return 'application/pgp-encrypted' !== $this->sContentType
return (!$oParent || !$oParent->isPgpEncrypted()) return (!$oParent || !$oParent->isPgpEncrypted())
@ -184,14 +184,14 @@ class BodyStructure implements \JsonSerializable
); );
} }
public function IsFlowedFormat() : bool public function IsFlowedFormat(): bool
{ {
return !empty($this->aContentTypeParams['format']) return !empty($this->aContentTypeParams['format'])
&& 'flowed' === \strtolower(\trim($this->aContentTypeParams['format'])) && 'flowed' === \strtolower(\trim($this->aContentTypeParams['format']))
&& !\in_array($this->sContentTransferEncoding, array('base64', 'quoted-printable')); && !\in_array($this->sContentTransferEncoding, array('base64', 'quoted-printable'));
} }
public function GetHtmlAndPlainParts() : array public function GetHtmlAndPlainParts(): array
{ {
$aParts = []; $aParts = [];
@ -231,7 +231,7 @@ class BodyStructure implements \JsonSerializable
return $aParts; return $aParts;
} }
public function SearchCharset() : string public function SearchCharset(): string
{ {
$gParts = $this->SearchByCallback(function ($oPart, $oParent) { $gParts = $this->SearchByCallback(function ($oPart, $oParent) {
return $oPart->Charset() && $oPart->isText() && !$oPart->IsAttachment($oParent); return $oPart->Charset() && $oPart->isText() && !$oPart->IsAttachment($oParent);
@ -246,7 +246,7 @@ class BodyStructure implements \JsonSerializable
return $gParts->valid() ? $gParts->current()->Charset() : ''; return $gParts->valid() ? $gParts->current()->Charset() : '';
} }
public function SearchByCallback(callable $fCallback, /*BodyStructure*/ $parent = null) : iterable public function SearchByCallback(callable $fCallback, /*?BodyStructure*/ $parent = null): iterable
{ {
if ($fCallback($this, $parent)) { if ($fCallback($this, $parent)) {
yield $this; yield $this;
@ -256,7 +256,7 @@ class BodyStructure implements \JsonSerializable
} }
} }
public function SearchAttachmentsParts() : iterable public function SearchAttachmentsParts(): iterable
{ {
return $this->SearchByCallback(function ($oItem, $oParent) { return $this->SearchByCallback(function ($oItem, $oParent) {
// return $oItem->IsAttachment(); // return $oItem->IsAttachment();
@ -264,7 +264,7 @@ class BodyStructure implements \JsonSerializable
}); });
} }
public function SearchByContentType(string $sContentType) : iterable public function SearchByContentType(string $sContentType): iterable
{ {
$sContentType = \strtolower($sContentType); $sContentType = \strtolower($sContentType);
return $this->SearchByCallback(function ($oItem) use ($sContentType) { return $this->SearchByCallback(function ($oItem) use ($sContentType) {
@ -272,14 +272,14 @@ class BodyStructure implements \JsonSerializable
}); });
} }
public function SearchByContentTypes(array $aContentTypes) : iterable public function SearchByContentTypes(array $aContentTypes): iterable
{ {
return $this->SearchByCallback(function ($oItem) use ($aContentTypes) { return $this->SearchByCallback(function ($oItem) use ($aContentTypes) {
return \in_array($oItem->sContentType, $aContentTypes); return \in_array($oItem->sContentType, $aContentTypes);
}); });
} }
public function GetPartByMimeIndex(string $sMimeIndex) : self public function GetPartByMimeIndex(string $sMimeIndex): self
{ {
$oPart = null; $oPart = null;
if (\strlen($sMimeIndex)) { if (\strlen($sMimeIndex)) {
@ -300,7 +300,7 @@ class BodyStructure implements \JsonSerializable
return $oPart; return $oPart;
} }
private static function decodeAttrParameter(array $aParams, string $sParamName, string $sCharset) : string private static function decodeAttrParameter(array $aParams, string $sParamName, string $sCharset): string
{ {
$sResult = ''; $sResult = '';
if (isset($aParams[$sParamName])) { if (isset($aParams[$sParamName])) {
@ -349,7 +349,7 @@ class BodyStructure implements \JsonSerializable
return $sResult; return $sResult;
} }
public static function NewInstance(array $aBodyStructure, string $sPartID = '') : ?self public static function NewInstance(array $aBodyStructure, string $sPartID = ''): ?self
{ {
if (2 > \count($aBodyStructure)) { if (2 > \count($aBodyStructure)) {
return null; return null;
@ -542,7 +542,7 @@ class BodyStructure implements \JsonSerializable
* Returns dict with key="charset" and value="US-ASCII" for array ("CHARSET" "US-ASCII"). * Returns dict with key="charset" and value="US-ASCII" for array ("CHARSET" "US-ASCII").
* Keys are lowercased (StringDictionary itself does this), values are not altered. * Keys are lowercased (StringDictionary itself does this), values are not altered.
*/ */
private static function getKeyValueListFromArrayList(array $aList) : array private static function getKeyValueListFromArrayList(array $aList): array
{ {
$aDict = array(); $aDict = array();
$iLen = \count($aList); $iLen = \count($aList);
@ -557,8 +557,8 @@ class BodyStructure implements \JsonSerializable
return $aDict; return $aDict;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'mimeIndex' => $this->sPartID, 'mimeIndex' => $this->sPartID,

View file

@ -26,7 +26,7 @@ class FetchResponse
$this->oImapResponse = $oImapResponse; $this->oImapResponse = $oImapResponse;
} }
public function GetEnvelope(bool $bForce = false) : ?array public function GetEnvelope(bool $bForce = false): ?array
{ {
if (null === $this->aEnvelopeCache || $bForce) { if (null === $this->aEnvelopeCache || $bForce) {
$this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE); $this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE);
@ -34,15 +34,12 @@ class FetchResponse
return $this->aEnvelopeCache; return $this->aEnvelopeCache;
} }
/** public function GetFetchEnvelopeValue(int $iIndex, ?string $mNullResult = null): mixed
* @return mixed
*/
public function GetFetchEnvelopeValue(int $iIndex, ?string $mNullResult = null)
{ {
return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult); return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult);
} }
public function GetFetchEnvelopeEmailCollection(int $iIndex, string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) : ?\MailSo\Mime\EmailCollection public function GetFetchEnvelopeEmailCollection(int $iIndex, string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1): ?\MailSo\Mime\EmailCollection
{ {
$oResult = null; $oResult = null;
$aEmails = $this->GetFetchEnvelopeValue($iIndex); $aEmails = $this->GetFetchEnvelopeValue($iIndex);
@ -71,7 +68,7 @@ class FetchResponse
return $oResult; return $oResult;
} }
public function GetFetchBodyStructure() : ?BodyStructure public function GetFetchBodyStructure(): ?BodyStructure
{ {
$aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE); $aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE);
@ -82,9 +79,8 @@ class FetchResponse
/** /**
* Like: UID, RFC822.SIZE, MODSEQ, INTERNALDATE, FLAGS, BODYSTRUCTURE * Like: UID, RFC822.SIZE, MODSEQ, INTERNALDATE, FLAGS, BODYSTRUCTURE
* @return mixed
*/ */
public function GetFetchValue(string $sFetchItemName) public function GetFetchValue(string $sFetchItemName): mixed
{ {
if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3])) { if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3])) {
$bNextIsValue = false; $bNextIsValue = false;
@ -104,9 +100,8 @@ class FetchResponse
/** /**
* Like: BODY[HEADER.FIELDS (RETURN-PATH RECEIVED MIME-VERSION MESSAGE-ID CONTENT-TYPE FROM TO CC BCC SENDER REPLY-TO DELIVERED-TO IN-REPLY-TO REFERENCES DATE SUBJECT SENSITIVITY X-MSMAIL-PRIORITY IMPORTANCE X-PRIORITY X-DRAFT-INFO RETURN-RECEIPT-TO DISPOSITION-NOTIFICATION-TO X-CONFIRM-READING-TO AUTHENTICATION-RESULTS X-DKIM-AUTHENTICATION-RESULTS LIST-UNSUBSCRIBE X-SPAM-STATUS X-SPAMD-RESULT X-BOGOSITY X-VIRUS X-VIRUS-SCANNED X-VIRUS-STATUS)] * Like: BODY[HEADER.FIELDS (RETURN-PATH RECEIVED MIME-VERSION MESSAGE-ID CONTENT-TYPE FROM TO CC BCC SENDER REPLY-TO DELIVERED-TO IN-REPLY-TO REFERENCES DATE SUBJECT SENSITIVITY X-MSMAIL-PRIORITY IMPORTANCE X-PRIORITY X-DRAFT-INFO RETURN-RECEIPT-TO DISPOSITION-NOTIFICATION-TO X-CONFIRM-READING-TO AUTHENTICATION-RESULTS X-DKIM-AUTHENTICATION-RESULTS LIST-UNSUBSCRIBE X-SPAM-STATUS X-SPAMD-RESULT X-BOGOSITY X-VIRUS X-VIRUS-SCANNED X-VIRUS-STATUS)]
* @return mixed
*/ */
public function GetHeaderFieldsValue() : string public function GetHeaderFieldsValue(): string
{ {
$bNextIsValue = false; $bNextIsValue = false;
@ -129,7 +124,7 @@ class FetchResponse
return ''; return '';
} }
public static function isValidImapResponse(Response $oImapResponse) : bool public static function isValidImapResponse(Response $oImapResponse): bool
{ {
return return
!$oImapResponse->IsStatusResponse !$oImapResponse->IsStatusResponse
@ -138,16 +133,13 @@ class FetchResponse
&& \is_array($oImapResponse->ResponseList[3]); && \is_array($oImapResponse->ResponseList[3]);
} }
public static function hasUidAndSize(Response $oImapResponse) : bool public static function hasUidAndSize(Response $oImapResponse): bool
{ {
return \in_array(Enumerations\FetchType::UID, $oImapResponse->ResponseList[3]) return \in_array(Enumerations\FetchType::UID, $oImapResponse->ResponseList[3])
&& \in_array(Enumerations\FetchType::RFC822_SIZE, $oImapResponse->ResponseList[3]); && \in_array(Enumerations\FetchType::RFC822_SIZE, $oImapResponse->ResponseList[3]);
} }
/** private static function findEnvelopeIndex(array $aEnvelope, int $iIndex, ?string $mNullResult): mixed
* @return mixed
*/
private static function findEnvelopeIndex(array $aEnvelope, int $iIndex, ?string $mNullResult)
{ {
return (isset($aEnvelope[$iIndex]) && '' !== $aEnvelope[$iIndex]) return (isset($aEnvelope[$iIndex]) && '' !== $aEnvelope[$iIndex])
? $aEnvelope[$iIndex] : $mNullResult; ? $aEnvelope[$iIndex] : $mNullResult;

View file

@ -53,22 +53,22 @@ class Folder implements \JsonSerializable
*/ */
} }
public function setAttributes(array $aAttributes) : void public function setAttributes(array $aAttributes): void
{ {
$this->aAttributes = \array_map('mb_strtolower', $aAttributes); $this->aAttributes = \array_map('mb_strtolower', $aAttributes);
} }
public function setSubscribed() : void public function setSubscribed(): void
{ {
$this->aAttributes = \array_unique(\array_merge($this->aAttributes, ['\\subscribed'])); $this->aAttributes = \array_unique(\array_merge($this->aAttributes, ['\\subscribed']));
} }
public function setDelimiter(?string $sDelimiter) : void public function setDelimiter(?string $sDelimiter): void
{ {
$this->sDelimiter = $sDelimiter; $this->sDelimiter = $sDelimiter;
} }
public function Name() : string public function Name(): string
{ {
$sNameRaw = $this->FullName; $sNameRaw = $this->FullName;
if ($this->sDelimiter) { if ($this->sDelimiter) {
@ -78,49 +78,49 @@ class Folder implements \JsonSerializable
return $sNameRaw; return $sNameRaw;
} }
public function Delimiter() : ?string public function Delimiter(): ?string
{ {
return $this->sDelimiter; return $this->sDelimiter;
} }
public function Selectable() : bool public function Selectable(): bool
{ {
return !\in_array('\\noselect', $this->aAttributes) return !\in_array('\\noselect', $this->aAttributes)
&& !\in_array('\\nonexistent', $this->aAttributes); && !\in_array('\\nonexistent', $this->aAttributes);
} }
public function IsSubscribed() : bool public function IsSubscribed(): bool
{ {
return \in_array('\\subscribed', $this->aAttributes); return \in_array('\\subscribed', $this->aAttributes);
} }
public function IsInbox() : bool public function IsInbox(): bool
{ {
return 'INBOX' === \strtoupper($this->FullName) || \in_array('\\inbox', $this->aAttributes); return 'INBOX' === \strtoupper($this->FullName) || \in_array('\\inbox', $this->aAttributes);
} }
public function SetMetadata(string $sName, string $sData) : void public function SetMetadata(string $sName, string $sData): void
{ {
$this->aMetadata[$sName] = $sData; $this->aMetadata[$sName] = $sData;
} }
public function SetAllMetadata(array $aMetadata) : void public function SetAllMetadata(array $aMetadata): void
{ {
$this->aMetadata = $aMetadata; $this->aMetadata = $aMetadata;
} }
public function GetMetadata(string $sName) : ?string public function GetMetadata(string $sName): ?string
{ {
return isset($this->aMetadata[$sName]) ? $this->aMetadata[$sName] : null; return isset($this->aMetadata[$sName]) ? $this->aMetadata[$sName] : null;
} }
public function Metadata() : array public function Metadata(): array
{ {
return $this->aMetadata; return $this->aMetadata;
} }
// JMAP RFC 8621 // JMAP RFC 8621
public function Role() : ?string public function Role(): ?string
{ {
$role = \strtolower($this->GetMetadata(MetadataKeys::SPECIALUSE) ?: ''); $role = \strtolower($this->GetMetadata(MetadataKeys::SPECIALUSE) ?: '');
if (!$role) { if (!$role) {
@ -145,8 +145,8 @@ class Folder implements \JsonSerializable
return $role ? \ltrim($role, '\\') : null; return $role ? \ltrim($role, '\\') : null;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$selectable = $this->Selectable(); $selectable = $this->Selectable();
$result = array( $result = array(

View file

@ -19,14 +19,14 @@ class FolderCollection extends \MailSo\Base\Collection
{ {
// public bool $Optimized = false; // public bool $Optimized = false;
public function append($oFolder, bool $bToTop = false) : void public function append($oFolder, bool $bToTop = false): void
{ {
assert($oFolder instanceof Folder); assert($oFolder instanceof Folder);
parent::append($oFolder, $bToTop); parent::append($oFolder, $bToTop);
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Collection/FolderCollection', '@Object' => 'Collection/FolderCollection',

View file

@ -40,15 +40,15 @@ class FolderInformation implements \JsonSerializable
$this->IsWritable = $bIsWritable; $this->IsWritable = $bIsWritable;
} }
public function IsFlagSupported(string $sFlag) : bool public function IsFlagSupported(string $sFlag): bool
{ {
return \in_array('\\*', $this->PermanentFlags) return \in_array('\\*', $this->PermanentFlags)
|| \in_array($sFlag, $this->PermanentFlags); || \in_array($sFlag, $this->PermanentFlags);
// || \in_array($sFlag, $this->Flags); // || \in_array($sFlag, $this->Flags);
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$result = array( $result = array(
'id' => $this->MAILBOXID, 'id' => $this->MAILBOXID,

View file

@ -49,7 +49,7 @@ class ImapClient extends \MailSo\Net\NetClient
*/ */
private bool $UTF8 = false; private bool $UTF8 = false;
public function Hash() : string public function Hash(): string
{ {
return \md5('ImapClientHash/'. return \md5('ImapClientHash/'.
$this->Settings->username . '@' . $this->Settings->username . '@' .
@ -64,8 +64,8 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
// public function Connect(Settings $oSettings) : void // public function Connect(Settings $oSettings): void
public function Connect(\MailSo\Net\ConnectSettings $oSettings) : void public function Connect(\MailSo\Net\ConnectSettings $oSettings): void
{ {
$this->aTagTimeouts['*'] = \microtime(true); $this->aTagTimeouts['*'] = \microtime(true);
@ -79,7 +79,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
private function StartTLS() : void private function StartTLS(): void
{ {
if ($this->hasCapability('STARTTLS')) { if ($this->hasCapability('STARTTLS')) {
$this->SendRequestGetResponse('STARTTLS'); $this->SendRequestGetResponse('STARTTLS');
@ -93,7 +93,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
public function supportsAuthType(string $sasl_type) : bool public function supportsAuthType(string $sasl_type): bool
{ {
return $this->hasCapability("AUTH={$sasl_type}"); return $this->hasCapability("AUTH={$sasl_type}");
} }
@ -104,7 +104,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function Login(Settings $oSettings) : self public function Login(Settings $oSettings): self
{ {
if ($this->bIsLoggined) { if ($this->bIsLoggined) {
return $this; return $this;
@ -242,7 +242,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function Logout() : void public function Logout(): void
{ {
if ($this->bIsLoggined) { if ($this->bIsLoggined) {
$this->bIsLoggined = false; $this->bIsLoggined = false;
@ -250,12 +250,12 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
public function IsLoggined() : bool public function IsLoggined(): bool
{ {
return $this->IsConnected() && $this->bIsLoggined; return $this->IsConnected() && $this->bIsLoggined;
} }
public function IsSelected() : bool public function IsSelected(): bool
{ {
return $this->IsLoggined() && $this->oCurrentFolderInfo; return $this->IsLoggined() && $this->oCurrentFolderInfo;
} }
@ -265,7 +265,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function Capability() : ?array public function Capability(): ?array
{ {
if (!$this->aCapaRaw) { if (!$this->aCapaRaw) {
$this->setCapabilities($this->SendRequestGetResponse('CAPABILITY')); $this->setCapabilities($this->SendRequestGetResponse('CAPABILITY'));
@ -276,7 +276,7 @@ class ImapClient extends \MailSo\Net\NetClient
return $this->aCapa; return $this->aCapa;
} }
public function Capabilities() : ?array public function Capabilities(): ?array
{ {
if (!$this->aCapaRaw) { if (!$this->aCapaRaw) {
$this->Capability(); $this->Capability();
@ -284,7 +284,7 @@ class ImapClient extends \MailSo\Net\NetClient
return $this->aCapaRaw; return $this->aCapaRaw;
} }
public function CapabilityValue(string $sExtentionName) : ?string public function CapabilityValue(string $sExtentionName): ?string
{ {
$sExtentionName = \trim($sExtentionName) . '='; $sExtentionName = \trim($sExtentionName) . '=';
$aCapabilities = $this->Capability() ?: []; $aCapabilities = $this->Capability() ?: [];
@ -296,7 +296,7 @@ class ImapClient extends \MailSo\Net\NetClient
return null; return null;
} }
private function setCapabilities(ResponseCollection $oResponseCollection) : void private function setCapabilities(ResponseCollection $oResponseCollection): void
{ {
$aList = $oResponseCollection->getCapabilityResult(); $aList = $oResponseCollection->getCapabilityResult();
$this->aCapaRaw = $aList; $this->aCapaRaw = $aList;
@ -330,7 +330,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function hasCapability(string $sExtentionName) : bool public function hasCapability(string $sExtentionName): bool
{ {
$sExtentionName = \trim($sExtentionName); $sExtentionName = \trim($sExtentionName);
return $sExtentionName && \in_array(\strtoupper($sExtentionName), $this->Capability() ?: []); return $sExtentionName && \in_array(\strtoupper($sExtentionName), $this->Capability() ?: []);
@ -339,7 +339,7 @@ class ImapClient extends \MailSo\Net\NetClient
/** /**
* RFC 5161 * RFC 5161
*/ */
public function Enable(/*string|array*/ $mCapabilityNames) : void public function Enable(string|array $mCapabilityNames): void
{ {
if (\is_string($mCapabilityNames)) { if (\is_string($mCapabilityNames)) {
$mCapabilityNames = [$mCapabilityNames]; $mCapabilityNames = [$mCapabilityNames];
@ -354,7 +354,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function GetNamespaces() : ?NamespaceResult public function GetNamespaces(): ?NamespaceResult
{ {
if (!$this->hasCapability('NAMESPACE')) { if (!$this->hasCapability('NAMESPACE')) {
return null; return null;
@ -382,7 +382,7 @@ class ImapClient extends \MailSo\Net\NetClient
* and that the client will need to discover upload limits for each mailbox, * and that the client will need to discover upload limits for each mailbox,
* as they might differ from mailbox to mailbox. * as they might differ from mailbox to mailbox.
*/ */
public function AppendLimit() : ?int public function AppendLimit(): ?int
{ {
$string = $this->CapabilityValue('APPENDLIMIT'); $string = $this->CapabilityValue('APPENDLIMIT');
return \is_null($string) ? null : (int) $string; return \is_null($string) ? null : (int) $string;
@ -393,7 +393,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function Noop() : self public function Noop(): self
{ {
$this->SendRequestGetResponse('NOOP'); $this->SendRequestGetResponse('NOOP');
return $this; return $this;
@ -405,7 +405,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function SendRequest(string $sCommand, array $aParams = array(), bool $bBreakOnLiteral = false) : string public function SendRequest(string $sCommand, array $aParams = array(), bool $bBreakOnLiteral = false): string
{ {
$sCommand = \trim($sCommand); $sCommand = \trim($sCommand);
if (!\strlen($sCommand)) { if (!\strlen($sCommand)) {
@ -438,13 +438,13 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function SendRequestGetResponse(string $sCommand, array $aParams = array()) : ResponseCollection public function SendRequestGetResponse(string $sCommand, array $aParams = array()): ResponseCollection
{ {
$this->SendRequest($sCommand, $aParams); $this->SendRequest($sCommand, $aParams);
return $this->getResponse(); return $this->getResponse();
} }
protected function getResponseValue(ResponseCollection $oResponseCollection, int $type = 0) : string protected function getResponseValue(ResponseCollection $oResponseCollection, int $type = 0): string
{ {
$oResponse = $oResponseCollection->getLast(); $oResponse = $oResponseCollection->getLast();
if ($oResponse && (!$type || $type === $oResponse->ResponseType)) { if ($oResponse && (!$type || $type === $oResponse->ResponseType)) {
@ -466,7 +466,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
protected function streamResponse(?string $sEndTag = null) : void protected function streamResponse(?string $sEndTag = null): void
{ {
try { try {
if (\is_resource($this->ConnectionResource())) { if (\is_resource($this->ConnectionResource())) {
@ -488,7 +488,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
protected function getResponse(?string $sEndTag = null) : ResponseCollection protected function getResponse(?string $sEndTag = null): ResponseCollection
{ {
try { try {
$oResult = new ResponseCollection; $oResult = new ResponseCollection;
@ -535,8 +535,8 @@ class ImapClient extends \MailSo\Net\NetClient
return $oResult; return $oResult;
} }
// public function yieldUntaggedResponses() : \Generator // public function yieldUntaggedResponses(): \Generator
public function yieldUntaggedResponses() : iterable public function yieldUntaggedResponses(): iterable
{ {
try { try {
$oResult = new ResponseCollection; $oResult = new ResponseCollection;
@ -577,7 +577,7 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
protected function prepareParamLine(array $aParams = array()) : string protected function prepareParamLine(array $aParams = array()): string
{ {
$sReturn = ''; $sReturn = '';
foreach ($aParams as $mParamItem) { foreach ($aParams as $mParamItem) {
@ -590,18 +590,18 @@ class ImapClient extends \MailSo\Net\NetClient
return $sReturn; return $sReturn;
} }
protected function getNewTag() : string protected function getNewTag(): string
{ {
++$this->iTagCount; ++$this->iTagCount;
return $this->getCurrentTag(); return $this->getCurrentTag();
} }
protected function getCurrentTag() : string protected function getCurrentTag(): string
{ {
return $this->TAG_PREFIX.$this->iTagCount; return $this->TAG_PREFIX.$this->iTagCount;
} }
public function EscapeString(?string $sStringForEscape) : string public function EscapeString(?string $sStringForEscape): string
{ {
if (null === $sStringForEscape) { if (null === $sStringForEscape) {
return 'NIL'; return 'NIL';
@ -617,7 +617,7 @@ class ImapClient extends \MailSo\Net\NetClient
return '"' . \addcslashes($sStringForEscape, '\\"') . '"'; return '"' . \addcslashes($sStringForEscape, '\\"') . '"';
} }
public function getLogName() : string public function getLogName(): string
{ {
return 'IMAP'; return 'IMAP';
} }
@ -626,7 +626,7 @@ class ImapClient extends \MailSo\Net\NetClient
* RFC 2971 * RFC 2971
* Don't have to be logged in to call this command * Don't have to be logged in to call this command
*/ */
public function ServerID() : string public function ServerID(): string
{ {
if ($this->hasCapability('ID')) { if ($this->hasCapability('ID')) {
foreach ($this->SendRequestGetResponse('ID', [null]) as $oResponse) { foreach ($this->SendRequestGetResponse('ID', [null]) as $oResponse) {
@ -647,7 +647,7 @@ class ImapClient extends \MailSo\Net\NetClient
* RFC 4978 * RFC 4978
* It is RECOMMENDED that the client uses TLS compression. * It is RECOMMENDED that the client uses TLS compression.
*//* *//*
public function Compress() : bool public function Compress(): bool
{ {
try { try {
if ($this->hasCapability('COMPRESS=DEFLATE')) { if ($this->hasCapability('COMPRESS=DEFLATE')) {
@ -663,12 +663,12 @@ class ImapClient extends \MailSo\Net\NetClient
return false; return false;
}*/ }*/
public function EscapeFolderName(string $sFolderName) : string public function EscapeFolderName(string $sFolderName): string
{ {
return $this->EscapeString($this->UTF8 ? $sFolderName : \MailSo\Base\Utils::Utf8ToUtf7Modified($sFolderName)); return $this->EscapeString($this->UTF8 ? $sFolderName : \MailSo\Base\Utils::Utf8ToUtf7Modified($sFolderName));
} }
public function toUTF8(string $sText) : string public function toUTF8(string $sText): string
{ {
return $this->UTF8 ? $sText : \MailSo\Base\Utils::Utf7ModifiedToUtf8($sText); return $this->UTF8 ? $sText : \MailSo\Base\Utils::Utf7ModifiedToUtf8($sText);
} }

View file

@ -59,7 +59,7 @@ class NamespaceResult implements \JsonSerializable
} }
} }
public function GetPersonalPrefix() : string public function GetPersonalPrefix(): string
{ {
$sPrefix = ''; $sPrefix = '';
if (isset($this->aPersonal[0])) { if (isset($this->aPersonal[0])) {
@ -72,8 +72,8 @@ class NamespaceResult implements \JsonSerializable
return $sPrefix; return $sPrefix;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Object/Namespaces', '@Object' => 'Object/Namespaces',

View file

@ -42,7 +42,7 @@ class THREAD extends Request
parent::__construct($oImapClient); parent::__construct($oImapClient);
} }
public function setAlgorithm(string $sAlgorithm) : void public function setAlgorithm(string $sAlgorithm): void
{ {
$sAlgorithm = \strtoupper($sAlgorithm); $sAlgorithm = \strtoupper($sAlgorithm);
if (!$this->oImapClient->hasCapability("THREAD={$sAlgorithm}")) { if (!$this->oImapClient->hasCapability("THREAD={$sAlgorithm}")) {
@ -51,7 +51,7 @@ class THREAD extends Request
$this->sAlgorithm = $sAlgorithm; $this->sAlgorithm = $sAlgorithm;
} }
public function SendRequestIterateResponse() : iterable public function SendRequestIterateResponse(): iterable
{ {
$this->oImapClient->SendRequest( $this->oImapClient->SendRequest(
($this->bUid ? 'UID THREAD' : 'THREAD'), ($this->bUid ? 'UID THREAD' : 'THREAD'),
@ -79,12 +79,7 @@ class THREAD extends Request
} }
} }
/** private function validateThreadItem(mixed $mValue): int|array|false
* @param mixed $mValue
*
* @return int | array | false
*/
private function validateThreadItem($mValue)
{ {
if (\is_numeric($mValue)) { if (\is_numeric($mValue)) {
$mValue = (int) $mValue; $mValue = (int) $mValue;

View file

@ -28,19 +28,19 @@ class ACL implements \JsonSerializable
$this->rights = $rights; $this->rights = $rights;
} }
public function identifier() : string public function identifier(): string
{ {
return $this->identifier; return $this->identifier;
} }
/** PHP 8.1 /** PHP 8.1
public function hasRight(string|\MailSo\Imap\Enumerations\FolderACL $right) public function hasRight(string|\MailSo\Imap\Enumerations\FolderACL $right): bool
{ {
if ($right instanceof \BackedEnum) { if ($right instanceof \BackedEnum) {
return \str_contains($this->rights, $right->value); return \str_contains($this->rights, $right->value);
} }
*/ */
public function hasRight(string $right) : bool public function hasRight(string $right): bool
{ {
$const = '\\MailSo\\Imap\\Enumerations\\FolderACL::' . \strtoupper($right); $const = '\\MailSo\\Imap\\Enumerations\\FolderACL::' . \strtoupper($right);
if (\defined($const)) { if (\defined($const)) {
@ -49,8 +49,8 @@ class ACL implements \JsonSerializable
return \str_contains($this->rights, $right); return \str_contains($this->rights, $right);
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return [ return [
'@Object' => 'Object/FolderACLRights', '@Object' => 'Object/FolderACLRights',

View file

@ -53,7 +53,7 @@ class SequenceSet /*extends \SplFixedArray*/ implements \Countable
return \in_array($value, $this->data); return \in_array($value, $this->data);
} }
public function indexOf($value)/*: int|false*/ public function indexOf($value): int|false
{ {
return \array_search($value, $this->data); return \array_search($value, $this->data);
} }

View file

@ -40,7 +40,7 @@ class Settings extends \MailSo\Net\ConnectSettings
public array public array
$disabled_capabilities = []; $disabled_capabilities = [];
public static function fromArray(array $aSettings) : self public static function fromArray(array $aSettings): self
{ {
$object = parent::fromArray($aSettings); $object = parent::fromArray($aSettings);
@ -119,8 +119,8 @@ class Settings extends \MailSo\Net\ConnectSettings
return $object; return $object;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
if (\in_array('SORT', $this->disabled_capabilities)) { if (\in_array('SORT', $this->disabled_capabilities)) {
$this->disabled_capabilities[] = 'ESORT'; $this->disabled_capabilities[] = 'ESORT';

View file

@ -48,7 +48,7 @@ abstract class Driver
$this->oTimeZone = new \DateTimeZone('UTC'); $this->oTimeZone = new \DateTimeZone('UTC');
} }
public function SetTimeZone(/*\DateTimeZone | string*/ $mTimeZone) : self public function SetTimeZone(\DateTimeZone|string $mTimeZone): self
{ {
$this->oTimeZone = $mTimeZone instanceof \DateTimeZone $this->oTimeZone = $mTimeZone instanceof \DateTimeZone
? $mTimeZone ? $mTimeZone
@ -56,43 +56,43 @@ abstract class Driver
return $this; return $this;
} }
public function DisableGuidPrefix() : self public function DisableGuidPrefix(): self
{ {
$this->bGuidPrefix = false; $this->bGuidPrefix = false;
return $this; return $this;
} }
public function DisableTimePrefix() : self public function DisableTimePrefix(): self
{ {
$this->bTimePrefix = false; $this->bTimePrefix = false;
return $this; return $this;
} }
public function DisableTypedPrefix() : self public function DisableTypedPrefix(): self
{ {
$this->bTypedPrefix = false; $this->bTypedPrefix = false;
return $this; return $this;
} }
abstract protected function writeImplementation($mDesc) : bool; abstract protected function writeImplementation($mDesc): bool;
protected function clearImplementation() : bool protected function clearImplementation(): bool
{ {
return true; return true;
} }
protected function getTimeWithMicroSec() : string protected function getTimeWithMicroSec(): string
{ {
return \substr((new \DateTime('now', $this->oTimeZone))->format('Y-m-d H:i:s.u'), 0, -3); return \substr((new \DateTime('now', $this->oTimeZone))->format('Y-m-d H:i:s.u'), 0, -3);
} }
protected function getTypedPrefix(int $iType, string $sName = '') : string protected function getTypedPrefix(int $iType, string $sName = ''): string
{ {
$sName = \strlen($sName) ? $sName : $this->sName; $sName = \strlen($sName) ? $sName : $this->sName;
return isset(self::PREFIXES[$iType]) ? $sName . self::PREFIXES[$iType].': ' : ''; return isset(self::PREFIXES[$iType]) ? $sName . self::PREFIXES[$iType].': ' : '';
} }
final public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false) final public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false): bool
{ {
$sDesc = \ltrim( $sDesc = \ltrim(
($this->bTimePrefix ? '['.$this->getTimeWithMicroSec().']' : ''). ($this->bTimePrefix ? '['.$this->getTimeWithMicroSec().']' : '').
@ -105,7 +105,7 @@ abstract class Driver
return $this->writeImplementation($sDesc); return $this->writeImplementation($sDesc);
} }
final public function Clear() : bool final public function Clear(): bool
{ {
return $this->clearImplementation(); return $this->clearImplementation();
} }

View file

@ -84,7 +84,7 @@ class Logger extends \SplFixedArray
/** /**
* @staticvar string $sCache; * @staticvar string $sCache;
*/ */
public static function Guid() : string public static function Guid(): string
{ {
static $sCache = null; static $sCache = null;
if (null === $sCache) { if (null === $sCache) {
@ -94,7 +94,7 @@ class Logger extends \SplFixedArray
return $sCache; return $sCache;
} }
public function append($oDriver) : void public function append($oDriver): void
{ {
if ($oDriver) { if ($oDriver) {
$this->setSize(1); $this->setSize(1);
@ -102,7 +102,7 @@ class Logger extends \SplFixedArray
} }
} }
public function IsEnabled() : bool public function IsEnabled(): bool
{ {
return 0 < $this->count(); return 0 < $this->count();
} }
@ -110,7 +110,7 @@ class Logger extends \SplFixedArray
public function AddSecret( public function AddSecret(
#[\SensitiveParameter] #[\SensitiveParameter]
string $sWord string $sWord
) : void ): void
{ {
// $this->bShowSecrets && $this->Write("AddSecret '{$sWord}'", \LOG_INFO); // $this->bShowSecrets && $this->Write("AddSecret '{$sWord}'", \LOG_INFO);
$sWord = \trim($sWord); $sWord = \trim($sWord);
@ -121,18 +121,18 @@ class Logger extends \SplFixedArray
} }
} }
public function SetShowSecrets(bool $bShow) : self public function SetShowSecrets(bool $bShow): self
{ {
$this->bShowSecrets = $bShow; $this->bShowSecrets = $bShow;
return $this; return $this;
} }
public function ShowSecrets() : bool public function ShowSecrets(): bool
{ {
return $this->bShowSecrets; return $this->bShowSecrets;
} }
public function SetLevel(int $iLevel) : self public function SetLevel(int $iLevel): self
{ {
$this->iLevel = $iLevel; $this->iLevel = $iLevel;
return $this; return $this;
@ -174,7 +174,7 @@ class Logger extends \SplFixedArray
\E_USER_DEPRECATED => '-USER_DEPRECATED' \E_USER_DEPRECATED => '-USER_DEPRECATED'
); );
public function __phpErrorHandler(int $iErrNo, string $sErrStr, string $sErrFile, int $iErrLine) : bool public function __phpErrorHandler(int $iErrNo, string $sErrStr, string $sErrFile, int $iErrLine): bool
{ {
if (\error_reporting() & $iErrNo) { if (\error_reporting() & $iErrNo) {
$this->Write( $this->Write(
@ -196,7 +196,7 @@ class Logger extends \SplFixedArray
\error_log('Uncaught exception: ' . $oException); \error_log('Uncaught exception: ' . $oException);
} }
public function __loggerShutDown() : void public function __loggerShutDown(): void
{ {
if ($this->bUsed) { if ($this->bUsed) {
$error = \error_get_last(); $error = \error_get_last();
@ -206,7 +206,7 @@ class Logger extends \SplFixedArray
} }
} }
public function signalHandler($signo, /*?array*/$siginfo = null) public function signalHandler(int $signo, mixed $siginfo = null): void
{ {
if (\SIGTERM == $signo) { if (\SIGTERM == $signo) {
exit; exit;
@ -219,7 +219,7 @@ class Logger extends \SplFixedArray
} }
} }
public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false) : bool public function Write(string $sDesc, int $iType = \LOG_INFO, string $sName = '', bool $bDiplayCrLf = false): bool
{ {
if ($this->iLevel < $iType) { if ($this->iLevel < $iType) {
return true; return true;
@ -241,17 +241,14 @@ class Logger extends \SplFixedArray
return (bool) $iResult; return (bool) $iResult;
} }
/** public function WriteDump(mixed $mValue, int $iType = \LOG_INFO, string $sName = ''): bool
* @param mixed $mValue
*/
public function WriteDump($mValue, int $iType = \LOG_INFO, string $sName = '') : bool
{ {
return $this->Write(\print_r($mValue, true), $iType, $sName); return $this->Write(\print_r($mValue, true), $iType, $sName);
} }
private $aExceptions = []; private $aExceptions = [];
public function WriteException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void public function WriteException(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void
{ {
if (!\in_array($oException, $this->aExceptions)) { if (!\in_array($oException, $this->aExceptions)) {
$this->Write((string) $oException, $iType, $sName); $this->Write((string) $oException, $iType, $sName);
@ -259,7 +256,7 @@ class Logger extends \SplFixedArray
} }
} }
public function WriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = '') : void public function WriteExceptionShort(\Throwable $oException, int $iType = \LOG_NOTICE, string $sName = ''): void
{ {
if (!\in_array($oException, $this->aExceptions)) { if (!\in_array($oException, $this->aExceptions)) {
$this->Write($oException->getMessage(), $iType, $sName); $this->Write($oException->getMessage(), $iType, $sName);

View file

@ -32,7 +32,7 @@ class Attachment implements \JsonSerializable
$this->oBodyStructure = $oBodyStructure; $this->oBodyStructure = $oBodyStructure;
} }
public function Clear() : self public function Clear(): self
{ {
$this->sFolder = ''; $this->sFolder = '';
$this->iUid = 0; $this->iUid = 0;
@ -41,23 +41,23 @@ class Attachment implements \JsonSerializable
return $this; return $this;
} }
public function Folder() : string public function Folder(): string
{ {
return $this->sFolder; return $this->sFolder;
} }
public function Uid() : int public function Uid(): int
{ {
return $this->iUid; return $this->iUid;
} }
public function __call(string $name, array $arguments) //: mixed public function __call(string $name, array $arguments): mixed
{ {
return $this->oBodyStructure->{$name}(...$arguments); return $this->oBodyStructure->{$name}(...$arguments);
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return \array_merge([ return \array_merge([
'@Object' => 'Object/Attachment', '@Object' => 'Object/Attachment',

View file

@ -37,12 +37,12 @@ class MailClient
$this->oImapClient = new \MailSo\Imap\ImapClient; $this->oImapClient = new \MailSo\Imap\ImapClient;
} }
public function ImapClient() : \MailSo\Imap\ImapClient public function ImapClient(): \MailSo\Imap\ImapClient
{ {
return $this->oImapClient; return $this->oImapClient;
} }
private function getEnvelopeOrHeadersRequestString() : string private function getEnvelopeOrHeadersRequestString(): string
{ {
if ($this->oImapClient->Settings->message_all_headers) { if ($this->oImapClient->Settings->message_all_headers) {
return FetchType::BODY_HEADER_PEEK; return FetchType::BODY_HEADER_PEEK;
@ -115,7 +115,7 @@ class MailClient
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
* @throws \MailSo\Mail\Exceptions\* * @throws \MailSo\Mail\Exceptions\*
*/ */
public function MessageSetFlag(string $sFolderName, SequenceSet $oRange, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false) : void public function MessageSetFlag(string $sFolderName, SequenceSet $oRange, string $sMessageFlag, bool $bSetAction = true, bool $bSkipUnsupportedFlag = false): void
{ {
if (\count($oRange)) { if (\count($oRange)) {
if ($this->oImapClient->FolderSelect($sFolderName)->IsFlagSupported($sMessageFlag)) { if ($this->oImapClient->FolderSelect($sFolderName)->IsFlagSupported($sMessageFlag)) {
@ -133,7 +133,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function Message(string $sFolderName, int $iIndex, bool $bIndexIsUid = true, ?\MailSo\Cache\CacheClient $oCacher = null) : ?Message public function Message(string $sFolderName, int $iIndex, bool $bIndexIsUid = true, ?\MailSo\Cache\CacheClient $oCacher = null): ?Message
{ {
if (1 > $iIndex) { if (1 > $iIndex) {
throw new \ValueError; throw new \ValueError;
@ -181,14 +181,12 @@ class MailClient
/** /**
* Streams mime part to $mCallback * Streams mime part to $mCallback
* *
* @param mixed $mCallback
*
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \MailSo\RuntimeException * @throws \MailSo\RuntimeException
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function MessageMimeStream($mCallback, string $sFolderName, int $iIndex, string $sMimeIndex) : bool public function MessageMimeStream(callable $mCallback, string $sFolderName, int $iIndex, string $sMimeIndex): bool
{ {
if (!\is_callable($mCallback)) { if (!\is_callable($mCallback)) {
throw new \ValueError; throw new \ValueError;
@ -279,7 +277,7 @@ class MailClient
return ($aFetchResponse && 1 === \count($aFetchResponse)); return ($aFetchResponse && 1 === \count($aFetchResponse));
} }
public function MessageAppendFile(string $sMessageFileName, string $sFolderToSave, ?array $aAppendFlags = null) : int public function MessageAppendFile(string $sMessageFileName, string $sFolderToSave, ?array $aAppendFlags = null): int
{ {
if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName)) { if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName)) {
throw new \ValueError; throw new \ValueError;
@ -299,7 +297,7 @@ class MailClient
* Returns list of new messages since $iPrevUidNext * Returns list of new messages since $iPrevUidNext
* Currently only for INBOX * Currently only for INBOX
*/ */
private function getFolderNextMessageInformation(string $sFolderName, int $iPrevUidNext, int $iCurrentUidNext) : array private function getFolderNextMessageInformation(string $sFolderName, int $iPrevUidNext, int $iCurrentUidNext): array
{ {
$aNewMessages = array(); $aNewMessages = array();
@ -349,7 +347,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, ?SequenceSet $oRange = null) : array public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, ?SequenceSet $oRange = null): array
{ {
if ($oRange) { if ($oRange) {
// $aInfo = $this->oImapClient->FolderExamine($sFolderName)->jsonSerialize(); // $aInfo = $this->oImapClient->FolderExamine($sFolderName)->jsonSerialize();
@ -391,7 +389,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function FolderHash(string $sFolderName) : string public function FolderHash(string $sFolderName): string
{ {
try try
{ {
@ -405,7 +403,7 @@ class MailClient
return ''; return '';
} }
public function MessageThread(string $sFolderName, string $sMessageID) : MessageCollection public function MessageThread(string $sFolderName, string $sMessageID): MessageCollection
{ {
$this->oImapClient->FolderExamine($sFolderName); $this->oImapClient->FolderExamine($sFolderName);
@ -434,7 +432,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
protected function ThreadsMap(string $sAlgorithm, MessageCollection $oMessageCollection, ?\MailSo\Cache\CacheClient $oCacher, bool $bBackground = false) : array protected function ThreadsMap(string $sAlgorithm, MessageCollection $oMessageCollection, ?\MailSo\Cache\CacheClient $oCacher, bool $bBackground = false): array
{ {
$oFolderInfo = $oMessageCollection->FolderInfo; $oFolderInfo = $oMessageCollection->FolderInfo;
$sFolderName = $oFolderInfo->FullName; $sFolderName = $oFolderInfo->FullName;
@ -512,7 +510,7 @@ class MailClient
} }
// All threads UID's except the most recent UID of each thread // All threads UID's except the most recent UID of each thread
protected function ThreadsOldUids(array $aAllThreads, MessageCollection $oMessageCollection, ?\MailSo\Cache\CacheClient $oCacher, bool $bBackground = false) : array protected function ThreadsOldUids(array $aAllThreads, MessageCollection $oMessageCollection, ?\MailSo\Cache\CacheClient $oCacher, bool $bBackground = false): array
{ {
$oFolderInfo = $oMessageCollection->FolderInfo; $oFolderInfo = $oMessageCollection->FolderInfo;
@ -585,7 +583,7 @@ class MailClient
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange, protected function MessageListByRequestIndexOrUids(MessageCollection $oMessageCollection, SequenceSet $oRange,
array &$aAllThreads = [], array &$aUnseenUIDs = []) : void array &$aAllThreads = [], array &$aUnseenUIDs = []): void
{ {
if (\count($oRange)) { if (\count($oRange)) {
$aFetchItems = array( $aFetchItems = array(
@ -633,7 +631,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
private function GetUids(MessageListParams $oParams, FolderInformation $oInfo, bool $onlyCache = false) : ?array private function GetUids(MessageListParams $oParams, FolderInformation $oInfo, bool $onlyCache = false): ?array
{ {
$oCacher = $oParams->oCacher; $oCacher = $oParams->oCacher;
$sFolderName = $oParams->sFolderName; $sFolderName = $oParams->sFolderName;
@ -725,7 +723,7 @@ class MailClient
return $aResultUids; return $aResultUids;
} }
public function MessageListUnseen(MessageListParams $oParams, FolderInformation $oInfo) : array public function MessageListUnseen(MessageListParams $oParams, FolderInformation $oInfo): array
{ {
$oUnseenParams = new MessageListParams; $oUnseenParams = new MessageListParams;
$oUnseenParams->sFolderName = $oParams->sFolderName; $oUnseenParams->sFolderName = $oParams->sFolderName;
@ -749,7 +747,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\* * @throws \MailSo\Net\Exceptions\*
* @throws \MailSo\Imap\Exceptions\* * @throws \MailSo\Imap\Exceptions\*
*/ */
public function MessageList(MessageListParams $oParams) : MessageCollection public function MessageList(MessageListParams $oParams): MessageCollection
{ {
if (0 > $oParams->iOffset || 0 > $oParams->iLimit) { if (0 > $oParams->iOffset || 0 > $oParams->iLimit) {
throw new \ValueError; throw new \ValueError;
@ -911,7 +909,7 @@ class MailClient
return $oMessageCollection; return $oMessageCollection;
} }
public function FindMessageUidByMessageId(string $sFolderName, string $sMessageId) : ?int public function FindMessageUidByMessageId(string $sFolderName, string $sMessageId): ?int
{ {
if (!\strlen($sMessageId)) { if (!\strlen($sMessageId)) {
throw new \ValueError; throw new \ValueError;
@ -924,7 +922,7 @@ class MailClient
return 1 === \count($aUids) && \is_numeric($aUids[0]) ? (int) $aUids[0] : null; return 1 === \count($aUids) && \is_numeric($aUids[0]) ? (int) $aUids[0] : null;
} }
public function Folders(string $sParent, string $sListPattern, bool $bUseListSubscribeStatus) : ?FolderCollection public function Folders(string $sParent, string $sListPattern, bool $bUseListSubscribeStatus): ?FolderCollection
{ {
$oFolderCollection = $this->oImapClient->FolderStatusList($sParent, $sListPattern); $oFolderCollection = $this->oImapClient->FolderStatusList($sParent, $sListPattern);
if (!$oFolderCollection->count()) { if (!$oFolderCollection->count()) {
@ -957,7 +955,7 @@ class MailClient
/** /**
* @throws \ValueError * @throws \ValueError
*/ */
public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = '') : ?\MailSo\Imap\Folder public function FolderCreate(string $sFolderNameInUtf8, string $sFolderParentFullName = '', bool $bSubscribeOnCreation = true, string $sDelimiter = ''): ?\MailSo\Imap\Folder
{ {
$sFolderNameInUtf8 = \trim($sFolderNameInUtf8); $sFolderNameInUtf8 = \trim($sFolderNameInUtf8);
$sFolderParentFullName = \trim($sFolderParentFullName); $sFolderParentFullName = \trim($sFolderParentFullName);
@ -1004,7 +1002,7 @@ class MailClient
/** /**
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function FolderRename(string $sPrevFolderFullName, string $sNewFolderFullName) : self public function FolderRename(string $sPrevFolderFullName, string $sNewFolderFullName): self
{ {
if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName)) { if (!\strlen($sPrevFolderFullName) || !\strlen($sNewFolderFullName)) {
throw new \ValueError; throw new \ValueError;
@ -1047,7 +1045,7 @@ class MailClient
/** /**
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
*/ */
public function SetLogger(?\MailSo\Log\Logger $oLogger) : void public function SetLogger(?\MailSo\Log\Logger $oLogger): void
{ {
$this->oLogger = $oLogger; $this->oLogger = $oLogger;
$this->oImapClient->SetLogger($oLogger); $this->oImapClient->SetLogger($oLogger);

View file

@ -92,52 +92,52 @@ class Message implements \JsonSerializable
return \property_exists($this, $k) ? $this->$k : null; return \property_exists($this, $k) ? $this->$k : null;
} }
public function Subject() : string public function Subject(): string
{ {
return $this->sSubject; return $this->sSubject;
} }
public function From() : ?\MailSo\Mime\EmailCollection public function From(): ?\MailSo\Mime\EmailCollection
{ {
return $this->oFrom; return $this->oFrom;
} }
public function Uid() : int public function Uid(): int
{ {
return $this->Uid; return $this->Uid;
} }
public function Attachments() : ?AttachmentCollection public function Attachments(): ?AttachmentCollection
{ {
return $this->Attachments; return $this->Attachments;
} }
public function setPlain(string $value) : void public function setPlain(string $value): void
{ {
$this->sPlain = $value; $this->sPlain = $value;
} }
public function setHtml(string $value) : void public function setHtml(string $value): void
{ {
$this->sHtml = $value; $this->sHtml = $value;
} }
private function setSpamScore($value) : void private function setSpamScore($value): void
{ {
$this->SpamScore = \intval(\max(0, \min(100, $value))); $this->SpamScore = \intval(\max(0, \min(100, $value)));
} }
public function SetThreads(array $aThreadUIDs) public function SetThreads(array $aThreadUIDs): void
{ {
$this->aThreadUIDs = $aThreadUIDs; $this->aThreadUIDs = $aThreadUIDs;
} }
public function SetThreadUnseen(array $aUnseenUIDs) public function SetThreadUnseen(array $aUnseenUIDs): void
{ {
$this->aThreadUnseenUIDs = $aUnseenUIDs; $this->aThreadUnseenUIDs = $aUnseenUIDs;
} }
public static function fromFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : self public static function fromFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null): self
{ {
$oMessage = new self; $oMessage = new self;
@ -463,7 +463,7 @@ class Message implements \JsonSerializable
return $oMessage; return $oMessage;
} }
public function ETag(string $sClientHash) : string public function ETag(string $sClientHash): string
{ {
return \md5('MessageHash/' . \implode('/', [ return \md5('MessageHash/' . \implode('/', [
$this->sFolder, $this->sFolder,
@ -477,7 +477,7 @@ class Message implements \JsonSerializable
// https://datatracker.ietf.org/doc/html/rfc5788#section-3.4.1 // https://datatracker.ietf.org/doc/html/rfc5788#section-3.4.1
// Thunderbird $label1 is same as $Important? // Thunderbird $label1 is same as $Important?
// Thunderbird $label4 is same as $todo? // Thunderbird $label4 is same as $todo?
protected function getFlags() : array protected function getFlags(): array
{ {
return \array_unique(\str_replace( return \array_unique(\str_replace(
['$readreceipt', '$replied', /* 'junk', 'nonjunk', '$queued', '$sent', 'sent'*/], ['$readreceipt', '$replied', /* 'junk', 'nonjunk', '$queued', '$sent', 'sent'*/],
@ -486,8 +486,8 @@ class Message implements \JsonSerializable
)); ));
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
/* /*
// JMAP-only RFC8621 keywords (RFC5788) // JMAP-only RFC8621 keywords (RFC5788)

View file

@ -36,8 +36,7 @@ class MessageCollection extends \MailSo\Base\Collection
public int $ThreadUid = 0; public int $ThreadUid = 0;
// MailSo\Imap\FolderInformation public ?\MailSo\Imap\FolderInformation $FolderInfo = null;
public $FolderInfo = null;
public array $NewMessages = array(); public array $NewMessages = array();
@ -45,19 +44,19 @@ class MessageCollection extends \MailSo\Base\Collection
public bool $Limited = false; public bool $Limited = false;
public function append($oMessage, bool $bToTop = false) : void public function append($oMessage, bool $bToTop = false): void
{ {
assert($oMessage instanceof Message); assert($oMessage instanceof Message);
parent::append($oMessage, $bToTop); parent::append($oMessage, $bToTop);
} }
public function Clear() : void public function Clear(): void
{ {
throw new \BadMethodCallException('disallowed'); throw new \BadMethodCallException('disallowed');
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return \array_merge(parent::jsonSerialize(), array( return \array_merge(parent::jsonSerialize(), array(
'totalEmails' => $this->totalEmails, 'totalEmails' => $this->totalEmails,

View file

@ -200,8 +200,8 @@ class Email implements \JsonSerializable
return $this->ToString(); return $this->ToString();
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Object/Email', '@Object' => 'Object/Email',

View file

@ -27,13 +27,13 @@ class EmailCollection extends \MailSo\Base\Collection
} }
} }
public function append($oEmail, bool $bToTop = false) : void public function append($oEmail, bool $bToTop = false): void
{ {
assert($oEmail instanceof Email); assert($oEmail instanceof Email);
parent::append($oEmail, $bToTop); parent::append($oEmail, $bToTop);
} }
public function Unique() : self public function Unique(): self
{ {
$aReturn = array(); $aReturn = array();
@ -47,7 +47,7 @@ class EmailCollection extends \MailSo\Base\Collection
return new static($aReturn); return new static($aReturn);
} }
public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false): string
{ {
$aReturn = array(); $aReturn = array();
foreach ($this as $oEmail) { foreach ($this as $oEmail) {
@ -57,12 +57,12 @@ class EmailCollection extends \MailSo\Base\Collection
return \implode(', ', $aReturn); return \implode(', ', $aReturn);
} }
public function __toString() : string public function __toString(): string
{ {
return $this->ToString(); return $this->ToString();
} }
private function parseEmailAddresses(string $sRawEmails) : void private function parseEmailAddresses(string $sRawEmails): void
{ {
// $sRawEmails = \MailSo\Base\Utils::Trim($sRawEmails); // $sRawEmails = \MailSo\Base\Utils::Trim($sRawEmails);
$sRawEmails = \trim($sRawEmails); $sRawEmails = \trim($sRawEmails);
@ -156,8 +156,8 @@ class EmailCollection extends \MailSo\Base\Collection
} }
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return \array_slice($this->getArrayCopy(), 0, 100); return \array_slice($this->getArrayCopy(), 0, 100);
} }

View file

@ -35,7 +35,7 @@ class Header implements \JsonSerializable
$this->initInputData($sName, $sValue, $sEncodedValueForReparse); $this->initInputData($sName, $sValue, $sEncodedValueForReparse);
} }
private function initInputData(string $sName, string $sValue, string $sEncodedValueForReparse) : void private function initInputData(string $sName, string $sValue, string $sEncodedValueForReparse): void
{ {
$this->sName = \trim($sName); $this->sName = \trim($sName);
$this->sFullValue = \trim($sValue); $this->sFullValue = \trim($sValue);
@ -62,7 +62,7 @@ class Header implements \JsonSerializable
} }
} }
public static function NewInstanceFromEncodedString(string $sEncodedLines, string $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1) : Header public static function NewInstanceFromEncodedString(string $sEncodedLines, string $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1): Header
{ {
if (empty($sIncomingCharset)) { if (empty($sIncomingCharset)) {
$sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1; $sIncomingCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1;
@ -81,27 +81,27 @@ class Header implements \JsonSerializable
return false; return false;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function Value() : string public function Value(): string
{ {
return $this->sValue; return $this->sValue;
} }
public function FullValue() : string public function FullValue(): string
{ {
return $this->sFullValue; return $this->sFullValue;
} }
public function EncodedValue() : string public function EncodedValue(): string
{ {
return $this->sEncodedValue ?: $this->sFullValue; return $this->sEncodedValue ?: $this->sFullValue;
} }
public function SetParentCharset(string $sParentCharset) : Header public function SetParentCharset(string $sParentCharset): Header
{ {
if ($this->sParentCharset !== $sParentCharset && \strlen($this->sEncodedValue)) { if ($this->sParentCharset !== $sParentCharset && \strlen($this->sEncodedValue)) {
$this->initInputData( $this->initInputData(
@ -116,17 +116,17 @@ class Header implements \JsonSerializable
return $this; return $this;
} }
public function Parameters() : ?ParameterCollection public function Parameters(): ?ParameterCollection
{ {
return $this->oParameters; return $this->oParameters;
} }
public function setParameter(string $sName, string $sValue) : void public function setParameter(string $sName, string $sValue): void
{ {
$this->oParameters->setParameter($sName, $sValue); $this->oParameters->setParameter($sName, $sValue);
} }
public function __toString() : string public function __toString(): string
{ {
$sResult = $this->sFullValue; $sResult = $this->sFullValue;
@ -159,12 +159,12 @@ class Header implements \JsonSerializable
return $sName . \wordwrap($sResult, 78 - \strlen($sName) - 1, "\r\n "); return $sName . \wordwrap($sResult, 78 - \strlen($sName) - 1, "\r\n ");
} }
private function IsSubject() : bool private function IsSubject(): bool
{ {
return \strtolower(Enumerations\Header::SUBJECT) === \strtolower($this->Name()); return \strtolower(Enumerations\Header::SUBJECT) === \strtolower($this->Name());
} }
private function IsParameterized() : bool private function IsParameterized(): bool
{ {
return \in_array(\strtolower($this->sName), array( return \in_array(\strtolower($this->sName), array(
\strtolower(Enumerations\Header::CONTENT_TYPE), \strtolower(Enumerations\Header::CONTENT_TYPE),
@ -173,7 +173,7 @@ class Header implements \JsonSerializable
)); ));
} }
private function IsEmail() : bool private function IsEmail(): bool
{ {
return \in_array(\strtolower($this->sName), array( return \in_array(\strtolower($this->sName), array(
\strtolower(Enumerations\Header::FROM_), \strtolower(Enumerations\Header::FROM_),
@ -186,7 +186,7 @@ class Header implements \JsonSerializable
)); ));
} }
public function ValueWithCharsetAutoDetect() : string public function ValueWithCharsetAutoDetect(): string
{ {
if (!\MailSo\Base\Utils::IsAscii($this->Value()) if (!\MailSo\Base\Utils::IsAscii($this->Value())
&& \strlen($this->sEncodedValue) && \strlen($this->sEncodedValue)
@ -198,8 +198,8 @@ class Header implements \JsonSerializable
return $this->Value(); return $this->Value();
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aResult = array( $aResult = array(
'@Object' => 'Object/MimeHeader', '@Object' => 'Object/MimeHeader',

View file

@ -27,30 +27,30 @@ class HeaderCollection extends \MailSo\Base\Collection
} }
} }
public function append($oHeader, bool $bToTop = false) : void public function append($oHeader, bool $bToTop = false): void
{ {
assert($oHeader instanceof Header); assert($oHeader instanceof Header);
parent::append($oHeader, $bToTop); parent::append($oHeader, $bToTop);
} }
public function AddByName(string $sName, string $sValue, bool $bToTop = false) : self public function AddByName(string $sName, string $sValue, bool $bToTop = false): self
{ {
$this->append(new Header($sName, $sValue), $bToTop); $this->append(new Header($sName, $sValue), $bToTop);
return $this; return $this;
} }
public function SetByName(string $sName, string $sValue, bool $bToTop = false) : self public function SetByName(string $sName, string $sValue, bool $bToTop = false): self
{ {
return $this->RemoveByName($sName)->Add(new Header($sName, $sValue), $bToTop); return $this->RemoveByName($sName)->Add(new Header($sName, $sValue), $bToTop);
} }
public function ValueByName(string $sHeaderName, bool $bCharsetAutoDetect = false) : string public function ValueByName(string $sHeaderName, bool $bCharsetAutoDetect = false): string
{ {
$oHeader = $this->GetByName($sHeaderName); $oHeader = $this->GetByName($sHeaderName);
return $oHeader ? ($bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value()) : ''; return $oHeader ? ($bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value()) : '';
} }
public function ValuesByName(string $sHeaderName) : array public function ValuesByName(string $sHeaderName): array
{ {
$aResult = array(); $aResult = array();
$sHeaderNameLower = \strtolower($sHeaderName); $sHeaderNameLower = \strtolower($sHeaderName);
@ -62,7 +62,7 @@ class HeaderCollection extends \MailSo\Base\Collection
return $aResult; return $aResult;
} }
public function RemoveByName(string $sHeaderName) : self public function RemoveByName(string $sHeaderName): self
{ {
$sHeaderName = \strtolower($sHeaderName); $sHeaderName = \strtolower($sHeaderName);
$this->exchangeArray(array_filter($this->getArrayCopy(), function ($oHeader) use ($sHeaderName) { $this->exchangeArray(array_filter($this->getArrayCopy(), function ($oHeader) use ($sHeaderName) {
@ -71,7 +71,7 @@ class HeaderCollection extends \MailSo\Base\Collection
return $this; return $this;
} }
public function GetAsEmailCollection(string $sHeaderName) : ?EmailCollection public function GetAsEmailCollection(string $sHeaderName): ?EmailCollection
{ {
if ($oHeader = $this->GetByName($sHeaderName)) { if ($oHeader = $this->GetByName($sHeaderName)) {
return new EmailCollection($oHeader->EncodedValue()); return new EmailCollection($oHeader->EncodedValue());
@ -79,14 +79,14 @@ class HeaderCollection extends \MailSo\Base\Collection
return new EmailCollection(); return new EmailCollection();
} }
public function ParameterValue(string $sHeaderName, string $sParamName) : string public function ParameterValue(string $sHeaderName, string $sParamName): string
{ {
$oHeader = $this->GetByName($sHeaderName); $oHeader = $this->GetByName($sHeaderName);
$oParameters = $oHeader ? $oHeader->Parameters() : null; $oParameters = $oHeader ? $oHeader->Parameters() : null;
return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : ''; return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : '';
} }
public function GetByName(string $sHeaderName) : ?Header public function GetByName(string $sHeaderName): ?Header
{ {
$sHeaderNameLower = \strtolower($sHeaderName); $sHeaderNameLower = \strtolower($sHeaderName);
foreach ($this as $oHeader) { foreach ($this as $oHeader) {
@ -97,7 +97,7 @@ class HeaderCollection extends \MailSo\Base\Collection
return null; return null;
} }
public function SetParentCharset(string $sParentCharset) : self public function SetParentCharset(string $sParentCharset): self
{ {
if (\strlen($sParentCharset) && $this->sParentCharset !== $sParentCharset) { if (\strlen($sParentCharset) && $this->sParentCharset !== $sParentCharset) {
foreach ($this as $oHeader) { foreach ($this as $oHeader) {
@ -108,7 +108,7 @@ class HeaderCollection extends \MailSo\Base\Collection
return $this; return $this;
} }
public function Parse(string $sRawHeaders, string $sParentCharset = '') : self public function Parse(string $sRawHeaders, string $sParentCharset = ''): self
{ {
$this->Clear(); $this->Clear();
@ -180,7 +180,7 @@ class HeaderCollection extends \MailSo\Base\Collection
* spf=pass (ORIGINATING: domain of "snappymail@domain.tld" designates 0.0.0.0 as permitted sender) smtp.mailfrom="snappymail@domain.tld"; * spf=pass (ORIGINATING: domain of "snappymail@domain.tld" designates 0.0.0.0 as permitted sender) smtp.mailfrom="snappymail@domain.tld";
* dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=domain.tld (policy=none) * dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=domain.tld (policy=none)
*/ */
public function AuthStatuses() : array public function AuthStatuses(): array
{ {
$aResult = [ $aResult = [
'dkim' => [], 'dkim' => [],
@ -222,13 +222,13 @@ class HeaderCollection extends \MailSo\Base\Collection
return $aResult; return $aResult;
} }
public function __toString() : string public function __toString(): string
{ {
return \implode("\r\n", $this->getArrayCopy()); return \implode("\r\n", $this->getArrayCopy());
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Collection/MimeHeaderCollection', '@Object' => 'Collection/MimeHeaderCollection',

View file

@ -27,7 +27,7 @@ class Parameter implements \JsonSerializable
$this->sValue = $sValue; $this->sValue = $sValue;
} }
public static function FromString(string $sRawParam) : self public static function FromString(string $sRawParam): self
{ {
$oParameter = new self('', ''); $oParameter = new self('', '');
@ -40,22 +40,22 @@ class Parameter implements \JsonSerializable
return $oParameter; return $oParameter;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function Value() : string public function Value(): string
{ {
return $this->sValue; return $this->sValue;
} }
public function setValue(string $sValue) : void public function setValue(string $sValue): void
{ {
$this->sValue = $sValue; $this->sValue = $sValue;
} }
public function ToString(bool $bConvertSpecialsName = false) : string public function ToString(bool $bConvertSpecialsName = false): string
{ {
if (!\strlen($this->sName)) { if (!\strlen($this->sName)) {
return ''; return '';
@ -72,13 +72,13 @@ class Parameter implements \JsonSerializable
return $this->sName . '="' . $this->sValue . '"'; return $this->sName . '="' . $this->sValue . '"';
} }
public function __toString() : string public function __toString(): string
{ {
return $this->ToString(); return $this->ToString();
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'name' => $this->sName, 'name' => $this->sName,

View file

@ -24,25 +24,25 @@ class ParameterCollection extends \MailSo\Base\Collection
\strlen($sRawParams) && $this->Parse($sRawParams); \strlen($sRawParams) && $this->Parse($sRawParams);
} }
public function append($oParameter, bool $bToTop = false) : void public function append($oParameter, bool $bToTop = false): void
{ {
assert($oParameter instanceof Parameter); assert($oParameter instanceof Parameter);
parent::offsetSet(\strtolower($oParameter->Name()), $oParameter); parent::offsetSet(\strtolower($oParameter->Name()), $oParameter);
} }
public function ParameterValueByName(string $sName) : string public function ParameterValueByName(string $sName): string
{ {
$oParam = $this->getParameter($sName); $oParam = $this->getParameter($sName);
return $oParam ? $oParam->Value() : ''; return $oParam ? $oParam->Value() : '';
} }
public function getParameter(string $sName) : ?Parameter public function getParameter(string $sName): ?Parameter
{ {
$sName = \strtolower(\trim($sName)); $sName = \strtolower(\trim($sName));
return parent::offsetExists($sName) ? parent::offsetGet($sName) : null; return parent::offsetExists($sName) ? parent::offsetGet($sName) : null;
} }
public function setParameter(string $sName, string $sValue) : void public function setParameter(string $sName, string $sValue): void
{ {
$oParam = $this->getParameter($sName); $oParam = $this->getParameter($sName);
if ($oParam) { if ($oParam) {
@ -52,7 +52,7 @@ class ParameterCollection extends \MailSo\Base\Collection
} }
} }
public function Parse(string $sRawParams) : self public function Parse(string $sRawParams): self
{ {
$this->Clear(); $this->Clear();
@ -67,7 +67,7 @@ class ParameterCollection extends \MailSo\Base\Collection
return $this; return $this;
} }
public function ToString(bool $bConvertSpecialsName = false) : string public function ToString(bool $bConvertSpecialsName = false): string
{ {
$aResult = array(); $aResult = array();
foreach ($this as $oParam) { foreach ($this as $oParam) {
@ -79,14 +79,14 @@ class ParameterCollection extends \MailSo\Base\Collection
return \count($aResult) ? \implode('; ', $aResult) : ''; return \count($aResult) ? \implode('; ', $aResult) : '';
} }
public function __toString() : string public function __toString(): string
{ {
return $this->ToString(); return $this->ToString();
} }
/* /*
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aResult = array(); $aResult = array();
foreach ($this as $oParam) { foreach ($this as $oParam) {
@ -99,7 +99,7 @@ class ParameterCollection extends \MailSo\Base\Collection
} }
*/ */
private function reParseParameters() : void private function reParseParameters(): void
{ {
$aDataToReParse = $this->getArrayCopy(); $aDataToReParse = $this->getArrayCopy();
$sCharset = \MailSo\Base\Enumerations\Charset::UTF_8; $sCharset = \MailSo\Base\Enumerations\Charset::UTF_8;

View file

@ -83,7 +83,7 @@ class ConnectSettings implements \JsonSerializable
} }
} }
public function fixUsername(string $value, bool $allowShorten = true) : string public function fixUsername(string $value, bool $allowShorten = true): string
{ {
$value = \SnappyMail\IDN::emailToAscii($value); $value = \SnappyMail\IDN::emailToAscii($value);
// $value = \SnappyMail\IDN::emailToAscii(\MailSo\Base\Utils::Trim($value)); // $value = \SnappyMail\IDN::emailToAscii(\MailSo\Base\Utils::Trim($value));
@ -104,7 +104,7 @@ class ConnectSettings implements \JsonSerializable
return $value; return $value;
} }
public static function fromArray(array $aSettings) : self public static function fromArray(array $aSettings): self
{ {
$object = new static; $object = new static;
$object->host = $aSettings['host']; $object->host = $aSettings['host'];
@ -128,8 +128,8 @@ class ConnectSettings implements \JsonSerializable
return $object; return $object;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
// '@Object' => 'Object/ConnectSettings', // '@Object' => 'Object/ConnectSettings',

View file

@ -50,7 +50,7 @@ class SSLContext implements \JsonSerializable
$this->local_cert = \trim($oConfig->Get('ssl', 'local_cert', '')); $this->local_cert = \trim($oConfig->Get('ssl', 'local_cert', ''));
} }
public static function fromArray(array $settings) : self public static function fromArray(array $settings): self
{ {
$object = new static; $object = new static;
foreach ($settings as $key => $value) { foreach ($settings as $key => $value) {
@ -59,8 +59,8 @@ class SSLContext implements \JsonSerializable
return $object; return $object;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aResult = \get_object_vars($this); $aResult = \get_object_vars($this);
// $aResult['@Object'] = 'Object/SSLContext'; // $aResult['@Object'] = 'Object/SSLContext';

View file

@ -23,7 +23,7 @@ class Settings extends \MailSo\Net\ConnectSettings
public bool $authLiteral = true; public bool $authLiteral = true;
public static function fromArray(array $aSettings) : self public static function fromArray(array $aSettings): self
{ {
$object = parent::fromArray($aSettings); $object = parent::fromArray($aSettings);
$object->enabled = !empty($aSettings['enabled']); $object->enabled = !empty($aSettings['enabled']);
@ -31,8 +31,8 @@ class Settings extends \MailSo\Net\ConnectSettings
return $object; return $object;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return \array_merge( return \array_merge(
parent::jsonSerialize(), parent::jsonSerialize(),

View file

@ -37,7 +37,7 @@ class Settings extends \MailSo\Net\ConnectSettings
$this->viewErrors = !!$oConfig->Get('labs', 'smtp_show_server_errors', false); $this->viewErrors = !!$oConfig->Get('labs', 'smtp_show_server_errors', false);
} }
public static function fromArray(array $aSettings) : self public static function fromArray(array $aSettings): self
{ {
$object = parent::fromArray($aSettings); $object = parent::fromArray($aSettings);
$object->useAuth = !empty($aSettings['useAuth']); $object->useAuth = !empty($aSettings['useAuth']);
@ -48,8 +48,8 @@ class Settings extends \MailSo\Net\ConnectSettings
return $object; return $object;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return \array_merge( return \array_merge(
parent::jsonSerialize(), parent::jsonSerialize(),

View file

@ -167,10 +167,7 @@ class Actions
return $this->oConfig; return $this->oConfig;
} }
/** protected function fabrica(string $sName, ?Model\Account $oAccount = null): mixed
* @return mixed
*/
protected function fabrica(string $sName, ?Model\Account $oAccount = null)
{ {
$mResult = null; $mResult = null;
$this->oPlugins->RunHook('main.fabrica', array($sName, &$mResult), false); $this->oPlugins->RunHook('main.fabrica', array($sName, &$mResult), false);
@ -958,12 +955,7 @@ class Actions
return $this; return $this;
} }
/** public function GetActionParam(string $sKey, mixed $mDefault = null): mixed
* @param mixed $mDefault = null
*
* @return mixed
*/
public function GetActionParam(string $sKey, ?mixed $mDefault = null)
{ {
return isset($this->aCurrentActionParams[$sKey]) ? return isset($this->aCurrentActionParams[$sKey]) ?
$this->aCurrentActionParams[$sKey] : $mDefault; $this->aCurrentActionParams[$sKey] : $mDefault;

View file

@ -7,10 +7,7 @@ use RainLoop\Utils;
trait Response trait Response
{ {
/** public function DefaultResponse(mixed $mResult, array $aAdditionalParams = array(), string $sActionName = ''): array
* @param mixed $mResult
*/
public function DefaultResponse($mResult, array $aAdditionalParams = array(), string $sActionName = '') : array
{ {
if (false === $mResult) { if (false === $mResult) {
if (!isset($aAdditionalParams['code'])) { if (!isset($aAdditionalParams['code'])) {
@ -28,12 +25,12 @@ trait Response
), $aAdditionalParams); ), $aAdditionalParams);
} }
public function TrueResponse(array $aAdditionalParams = array()) : array public function TrueResponse(array $aAdditionalParams = array()): array
{ {
return $this->DefaultResponse(true, $aAdditionalParams); return $this->DefaultResponse(true, $aAdditionalParams);
} }
public function FalseResponse(int $iErrorCode = 0, string $sErrorMessage = '', string $sAdditionalErrorMessage = '') : array public function FalseResponse(int $iErrorCode = 0, string $sErrorMessage = '', string $sAdditionalErrorMessage = ''): array
{ {
return $this->DefaultResponse(false, [ return $this->DefaultResponse(false, [
'code' => $iErrorCode, 'code' => $iErrorCode,
@ -42,7 +39,7 @@ trait Response
]); ]);
} }
public function ExceptionResponse(\Throwable $oException) : array public function ExceptionResponse(\Throwable $oException): array
{ {
$iErrorCode = Notifications::UnknownError; $iErrorCode = Notifications::UnknownError;
$sErrorMessage = $oException->getMessage(); $sErrorMessage = $oException->getMessage();
@ -69,13 +66,8 @@ trait Response
]); ]);
} }
/**
* @param mixed $mResponse
*
* @return mixed
*/
private $aCheckableFolder = null; private $aCheckableFolder = null;
private function responseObject($mResponse, string $sParent = '') private function responseObject(mixed $mResponse, string $sParent = ''): mixed
{ {
if (!($mResponse instanceof \JsonSerializable)) { if (!($mResponse instanceof \JsonSerializable)) {
if (\is_object($mResponse)) { if (\is_object($mResponse)) {

View file

@ -33,56 +33,47 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
\MailSo\Base\Utils::FunctionsCallable(array('apcu_fetch', 'apcu_store')); \MailSo\Base\Utils::FunctionsCallable(array('apcu_fetch', 'apcu_store'));
} }
public function offsetExists($offset) : bool public function offsetExists(mixed $offset): bool
{ {
} }
#[\ReturnTypeWillChange] public function offsetGet(mixed $offset): mixed
public function offsetGet($offset)
{ {
$offset = \explode('/', $offset, 2); $offset = \explode('/', $offset, 2);
$this->Get($offset[0], $offset[1]); $this->Get($offset[0], $offset[1]);
} }
public function offsetSet($offset, $value) : void public function offsetSet(mixed $offset, mixed $value): void
{ {
$offset = \explode('/', $offset, 2); $offset = \explode('/', $offset, 2);
$this->Set($offset[0], $offset[1], $value); $this->Set($offset[0], $offset[1], $value);
} }
public function offsetUnset($offset) : void public function offsetUnset(mixed $offset): void
{ {
} }
protected abstract function defaultValues() : array; protected abstract function defaultValues(): array;
public function IsInited() : bool public function IsInited(): bool
{ {
return \is_array($this->aData) && \count($this->aData); return \is_array($this->aData) && \count($this->aData);
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return $this->aData;; return $this->aData;;
} }
/** public function Get(string $sSection, string $sName, mixed $mDefault = null): mixed
* @param mixed $mDefault = null
*
* @return mixed
*/
public function Get(string $sSection, string $sName, $mDefault = null)
{ {
return isset($this->aData[$sSection][$sName][0]) return isset($this->aData[$sSection][$sName][0])
? $this->aData[$sSection][$sName][0] ? $this->aData[$sSection][$sName][0]
: $mDefault; : $mDefault;
} }
/** public function Set(string $sSectionKey, string $sParamKey, mixed $mParamValue): void
* @param mixed $mParamValue
*/
public function Set(string $sSectionKey, string $sParamKey, $mParamValue) : void
{ {
if (isset($this->aData[$sSectionKey][$sParamKey][0])) { if (isset($this->aData[$sSectionKey][$sParamKey][0])) {
if (!\is_scalar($mParamValue)) { if (!\is_scalar($mParamValue)) {
@ -109,7 +100,7 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
} }
} }
public function getDecrypted(string $sSection, string $sName, $mDefault = null) public function getDecrypted(string $sSection, string $sName, mixed $mDefault = null)
{ {
// $salt = \basename($this->sFile) not possible due to RainLoop\Plugins\Property // $salt = \basename($this->sFile) not possible due to RainLoop\Plugins\Property
if (!empty($this->aData[$sSection][$sName][0])) try { if (!empty($this->aData[$sSection][$sName][0])) try {
@ -119,19 +110,19 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
return $mDefault; return $mDefault;
} }
public function setEncrypted(string $sSectionKey, string $sParamKey, $mParamValue) : void public function setEncrypted(string $sSectionKey, string $sParamKey, mixed $mParamValue): void
{ {
// $salt = \basename($this->sFile) not possible due to RainLoop\Plugins\Property // $salt = \basename($this->sFile) not possible due to RainLoop\Plugins\Property
$mParamValue = \SnappyMail\Crypt::EncryptToJSON($mParamValue, \APP_SALT); $mParamValue = \SnappyMail\Crypt::EncryptToJSON($mParamValue, \APP_SALT);
$this->Set($sSectionKey, $sParamKey, $mParamValue); $this->Set($sSectionKey, $sParamKey, $mParamValue);
} }
private function cacheKey() : string private function cacheKey(): string
{ {
return 'config:'.\sha1($this->sFile).':'.\sha1($this->sAdditionalFile).':'; return 'config:'.\sha1($this->sFile).':'.\sha1($this->sAdditionalFile).':';
} }
private function loadDataFromCache() : bool private function loadDataFromCache(): bool
{ {
if ($this->bUseApcCache) { if ($this->bUseApcCache) {
$iMTime = \filemtime($this->sFile); $iMTime = \filemtime($this->sFile);
@ -157,7 +148,7 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
return false; return false;
} }
private function storeDataToCache() : bool private function storeDataToCache(): bool
{ {
if ($this->bUseApcCache) { if ($this->bUseApcCache) {
$iMTime = \filemtime($this->sFile); $iMTime = \filemtime($this->sFile);
@ -179,7 +170,7 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
return false; return false;
} }
private function clearCache() : bool private function clearCache(): bool
{ {
if ($this->bUseApcCache) { if ($this->bUseApcCache) {
$sKey = $this->cacheKey(); $sKey = $this->cacheKey();
@ -193,7 +184,7 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
return false; return false;
} }
public function Load() : bool public function Load(): bool
{ {
$sFile = $this->sFile; $sFile = $this->sFile;
if (!\file_exists($sFile) && \str_ends_with($sFile, '.json')) { if (!\file_exists($sFile) && \str_ends_with($sFile, '.json')) {
@ -248,7 +239,7 @@ abstract class AbstractConfig implements \ArrayAccess, \JsonSerializable
return $this->Save(); return $this->Save();
} }
public function Save() : bool public function Save(): bool
{ {
if (\file_exists($this->sFile) && !\is_writable($this->sFile)) { if (\file_exists($this->sFile) && !\is_writable($this->sFile)) {
return false; return false;

View file

@ -14,7 +14,7 @@ class Application extends \RainLoop\Config\AbstractConfig
APP_CONFIGURATION_NAME); APP_CONFIGURATION_NAME);
} }
public function Load() : bool public function Load(): bool
{ {
$bResult = parent::Load(); $bResult = parent::Load();
@ -64,12 +64,7 @@ class Application extends \RainLoop\Config\AbstractConfig
return $bResult; return $bResult;
} }
/** public function Get(string $sSection, string $sName, mixed $mDefault = null): mixed
* @param mixed $mDefault = null
*
* @return mixed
*/
public function Get(string $sSection, string $sName, $mDefault = null)
{ {
$mResult = parent::Get($sSection, $sName, $mDefault); $mResult = parent::Get($sSection, $sName, $mDefault);
if ($this->aReplaceEnv && \is_string($mResult)) { if ($this->aReplaceEnv && \is_string($mResult)) {
@ -92,7 +87,7 @@ class Application extends \RainLoop\Config\AbstractConfig
return $mResult; return $mResult;
} }
public function Set(string $sSectionKey, string $sParamKey, $mParamValue) : void public function Set(string $sSectionKey, string $sParamKey, $mParamValue): void
{ {
// Workarounds for the changed application structure // Workarounds for the changed application structure
if ('webmail' === $sSectionKey) { if ('webmail' === $sSectionKey) {
@ -143,17 +138,17 @@ class Application extends \RainLoop\Config\AbstractConfig
parent::Set($sSectionKey, $sParamKey, $mParamValue); parent::Set($sSectionKey, $sParamKey, $mParamValue);
} }
public function SetPassword(\SnappyMail\SensitiveString $oPassword) : void public function SetPassword(\SnappyMail\SensitiveString $oPassword): void
{ {
$this->Set('security', 'admin_password', \password_hash($oPassword, PASSWORD_DEFAULT)); $this->Set('security', 'admin_password', \password_hash($oPassword, PASSWORD_DEFAULT));
} }
public function ValidatePassword(\SnappyMail\SensitiveString $oPassword) : bool public function ValidatePassword(\SnappyMail\SensitiveString $oPassword): bool
{ {
return \strlen($oPassword) && \password_verify($oPassword, $this->Get('security', 'admin_password', '')); return \strlen($oPassword) && \password_verify($oPassword, $this->Get('security', 'admin_password', ''));
} }
public function Save() : bool public function Save(): bool
{ {
$this->Set('version', 'current', APP_VERSION); $this->Set('version', 'current', APP_VERSION);
$this->Set('version', 'saved', \gmdate('r')); $this->Set('version', 'saved', \gmdate('r'));
@ -161,7 +156,7 @@ class Application extends \RainLoop\Config\AbstractConfig
return parent::Save(); return parent::Save();
} }
protected function defaultValues() : array protected function defaultValues(): array
{ {
$value = \ini_get('upload_max_filesize'); $value = \ini_get('upload_max_filesize');
$upload_max_filesize = \intval($value); $upload_max_filesize = \intval($value);

View file

@ -31,13 +31,13 @@ class Plugin extends \RainLoop\Config\AbstractConfig
parent::__construct('plugin-'.$sPluginName.'.json'); parent::__construct('plugin-'.$sPluginName.'.json');
} }
protected function defaultValues() : array protected function defaultValues(): array
{ {
return $this->aMap; return $this->aMap;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aData = []; $aData = [];
foreach (parent::jsonSerialize() as $sSectionKey => $aSectionValue) { foreach (parent::jsonSerialize() as $sSectionKey => $aSectionValue) {

View file

@ -23,38 +23,38 @@ abstract class Account implements \JsonSerializable
private ?Domain $oDomain = null; private ?Domain $oDomain = null;
public function Email() : string public function Email(): string
{ {
return $this->sEmail; return $this->sEmail;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function ImapUser() : string public function ImapUser(): string
{ {
return $this->sImapUser; return $this->sImapUser;
} }
public function ImapPass() : string public function ImapPass(): string
{ {
return $this->oImapPass ? $this->oImapPass->getValue() : ''; return $this->oImapPass ? $this->oImapPass->getValue() : '';
} }
public function SmtpUser() : string public function SmtpUser(): string
{ {
return $this->sSmtpUser ?: ($this->oDomain ? $this->oDomain->SmtpSettings()->fixUsername($this->sEmail) : ''); return $this->sSmtpUser ?: ($this->oDomain ? $this->oDomain->SmtpSettings()->fixUsername($this->sEmail) : '');
// return $this->sSmtpUser ?: $this->sEmail ?: $this->sImapUser; // return $this->sSmtpUser ?: $this->sEmail ?: $this->sImapUser;
} }
public function Domain() : ?Domain public function Domain(): ?Domain
{ {
return $this->oDomain; return $this->oDomain;
} }
public function Hash() : string public function Hash(): string
{ {
return \sha1(\implode(APP_SALT, [ return \sha1(\implode(APP_SALT, [
$this->sEmail, $this->sEmail,
@ -64,28 +64,28 @@ abstract class Account implements \JsonSerializable
])); ]));
} }
public function setImapUser(string $sImapUser) : void public function setImapUser(string $sImapUser): void
{ {
$this->sImapUser = $sImapUser; $this->sImapUser = $sImapUser;
} }
public function setImapPass(SensitiveString $oPassword) : void public function setImapPass(SensitiveString $oPassword): void
{ {
$this->oImapPass = $oPassword; $this->oImapPass = $oPassword;
} }
public function setSmtpUser(string $sSmtpUser) : void public function setSmtpUser(string $sSmtpUser): void
{ {
$this->sSmtpUser = $sSmtpUser; $this->sSmtpUser = $sSmtpUser;
} }
public function setSmtpPass(SensitiveString $oPassword) : void public function setSmtpPass(SensitiveString $oPassword): void
{ {
$this->oSmtpPass = $oPassword; $this->oSmtpPass = $oPassword;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$result = [ $result = [
'email' => $this->sEmail, 'email' => $this->sEmail,
@ -122,7 +122,7 @@ abstract class Account implements \JsonSerializable
/** /**
* Converts old numeric array to new associative array * Converts old numeric array to new associative array
*/ */
public static function convertArray(array $aAccount) : array public static function convertArray(array $aAccount): array
{ {
if (isset($aAccount['email'])) { if (isset($aAccount['email'])) {
return $aAccount; return $aAccount;
@ -193,7 +193,7 @@ abstract class Account implements \JsonSerializable
return $oAccount; return $oAccount;
} }
public function ImapConnectAndLogin(\RainLoop\Plugins\Manager $oPlugins, \MailSo\Imap\ImapClient $oImapClient, \RainLoop\Config\Application $oConfig) : bool public function ImapConnectAndLogin(\RainLoop\Plugins\Manager $oPlugins, \MailSo\Imap\ImapClient $oImapClient, \RainLoop\Config\Application $oConfig): bool
{ {
$oSettings = $this->Domain()->ImapSettings(); $oSettings = $this->Domain()->ImapSettings();
$oSettings->timeout = \max($oSettings->timeout, (int) $oConfig->Get('imap', 'timeout', $oSettings->timeout)); $oSettings->timeout = \max($oSettings->timeout, (int) $oConfig->Get('imap', 'timeout', $oSettings->timeout));
@ -218,7 +218,7 @@ abstract class Account implements \JsonSerializable
return $this->netClientLogin($oImapClient, $oPlugins); return $this->netClientLogin($oImapClient, $oPlugins);
} }
public function SmtpConnectAndLogin(\RainLoop\Plugins\Manager $oPlugins, \MailSo\Smtp\SmtpClient $oSmtpClient) : bool public function SmtpConnectAndLogin(\RainLoop\Plugins\Manager $oPlugins, \MailSo\Smtp\SmtpClient $oSmtpClient): bool
{ {
$oSettings = $this->Domain()->SmtpSettings(); $oSettings = $this->Domain()->SmtpSettings();
$oSettings->username = $this->SmtpUser(); $oSettings->username = $this->SmtpUser();
@ -257,7 +257,7 @@ abstract class Account implements \JsonSerializable
return $this->netClientLogin($oSieveClient, $oPlugins); return $this->netClientLogin($oSieveClient, $oPlugins);
} }
private function netClientLogin(\MailSo\Net\NetClient $oClient, \RainLoop\Plugins\Manager $oPlugins) : bool private function netClientLogin(\MailSo\Net\NetClient $oClient, \RainLoop\Plugins\Manager $oPlugins): bool
{ {
/* /*
$encrypted = !empty(\stream_get_meta_data($oClient->ConnectionResource())['crypto']); $encrypted = !empty(\stream_get_meta_data($oClient->ConnectionResource())['crypto']);
@ -280,7 +280,7 @@ abstract class Account implements \JsonSerializable
/* /*
// Stores settings in AdditionalAccount else MainAccount // Stores settings in AdditionalAccount else MainAccount
public function settingsLocal() : \RainLoop\Settings public function settingsLocal(): \RainLoop\Settings
{ {
return \RainLoop\Api::Actions()->SettingsProvider(true)->Load($this); return \RainLoop\Api::Actions()->SettingsProvider(true)->Load($this);
} }
@ -289,19 +289,19 @@ abstract class Account implements \JsonSerializable
/** /**
* @deprecated since v2.36.1 * @deprecated since v2.36.1
*/ */
public function IncLogin() : string public function IncLogin(): string
{ {
return $this->ImapUser(); return $this->ImapUser();
} }
public function IncPassword() : string public function IncPassword(): string
{ {
return $this->ImapPass(); return $this->ImapPass();
} }
public function OutLogin() : string public function OutLogin(): string
{ {
return $this->SmtpUser(); return $this->SmtpUser();
} }
public function SetPassword(SensitiveString $oPassword) : void public function SetPassword(SensitiveString $oPassword): void
{ {
$this->oImapPass = $oPassword; $this->oImapPass = $oPassword;
} }

View file

@ -39,7 +39,7 @@ class Domain implements \JsonSerializable
$this->whiteList = \trim($this->whiteList); $this->whiteList = \trim($this->whiteList);
} }
public function Name() : string public function Name(): string
{ {
return $this->Name; return $this->Name;
} }
@ -47,7 +47,7 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function IncHost() : string public function IncHost(): string
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->IMAP->host; return $this->IMAP->host;
@ -56,7 +56,7 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function IncPort() : int public function IncPort(): int
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->IMAP->port; return $this->IMAP->port;
@ -65,7 +65,7 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function IncShortLogin() : bool public function IncShortLogin(): bool
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->IMAP->shortLogin; return $this->IMAP->shortLogin;
@ -74,7 +74,7 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function UseSieve() : bool public function UseSieve(): bool
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->Sieve->enabled; return $this->Sieve->enabled;
@ -83,7 +83,7 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function OutHost() : string public function OutHost(): string
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->SMTP->host; return $this->SMTP->host;
@ -92,19 +92,19 @@ class Domain implements \JsonSerializable
/** /**
* @deprecated * @deprecated
*/ */
public function OutPort() : int public function OutPort(): int
{ {
\trigger_error('Deprecated function called.', \E_USER_DEPRECATED); \trigger_error('Deprecated function called.', \E_USER_DEPRECATED);
return $this->SMTP->port; return $this->SMTP->port;
} }
public function SetAliasName(string $sAliasName) : void public function SetAliasName(string $sAliasName): void
{ {
// $this->aliasName = \SnappyMail\IDN::toAscii($sAliasName); // $this->aliasName = \SnappyMail\IDN::toAscii($sAliasName);
$this->aliasName = \strtolower(\idn_to_ascii($sAliasName)); $this->aliasName = \strtolower(\idn_to_ascii($sAliasName));
} }
public function ValidateWhiteList(string $sEmail) : bool public function ValidateWhiteList(string $sEmail): bool
{ {
$sW = $this->whiteList; $sW = $this->whiteList;
if (!$sW) { if (!$sW) {
@ -125,17 +125,17 @@ class Domain implements \JsonSerializable
return false; return false;
} }
public function ImapSettings() : \MailSo\Imap\Settings public function ImapSettings(): \MailSo\Imap\Settings
{ {
return $this->IMAP; return $this->IMAP;
} }
public function SieveSettings() : \MailSo\Sieve\Settings public function SieveSettings(): \MailSo\Sieve\Settings
{ {
return $this->Sieve; return $this->Sieve;
} }
public function SmtpSettings() : \MailSo\Smtp\Settings public function SmtpSettings(): \MailSo\Smtp\Settings
{ {
return $this->SMTP; return $this->SMTP;
} }
@ -143,7 +143,7 @@ class Domain implements \JsonSerializable
/** /**
* See jsonSerialize() for valid values * See jsonSerialize() for valid values
*/ */
public static function fromArray(string $sName, array $aDomain) : ?self public static function fromArray(string $sName, array $aDomain): ?self
{ {
if (!\strlen($sName)) { if (!\strlen($sName)) {
return null; return null;
@ -186,7 +186,7 @@ class Domain implements \JsonSerializable
/** /**
* Used by old RainLoop ToIniString() * Used by old RainLoop ToIniString()
*/ */
public static function fromIniArray(string $sName, array $aDomain) : ?self public static function fromIniArray(string $sName, array $aDomain): ?self
{ {
$oDomain = null; $oDomain = null;
if (\strlen($sName) && \strlen($aDomain['imap_host'])) { if (\strlen($sName) && \strlen($aDomain['imap_host'])) {
@ -220,7 +220,7 @@ class Domain implements \JsonSerializable
/** /**
* Use by old RainLoop fromIniArray() * Use by old RainLoop fromIniArray()
*/ */
public static function StrConnectionSecurityTypeToCons(string $sType) : int public static function StrConnectionSecurityTypeToCons(string $sType): int
{ {
switch (\strtoupper($sType)) switch (\strtoupper($sType))
{ {
@ -232,8 +232,8 @@ class Domain implements \JsonSerializable
return ConnectionSecurityType::NONE; return ConnectionSecurityType::NONE;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$aResult = array( $aResult = array(
// '@Object' => 'Object/Domain', // '@Object' => 'Object/Domain',

View file

@ -49,7 +49,7 @@ class Identity implements \JsonSerializable
} }
} }
function toMime() : \MailSo\Mime\Email function toMime(): \MailSo\Mime\Email
{ {
return new \MailSo\Mime\Email($this->sEmail, $this->sName); return new \MailSo\Mime\Email($this->sEmail, $this->sName);
} }
@ -143,8 +143,8 @@ class Identity implements \JsonSerializable
); );
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Object/Identity', '@Object' => 'Object/Identity',

View file

@ -19,15 +19,15 @@ abstract class Base
return !!\class_exists('PDO'); return !!\class_exists('PDO');
} }
abstract protected function getPdoSettings() : \RainLoop\Pdo\Settings; abstract protected function getPdoSettings(): \RainLoop\Pdo\Settings;
public function sqliteNoCaseCollationHelper(string $sStr1, string $sStr2) : int public function sqliteNoCaseCollationHelper(string $sStr1, string $sStr2): int
{ {
$this->oLogger->WriteDump(array($sStr1, $sStr2)); $this->oLogger->WriteDump(array($sStr1, $sStr2));
return \strcmp(\mb_strtoupper($sStr1, 'UTF-8'), \mb_strtoupper($sStr2, 'UTF-8')); return \strcmp(\mb_strtoupper($sStr1, 'UTF-8'), \mb_strtoupper($sStr2, 'UTF-8'));
} }
public static function getAvailableDrivers() : array public static function getAvailableDrivers(): array
{ {
return \class_exists('PDO', false) return \class_exists('PDO', false)
? \array_values(\array_intersect(['mysql', 'pgsql', 'sqlite'], \PDO::getAvailableDrivers())) ? \array_values(\array_intersect(['mysql', 'pgsql', 'sqlite'], \PDO::getAvailableDrivers()))
@ -38,7 +38,7 @@ abstract class Base
* *
* @throws \Exception * @throws \Exception
*/ */
protected function getPDO() : \PDO protected function getPDO(): \PDO
{ {
if ($this->oPDO) { if ($this->oPDO) {
return $this->oPDO; return $this->oPDO;
@ -100,7 +100,7 @@ abstract class Base
return $oPdo; return $oPdo;
} }
protected function lastInsertId(?string $sTabelName = null, ?string $sColumnName = null) : string protected function lastInsertId(?string $sTabelName = null, ?string $sColumnName = null): string
{ {
$mName = null; $mName = null;
if ('pgsql' === $this->sDbType && null !== $sTabelName && $sColumnName !== null) { if ('pgsql' === $this->sDbType && null !== $sTabelName && $sColumnName !== null) {
@ -110,22 +110,22 @@ abstract class Base
return null === $mName ? $this->getPDO()->lastInsertId() : $this->getPDO()->lastInsertId($mName); return null === $mName ? $this->getPDO()->lastInsertId() : $this->getPDO()->lastInsertId($mName);
} }
protected function beginTransaction() : bool protected function beginTransaction(): bool
{ {
return $this->getPDO()->beginTransaction(); return $this->getPDO()->beginTransaction();
} }
protected function commit() : bool protected function commit(): bool
{ {
return $this->getPDO()->commit(); return $this->getPDO()->commit();
} }
protected function rollBack() : bool protected function rollBack(): bool
{ {
return $this->getPDO()->rollBack(); return $this->getPDO()->rollBack();
} }
protected function prepareAndExecute(string $sSql, array $aParams = array(), bool $bMultiplyParams = false, bool $bLogParams = false) : ?\PDOStatement protected function prepareAndExecute(string $sSql, array $aParams = array(), bool $bMultiplyParams = false, bool $bLogParams = false): ?\PDOStatement
{ {
if ($this->bExplain && !$bMultiplyParams) { if ($this->bExplain && !$bMultiplyParams) {
$this->prepareAndExplain($sSql, $aParams); $this->prepareAndExplain($sSql, $aParams);
@ -180,10 +180,7 @@ abstract class Base
} }
} }
/** protected function writeLog(mixed $mData): void
* @param mixed $mData
*/
protected function writeLog($mData)
{ {
if ($this->oLogger) { if ($this->oLogger) {
if ($mData instanceof \Throwable) { if ($mData instanceof \Throwable) {
@ -196,13 +193,13 @@ abstract class Base
} }
} }
public function quoteValue(string $sValue) : string public function quoteValue(string $sValue): string
{ {
$oPdo = $this->getPDO(); $oPdo = $this->getPDO();
return $oPdo ? $oPdo->quote((string) $sValue, \PDO::PARAM_STR) : '\'\''; return $oPdo ? $oPdo->quote((string) $sValue, \PDO::PARAM_STR) : '\'\'';
} }
protected function getVersion(string $sName) : ?int protected function getVersion(string $sName): ?int
{ {
$oPdo = $this->getPDO(); $oPdo = $this->getPDO();
if ($oPdo) { if ($oPdo) {
@ -224,7 +221,7 @@ abstract class Base
return null; return null;
} }
protected function setVersion(string $sName, int $iVersion) : bool protected function setVersion(string $sName, int $iVersion): bool
{ {
$bResult = false; $bResult = false;
$oPdo = $this->getPDO(); $oPdo = $this->getPDO();
@ -283,7 +280,7 @@ abstract class Base
return $bResult; return $bResult;
} }
protected function dataBaseUpgrade(string $sName, array $aData = array()) : bool protected function dataBaseUpgrade(string $sName, array $aData = array()): bool
{ {
$iFromVersion = null; $iFromVersion = null;
try try

View file

@ -39,18 +39,18 @@ abstract class AbstractPlugin
$this->sName = static::NAME; $this->sName = static::NAME;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function Description() : string public function Description(): string
{ {
$sFile = $this->Path().'/README'; $sFile = $this->Path().'/README';
return \is_readable($sFile) ? \file_get_contents($sFile) : static::DESCRIPTION; return \is_readable($sFile) ? \file_get_contents($sFile) : static::DESCRIPTION;
} }
public function UseLangs(?bool $bLangs = null) : bool public function UseLangs(?bool $bLangs = null): bool
{ {
if (null !== $bLangs) { if (null !== $bLangs) {
$this->bLangs = $bLangs; $this->bLangs = $bLangs;
@ -59,47 +59,47 @@ abstract class AbstractPlugin
return $this->bLangs; return $this->bLangs;
} }
protected function configMapping() : array protected function configMapping(): array
{ {
return array(); return array();
} }
public function Supported() : string public function Supported(): string
{ {
return ''; return '';
} }
public function Init() : void public function Init(): void
{ {
} }
public function FilterAppDataPluginSection(bool $bAdmin, bool $bAuth, array &$aConfig) : void public function FilterAppDataPluginSection(bool $bAdmin, bool $bAuth, array &$aConfig): void
{ {
} }
final public function Hash() : string final public function Hash(): string
{ {
return static::class . '@' . static::VERSION; return static::class . '@' . static::VERSION;
} }
final public function Config() : \RainLoop\Config\Plugin final public function Config(): \RainLoop\Config\Plugin
{ {
return $this->oPluginConfig; return $this->oPluginConfig;
} }
final public function Manager() : \RainLoop\Plugins\Manager final public function Manager(): \RainLoop\Plugins\Manager
{ {
return $this->oPluginManager; return $this->oPluginManager;
} }
final public function Path() : string final public function Path(): string
{ {
return $this->sPath; return $this->sPath;
} }
final public function ConfigMap(bool $flatten = false) : array final public function ConfigMap(bool $flatten = false): array
{ {
if (null === $this->aConfigMap) { if (null === $this->aConfigMap) {
$this->aConfigMap = $this->configMapping(); $this->aConfigMap = $this->configMapping();
@ -126,28 +126,28 @@ abstract class AbstractPlugin
return $this->aConfigMap; return $this->aConfigMap;
} }
final public function SetPath(string $sPath) : self final public function SetPath(string $sPath): self
{ {
$this->sPath = $sPath; $this->sPath = $sPath;
return $this; return $this;
} }
final public function SetName(string $sName) : self final public function SetName(string $sName): self
{ {
$this->sName = $sName; $this->sName = $sName;
return $this; return $this;
} }
final public function SetPluginManager(\RainLoop\Plugins\Manager $oPluginManager) : self final public function SetPluginManager(\RainLoop\Plugins\Manager $oPluginManager): self
{ {
$this->oPluginManager = $oPluginManager; $this->oPluginManager = $oPluginManager;
return $this; return $this;
} }
final public function SetPluginConfig(\RainLoop\Config\Plugin $oPluginConfig) : self final public function SetPluginConfig(\RainLoop\Config\Plugin $oPluginConfig): self
{ {
$this->oPluginConfig = $oPluginConfig; $this->oPluginConfig = $oPluginConfig;
if ($oPluginConfig->IsInited() && !$oPluginConfig->Load()) { if ($oPluginConfig->IsInited() && !$oPluginConfig->Load()) {
@ -156,7 +156,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addHook(string $sHookName, string $sFunctionName) : self final protected function addHook(string $sHookName, string $sFunctionName): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddHook($sHookName, array($this, $sFunctionName)); $this->oPluginManager->AddHook($sHookName, array($this, $sFunctionName));
@ -165,7 +165,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addCss(string $sFile, bool $bAdminScope = false) : self final protected function addCss(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddCss($this->sPath.'/'.$sFile, $bAdminScope); $this->oPluginManager->AddCss($this->sPath.'/'.$sFile, $bAdminScope);
@ -174,7 +174,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addJs(string $sFile, bool $bAdminScope = false) : self final protected function addJs(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddJs($this->sPath.'/'.$sFile, $bAdminScope); $this->oPluginManager->AddJs($this->sPath.'/'.$sFile, $bAdminScope);
@ -183,7 +183,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addTemplate(string $sFile, bool $bAdminScope = false) : self final protected function addTemplate(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope); $this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
@ -192,7 +192,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addPartHook(string $sActionName, string $sFunctionName) : self final protected function addPartHook(string $sActionName, string $sFunctionName): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddAdditionalPartAction($sActionName, array($this, $sFunctionName)); $this->oPluginManager->AddAdditionalPartAction($sActionName, array($this, $sFunctionName));
@ -201,7 +201,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
final protected function addJsonHook(string $sActionName, string $sFunctionName = '') : self final protected function addJsonHook(string $sActionName, string $sFunctionName = ''): self
{ {
if ($this->oPluginManager) { if ($this->oPluginManager) {
$this->oPluginManager->AddAdditionalJsonAction($sActionName, array($this, $sFunctionName ?: $sActionName)); $this->oPluginManager->AddAdditionalJsonAction($sActionName, array($this, $sFunctionName ?: $sActionName));
@ -210,10 +210,7 @@ abstract class AbstractPlugin
return $this; return $this;
} }
/** final protected function jsonResponse(string $sFunctionName, mixed $mData): false|string|array
* @return mixed false|string|array
*/
final protected function jsonResponse(string $sFunctionName, $mData)
{ {
return $this->oPluginManager return $this->oPluginManager
? $this->oPluginManager->JsonResponseHelper( ? $this->oPluginManager->JsonResponseHelper(
@ -221,26 +218,21 @@ abstract class AbstractPlugin
: \json_encode($mData); : \json_encode($mData);
} }
/** final public function jsonParam(string $sKey, mixed $mDefault = null): mixed
* @param mixed $mDefault = null
*
* @return mixed
*/
final public function jsonParam(string $sKey, $mDefault = null)
{ {
return $this->oPluginManager return $this->oPluginManager
? $this->oPluginManager->Actions()->GetActionParam($sKey, $mDefault) ? $this->oPluginManager->Actions()->GetActionParam($sKey, $mDefault)
: $mDefault; : $mDefault;
} }
final public function getUserSettings() : array final public function getUserSettings(): array
{ {
return $this->oPluginManager return $this->oPluginManager
? $this->oPluginManager->GetUserPluginSettings($this->Name()) ? $this->oPluginManager->GetUserPluginSettings($this->Name())
: array(); : array();
} }
final public function saveUserSettings(array $aSettings) : bool final public function saveUserSettings(array $aSettings): bool
{ {
return $this->oPluginManager return $this->oPluginManager
&& $this->oPluginManager->SaveUserPluginSettings($this->Name(), $aSettings); && $this->oPluginManager->SaveUserPluginSettings($this->Name(), $aSettings);

View file

@ -45,7 +45,7 @@ class Manager
} }
} }
public function loadPlugin(string $sName) : bool public function loadPlugin(string $sName): bool
{ {
if (!isset($this->aPlugins[$sName])) { if (!isset($this->aPlugins[$sName])) {
$oPlugin = $this->CreatePluginByName($sName); $oPlugin = $this->CreatePluginByName($sName);
@ -57,7 +57,7 @@ class Manager
return isset($this->aPlugins[$sName]); return isset($this->aPlugins[$sName]);
} }
protected static function getPluginPath(string $sName) : ?string protected static function getPluginPath(string $sName): ?string
{ {
$sPath = APP_PLUGINS_PATH.$sName; $sPath = APP_PLUGINS_PATH.$sName;
if (\is_readable("{$sPath}/index.php")) { if (\is_readable("{$sPath}/index.php")) {
@ -69,7 +69,7 @@ class Manager
return null; return null;
} }
public function CreatePluginByName(string $sName) : ?\RainLoop\Plugins\AbstractPlugin public function CreatePluginByName(string $sName): ?\RainLoop\Plugins\AbstractPlugin
{ {
$oPlugin = null; $oPlugin = null;
@ -90,7 +90,7 @@ class Manager
return $oPlugin; return $oPlugin;
} }
public function InstalledPlugins() : array public function InstalledPlugins(): array
{ {
$aList = array(); $aList = array();
@ -121,7 +121,7 @@ class Manager
return $aList; return $aList;
} }
public function convertPluginFolderNameToClassName(string $sFolderName) : string public function convertPluginFolderNameToClassName(string $sFolderName): string
{ {
$aParts = \array_map('ucfirst', \array_map('strtolower', $aParts = \array_map('ucfirst', \array_map('strtolower',
\explode(' ', \preg_replace('/[^a-z0-9]+/', ' ', $sFolderName)))); \explode(' ', \preg_replace('/[^a-z0-9]+/', ' ', $sFolderName))));
@ -129,7 +129,7 @@ class Manager
return \implode($aParts).'Plugin'; return \implode($aParts).'Plugin';
} }
public function loadPluginByName(string $sName) : ?string public function loadPluginByName(string $sName): ?string
{ {
if (\preg_match('/^[a-z0-9\\-]+$/', $sName)) { if (\preg_match('/^[a-z0-9\\-]+$/', $sName)) {
$sClassName = $this->convertPluginFolderNameToClassName($sName); $sClassName = $this->convertPluginFolderNameToClassName($sName);
@ -148,12 +148,12 @@ class Manager
return null; return null;
} }
public function Actions() : \RainLoop\Actions public function Actions(): \RainLoop\Actions
{ {
return $this->oActions; return $this->oActions;
} }
public function Hash() : string public function Hash(): string
{ {
return \md5( return \md5(
\array_reduce($this->aPlugins, function($sResult, $oPlugin){ \array_reduce($this->aPlugins, function($sResult, $oPlugin){
@ -164,12 +164,12 @@ class Manager
); );
} }
public function HaveJs(bool $bAdminScope = false) : bool public function HaveJs(bool $bAdminScope = false): bool
{ {
return $this->bIsEnabled && \count($this->aJs[$bAdminScope ? 1 : 0]); return $this->bIsEnabled && \count($this->aJs[$bAdminScope ? 1 : 0]);
} }
public function CompileCss(bool $bAdminScope, bool &$bLess, bool $bMinified) : string public function CompileCss(bool $bAdminScope, bool &$bLess, bool $bMinified): string
{ {
$aResult = array(); $aResult = array();
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
@ -189,7 +189,7 @@ class Manager
return \implode("\n", $aResult); return \implode("\n", $aResult);
} }
public function CompileJs(bool $bAdminScope = false, bool $bMinified = false) : string public function CompileJs(bool $bAdminScope = false, bool $bMinified = false): string
{ {
$aResult = array(); $aResult = array();
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
@ -209,7 +209,7 @@ class Manager
return \implode("\n", $aResult); return \implode("\n", $aResult);
} }
public function CompileTemplate(array &$aList, bool $bAdminScope = false) : void public function CompileTemplate(array &$aList, bool $bAdminScope = false): void
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
$aTemplates = $bAdminScope ? $this->aAdminTemplates : $this->aTemplates; $aTemplates = $bAdminScope ? $this->aAdminTemplates : $this->aTemplates;
@ -222,7 +222,7 @@ class Manager
} }
} }
public function InitAppData(bool $bAdmin, array &$aAppData, ?\RainLoop\Model\Account $oAccount = null) : self public function InitAppData(bool $bAdmin, array &$aAppData, ?\RainLoop\Model\Account $oAccount = null): self
{ {
if ($this->bIsEnabled && isset($aAppData['Plugins']) && \is_array($aAppData['Plugins'])) { if ($this->bIsEnabled && isset($aAppData['Plugins']) && \is_array($aAppData['Plugins'])) {
$bAuth = !empty($aAppData['Auth']); $bAuth = !empty($aAppData['Auth']);
@ -255,10 +255,7 @@ class Manager
return $this; return $this;
} }
/** public function AddHook(string $sHookName, callable $mCallbak): self
* @param mixed $mCallbak
*/
public function AddHook(string $sHookName, $mCallbak) : self
{ {
if ($this->bIsEnabled && \is_callable($mCallbak)) { if ($this->bIsEnabled && \is_callable($mCallbak)) {
$sHookName = \strtolower($sHookName); $sHookName = \strtolower($sHookName);
@ -270,7 +267,7 @@ class Manager
return $this; return $this;
} }
public function AddCss(string $sFile, bool $bAdminScope = false) : self public function AddCss(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
$this->aCss[$bAdminScope ? 1 : 0][] = $sFile; $this->aCss[$bAdminScope ? 1 : 0][] = $sFile;
@ -278,7 +275,7 @@ class Manager
return $this; return $this;
} }
public function AddJs(string $sFile, bool $bAdminScope = false) : self public function AddJs(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
$this->aJs[$bAdminScope ? 1 : 0][$sFile] = $sFile; $this->aJs[$bAdminScope ? 1 : 0][$sFile] = $sFile;
@ -287,7 +284,7 @@ class Manager
return $this; return $this;
} }
public function AddTemplate(string $sFile, bool $bAdminScope = false) : self public function AddTemplate(string $sFile, bool $bAdminScope = false): self
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
if ($bAdminScope) { if ($bAdminScope) {
@ -324,7 +321,7 @@ class Manager
} }
*/ */
public function RunHook(string $sHookName, array $aArg = array(), bool $bLogHook = true) : self public function RunHook(string $sHookName, array $aArg = array(), bool $bLogHook = true): self
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
$sHookName = \strtolower($sHookName); $sHookName = \strtolower($sHookName);
@ -344,10 +341,7 @@ class Manager
return $this; return $this;
} }
/** public function AddAdditionalPartAction(string $sActionName, callable $mCallbak): self
* @param mixed $mCallbak
*/
public function AddAdditionalPartAction(string $sActionName, $mCallbak) : self
{ {
if ($this->bIsEnabled && \is_callable($mCallbak)) { if ($this->bIsEnabled && \is_callable($mCallbak)) {
$sActionName = \strtolower($sActionName); $sActionName = \strtolower($sActionName);
@ -361,7 +355,7 @@ class Manager
return $this; return $this;
} }
public function RunAdditionalPart(string $sActionName, array $aParts = array()) : bool public function RunAdditionalPart(string $sActionName, array $aParts = array()): bool
{ {
$bResult = false; $bResult = false;
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
@ -376,7 +370,7 @@ class Manager
return $bResult; return $bResult;
} }
public function AddAdditionalJsonAction(string $sActionName, callable $mCallback) : self public function AddAdditionalJsonAction(string $sActionName, callable $mCallback): self
{ {
$sActionName = "DoPlugin{$sActionName}"; $sActionName = "DoPlugin{$sActionName}";
if ($this->bIsEnabled && \strlen($sActionName) && !isset($this->aAdditionalJson[$sActionName])) { if ($this->bIsEnabled && \strlen($sActionName) && !isset($this->aAdditionalJson[$sActionName])) {
@ -385,28 +379,22 @@ class Manager
return $this; return $this;
} }
public function HasAdditionalJson(string $sActionName) : bool public function HasAdditionalJson(string $sActionName): bool
{ {
return $this->bIsEnabled && isset($this->aAdditionalJson[$sActionName]); return $this->bIsEnabled && isset($this->aAdditionalJson[$sActionName]);
} }
/** public function RunAdditionalJson(string $sActionName): mixed
* @return mixed
*/
public function RunAdditionalJson(string $sActionName)
{ {
return $this->HasAdditionalJson($sActionName) ? $this->aAdditionalJson[$sActionName]() : false; return $this->HasAdditionalJson($sActionName) ? $this->aAdditionalJson[$sActionName](): false;
} }
/** public function JsonResponseHelper(string $sFunctionName, mixed $mData): array
* @param mixed $mData
*/
public function JsonResponseHelper(string $sFunctionName, $mData) : array
{ {
return $this->oActions->DefaultResponse($mData, [], $sFunctionName); return $this->oActions->DefaultResponse($mData, [], $sFunctionName);
} }
public function GetUserPluginSettings(string $sPluginName) : array public function GetUserPluginSettings(string $sPluginName): array
{ {
$oAccount = $this->oActions->getAccountFromToken(); $oAccount = $this->oActions->getAccountFromToken();
if ($oAccount) { if ($oAccount) {
@ -422,7 +410,7 @@ class Manager
return array(); return array();
} }
public function SaveUserPluginSettings(string $sPluginName, array $aSettings) : bool public function SaveUserPluginSettings(string $sPluginName, array $aSettings): bool
{ {
$oAccount = $this->oActions->getAccountFromToken(); $oAccount = $this->oActions->getAccountFromToken();
if ($oAccount) { if ($oAccount) {
@ -452,7 +440,7 @@ class Manager
return false; return false;
} }
public function ReadLang(string $sLang, array &$aLang) : void public function ReadLang(string $sLang, array &$aLang): void
{ {
if ($this->bIsEnabled) { if ($this->bIsEnabled) {
foreach ($this->aPlugins as $oPlugin) { foreach ($this->aPlugins as $oPlugin) {
@ -492,22 +480,22 @@ class Manager
} }
} }
public function IsEnabled() : bool public function IsEnabled(): bool
{ {
return $this->bIsEnabled; return $this->bIsEnabled;
} }
public function count() : int public function count(): int
{ {
return $this->bIsEnabled ? \count($this->aPlugins) : 0; return $this->bIsEnabled ? \count($this->aPlugins) : 0;
} }
public function WriteLog(string $sDesc, int $iType = \LOG_INFO) : void public function WriteLog(string $sDesc, int $iType = \LOG_INFO): void
{ {
$this->logWrite($sDesc, $iType, 'PLUGIN'); $this->logWrite($sDesc, $iType, 'PLUGIN');
} }
public function WriteException(string $sDesc, int $iType = \LOG_INFO) : void public function WriteException(string $sDesc, int $iType = \LOG_INFO): void
{ {
$this->logException($sDesc, $iType, 'PLUGIN'); $this->logException($sDesc, $iType, 'PLUGIN');
} }

View file

@ -8,10 +8,7 @@ class Property implements \JsonSerializable
{ {
private string $sName; private string $sName;
/** private mixed $mValue;
* @var mixed
*/
private $mValue;
private string $sLabel = ''; private string $sLabel = '';
@ -21,10 +18,7 @@ class Property implements \JsonSerializable
private bool $bAllowedInJs = false; private bool $bAllowedInJs = false;
/** private mixed $mDefaultValue = '';
* @var mixed
*/
private $mDefaultValue = '';
private array $aOptions = []; private array $aOptions = [];
@ -37,21 +31,18 @@ class Property implements \JsonSerializable
$this->sName = $sName; $this->sName = $sName;
} }
public static function NewInstance(string $sName) : self public static function NewInstance(string $sName): self
{ {
return new self($sName); return new self($sName);
} }
public function SetType(int $iType) : self public function SetType(int $iType): self
{ {
$this->iType = (int) $iType; $this->iType = (int) $iType;
return $this; return $this;
} }
/** public function SetValue(mixed $mValue): void
* @param mixed $mValue
*/
public function SetValue($mValue) : void
{ {
$this->mValue = null; $this->mValue = null;
switch ($this->iType) { switch ($this->iType) {
@ -87,7 +78,7 @@ class Property implements \JsonSerializable
/** /**
* @param mixed $mDefaultValue * @param mixed $mDefaultValue
*/ */
public function SetDefaultValue($mDefaultValue) : self public function SetDefaultValue($mDefaultValue): self
{ {
if (\is_array($mDefaultValue)) { if (\is_array($mDefaultValue)) {
$this->aOptions = $mDefaultValue; $this->aOptions = $mDefaultValue;
@ -97,95 +88,89 @@ class Property implements \JsonSerializable
return $this; return $this;
} }
public function SetOptions(array $aOptions) : self public function SetOptions(array $aOptions): self
{ {
$this->aOptions = $aOptions; $this->aOptions = $aOptions;
return $this; return $this;
} }
public function SetPlaceholder(string $sPlaceholder) : self public function SetPlaceholder(string $sPlaceholder): self
{ {
$this->sPlaceholder = $sPlaceholder; $this->sPlaceholder = $sPlaceholder;
return $this; return $this;
} }
public function SetLabel(string $sLabel) : self public function SetLabel(string $sLabel): self
{ {
$this->sLabel = $sLabel; $this->sLabel = $sLabel;
return $this; return $this;
} }
public function SetDescription(string $sDesc) : self public function SetDescription(string $sDesc): self
{ {
$this->sDesc = $sDesc; $this->sDesc = $sDesc;
return $this; return $this;
} }
public function SetAllowedInJs(bool $bValue = true) : self public function SetAllowedInJs(bool $bValue = true): self
{ {
$this->bAllowedInJs = $bValue; $this->bAllowedInJs = $bValue;
return $this; return $this;
} }
public function SetEncrypted(bool $bValue = true) : self public function SetEncrypted(bool $bValue = true): self
{ {
$this->encrypted = $bValue; $this->encrypted = $bValue;
return $this; return $this;
} }
public function Name() : string public function Name(): string
{ {
return $this->sName; return $this->sName;
} }
public function AllowedInJs() : bool public function AllowedInJs(): bool
{ {
return $this->bAllowedInJs; return $this->bAllowedInJs;
} }
public function Description() : string public function Description(): string
{ {
return $this->sDesc; return $this->sDesc;
} }
public function Label() : string public function Label(): string
{ {
return $this->sLabel; return $this->sLabel;
} }
public function Type() : int public function Type(): int
{ {
return $this->iType; return $this->iType;
} }
/** public function DefaultValue(): mixed
* @return mixed
*/
public function DefaultValue()
{ {
return $this->mDefaultValue; return $this->mDefaultValue;
} }
public function Options() : array public function Options(): array
{ {
return $this->aOptions; return $this->aOptions;
} }
public function Placeholder() : string public function Placeholder(): string
{ {
return $this->sPlaceholder; return $this->sPlaceholder;
} }
/** public function Value(): mixed
* @return mixed
*/
public function Value()
{ {
return $this->mValue; return $this->mValue;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
$mValue = $this->mValue; $mValue = $this->mValue;
if ($this->encrypted && $mValue) try { if ($this->encrypted && $mValue) try {

View file

@ -5,18 +5,15 @@ namespace RainLoop\Plugins;
//class PropertyCollection extends \MailSo\Base\Collection //class PropertyCollection extends \MailSo\Base\Collection
class PropertyCollection extends \ArrayObject implements \JsonSerializable class PropertyCollection extends \ArrayObject implements \JsonSerializable
{ {
/** private string $sLabel;
* @var string
*/
private $sLabel;
function __construct(string $sLabel) function __construct(string $sLabel)
{ {
$this->sLabel = $sLabel; $this->sLabel = $sLabel;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Object/PluginProperty', '@Object' => 'Object/PluginProperty',

View file

@ -84,7 +84,7 @@ trait CardDAV
return $mResult; return $mResult;
} }
protected function davClientRequest(DAVClient $oClient, string $sCmd, string $sUrl, $mData = null) : ?\SnappyMail\HTTP\Response protected function davClientRequest(DAVClient $oClient, string $sCmd, string $sUrl, mixed $mData = null): ?\SnappyMail\HTTP\Response
{ {
\MailSo\Base\Utils::ResetTimeLimit(); \MailSo\Base\Utils::ResetTimeLimit();
@ -111,7 +111,7 @@ trait CardDAV
return null; return null;
} }
private function detectionPropFind(DAVClient $oClient, string $sPath) : ?array private function detectionPropFind(DAVClient $oClient, string $sPath): ?array
{ {
try try
{ {
@ -133,7 +133,7 @@ trait CardDAV
private function getContactsPaths(DAVClient $oClient, string $sPath, string $sUser, private function getContactsPaths(DAVClient $oClient, string $sPath, string $sUser,
#[\SensitiveParameter] #[\SensitiveParameter]
string $sPassword, string $sPassword,
string $sProxy = '') : array string $sProxy = ''): array
{ {
$aContactsPaths = array(); $aContactsPaths = array();
@ -263,7 +263,7 @@ trait CardDAV
/** /**
* Checks if remote path resourcetype is an addressbook * Checks if remote path resourcetype is an addressbook
*/ */
private function checkContactsPath(DAVClient $oClient, string $sPath) : bool private function checkContactsPath(DAVClient $oClient, string $sPath): bool
{ {
$aResponse = $oClient->propFind($sPath, array( $aResponse = $oClient->propFind($sPath, array(
'{DAV:}resourcetype' '{DAV:}resourcetype'
@ -290,7 +290,7 @@ trait CardDAV
#[\SensitiveParameter] #[\SensitiveParameter]
string $sPassword, string $sPassword,
string $sProxy = '' string $sProxy = ''
) : DAVClient ): DAVClient
{ {
if (!\preg_match('/^http[s]?:\/\//i', $sUrl)) { if (!\preg_match('/^http[s]?:\/\//i', $sUrl)) {
$sUrl = \preg_replace('/^fruux\.com/i', 'dav.fruux.com', $sUrl); $sUrl = \preg_replace('/^fruux\.com/i', 'dav.fruux.com', $sUrl);
@ -331,7 +331,7 @@ trait CardDAV
return $oClient; return $oClient;
} }
public function getDavClient() : ?DAVClient public function getDavClient(): ?DAVClient
{ {
if (!$this->aDAVConfig['Mode']) { if (!$this->aDAVConfig['Mode']) {
return null; return null;
@ -408,7 +408,7 @@ trait CardDAV
return $bGood ? $oClient : null; return $bGood ? $oClient : null;
} }
private static function hasDAVCollection($aItem) private static function hasDAVCollection($aItem): bool
{ {
return !empty($aItem['{DAV:}resourcetype']) return !empty($aItem['{DAV:}resourcetype'])
&& \is_array($aItem['{DAV:}resourcetype']) && \is_array($aItem['{DAV:}resourcetype'])

View file

@ -78,8 +78,8 @@ class Contact implements \JsonSerializable
$this->IdContactStr = $sUid; $this->IdContactStr = $sUid;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return array( return array(
'@Object' => 'Object/Contact', '@Object' => 'Object/Contact',

View file

@ -6,30 +6,15 @@ use RainLoop\Providers\AddressBook\Enumerations\PropertyType;
class Property implements \JsonSerializable class Property implements \JsonSerializable
{ {
/** public int $IdProperty = 0;
* @var int
*/
public $IdProperty = 0;
/** public int $Type;
* @var int
*/
public $Type;
/** public string $TypeStr;
* @var string
*/
public $TypeStr;
/** public string $Value;
* @var string
*/
public $Value;
/** public int $Frec = 0;
* @var int
*/
public $Frec = 0;
public function __construct(int $iType = PropertyType::UNKNOWN, string $sValue = '', string $sTypeStr = '') public function __construct(int $iType = PropertyType::UNKNOWN, string $sValue = '', string $sTypeStr = '')
{ {
@ -38,8 +23,7 @@ class Property implements \JsonSerializable
$this->TypeStr = $sTypeStr; $this->TypeStr = $sTypeStr;
} }
#[\ReturnTypeWillChange] public function jsonSerialize(): mixed
public function jsonSerialize()
{ {
throw new \Exception('Obsolete ' . __CLASS__ . '::jsonSerialize()'); throw new \Exception('Obsolete ' . __CLASS__ . '::jsonSerialize()');
} }

View file

@ -9,10 +9,7 @@ use
class Legacy class Legacy
{ {
/** private static function yieldPropertyHelper(mixed $oArrayProp, int $iType): iterable
* @param mixed $oProp
*/
private static function yieldPropertyHelper($oArrayProp, int $iType) : iterable
{ {
$aTmp = []; $aTmp = [];
foreach ($oArrayProp as $oProp) { foreach ($oArrayProp as $oProp) {
@ -31,10 +28,7 @@ class Legacy
} }
} }
/** private static function getPropertyValueHelper(mixed $oProp, bool $bOldVersion): string
* @param mixed $oProp
*/
private static function getPropertyValueHelper($oProp, bool $bOldVersion) : string
{ {
$sValue = \trim($oProp); $sValue = \trim($oProp);
if ($bOldVersion && !isset($oProp->parameters['CHARSET'])) { if ($bOldVersion && !isset($oProp->parameters['CHARSET'])) {
@ -48,7 +42,7 @@ class Legacy
return \MailSo\Base\Utils::Utf8Clear($sValue); return \MailSo\Base\Utils::Utf8Clear($sValue);
} }
public static function VCardToProperties(\Sabre\VObject\Component\VCard $oVCard) : iterable public static function VCardToProperties(\Sabre\VObject\Component\VCard $oVCard): iterable
{ {
yield new Property(PropertyType::JCARD, \json_encode($oVCard)); yield new Property(PropertyType::JCARD, \json_encode($oVCard));

View file

@ -70,26 +70,26 @@ class PdoAddressBook
return \in_array($sType, static::getAvailableDrivers()) ? $sType : 'sqlite'; return \in_array($sType, static::getAvailableDrivers()) ? $sType : 'sqlite';
} }
public function IsSupported() : bool public function IsSupported(): bool
{ {
$aDrivers = static::getAvailableDrivers(); $aDrivers = static::getAvailableDrivers();
return \is_array($aDrivers) && \in_array($this->settings->driver, $aDrivers); return \is_array($aDrivers) && \in_array($this->settings->driver, $aDrivers);
} }
public function SetEmail(string $sEmail) : bool public function SetEmail(string $sEmail): bool
{ {
$this->iUserID = $this->getUserId($sEmail); $this->iUserID = $this->getUserId($sEmail);
return 0 < $this->iUserID; return 0 < $this->iUserID;
} }
private function flushDeletedContacts() : bool private function flushDeletedContacts(): bool
{ {
return !!$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user AND deleted = 1', array( return !!$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user AND deleted = 1', array(
':id_user' => array($this->iUserID, \PDO::PARAM_INT) ':id_user' => array($this->iUserID, \PDO::PARAM_INT)
)); ));
} }
private function prepareDatabaseSyncData() : array private function prepareDatabaseSyncData(): array
{ {
$aResult = array(); $aResult = array();
$oStmt = $this->prepareAndExecute('SELECT id_contact, id_contact_str, changed, deleted, etag $oStmt = $this->prepareAndExecute('SELECT id_contact, id_contact_str, changed, deleted, etag
@ -122,7 +122,7 @@ class PdoAddressBook
return $aResult; return $aResult;
} }
public function Sync() : bool public function Sync(): bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
\SnappyMail\Log::warning('PdoAddressBook', 'Sync() invalid $iUserID'); \SnappyMail\Log::warning('PdoAddressBook', 'Sync() invalid $iUserID');
@ -329,7 +329,7 @@ class PdoAddressBook
return true; return true;
} }
public function Export(string $sType = 'vcf') : bool public function Export(string $sType = 'vcf'): bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
\SnappyMail\Log::warning('PdoAddressBook', 'Export() invalid $iUserID'); \SnappyMail\Log::warning('PdoAddressBook', 'Export() invalid $iUserID');
@ -364,7 +364,7 @@ class PdoAddressBook
return true; return true;
} }
public function ContactSave(Contact $oContact) : bool public function ContactSave(Contact $oContact): bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
\SnappyMail\Log::warning('PdoAddressBook', 'ContactSave() invalid $iUserID'); \SnappyMail\Log::warning('PdoAddressBook', 'ContactSave() invalid $iUserID');
@ -464,7 +464,7 @@ class PdoAddressBook
return 0 < $iIdContact; return 0 < $iIdContact;
} }
public function DeleteContacts(array $aContactIds) : bool public function DeleteContacts(array $aContactIds): bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
\SnappyMail\Log::warning('PdoAddressBook', 'DeleteContacts() invalid $iUserID'); \SnappyMail\Log::warning('PdoAddressBook', 'DeleteContacts() invalid $iUserID');
@ -493,7 +493,7 @@ class PdoAddressBook
return true; return true;
} }
public function DeleteAllContacts(string $sEmail) : bool public function DeleteAllContacts(string $sEmail): bool
{ {
$iUserID = $this->getUserId($sEmail); $iUserID = $this->getUserId($sEmail);
@ -505,7 +505,7 @@ class PdoAddressBook
return true; return true;
} }
protected function getContactsFromPDO(?\PDOStatement $oStmt) : array protected function getContactsFromPDO(?\PDOStatement $oStmt): array
{ {
if ($oStmt) { if ($oStmt) {
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC); $aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
@ -647,7 +647,7 @@ class PdoAddressBook
return []; return [];
} }
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0): array
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
return []; return [];
@ -726,10 +726,7 @@ class PdoAddressBook
return []; return [];
} }
/** public function GetContactByEmail(string $sEmail): ?Contact
* @param mixed $mID
*/
public function GetContactByEmail(string $sEmail) : ?Contact
{ {
$sLowerSearch = $this->specialConvertSearchValueLower($sEmail); $sLowerSearch = $this->specialConvertSearchValueLower($sEmail);
@ -766,10 +763,7 @@ class PdoAddressBook
return null; return null;
} }
/** public function GetContactByID(mixed $mID, bool $bIsStrID = false): ?Contact
* @param mixed $mID
*/
public function GetContactByID($mID, bool $bIsStrID = false) : ?Contact
{ {
$mID = \trim($mID); $mID = \trim($mID);
@ -812,7 +806,7 @@ class PdoAddressBook
/** /**
* @throws \ValueError * @throws \ValueError
*/ */
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array public function GetSuggestions(string $sSearch, int $iLimit = 20): array
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
return []; return [];
@ -977,7 +971,7 @@ class PdoAddressBook
/** /**
* @throws \ValueError * @throws \ValueError
*/ */
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool public function IncFrec(array $aEmails, bool $bCreateAuto = true): bool
{ {
if (1 > $this->iUserID) { if (1 > $this->iUserID) {
return false; return false;
@ -1097,7 +1091,7 @@ class PdoAddressBook
)); ));
} }
public function Test() : string public function Test(): string
{ {
$sResult = ''; $sResult = '';
try { try {
@ -1120,7 +1114,7 @@ class PdoAddressBook
return $sResult; return $sResult;
} }
private function SyncDatabase() : bool private function SyncDatabase(): bool
{ {
static $mCache = null; static $mCache = null;
if (null !== $mCache) { if (null !== $mCache) {
@ -1142,7 +1136,7 @@ class PdoAddressBook
return $mCache; return $mCache;
} }
private function getContactFreq(int $iUserID, int $iIdContact) : array private function getContactFreq(int $iUserID, int $iIdContact): array
{ {
$aResult = array(); $aResult = array();
@ -1168,7 +1162,7 @@ class PdoAddressBook
return $aResult; return $aResult;
} }
private function specialConvertSearchValue(string $sSearch, string $sEscapeSign = '=') : string private function specialConvertSearchValue(string $sSearch, string $sEscapeSign = '='): string
{ {
return '%'.\str_replace(array($sEscapeSign, '_', '%'), return '%'.\str_replace(array($sEscapeSign, '_', '%'),
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%'; array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
@ -1181,7 +1175,7 @@ class PdoAddressBook
(string) \mb_strtolower($sSearch)).'%'; (string) \mb_strtolower($sSearch)).'%';
} }
protected function getPdoSettings() : \RainLoop\Pdo\Settings protected function getPdoSettings(): \RainLoop\Pdo\Settings
{ {
$sSslCa = $this->settings->sslCa; $sSslCa = $this->settings->sslCa;
if ($sSslCa && !\is_file($sSslCa)) { if ($sSslCa && !\is_file($sSslCa)) {
@ -1195,7 +1189,7 @@ class PdoAddressBook
/** /**
* @throws \ValueError * @throws \ValueError
*/ */
protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true) : int protected function getUserId(string $sEmail, bool $bSkipInsert = false, bool $bCache = true): int
{ {
static $aCache = array(); static $aCache = array();

View file

@ -89,7 +89,7 @@ class Utils
*/ */
); );
public static function CsvStreamToContacts(/*resource*/ $rFile, string $sDelimiter) : iterable public static function CsvStreamToContacts(/*resource*/ $rFile, string $sDelimiter): iterable
{ {
\setlocale(LC_CTYPE, 'en_US.UTF-8'); \setlocale(LC_CTYPE, 'en_US.UTF-8');
@ -140,7 +140,7 @@ class Utils
} }
} }
public static function VCardToCsv($stream, VCard $oVCard, bool $bWithHeader = false)/* : int|false*/ public static function VCardToCsv($stream, VCard $oVCard, bool $bWithHeader = false): int|false
{ {
$aData = array(); $aData = array();
if ($bWithHeader) { if ($bWithHeader) {
@ -198,7 +198,7 @@ class Utils
)); ));
} }
public static function VcfStreamToContacts(/*resource*/ $rFile) : iterable public static function VcfStreamToContacts(/*resource*/ $rFile): iterable
{ {
$oVCardSplitter = new \Sabre\VObject\Splitter\VCard($rFile); $oVCardSplitter = new \Sabre\VObject\Splitter\VCard($rFile);
if ($oVCardSplitter) { if ($oVCardSplitter) {
@ -213,7 +213,7 @@ class Utils
} }
} }
/* /*
public static function QrCode(string $sVcfData) : string public static function QrCode(string $sVcfData): string
{ {
MECARD:N:djmaze;ORG:SnappyMail;TEL:+31012345678;URL:https\://snappymail.eu;EMAIL:info@snappymail.eu;ADR:address line;; MECARD:N:djmaze;ORG:SnappyMail;TEL:+31012345678;URL:https\://snappymail.eu;EMAIL:info@snappymail.eu;ADR:address line;;
VCARD VCARD

View file

@ -4,28 +4,21 @@ namespace RainLoop\Providers\Files;
class FileStorage implements \RainLoop\Providers\Files\IFiles class FileStorage implements \RainLoop\Providers\Files\IFiles
{ {
/** private array $aResources = array();
* @var array
*/
private $aResources;
/** private ?string $sDataPath;
* @var string
*/
private $sDataPath;
public function __construct(string $sStoragePath) public function __construct(string $sStoragePath)
{ {
$this->aResources = array();
$this->sDataPath = \rtrim(\trim($sStoragePath), '\\/'); $this->sDataPath = \rtrim(\trim($sStoragePath), '\\/');
} }
public function GenerateLocalFullFileName(\RainLoop\Model\Account $oAccount, string $sKey) : string public function GenerateLocalFullFileName(\RainLoop\Model\Account $oAccount, string $sKey): string
{ {
return $this->generateFullFileName($oAccount, $sKey, true); return $this->generateFullFileName($oAccount, $sKey, true);
} }
public function PutFile(\RainLoop\Model\Account $oAccount, string $sKey, /*resource*/ $rSource) : bool public function PutFile(\RainLoop\Model\Account $oAccount, string $sKey, /*resource*/ $rSource): bool
{ {
$bResult = false; $bResult = false;
if ($rSource) { if ($rSource) {
@ -38,7 +31,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return $bResult; return $bResult;
} }
public function MoveUploadedFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sSource) : bool public function MoveUploadedFile(\RainLoop\Model\Account $oAccount, string $sKey, string $sSource): bool
{ {
return \move_uploaded_file($sSource, return \move_uploaded_file($sSource,
$this->generateFullFileName($oAccount, $sKey, true)); $this->generateFullFileName($oAccount, $sKey, true));
@ -66,13 +59,13 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return $mResult; return $mResult;
} }
public function GetFileName(\RainLoop\Model\Account $oAccount, string $sKey) /*: string|false*/ public function GetFileName(\RainLoop\Model\Account $oAccount, string $sKey): string|false
{ {
$sFileName = $this->generateFullFileName($oAccount, $sKey); $sFileName = $this->generateFullFileName($oAccount, $sKey);
return \file_exists($sFileName) ? $sFileName : false; return \file_exists($sFileName) ? $sFileName : false;
} }
public function Clear(\RainLoop\Model\Account $oAccount, string $sKey) : bool public function Clear(\RainLoop\Model\Account $oAccount, string $sKey): bool
{ {
$sFileName = $this->generateFullFileName($oAccount, $sKey); $sFileName = $this->generateFullFileName($oAccount, $sKey);
if (\file_exists($sFileName)) { if (\file_exists($sFileName)) {
@ -84,18 +77,18 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return false; return false;
} }
public function FileSize(\RainLoop\Model\Account $oAccount, string $sKey) /*: int|false*/ public function FileSize(\RainLoop\Model\Account $oAccount, string $sKey): int|false
{ {
$sFileName = $this->generateFullFileName($oAccount, $sKey); $sFileName = $this->generateFullFileName($oAccount, $sKey);
return \file_exists($sFileName) ? \filesize($sFileName) : false; return \file_exists($sFileName) ? \filesize($sFileName) : false;
} }
public function FileExists(\RainLoop\Model\Account $oAccount, string $sKey) : bool public function FileExists(\RainLoop\Model\Account $oAccount, string $sKey): bool
{ {
return \file_exists($this->generateFullFileName($oAccount, $sKey)); return \file_exists($this->generateFullFileName($oAccount, $sKey));
} }
public function GC(int $iTimeToClearInHours = 24) : bool public function GC(int $iTimeToClearInHours = 24): bool
{ {
if (0 < $iTimeToClearInHours) { if (0 < $iTimeToClearInHours) {
$iTimeToClear = 3600 * $iTimeToClearInHours; $iTimeToClear = 3600 * $iTimeToClearInHours;
@ -113,7 +106,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return false; return false;
} }
public function CloseAllOpenedFiles() : bool public function CloseAllOpenedFiles(): bool
{ {
if (\is_array($this->aResources) && \count($this->aResources)) if (\is_array($this->aResources) && \count($this->aResources))
{ {
@ -129,7 +122,7 @@ class FileStorage implements \RainLoop\Providers\Files\IFiles
return true; return true;
} }
private function generateFullFileName(\RainLoop\Model\Account $oAccount, string $sKey, bool $bMkDir = false) : string private function generateFullFileName(\RainLoop\Model\Account $oAccount, string $sKey, bool $bMkDir = false): string
{ {
if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) { if ($oAccount instanceof \RainLoop\Model\AdditionalAccount) {
$sEmail = $oAccount->ParentEmail(); $sEmail = $oAccount->ParentEmail();

View file

@ -2,6 +2,8 @@
namespace RainLoop\Providers; namespace RainLoop\Providers;
use RainLoop\Model\Account;
class Storage extends \RainLoop\Providers\AbstractProvider class Storage extends \RainLoop\Providers\AbstractProvider
{ {
/** /**
@ -14,77 +16,55 @@ class Storage extends \RainLoop\Providers\AbstractProvider
$this->oDriver = $oDriver; $this->oDriver = $oDriver;
} }
/** private function verifyAccount(Account|string|null $mAccount, int $iStorageType): bool
* @param \RainLoop\Model\Account|string|null $mAccount
*/
private function verifyAccount($mAccount, int $iStorageType) : bool
{ {
return \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType return \RainLoop\Providers\Storage\Enumerations\StorageType::NOBODY === $iStorageType
|| $mAccount instanceof \RainLoop\Model\Account || $mAccount instanceof Account
|| \is_string($mAccount); || \is_string($mAccount);
} }
/** public function Put(Account|string|null $mAccount, int $iStorageType, string $sKey, string $sValue): bool
* @param \RainLoop\Model\Account|string|null $mAccount
* @param mixed $sValue
*/
public function Put($mAccount, int $iStorageType, string $sKey, string $sValue) : bool
{ {
return $this->verifyAccount($mAccount, $iStorageType) return $this->verifyAccount($mAccount, $iStorageType)
? $this->oDriver->Put($mAccount, $iStorageType, $sKey, $sValue) ? $this->oDriver->Put($mAccount, $iStorageType, $sKey, $sValue)
: false; : false;
} }
/** public function Get(Account|string|null $mAccount, int $iStorageType, string $sKey, mixed $mDefault = false): mixed
* @param \RainLoop\Model\Account|string|null $mAccount
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($mAccount, int $iStorageType, string $sKey, $mDefault = false)
{ {
return $this->verifyAccount($mAccount, $iStorageType) return $this->verifyAccount($mAccount, $iStorageType)
? $this->oDriver->Get($mAccount, $iStorageType, $sKey, $mDefault) ? $this->oDriver->Get($mAccount, $iStorageType, $sKey, $mDefault)
: $mDefault; : $mDefault;
} }
/** public function Clear(Account|string|null $mAccount, int $iStorageType, string $sKey): bool
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function Clear($mAccount, int $iStorageType, string $sKey) : bool
{ {
return $this->verifyAccount($mAccount, $iStorageType) return $this->verifyAccount($mAccount, $iStorageType)
? $this->oDriver->Clear($mAccount, $iStorageType, $sKey) ? $this->oDriver->Clear($mAccount, $iStorageType, $sKey)
: false; : false;
} }
/** public function DeleteStorage(Account|string $mAccount): bool
* @param \RainLoop\Model\Account|string $mAccount
*/
public function DeleteStorage($mAccount) : bool
{ {
return $this->oDriver->DeleteStorage($mAccount); return $this->oDriver->DeleteStorage($mAccount);
} }
/** public function GenerateFilePath(Account|string|null $mAccount, int $iStorageType, bool $bMkDir = false): string
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function GenerateFilePath($mAccount, int $iStorageType, bool $bMkDir = false) : string
{ {
return $this->oDriver->GenerateFilePath($mAccount, $iStorageType, $bMkDir); return $this->oDriver->GenerateFilePath($mAccount, $iStorageType, $bMkDir);
} }
public function IsActive() : bool public function IsActive(): bool
{ {
return true; return true;
} }
public function IsLocal() : bool public function IsLocal(): bool
{ {
return $this->oDriver->IsLocal(); return $this->oDriver->IsLocal();
} }
public function GC() : void public function GC(): void
{ {
$this->oDriver->GC(); $this->oDriver->GC();
} }

View file

@ -3,6 +3,7 @@
namespace RainLoop\Providers\Storage; namespace RainLoop\Providers\Storage;
use RainLoop\Providers\Storage\Enumerations\StorageType; use RainLoop\Providers\Storage\Enumerations\StorageType;
use RainLoop\Model\Account;
class FileStorage implements \RainLoop\Providers\Storage\IStorage class FileStorage implements \RainLoop\Providers\Storage\IStorage
{ {
@ -18,10 +19,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
$this->bLocal = $bLocal; $this->bLocal = $bLocal;
} }
/** public function Put(Account|string|null $mAccount, int $iStorageType, string $sKey, string $sValue): bool
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function Put($mAccount, int $iStorageType, string $sKey, string $sValue) : bool
{ {
$sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey, true); $sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey, true);
try { try {
@ -33,13 +31,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return false; return false;
} }
/** public function Get(Account|string|null $mAccount, int $iStorageType, string $sKey, mixed $mDefault = false): mixed
* @param \RainLoop\Model\Account|string|null $mAccount
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($mAccount, int $iStorageType, string $sKey, $mDefault = false)
{ {
$mValue = false; $mValue = false;
$sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey); $sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey);
@ -53,19 +45,13 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return false === $mValue ? $mDefault : $mValue; return false === $mValue ? $mDefault : $mValue;
} }
/** public function Clear(Account|string|null $mAccount, int $iStorageType, string $sKey): bool
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function Clear($mAccount, int $iStorageType, string $sKey) : bool
{ {
$sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey); $sFileName = $this->generateFileName($mAccount, $iStorageType, $sKey);
return $sFileName && \file_exists($sFileName) && \unlink($sFileName); return $sFileName && \file_exists($sFileName) && \unlink($sFileName);
} }
/** public function DeleteStorage(Account|string|null $mAccount): bool
* @param \RainLoop\Model\Account|string $mAccount
*/
public function DeleteStorage($mAccount) : bool
{ {
$sPath = $this->generateFileName($mAccount, StorageType::CONFIG, ''); $sPath = $this->generateFileName($mAccount, StorageType::CONFIG, '');
if ($sPath && \is_dir($sPath)) { if ($sPath && \is_dir($sPath)) {
@ -79,10 +65,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return $this->bLocal; return $this->bLocal;
} }
/** public function GenerateFilePath(Account|string|null $mAccount, int $iStorageType, bool $bMkDir = false): string
* @param \RainLoop\Model\Account|string|null $mAccount
*/
public function GenerateFilePath($mAccount, int $iStorageType, bool $bMkDir = false) : string
{ {
$sEmail = $sSubFolder = $sFilePath = ''; $sEmail = $sSubFolder = $sFilePath = '';
if (null === $mAccount || StorageType::NOBODY === $iStorageType) { if (null === $mAccount || StorageType::NOBODY === $iStorageType) {
@ -142,10 +125,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return $sFilePath; return $sFilePath;
} }
/** protected function generateFileName(Account|string|null $mAccount, int $iStorageType, string $sKey, bool $bMkDir = false): string
* @param \RainLoop\Model\Account|string|null $mAccount
*/
protected function generateFileName($mAccount, int $iStorageType, string $sKey, bool $bMkDir = false) : string
{ {
$sFilePath = $this->GenerateFilePath($mAccount, $iStorageType, $bMkDir); $sFilePath = $this->GenerateFilePath($mAccount, $iStorageType, $bMkDir);
if ($sFilePath) { if ($sFilePath) {
@ -158,7 +138,7 @@ class FileStorage implements \RainLoop\Providers\Storage\IStorage
return $sFilePath; return $sFilePath;
} }
public function GC() : void public function GC(): void
{ {
\clearstatcache(); \clearstatcache();
foreach (\glob("{$this->sDataPath}/*", GLOB_ONLYDIR) as $sDomain) { foreach (\glob("{$this->sDataPath}/*", GLOB_ONLYDIR) as $sDomain) {

View file

@ -2,25 +2,15 @@
namespace RainLoop\Providers\Storage; namespace RainLoop\Providers\Storage;
use RainLoop\Model\Account;
interface IStorage interface IStorage
{ {
/** public function Put(Account|string|null $mAccount, int $iStorageType, string $sKey, string $sValue): bool;
* @param \RainLoop\Model\Account|null $mAccount
*/
public function Put($mAccount, int $iStorageType, string $sKey, string $sValue) : bool;
/** public function Get(Account|string|null $mAccount, int $iStorageType, string $sKey, mixed $mDefault = false): mixed;
* @param \RainLoop\Model\Account|null $mAccount
* @param mixed $mDefault = false
*
* @return mixed
*/
public function Get($mAccount, int $iStorageType, string $sKey, $mDefault = false);
/** public function Clear(Account|string|null $mAccount, int $iStorageType, string $sKey): bool;
* @param \RainLoop\Model\Account|null $mAccount
*/
public function Clear($mAccount, int $iStorageType, string $sKey) : bool;
public function IsLocal() : bool; public function IsLocal(): bool;
} }

View file

@ -38,26 +38,18 @@ class Settings implements \JsonSerializable
return $this->aData; return $this->aData;
} }
#[\ReturnTypeWillChange] // public function jsonSerialize(): array
public function jsonSerialize() public function jsonSerialize(): mixed
{ {
return $this->aData;; return $this->aData;;
} }
/** public function GetConf(string $sName, mixed $mDefValue = null): mixed
* @param mixed $mDefValue = null
*
* @return mixed
*/
public function GetConf(string $sName, $mDefValue = null)
{ {
return isset($this->aData[$sName]) ? $this->aData[$sName] : $mDefValue; return isset($this->aData[$sName]) ? $this->aData[$sName] : $mDefValue;
} }
/** public function SetConf(string $sName, mixed $mValue): void
* @param mixed $mValue
*/
public function SetConf(string $sName, $mValue) : void
{ {
$this->aData[$sName] = $mValue; $this->aData[$sName] = $mValue;
} }

View file

@ -21,7 +21,7 @@ class Utils
* @param mixed $value * @param mixed $value
* @param int $flags Bitmask * @param int $flags Bitmask
*/ */
public static function jsonEncode($value, int $flags = \JSON_INVALID_UTF8_SUBSTITUTE) : string public static function jsonEncode(mixed $value, int $flags = \JSON_INVALID_UTF8_SUBSTITUTE): string
{ {
try { try {
/* Issue with \SnappyMail\HTTP\Stream /* Issue with \SnappyMail\HTTP\Stream
@ -36,7 +36,7 @@ class Utils
return ''; return '';
} }
public static function EncodeKeyValuesQ(array $aValues, string $sCustomKey = '') : string public static function EncodeKeyValuesQ(array $aValues, string $sCustomKey = ''): string
{ {
return \SnappyMail\Crypt::EncryptUrlSafe( return \SnappyMail\Crypt::EncryptUrlSafe(
$aValues, $aValues,
@ -44,7 +44,7 @@ class Utils
); );
} }
public static function DecodeKeyValuesQ(string $sEncodedValues, string $sCustomKey = '') : array public static function DecodeKeyValuesQ(string $sEncodedValues, string $sCustomKey = ''): array
{ {
return \SnappyMail\Crypt::DecryptUrlSafe( return \SnappyMail\Crypt::DecryptUrlSafe(
$sEncodedValues, $sEncodedValues,
@ -52,7 +52,7 @@ class Utils
) ?: array(); ) ?: array();
} }
public static function GetSessionToken(bool $generate = true) : ?string public static function GetSessionToken(bool $generate = true): ?string
{ {
$sToken = \SnappyMail\Cookies::get(self::SESSION_TOKEN); $sToken = \SnappyMail\Cookies::get(self::SESSION_TOKEN);
if (!$sToken) { if (!$sToken) {
@ -66,7 +66,7 @@ class Utils
return \sha1('Session'.APP_SALT.$sToken.'Token'.APP_SALT); return \sha1('Session'.APP_SALT.$sToken.'Token'.APP_SALT);
} }
public static function GetConnectionToken() : string public static function GetConnectionToken(): string
{ {
$oActions = \RainLoop\Api::Actions(); $oActions = \RainLoop\Api::Actions();
$oAccount = $oActions->getAccountFromToken(false); $oAccount = $oActions->getAccountFromToken(false);
@ -85,13 +85,13 @@ class Utils
return '0-' . \sha1('Connection'.APP_SALT.$sToken.'Token'.APP_SALT); return '0-' . \sha1('Connection'.APP_SALT.$sToken.'Token'.APP_SALT);
} }
public static function GetCsrfToken() : string public static function GetCsrfToken(): string
{ {
return self::GetConnectionToken(); return self::GetConnectionToken();
// return \sha1('Csrf'.APP_SALT.self::GetConnectionToken().'Token'.APP_SALT); // return \sha1('Csrf'.APP_SALT.self::GetConnectionToken().'Token'.APP_SALT);
} }
public static function UpdateConnectionToken() : void public static function UpdateConnectionToken(): void
{ {
$sToken = \SnappyMail\Cookies::get(self::CONNECTION_TOKEN); $sToken = \SnappyMail\Cookies::get(self::CONNECTION_TOKEN);
if ($sToken) { if ($sToken) {
@ -99,7 +99,7 @@ class Utils
} }
} }
public static function ClearHtmlOutput(string $sHtml) : string public static function ClearHtmlOutput(string $sHtml): string
{ {
// return $sHtml; // return $sHtml;
return \preg_replace('/>\\s+</', '> <', \preg_replace( return \preg_replace('/>\\s+</', '> <', \preg_replace(
@ -109,7 +109,7 @@ class Utils
)); ));
} }
public static function WebPath() : string public static function WebPath(): string
{ {
static $sAppPath; static $sAppPath;
if (!$sAppPath) { if (!$sAppPath) {
@ -120,7 +120,7 @@ class Utils
return $sAppPath; return $sAppPath;
} }
public static function WebVersionPath() : string public static function WebVersionPath(): string
{ {
return self::WebPath() . 'snappymail/v/' . APP_VERSION . '/'; return self::WebPath() . 'snappymail/v/' . APP_VERSION . '/';
/** /**
@ -130,12 +130,12 @@ class Utils
// return self::WebPath() . \str_replace(APP_INDEX_ROOT_PATH, '', APP_VERSION_ROOT_PATH); // return self::WebPath() . \str_replace(APP_INDEX_ROOT_PATH, '', APP_VERSION_ROOT_PATH);
} }
public static function WebStaticPath(string $path = '') : string public static function WebStaticPath(string $path = ''): string
{ {
return self::WebVersionPath() . 'static/' . $path; return self::WebVersionPath() . 'static/' . $path;
} }
public static function inOpenBasedir(string $name) : string public static function inOpenBasedir(string $name): string
{ {
static $open_basedir; static $open_basedir;
if (null === $open_basedir) { if (null === $open_basedir) {
@ -153,7 +153,7 @@ class Utils
return true; return true;
} }
public static function saveFile(string $filename, string $data) : void public static function saveFile(string $filename, string $data): void
{ {
$dir = \dirname($filename); $dir = \dirname($filename);
if (!\is_dir($dir) && !\mkdir($dir, 0700, true)) { if (!\is_dir($dir) && !\mkdir($dir, 0700, true)) {

View file

@ -10,7 +10,7 @@ abstract class Crypt
{ {
protected static $cipher = ''; protected static $cipher = '';
public static function listCiphers() : array public static function listCiphers(): array
{ {
$list = array(); $list = array();
if (\function_exists('openssl_get_cipher_methods')) { if (\function_exists('openssl_get_cipher_methods')) {
@ -25,12 +25,12 @@ abstract class Crypt
return $list; return $list;
} }
public static function cipherSupported(string $cipher) : bool public static function cipherSupported(string $cipher): bool
{ {
return \in_array($cipher, static::listCiphers()); return \in_array($cipher, static::listCiphers());
} }
public static function setCipher(string $cipher) : bool public static function setCipher(string $cipher): bool
{ {
if (static::cipherSupported($cipher)) { if (static::cipherSupported($cipher)) {
static::$cipher = $cipher; static::$cipher = $cipher;
@ -46,7 +46,7 @@ abstract class Crypt
private static function Passphrase( private static function Passphrase(
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key ?string $key
) : string ): string
{ {
if (!$key) { if (!$key) {
if (empty($_COOKIE['smctoken'])) { if (empty($_COOKIE['smctoken'])) {
@ -61,7 +61,7 @@ abstract class Crypt
public static function Decrypt(array $data, public static function Decrypt(array $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : mixed */ ): mixed
{ {
if (3 === \count($data) && isset($data[0], $data[1], $data[2]) && \strlen($data[0])) { if (3 === \count($data) && isset($data[0], $data[1], $data[2]) && \strlen($data[0])) {
$fn = "{$data[0]}Decrypt"; $fn = "{$data[0]}Decrypt";
@ -86,7 +86,7 @@ abstract class Crypt
public static function DecryptFromJSON(string $data, public static function DecryptFromJSON(string $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : mixed */ ): mixed
{ {
$data = static::jsonDecode($data); $data = static::jsonDecode($data);
if (!\is_array($data)) { if (!\is_array($data)) {
@ -99,7 +99,7 @@ abstract class Crypt
public static function DecryptUrlSafe(string $data, public static function DecryptUrlSafe(string $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : mixed */ ): mixed
{ {
$data = \explode('.', $data); $data = \explode('.', $data);
if (!\is_array($data)) { if (!\is_array($data)) {
@ -114,7 +114,7 @@ abstract class Crypt
$data, $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : array ): array
{ {
$data = \json_encode($data); $data = \json_encode($data);
@ -152,7 +152,7 @@ abstract class Crypt
$data, $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : string ): string
{ {
return \json_encode(\array_map('base64_encode', static::Encrypt($data, $key))); return \json_encode(\array_map('base64_encode', static::Encrypt($data, $key)));
} }
@ -162,7 +162,7 @@ abstract class Crypt
$data, $data,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : string ): string
{ {
return \implode('.', \array_map('MailSo\\Base\\Utils::UrlSafeBase64Encode', static::Encrypt($data, $key))); return \implode('.', \array_map('MailSo\\Base\\Utils::UrlSafeBase64Encode', static::Encrypt($data, $key)));
} }
@ -170,7 +170,7 @@ abstract class Crypt
public static function SodiumDecrypt(string $data, string $nonce, public static function SodiumDecrypt(string $data, string $nonce,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : string|false */ ): string|false
{ {
if (!\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) { if (!\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt')) {
throw new \Exception('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt not callable'); throw new \Exception('sodium_crypto_aead_xchacha20poly1305_ietf_decrypt not callable');
@ -189,7 +189,7 @@ abstract class Crypt
string $nonce, string $nonce,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : string ): string
{ {
if (!\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) { if (!\is_callable('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt')) {
throw new \Exception('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt not callable'); throw new \Exception('sodium_crypto_aead_xchacha20poly1305_ietf_encrypt not callable');
@ -209,7 +209,7 @@ abstract class Crypt
public static function OpenSSLDecrypt(string $data, string $iv, public static function OpenSSLDecrypt(string $data, string $iv,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : string|false */ ): string|false
{ {
if (!$data || !$iv) { if (!$data || !$iv) {
throw new \ValueError('$data or $iv is empty string'); throw new \ValueError('$data or $iv is empty string');
@ -236,7 +236,7 @@ abstract class Crypt
string $iv, string $iv,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : string ): string
{ {
if (!$data || !$iv) { if (!$data || !$iv) {
throw new \ValueError('$data or $iv is empty string'); throw new \ValueError('$data or $iv is empty string');
@ -264,7 +264,7 @@ abstract class Crypt
public static function XxteaDecrypt(string $data, string $salt, public static function XxteaDecrypt(string $data, string $salt,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) /* : mixed */ ): mixed
{ {
if (!$data || !$salt) { if (!$data || !$salt) {
throw new \ValueError('$data or $salt is empty string'); throw new \ValueError('$data or $salt is empty string');
@ -281,7 +281,7 @@ abstract class Crypt
string $salt, string $salt,
#[\SensitiveParameter] #[\SensitiveParameter]
?string $key = null ?string $key = null
) : string ): string
{ {
if (!$data || !$salt) { if (!$data || !$salt) {
throw new \ValueError('$data or $salt is empty string'); throw new \ValueError('$data or $salt is empty string');
@ -296,7 +296,7 @@ abstract class Crypt
return $result; return $result;
} }
private static function jsonDecode(string $data) /*: mixed*/ private static function jsonDecode(string $data): mixed
{ {
return \json_decode($data, true, 512, JSON_THROW_ON_ERROR); return \json_decode($data, true, 512, JSON_THROW_ON_ERROR);
} }

View file

@ -42,7 +42,7 @@ class Temporary
return $this->fp; return $this->fp;
} }
public function writeFromStream(/*resource*/ $from)/* : int|false*/ public function writeFromStream(/*resource*/ $from): int|false
{ {
$fp = $this->fopen(); $fp = $this->fopen();
// return \stream_copy_to_stream($from, $fp); // Fails // return \stream_copy_to_stream($from, $fp); // Fails
@ -51,12 +51,12 @@ class Temporary
return $bytes; return $bytes;
} }
public function putContents($data, int $flags = 0)/* : int|false*/ public function putContents(mixed $data, int $flags = 0): int|false
{ {
return \file_put_contents($this->filename, $data /*, $flags, $context*/); return \file_put_contents($this->filename, $data /*, $flags, $context*/);
} }
public function getContents()/* : string|false*/ public function getContents(): string|false
{ {
return \file_get_contents($this->filename); return \file_get_contents($this->filename);
} }

View file

@ -91,7 +91,7 @@ abstract class Base
} }
} }
public static function isSupported() : bool public static function isSupported(): bool
{ {
return \is_callable('shell_exec') && \is_callable('proc_open'); return \is_callable('shell_exec') && \is_callable('proc_open');
} }
@ -104,7 +104,7 @@ abstract class Base
/** /**
* Decrypts a given text * Decrypts a given text
*/ */
public function decrypt(string $text) /*: string|false */ public function decrypt(string $text): string|false
{ {
return false; return false;
} }
@ -112,7 +112,7 @@ abstract class Base
/** /**
* Decrypts a given file * Decrypts a given file
*/ */
public function decryptFile(string $filename) /*: string|false */ public function decryptFile(string $filename): string|false
{ {
return false; return false;
} }
@ -120,7 +120,7 @@ abstract class Base
/** /**
* Decrypts a given stream * Decrypts a given stream
*/ */
public function decryptStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function decryptStream($fp, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -128,7 +128,7 @@ abstract class Base
/** /**
* Decrypts and verifies a given text * Decrypts and verifies a given text
*/ */
public function decryptVerify(string $text, string &$plaintext) /*: array|false*/ public function decryptVerify(string $text, string &$plaintext): array|false
{ {
return false; return false;
} }
@ -136,7 +136,7 @@ abstract class Base
/** /**
* Decrypts and verifies a given file * Decrypts and verifies a given file
*/ */
public function decryptVerifyFile(string $filename, string &$plaintext) /*: array|false*/ public function decryptVerifyFile(string $filename, string &$plaintext): array|false
{ {
return false; return false;
} }
@ -144,7 +144,7 @@ abstract class Base
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encrypt(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function encrypt(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -152,12 +152,12 @@ abstract class Base
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encryptFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function encryptFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false*/ public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -165,7 +165,7 @@ abstract class Base
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSign(string $plaintext) /*: string|false*/ public function encryptSign(string $plaintext): string|false
{ {
return false; return false;
} }
@ -173,7 +173,7 @@ abstract class Base
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSignFile(string $filename) /*: string|false*/ public function encryptSignFile(string $filename): string|false
{ {
return false; return false;
} }
@ -181,7 +181,7 @@ abstract class Base
/** /**
* Exports a public or private key * Exports a public or private key
*/ */
public function export(string $fingerprint, ?SensitiveString $passphrase = null) /*: string|false*/ public function export(string $fingerprint, ?SensitiveString $passphrase = null): string|false
{ {
return false; return false;
} }
@ -189,7 +189,7 @@ abstract class Base
/** /**
* Imports a key * Imports a key
*/ */
public function import(string $keydata) /*: array|false*/ public function import(string $keydata): array|false
{ {
return false; return false;
} }
@ -197,7 +197,7 @@ abstract class Base
/** /**
* Imports a key * Imports a key
*/ */
public function importFile(string $filename) /*: array|false*/ public function importFile(string $filename): array|false
{ {
return false; return false;
} }
@ -210,7 +210,7 @@ abstract class Base
/** /**
* Returns an array with information about all keys that matches the given pattern * Returns an array with information about all keys that matches the given pattern
*/ */
public function keyInfo(string $pattern, bool $private = false) : array public function keyInfo(string $pattern, bool $private = false): array
{ {
return []; return [];
} }
@ -220,14 +220,14 @@ abstract class Base
* GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT. * GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT.
* By default GNUPG_ERROR_SILENT is used. * By default GNUPG_ERROR_SILENT is used.
*/ */
public function setErrorMode(int $errormode) : void public function setErrorMode(int $errormode): void
{ {
} }
/** /**
* Signs a given text * Signs a given text
*/ */
public function sign(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function sign(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -235,7 +235,7 @@ abstract class Base
/** /**
* Signs a given file * Signs a given file
*/ */
public function signFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function signFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -243,7 +243,7 @@ abstract class Base
/** /**
* Signs a given file * Signs a given file
*/ */
public function signStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function signStream($fp, /*string|resource*/ $output = null): string|false
{ {
return false; return false;
} }
@ -251,7 +251,7 @@ abstract class Base
/** /**
* Verifies a signed text * Verifies a signed text
*/ */
public function verify(string $signed_text, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verify(string $signed_text, string $signature, ?string &$plaintext = null): array|false
{ {
return false; return false;
} }
@ -259,7 +259,7 @@ abstract class Base
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyFile(string $filename, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyFile(string $filename, string $signature, ?string &$plaintext = null): array|false
{ {
return false; return false;
} }
@ -267,12 +267,12 @@ abstract class Base
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyStream($fp, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyStream($fp, string $signature, ?string &$plaintext = null): array|false
{ {
return false; return false;
} }
public function getEncryptedMessageKeys(/*string|resource*/ $data) : array public function getEncryptedMessageKeys(/*string|resource*/ $data): array
{ {
return []; return [];
} }
@ -284,7 +284,7 @@ abstract class Base
/** /**
* Add a key for decryption * Add a key for decryption
*/ */
public function addDecryptKey(string $fingerprint, SensitiveString $passphrase) : bool public function addDecryptKey(string $fingerprint, SensitiveString $passphrase): bool
{ {
$this->addPinentry($fingerprint, $passphrase); $this->addPinentry($fingerprint, $passphrase);
return true; return true;
@ -293,7 +293,7 @@ abstract class Base
/** /**
* Add a key for encryption * Add a key for encryption
*/ */
public function addEncryptKey(string $fingerprint) : bool public function addEncryptKey(string $fingerprint): bool
{ {
$this->encryptKeys[$fingerprint] = 1; $this->encryptKeys[$fingerprint] = 1;
return true; return true;
@ -302,13 +302,13 @@ abstract class Base
/** /**
* Add a key for signing * Add a key for signing
*/ */
public function addSignKey(string $fingerprint, SensitiveString $passphrase) : bool public function addSignKey(string $fingerprint, SensitiveString $passphrase): bool
{ {
$this->addPinentry($fingerprint, $passphrase); $this->addPinentry($fingerprint, $passphrase);
return true; return true;
} }
public function clear() : bool public function clear(): bool
{ {
$this->clearPinentries(); $this->clearPinentries();
$this->clearEncryptKeys(); $this->clearEncryptKeys();
@ -318,7 +318,7 @@ abstract class Base
/** /**
* Removes all keys which were set for decryption before * Removes all keys which were set for decryption before
*/ */
public function clearDecryptKeys() : bool public function clearDecryptKeys(): bool
{ {
return $this->clearPinentries(); return $this->clearPinentries();
} }
@ -326,7 +326,7 @@ abstract class Base
/** /**
* Removes all keys which were set for encryption before * Removes all keys which were set for encryption before
*/ */
public function clearEncryptKeys() : bool public function clearEncryptKeys(): bool
{ {
$this->encryptKeys = []; $this->encryptKeys = [];
return true; return true;
@ -335,7 +335,7 @@ abstract class Base
/** /**
* Removes all keys which were set for signing before * Removes all keys which were set for signing before
*/ */
public function clearSignKeys() : bool public function clearSignKeys(): bool
{ {
return $this->clearPinentries(); return $this->clearPinentries();
} }
@ -343,7 +343,7 @@ abstract class Base
/** /**
* Returns the engine info * Returns the engine info
*/ */
public function getEngineInfo() : array public function getEngineInfo(): array
{ {
return [ return [
'protocol' => null, 'protocol' => null,
@ -357,7 +357,7 @@ abstract class Base
* Add private key passphrase for decrypt, sign or export * Add private key passphrase for decrypt, sign or export
* $keyId or fingerprint * $keyId or fingerprint
*/ */
public function addPinentry(string $keyId, SensitiveString $passphrase) public function addPinentry(string $keyId, SensitiveString $passphrase): self
{ {
/** /**
* Test first? * Test first?
@ -378,7 +378,7 @@ abstract class Base
/** /**
* Removes all keys which were set for decryption, signing and export * Removes all keys which were set for decryption, signing and export
*/ */
public function clearPinentries() : bool public function clearPinentries(): bool
{ {
$this->pinentries = []; $this->pinentries = [];
return true; return true;
@ -388,18 +388,18 @@ abstract class Base
* Toggle the armored output * Toggle the armored output
* When true the output is ASCII * When true the output is ASCII
*/ */
public function setArmor(bool $armor = true) : bool public function setArmor(bool $armor = true): bool
{ {
$this->armor = $armor; $this->armor = $armor;
return true; return true;
} }
protected function _debug(string $msg) : void protected function _debug(string $msg): void
{ {
\SnappyMail\Log::debug('GPG', $msg); \SnappyMail\Log::debug('GPG', $msg);
} }
protected function setInput(&$input) : void protected function setInput(&$input): void
{ {
if (\is_resource($input)) { if (\is_resource($input)) {
// https://github.com/the-djmaze/snappymail/issues/331 // https://github.com/the-djmaze/snappymail/issues/331
@ -437,7 +437,7 @@ abstract class Base
// echo \shell_exec('gpg-agent --daemon --homedir $home 2>&1'); // echo \shell_exec('gpg-agent --daemon --homedir $home 2>&1');
} }
protected function getPassphrase($key) protected function getPassphrase($key): string
{ {
$passphrase = ''; $passphrase = '';
$keyIdLength = \strlen($key); $keyIdLength = \strlen($key);
@ -454,7 +454,7 @@ abstract class Base
return ''; return '';
} }
protected function proc_close() : int protected function proc_close(): int
{ {
$exitCode = 0; $exitCode = 0;
@ -485,7 +485,7 @@ abstract class Base
return $exitCode; return $exitCode;
} }
protected static function findBinary($name) : ?string protected static function findBinary($name): ?string
{ {
$binary = \function_exists('shell_exec') ? \trim((string) \shell_exec('which ' . \escapeshellarg($name))) : ''; $binary = \function_exists('shell_exec') ? \trim((string) \shell_exec('which ' . \escapeshellarg($name))) : '';
if ($binary && \RainLoop\Utils::inOpenBasedir($binary) && \is_executable($binary)) { if ($binary && \RainLoop\Utils::inOpenBasedir($binary) && \is_executable($binary)) {

View file

@ -71,7 +71,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
} }
} }
public static function isSupported() : bool public static function isSupported(): bool
{ {
return parent::isSupported() && static::findBinary('gpg'); return parent::isSupported() && static::findBinary('gpg');
} }
@ -99,7 +99,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given text * Decrypts a given text
*/ */
public function decrypt(string $text) /*: string|false */ public function decrypt(string $text): string|false
{ {
return $this->_decrypt($text); return $this->_decrypt($text);
} }
@ -107,7 +107,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given file * Decrypts a given file
*/ */
public function decryptFile(string $filename) /*: string|false */ public function decryptFile(string $filename): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -123,7 +123,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given stream * Decrypts a given stream
*/ */
public function decryptStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function decryptStream($fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -135,7 +135,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts and verifies a given text * Decrypts and verifies a given text
*/ */
public function decryptVerify(string $text, string &$plaintext) /*: array|false*/ public function decryptVerify(string $text, string &$plaintext): array|false
{ {
// TODO: https://github.com/the-djmaze/snappymail/issues/89 // TODO: https://github.com/the-djmaze/snappymail/issues/89
return false; return false;
@ -144,7 +144,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts and verifies a given file * Decrypts and verifies a given file
*/ */
public function decryptVerifyFile(string $filename, string &$plaintext) /*: array|false*/ public function decryptVerifyFile(string $filename, string &$plaintext): array|false
{ {
// TODO: https://github.com/the-djmaze/snappymail/issues/89 // TODO: https://github.com/the-djmaze/snappymail/issues/89
return false; return false;
@ -175,7 +175,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encrypt(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function encrypt(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return $this->_encrypt($plaintext, $output); return $this->_encrypt($plaintext, $output);
} }
@ -183,7 +183,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encryptFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function encryptFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -196,7 +196,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
} }
} }
public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false*/ public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -208,7 +208,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSign(string $plaintext) /*: string|false*/ public function encryptSign(string $plaintext): string|false
{ {
return false; return false;
} }
@ -216,7 +216,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSignFile(string $filename) /*: string|false*/ public function encryptSignFile(string $filename): string|false
{ {
return false; return false;
} }
@ -224,7 +224,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Exports a public or private key * Exports a public or private key
*/ */
public function export(string $fingerprint, ?SensitiveString $passphrase = null) /*: string|false*/ public function export(string $fingerprint, ?SensitiveString $passphrase = null): string|false
{ {
// \SnappyMail\Log::debug('GnuPG', "export({$fingerprint}, {$passphrase})"); // \SnappyMail\Log::debug('GnuPG', "export({$fingerprint}, {$passphrase})");
$private = null !== $passphrase; $private = null !== $passphrase;
@ -246,7 +246,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the errortext, if a function fails * Returns the errortext, if a function fails
*/ */
public function getError() /*: string|false*/ public function getError(): string|false
{ {
return false; return false;
} }
@ -254,7 +254,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the error info * Returns the error info
*/ */
public function getErrorInfo() : array public function getErrorInfo(): array
{ {
return []; return [];
} }
@ -262,7 +262,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the currently active protocol for all operations * Returns the currently active protocol for all operations
*/ */
public function getProtocol() : int public function getProtocol(): int
{ {
return 0; // GPGME_PROTOCOL_OpenPGP return 0; // GPGME_PROTOCOL_OpenPGP
} }
@ -272,7 +272,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
* Also saves revocation certificate in {homedir}/openpgp-revocs.d/ * Also saves revocation certificate in {homedir}/openpgp-revocs.d/
* https://www.gnupg.org/documentation/manuals/gnupg/OpenPGP-Key-Management.html * https://www.gnupg.org/documentation/manuals/gnupg/OpenPGP-Key-Management.html
*/ */
public function generateKey(string $uid, SensitiveString $passphrase) /*: string|false*/ public function generateKey(string $uid, SensitiveString $passphrase): string|false
{ {
$settings = new PGPKeySettings; $settings = new PGPKeySettings;
$settings->name = $uid; $settings->name = $uid;
@ -338,7 +338,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
return $fingerprint; return $fingerprint;
} }
protected function _importKey($input) /*: array|false*/ protected function _importKey($input): array|false
{ {
$arguments = ['--import']; $arguments = ['--import'];
@ -374,7 +374,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Imports a key * Imports a key
*/ */
public function import(string $keydata) /*: array|false*/ public function import(string $keydata): array|false
{ {
if (!$keydata) { if (!$keydata) {
throw new \Exception('No valid input data found.'); throw new \Exception('No valid input data found.');
@ -385,7 +385,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Imports a key * Imports a key
*/ */
public function importFile(string $filename) /*: array|false*/ public function importFile(string $filename): array|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -398,7 +398,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
} }
} }
public function deleteKey(string $keyId, bool $private) : bool public function deleteKey(string $keyId, bool $private): bool
{ {
$key = $this->keyInfo($keyId, $private); $key = $this->keyInfo($keyId, $private);
if (!$key) { if (!$key) {
@ -425,7 +425,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns an array with information about all keys that matches the given pattern * Returns an array with information about all keys that matches the given pattern
*/ */
public function keyInfo(string $pattern, bool $private = false) : array public function keyInfo(string $pattern, bool $private = false): array
{ {
// According to The file 'doc/DETAILS' in the GnuPG distribution, using // According to The file 'doc/DETAILS' in the GnuPG distribution, using
// double '--with-fingerprint' also prints the fingerprint for subkeys. // double '--with-fingerprint' also prints the fingerprint for subkeys.
@ -554,7 +554,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns an array with information about all keys that matches the given pattern * Returns an array with information about all keys that matches the given pattern
*/ */
public function allKeysInfo(string $pattern) : array public function allKeysInfo(string $pattern): array
{ {
$keys = [ $keys = [
'public' => [], 'public' => [],
@ -580,7 +580,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
* GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT. * GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT.
* By default GNUPG_ERROR_SILENT is used. * By default GNUPG_ERROR_SILENT is used.
*/ */
public function setErrorMode(int $errormode) : void public function setErrorMode(int $errormode): void
{ {
} }
@ -589,13 +589,13 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
* GNUPG_SIG_MODE_NORMAL, GNUPG_SIG_MODE_DETACH, GNUPG_SIG_MODE_CLEAR * GNUPG_SIG_MODE_NORMAL, GNUPG_SIG_MODE_DETACH, GNUPG_SIG_MODE_CLEAR
* By default GNUPG_SIG_MODE_CLEAR * By default GNUPG_SIG_MODE_CLEAR
*/ */
public function setSignMode(int $signmode) : bool public function setSignMode(int $signmode): bool
{ {
$this->signmode = $signmode; $this->signmode = $signmode;
return true; return true;
} }
protected function _sign(/*string|resource*/ $input, /*string|resource*/ $output = null, bool $textmode = true) /*: string|false*/ protected function _sign(/*string|resource*/ $input, /*string|resource*/ $output = null, bool $textmode = true): string|false
{ {
if (empty($this->pinentries)) { if (empty($this->pinentries)) {
throw new \Exception('No signing keys specified.'); throw new \Exception('No signing keys specified.');
@ -639,7 +639,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given text * Signs a given text
*/ */
public function sign(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function sign(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return $this->_sign($plaintext, $output); return $this->_sign($plaintext, $output);
} }
@ -647,7 +647,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given file * Signs a given file
*/ */
public function signFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function signFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -663,7 +663,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given file * Signs a given file
*/ */
public function signStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function signStream($fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -672,7 +672,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
return $this->_sign($fp, $output); return $this->_sign($fp, $output);
} }
protected function _verify($input, string $signature) /*: array|false*/ protected function _verify($input, string $signature): array|false
{ {
$arguments = ['--verify']; $arguments = ['--verify'];
if ($signature) { if ($signature) {
@ -739,7 +739,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a signed text * Verifies a signed text
*/ */
public function verify(string $signed_text, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verify(string $signed_text, string $signature, ?string &$plaintext = null): array|false
{ {
return $this->_verify($signed_text, $signature); return $this->_verify($signed_text, $signature);
} }
@ -747,7 +747,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyFile(string $filename, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyFile(string $filename, string $signature, ?string &$plaintext = null): array|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -763,7 +763,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyStream($fp, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyStream($fp, string $signature, ?string &$plaintext = null): array|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -772,7 +772,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
return $this->_verify($fp, $signature); return $this->_verify($fp, $signature);
} }
public function getEncryptedMessageKeys(/*string|resource*/ $data) : array public function getEncryptedMessageKeys(/*string|resource*/ $data): array
{ {
$this->_debug('BEGIN DETECT MESSAGE KEY IDs'); $this->_debug('BEGIN DETECT MESSAGE KEY IDs');
$this->setInput($data); $this->setInput($data);
@ -803,7 +803,7 @@ class PGP extends Base implements \SnappyMail\PGP\PGPInterface
return $output ? true : ($result ? $result['output'] : false); return $output ? true : ($result ? $result['output'] : false);
} }
private function exec(array $arguments, bool $throw = true) /*: array|false*/ private function exec(array $arguments, bool $throw = true): array|false
{ {
if (\version_compare($this->version, '2.2.5', '<')) { if (\version_compare($this->version, '2.2.5', '<')) {
\SnappyMail\Log::error('GPG', "{$this->version} too old"); \SnappyMail\Log::error('GPG', "{$this->version} too old");

View file

@ -58,7 +58,7 @@ class SMIME extends Base
} }
} }
public static function isSupported() : bool public static function isSupported(): bool
{ {
return parent::isSupported() && static::findBinary('gpgsm'); return parent::isSupported() && static::findBinary('gpgsm');
} }
@ -97,7 +97,7 @@ class SMIME extends Base
/** /**
* Decrypts a given text * Decrypts a given text
*/ */
public function decrypt(string $text) /*: string|false */ public function decrypt(string $text): string|false
{ {
return $this->_decrypt($text); return $this->_decrypt($text);
} }
@ -105,7 +105,7 @@ class SMIME extends Base
/** /**
* Decrypts a given file * Decrypts a given file
*/ */
public function decryptFile(string $filename) /*: string|false */ public function decryptFile(string $filename): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -121,7 +121,7 @@ class SMIME extends Base
/** /**
* Decrypts a given stream * Decrypts a given stream
*/ */
public function decryptStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function decryptStream($fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -132,7 +132,7 @@ class SMIME extends Base
/** /**
* Decrypts and verifies a given text * Decrypts and verifies a given text
*/ */
public function decryptVerify(string $text, string &$plaintext) /*: array|false*/ public function decryptVerify(string $text, string &$plaintext): array|false
{ {
// TODO: https://github.com/the-djmaze/snappymail/issues/89 // TODO: https://github.com/the-djmaze/snappymail/issues/89
return false; return false;
@ -141,7 +141,7 @@ class SMIME extends Base
/** /**
* Decrypts and verifies a given file * Decrypts and verifies a given file
*/ */
public function decryptVerifyFile(string $filename, string &$plaintext) /*: array|false*/ public function decryptVerifyFile(string $filename, string &$plaintext): array|false
{ {
// TODO: https://github.com/the-djmaze/snappymail/issues/89 // TODO: https://github.com/the-djmaze/snappymail/issues/89
return false; return false;
@ -178,7 +178,7 @@ class SMIME extends Base
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encrypt(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function encrypt(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return $this->_encrypt($plaintext, $output); return $this->_encrypt($plaintext, $output);
} }
@ -186,7 +186,7 @@ class SMIME extends Base
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encryptFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function encryptFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -199,7 +199,7 @@ class SMIME extends Base
} }
} }
public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false*/ public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -210,7 +210,7 @@ class SMIME extends Base
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSign(string $plaintext) /*: string|false*/ public function encryptSign(string $plaintext): string|false
{ {
return false; return false;
} }
@ -218,7 +218,7 @@ class SMIME extends Base
/** /**
* Encrypts and signs a given text * Encrypts and signs a given text
*/ */
public function encryptSignFile(string $filename) /*: string|false*/ public function encryptSignFile(string $filename): string|false
{ {
return false; return false;
} }
@ -226,7 +226,7 @@ class SMIME extends Base
/** /**
* Exports a public or private key * Exports a public or private key
*/ */
public function export(string $fingerprint, ?SensitiveString $passphrase = null) /*: string|false*/ public function export(string $fingerprint, ?SensitiveString $passphrase = null): string|false
{ {
$private = null !== $passphrase; $private = null !== $passphrase;
$keys = $this->keyInfo($fingerprint, $private); $keys = $this->keyInfo($fingerprint, $private);
@ -244,7 +244,7 @@ class SMIME extends Base
return $result['output']; return $result['output'];
} }
protected function _importKey($input) /*: array|false*/ protected function _importKey($input): array|false
{ {
$arguments = ['--import']; $arguments = ['--import'];
@ -284,7 +284,7 @@ class SMIME extends Base
/** /**
* Imports a key * Imports a key
*/ */
public function import(string $keydata) /*: array|false*/ public function import(string $keydata): array|false
{ {
if (!$keydata) { if (!$keydata) {
throw new \Exception('No valid input data found.'); throw new \Exception('No valid input data found.');
@ -295,7 +295,7 @@ class SMIME extends Base
/** /**
* Imports a key * Imports a key
*/ */
public function importFile(string $filename) /*: array|false*/ public function importFile(string $filename): array|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -335,7 +335,7 @@ class SMIME extends Base
/** /**
* Returns an array with information about all keys that matches the given pattern * Returns an array with information about all keys that matches the given pattern
*/ */
public function keyInfo(string $pattern, bool $private = false) : array public function keyInfo(string $pattern, bool $private = false): array
{ {
// According to The file 'doc/DETAILS' in the GnuPG distribution, using // According to The file 'doc/DETAILS' in the GnuPG distribution, using
// double '--with-fingerprint' also prints the fingerprint for subkeys. // double '--with-fingerprint' also prints the fingerprint for subkeys.
@ -457,7 +457,7 @@ class SMIME extends Base
return $keys; return $keys;
} }
protected function _sign(/*string|resource*/ $input, /*string|resource*/ $output = null) /*: string|false*/ protected function _sign(/*string|resource*/ $input, /*string|resource*/ $output = null): string|false
{ {
if (empty($this->pinentries)) { if (empty($this->pinentries)) {
throw new \Exception('No signing keys specified.'); throw new \Exception('No signing keys specified.');
@ -492,7 +492,7 @@ class SMIME extends Base
/** /**
* Signs a given text * Signs a given text
*/ */
public function sign(string $plaintext, /*string|resource*/ $output = null) /*: string|false*/ public function sign(string $plaintext, /*string|resource*/ $output = null): string|false
{ {
return $this->_sign($plaintext, $output); return $this->_sign($plaintext, $output);
} }
@ -500,7 +500,7 @@ class SMIME extends Base
/** /**
* Signs a given file * Signs a given file
*/ */
public function signFile(string $filename, /*string|resource*/ $output = null) /*: string|false*/ public function signFile(string $filename, /*string|resource*/ $output = null): string|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -516,7 +516,7 @@ class SMIME extends Base
/** /**
* Signs a given file * Signs a given file
*/ */
public function signStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function signStream($fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -524,7 +524,7 @@ class SMIME extends Base
return $this->_sign($fp, $output); return $this->_sign($fp, $output);
} }
protected function _verify($input, string $signature) /*: array|false*/ protected function _verify($input, string $signature): array|false
{ {
$arguments = ['--verify']; $arguments = ['--verify'];
if ($signature) { if ($signature) {
@ -589,7 +589,7 @@ class SMIME extends Base
/** /**
* Verifies a signed text * Verifies a signed text
*/ */
public function verify(string $signed_text, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verify(string $signed_text, string $signature, ?string &$plaintext = null): array|false
{ {
return $this->_verify($signed_text, $signature); return $this->_verify($signed_text, $signature);
} }
@ -597,7 +597,7 @@ class SMIME extends Base
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyFile(string $filename, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyFile(string $filename, string $signature, ?string &$plaintext = null): array|false
{ {
$fp = \fopen($filename, 'rb'); $fp = \fopen($filename, 'rb');
try { try {
@ -613,7 +613,7 @@ class SMIME extends Base
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyStream($fp, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyStream($fp, string $signature, ?string &$plaintext = null): array|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -621,7 +621,7 @@ class SMIME extends Base
return $this->_verify($fp, $signature); return $this->_verify($fp, $signature);
} }
public function getEncryptedMessageKeys(/*string|resource*/ $data) : array public function getEncryptedMessageKeys(/*string|resource*/ $data): array
{ {
$this->_debug('BEGIN DETECT MESSAGE KEY IDs'); $this->_debug('BEGIN DETECT MESSAGE KEY IDs');
$this->setInput($data); $this->setInput($data);
@ -643,7 +643,7 @@ class SMIME extends Base
return $info['ENC_TO']; return $info['ENC_TO'];
} }
private function exec(array $arguments, bool $throw = true) /*: array|false*/ private function exec(array $arguments, bool $throw = true): array|false
{ {
if (\version_compare($this->version, '2.2.5', '<')) { if (\version_compare($this->version, '2.2.5', '<')) {
\SnappyMail\Log::error('GPG', "{$this->version} too old"); \SnappyMail\Log::error('GPG', "{$this->version} too old");
@ -1032,7 +1032,7 @@ class SMIME extends Base
return ''; return '';
} }
protected function proc_close() : int protected function proc_close(): int
{ {
$exitCode = 0; $exitCode = 0;

View file

@ -47,7 +47,7 @@ class Response
return \property_exists($this, $k) ? $this->$k : null; return \property_exists($this, $k) ? $this->$k : null;
} }
public function decoded()/*: string|false*/ public function decoded(): string|false
{ {
$body = $this->body; $body = $this->body;
if (\function_exists('gzinflate') && isset($this->headers['content-encoding']) if (\function_exists('gzinflate') && isset($this->headers['content-encoding'])
@ -61,10 +61,7 @@ class Response
return $body; return $body;
} }
/** public function getHeader(mixed $names): string|array|null
* returns string, array or null
*/
public function getHeader($names)
{ {
$names = \is_array($names) ? $names : array($names); $names = \is_array($names) ? $names : array($names);
foreach ($names as $n) { foreach ($names as $n) {
@ -76,12 +73,12 @@ class Response
return null; return null;
} }
public function getHeaders() : array public function getHeaders(): array
{ {
return $this->headers; return $this->headers;
} }
public function getRedirectLocation() : ?string public function getRedirectLocation(): ?string
{ {
if ($location = $this->getHeader('location')) { if ($location = $this->getHeader('location')) {
$uri = \is_array($location) ? $location[0] : $location; $uri = \is_array($location) ? $location[0] : $location;

View file

@ -6,15 +6,15 @@ use MailSo\Base\Utils;
abstract class JWT abstract class JWT
{ {
private static function jsonEncode($data) private static function jsonEncode(mixed $data): string|false
{ {
return Utils::UrlSafeBase64Encode(\json_encode($payload, JSON_THROW_ON_ERROR)); return Utils::UrlSafeBase64Encode(\json_encode($payload, \JSON_THROW_ON_ERROR));
} }
private static function jsonDecode($data) private static function jsonDecode(string $data): mixed
{ {
$data = Utils::UrlSafeBase64Decode($data); $data = Utils::UrlSafeBase64Decode($data);
return \json_decode($data, false, 8, JSON_BIGINT_AS_STRING | JSON_THROW_ON_ERROR); return \json_decode($data, false, 8, \JSON_BIGINT_AS_STRING | \JSON_THROW_ON_ERROR);
} }
/** /**
@ -26,7 +26,7 @@ abstract class JWT
* @param int $timestamp Allow the current timestamp to be specified. default time() * @param int $timestamp Allow the current timestamp to be specified. default time()
* @param int $leeway When checking nbf (Not Before) Claim, iat (Issued At) Claim or expiration times, we want to provide some extra leeway time to account for clock skew. * @param int $leeway When checking nbf (Not Before) Claim, iat (Issued At) Claim or expiration times, we want to provide some extra leeway time to account for clock skew.
*/ */
public static function decode(string $jwt, $key, ?int $timestamp = null, int $leeway = 0) : object public static function decode(string $jwt, string|array $key, ?int $timestamp = null, int $leeway = 0): object
{ {
$timestamp = $timestamp ?: \time(); $timestamp = $timestamp ?: \time();
@ -101,7 +101,7 @@ abstract class JWT
* *
* @return string A signed JWT * @return string A signed JWT
*/ */
public static function encode($payload, string $key, string $alg = 'HS256', $keyId = null, array $header = array()) : string public static function encode(object|array $payload, string $key, string $alg = 'HS256', mixed $keyId = null, array $header = array()): string
{ {
$header = \array_merge($header, array('typ' => 'JWT', 'alg' => $alg)); $header = \array_merge($header, array('typ' => 'JWT', 'alg' => $alg));
if ($keyId) { if ($keyId) {
@ -125,7 +125,10 @@ abstract class JWT
* *
* @return string An encrypted message * @return string An encrypted message
*/ */
public static function sign(string $msg, $key, string $alg = 'HS256', string $passphrase = '') : string public static function sign(string $msg, $key, string $alg = 'HS256',
#[\SensitiveParameter]
string $passphrase = ''
): string
{ {
switch ($alg) switch ($alg)
{ {
@ -173,7 +176,7 @@ abstract class JWT
* *
* @return bool * @return bool
*/ */
private static function verify(string $msg, string $signature, $key, string $alg) : bool private static function verify(string $msg, string $signature, $key, string $alg): bool
{ {
switch ($alg) switch ($alg)
{ {

View file

@ -176,7 +176,7 @@ abstract class Keyservers
* Sends a PGP public key to a public keyserver. * Sends a PGP public key to a public keyserver.
* *
* @param string $host * @param string $host
* @param mixed $key The PGP public key. * @param string $key The PGP public key.
* *
* @throws Exception * @throws Exception
*/ */

View file

@ -54,7 +54,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
$this->GnuPG->clearsignkeys(); $this->GnuPG->clearsignkeys();
} }
public static function isSupported() : bool public static function isSupported(): bool
{ {
// Disabled due to failures with "no passphrase" while a passphrase does exist // Disabled due to failures with "no passphrase" while a passphrase does exist
return false && \class_exists('gnupg') && \version_compare(\phpversion('gnupg'), '1.5', '>='); return false && \class_exists('gnupg') && \version_compare(\phpversion('gnupg'), '1.5', '>=');
@ -68,7 +68,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
} }
} }
public function getGPG(bool $throw = true) : ?GPG public function getGPG(bool $throw = true): ?GPG
{ {
if (!$this->GPG) { if (!$this->GPG) {
if (GPG::isSupported()) { if (GPG::isSupported()) {
@ -83,7 +83,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Add a key for decryption * Add a key for decryption
*/ */
public function addDecryptKey(string $fingerprint, SensitiveString $passphrase) : bool public function addDecryptKey(string $fingerprint, SensitiveString $passphrase): bool
{ {
// \SnappyMail\Log::debug('GnuPG', "addDecryptKey({$fingerprint}, {$passphrase})"); // \SnappyMail\Log::debug('GnuPG', "addDecryptKey({$fingerprint}, {$passphrase})");
return $this->GnuPG->adddecryptkey($fingerprint, \strval($passphrase)) || $this->gnupgError(); return $this->GnuPG->adddecryptkey($fingerprint, \strval($passphrase)) || $this->gnupgError();
@ -92,7 +92,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Add a key for encryption * Add a key for encryption
*/ */
public function addEncryptKey(string $fingerprint) : bool public function addEncryptKey(string $fingerprint): bool
{ {
return $this->GnuPG->addencryptkey($fingerprint) || $this->gnupgError(); return $this->GnuPG->addencryptkey($fingerprint) || $this->gnupgError();
} }
@ -100,7 +100,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Add a key for signing * Add a key for signing
*/ */
public function addSignKey(string $fingerprint, SensitiveString $passphrase) : bool public function addSignKey(string $fingerprint, SensitiveString $passphrase): bool
{ {
// \SnappyMail\Log::debug('GnuPG', "addSignKey({$fingerprint}, {$passphrase})"); // \SnappyMail\Log::debug('GnuPG', "addSignKey({$fingerprint}, {$passphrase})");
return $this->GnuPG->addsignkey($fingerprint, \strval($passphrase)) || $this->gnupgError(); return $this->GnuPG->addsignkey($fingerprint, \strval($passphrase)) || $this->gnupgError();
@ -109,7 +109,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Removes all keys which were set for decryption before * Removes all keys which were set for decryption before
*/ */
public function clearDecryptKeys() : bool public function clearDecryptKeys(): bool
{ {
return $this->GnuPG->cleardecryptkeys(); return $this->GnuPG->cleardecryptkeys();
} }
@ -117,7 +117,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Removes all keys which were set for encryption before * Removes all keys which were set for encryption before
*/ */
public function clearEncryptKeys() : bool public function clearEncryptKeys(): bool
{ {
return $this->GnuPG->clearencryptkeys(); return $this->GnuPG->clearencryptkeys();
} }
@ -125,7 +125,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Removes all keys which were set for signing before * Removes all keys which were set for signing before
*/ */
public function clearSignKeys() : bool public function clearSignKeys(): bool
{ {
return $this->GnuPG->clearsignkeys(); return $this->GnuPG->clearsignkeys();
} }
@ -133,7 +133,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given text * Decrypts a given text
*/ */
public function decrypt(string $text) /*: string|false */ public function decrypt(string $text): string|false
{ {
$result = $this->GnuPG->decrypt($text); $result = $this->GnuPG->decrypt($text);
(false === $result) && $this->gnupgError(); (false === $result) && $this->gnupgError();
@ -143,7 +143,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given file * Decrypts a given file
*/ */
public function decryptFile(string $filename) /*: string|false */ public function decryptFile(string $filename): string|false
{ {
$result = $this->GnuPG->decrypt(\file_get_contents($filename)); $result = $this->GnuPG->decrypt(\file_get_contents($filename));
(false === $result) && $this->gnupgError(); (false === $result) && $this->gnupgError();
@ -153,7 +153,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts a given resource * Decrypts a given resource
*/ */
public function decryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false */ public function decryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');
@ -167,7 +167,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts and verifies a given text * Decrypts and verifies a given text
*/ */
public function decryptVerify(string $text, string &$plaintext) /*: array|false*/ public function decryptVerify(string $text, string &$plaintext): array|false
{ {
$result = $this->GnuPG->decryptverify($text, $plaintext); $result = $this->GnuPG->decryptverify($text, $plaintext);
(false === $result) && $this->gnupgError(); (false === $result) && $this->gnupgError();
@ -177,14 +177,14 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Decrypts and verifies a given file * Decrypts and verifies a given file
*/ */
public function decryptVerifyFile(string $filename, string &$plaintext) /*: array|false*/ public function decryptVerifyFile(string $filename, string &$plaintext): array|false
{ {
$result = $this->GnuPG->decryptverify(\file_get_contents($filename), $plaintext); $result = $this->GnuPG->decryptverify(\file_get_contents($filename), $plaintext);
(false === $result) && $this->gnupgError(); (false === $result) && $this->gnupgError();
return $result; return $result;
} }
public function deleteKey(string $keyId, bool $private) : bool public function deleteKey(string $keyId, bool $private): bool
{ {
return $this->getGPG()->deleteKey($keyId, $private); return $this->getGPG()->deleteKey($keyId, $private);
} }
@ -192,7 +192,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encrypt(string $plaintext) /*: string|false*/ public function encrypt(string $plaintext): string|false
{ {
return $this->GnuPG->encrypt($plaintext) ?: $this->gnupgError(); return $this->GnuPG->encrypt($plaintext) ?: $this->gnupgError();
} }
@ -200,12 +200,12 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Encrypts a given text * Encrypts a given text
*/ */
public function encryptFile(string $filename) /*: string|false*/ public function encryptFile(string $filename): string|false
{ {
return $this->GnuPG->encrypt(\file_get_contents($filename)) ?: $this->gnupgError(); return $this->GnuPG->encrypt(\file_get_contents($filename)) ?: $this->gnupgError();
} }
public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false*/ public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false
{ {
\rewind($fp); \rewind($fp);
return $this->GnuPG->encrypt(\stream_get_contents($fp)) ?: $this->gnupgError(); return $this->GnuPG->encrypt(\stream_get_contents($fp)) ?: $this->gnupgError();
@ -214,7 +214,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Exports a key * Exports a key
*/ */
public function export(string $fingerprint, ?SensitiveString $passphrase = null) /*: string|false*/ public function export(string $fingerprint, ?SensitiveString $passphrase = null): string|false
{ {
if (null !== $passphrase) { if (null !== $passphrase) {
return $this->getGPG()->export($fingerprint, $passphrase); return $this->getGPG()->export($fingerprint, $passphrase);
@ -225,7 +225,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the engine info * Returns the engine info
*/ */
public function getEngineInfo() : array public function getEngineInfo(): array
{ {
return $this->GnuPG->getengineinfo(); return $this->GnuPG->getengineinfo();
} }
@ -233,7 +233,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the errortext, if a function fails * Returns the errortext, if a function fails
*/ */
public function getError() /*: string|false*/ public function getError(): string|false
{ {
return $this->GnuPG->geterror(); return $this->GnuPG->geterror();
} }
@ -241,7 +241,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the error info * Returns the error info
*/ */
public function getErrorInfo() : array public function getErrorInfo(): array
{ {
return $this->GnuPG->geterrorinfo(); return $this->GnuPG->geterrorinfo();
} }
@ -249,7 +249,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns the currently active protocol for all operations * Returns the currently active protocol for all operations
*/ */
public function getProtocol() : int public function getProtocol(): int
{ {
return $this->GnuPG->getprotocol(); return $this->GnuPG->getprotocol();
} }
@ -257,7 +257,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Generates a key * Generates a key
*/ */
public function generateKey(string $uid, SensitiveString $passphrase) /*: string|false*/ public function generateKey(string $uid, SensitiveString $passphrase): string|false
{ {
$GPG = $this->getGPG(false); $GPG = $this->getGPG(false);
return $GPG ? $GPG->generateKey($uid, $passphrase) : false; return $GPG ? $GPG->generateKey($uid, $passphrase) : false;
@ -266,7 +266,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Imports a key * Imports a key
*/ */
public function import(string $keydata) /*: array|false*/ public function import(string $keydata): array|false
{ {
return $this->GnuPG->import($keydata); return $this->GnuPG->import($keydata);
} }
@ -274,12 +274,12 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Imports a key * Imports a key
*/ */
public function importFile(string $filename) /*: array|false*/ public function importFile(string $filename): array|false
{ {
return $this->GnuPG->import(\file_get_contents($filename)) ?: $this->gnupgError(); return $this->GnuPG->import(\file_get_contents($filename)) ?: $this->gnupgError();
} }
public function keyInfo(string $pattern, bool $private = false) : array public function keyInfo(string $pattern, bool $private = false): array
{ {
return $this->GnuPG->keyinfo($pattern, $private ? 1 : 0); return $this->GnuPG->keyinfo($pattern, $private ? 1 : 0);
} }
@ -287,7 +287,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Returns an array with information about all keys that matches the given pattern * Returns an array with information about all keys that matches the given pattern
*/ */
public function allKeysInfo(string $pattern) : array public function allKeysInfo(string $pattern): array
{ {
$keys = [ $keys = [
'public' => [], 'public' => [],
@ -312,7 +312,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
* Toggle armored output * Toggle armored output
* When true the output is ASCII * When true the output is ASCII
*/ */
public function setArmor(bool $armor = true) : bool public function setArmor(bool $armor = true): bool
{ {
return $this->GnuPG->setarmor($armor ? 1 : 0); return $this->GnuPG->setarmor($armor ? 1 : 0);
} }
@ -322,7 +322,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
* GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT. * GNUPG_ERROR_WARNING, GNUPG_ERROR_EXCEPTION and GNUPG_ERROR_SILENT.
* By default GNUPG_ERROR_SILENT is used. * By default GNUPG_ERROR_SILENT is used.
*/ */
public function setErrorMode(int $errormode) : void public function setErrorMode(int $errormode): void
{ {
$this->GnuPG->seterrormode($errormode); $this->GnuPG->seterrormode($errormode);
} }
@ -332,7 +332,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
* GNUPG_SIG_MODE_NORMAL, GNUPG_SIG_MODE_DETACH and GNUPG_SIG_MODE_CLEAR. * GNUPG_SIG_MODE_NORMAL, GNUPG_SIG_MODE_DETACH and GNUPG_SIG_MODE_CLEAR.
* By default GNUPG_SIG_MODE_CLEAR * By default GNUPG_SIG_MODE_CLEAR
*/ */
public function setSignMode(int $signmode) : bool public function setSignMode(int $signmode): bool
{ {
return $this->GnuPG->setsignmode($signmode); return $this->GnuPG->setsignmode($signmode);
} }
@ -340,7 +340,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given text * Signs a given text
*/ */
public function sign(string $plaintext) /*: string|false*/ public function sign(string $plaintext): string|false
{ {
return $this->GnuPG->sign($plaintext) ?: $this->gnupgError(); return $this->GnuPG->sign($plaintext) ?: $this->gnupgError();
} }
@ -348,7 +348,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given file * Signs a given file
*/ */
public function signFile(string $filename) /*: string|false*/ public function signFile(string $filename): string|false
{ {
return $this->GnuPG->sign(\file_get_contents($filename)) ?: $this->gnupgError(); return $this->GnuPG->sign(\file_get_contents($filename)) ?: $this->gnupgError();
} }
@ -356,7 +356,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Signs a given file * Signs a given file
*/ */
public function signStream($fp, /*string|resource*/ $output = null) /*: string|false*/ public function signStream($fp, /*string|resource*/ $output = null): string|false
{ {
\rewind($fp); \rewind($fp);
return $this->GnuPG->sign(\stream_get_contents($fp)) ?: $this->gnupgError(); return $this->GnuPG->sign(\stream_get_contents($fp)) ?: $this->gnupgError();
@ -365,7 +365,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a signed text * Verifies a signed text
*/ */
public function verify(string $signed_text, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verify(string $signed_text, string $signature, ?string &$plaintext = null): array|false
{ {
$result = $this->GnuPG->verify($signed_text, $signature ?: false, $plaintext) ?: $this->gnupgError(); $result = $this->GnuPG->verify($signed_text, $signature ?: false, $plaintext) ?: $this->gnupgError();
if (!$result) { if (!$result) {
@ -378,7 +378,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a signed file * Verifies a signed file
*/ */
public function verifyFile(string $filename, string $signature, ?string &$plaintext = null) /*: array|false*/ public function verifyFile(string $filename, string $signature, ?string &$plaintext = null): array|false
{ {
return $this->GnuPG->verify(\file_get_contents($filename), $signature, $plaintext) ?: $this->gnupgError(); return $this->GnuPG->verify(\file_get_contents($filename), $signature, $plaintext) ?: $this->gnupgError();
} }
@ -386,7 +386,7 @@ class PECL implements \SnappyMail\PGP\PGPInterface
/** /**
* Verifies a given resource * Verifies a given resource
*/ */
public function verifyStream(/*resource*/ $fp, string $signature, ?string &$plaintext = null) /*: array|false */ public function verifyStream(/*resource*/ $fp, string $signature, ?string &$plaintext = null): array|false
{ {
if (!$fp || !\is_resource($fp)) { if (!$fp || !\is_resource($fp)) {
throw new \Exception('Invalid stream resource'); throw new \Exception('Invalid stream resource');

View file

@ -6,40 +6,40 @@ use SnappyMail\SensitiveString;
interface PGPInterface interface PGPInterface
{ {
public static function isSupported() : bool; public static function isSupported(): bool;
// public function addPinentry(string $keyId, SensitiveString $passphrase); // public function addPinentry(string $keyId, SensitiveString $passphrase);
// public function clearPinentries() : bool // public function clearPinentries(): bool
public function addDecryptKey(string $fingerprint, SensitiveString $passphrase) : bool; public function addDecryptKey(string $fingerprint, SensitiveString $passphrase): bool;
public function addEncryptKey(string $fingerprint) : bool; public function addEncryptKey(string $fingerprint): bool;
public function addSignKey(string $fingerprint, SensitiveString $passphrase) : bool; public function addSignKey(string $fingerprint, SensitiveString $passphrase): bool;
public function clearDecryptKeys() : bool; public function clearDecryptKeys(): bool;
public function clearEncryptKeys() : bool; public function clearEncryptKeys(): bool;
public function clearSignKeys() : bool; public function clearSignKeys(): bool;
public function decrypt(string $text) /*: string|false */; public function decrypt(string $text): string|false;
public function decryptFile(string $filename) /*: string|false */; public function decryptFile(string $filename): string|false;
public function decryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false */; public function decryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false;
public function decryptVerify(string $text, string &$plaintext) /*: array|false*/; public function decryptVerify(string $text, string &$plaintext): array|false;
public function decryptVerifyFile(string $filename, string &$plaintext) /*: array|false*/; public function decryptVerifyFile(string $filename, string &$plaintext): array|false;
public function deleteKey(string $keyId, bool $private) : bool; public function deleteKey(string $keyId, bool $private): bool;
public function encrypt(string $plaintext) /*: string|false*/; public function encrypt(string $plaintext): string|false;
public function encryptFile(string $filename) /*: string|false*/; public function encryptFile(string $filename): string|false;
public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null) /*: string|false*/; public function encryptStream(/*resource*/ $fp, /*string|resource*/ $output = null): string|false;
public function export(string $fingerprint, ?SensitiveString $passphrase = null) /*: string|false*/; public function export(string $fingerprint, ?SensitiveString $passphrase = null): string|false;
public function getEngineInfo() : array; public function getEngineInfo(): array;
public function getError() /*: string|false*/; public function getError(): string|false;
public function getErrorInfo() : array; public function getErrorInfo(): array;
public function getProtocol() : int; public function getProtocol(): int;
public function generateKey(string $uid, SensitiveString $passphrase) /*: string|false*/; public function generateKey(string $uid, SensitiveString $passphrase): string|false;
public function import(string $keydata) /*: array|false*/; public function import(string $keydata): array|false;
public function importFile(string $filename) /*: array|false*/; public function importFile(string $filename): array|false;
public function allKeysInfo(string $pattern) : array; public function allKeysInfo(string $pattern): array;
public function setArmor(bool $armor = true) : bool; public function setArmor(bool $armor = true): bool;
public function setErrorMode(int $errormode) : void; public function setErrorMode(int $errormode): void;
public function setSignMode(int $signmode) : bool; public function setSignMode(int $signmode): bool;
public function sign(string $plaintext) /*: string|false*/; public function sign(string $plaintext): string|false;
public function signFile(string $filename) /*: string|false*/; public function signFile(string $filename): string|false;
public function signStream($fp, /*string|resource*/ $output = null) /*: string|false*/; public function signStream($fp, /*string|resource*/ $output = null): string|false;
public function verify(string $signed_text, string $signature, ?string &$plaintext = null) /*: array|false*/; public function verify(string $signed_text, string $signature, ?string &$plaintext = null): array|false;
public function verifyFile(string $filename, string $signature, ?string &$plaintext = null) /*: array|false*/; public function verifyFile(string $filename, string $signature, ?string &$plaintext = null): array|false;
public function verifyStream(/*resource*/ $fp, string $signature, ?string &$plaintext = null) /*: array|false */; public function verifyStream(/*resource*/ $fp, string $signature, ?string &$plaintext = null): array|false;
} }

View file

@ -61,8 +61,7 @@ class SensitiveString /* extends SensitiveParameterValue | SensitiveParameter */
return $this->getValue(); return $this->getValue();
} }
#[\ReturnTypeWillChange] public function jsonSerialize(): mixed
public function jsonSerialize()
{ {
throw new \Exception("JSON serialization of 'SnappyMail\\SensitiveString' is not allowed"); throw new \Exception("JSON serialization of 'SnappyMail\\SensitiveString' is not allowed");
} }

View file

@ -57,7 +57,7 @@ class Certificate
/** /**
* Verifies if a certificate can be used for a particular purpose * Verifies if a certificate can be used for a particular purpose
*/ */
public function checkPurpose(int $purpose, array $cainfo = array(), ?string $untrustedfile = null)/*: bool|int*/ public function checkPurpose(int $purpose, array $cainfo = array(), ?string $untrustedfile = null): bool|int
{ {
if ($this->x509) { if ($this->x509) {
return \openssl_x509_checkpurpose($this->x509, $purpose, $cainfo, $untrustedfile); return \openssl_x509_checkpurpose($this->x509, $purpose, $cainfo, $untrustedfile);
@ -65,14 +65,14 @@ class Certificate
return false; return false;
} }
public function canSign() : bool public function canSign(): bool
{ {
return $this->x509 return $this->x509
? true === \openssl_x509_checkpurpose($this->x509, \X509_PURPOSE_SMIME_SIGN) ? true === \openssl_x509_checkpurpose($this->x509, \X509_PURPOSE_SMIME_SIGN)
: false; : false;
} }
public function canEncrypt() : bool public function canEncrypt(): bool
{ {
return $this->x509 return $this->x509
? true === \openssl_x509_checkpurpose($this->x509, \X509_PURPOSE_SMIME_ENCRYPT) ? true === \openssl_x509_checkpurpose($this->x509, \X509_PURPOSE_SMIME_ENCRYPT)
@ -82,7 +82,7 @@ class Certificate
/** /**
* Returns the certificate in a PEM encoded format string * Returns the certificate in a PEM encoded format string
*/ */
public function export(bool $notext = true) : ?string public function export(bool $notext = true): ?string
{ {
if ($this->x509) { if ($this->x509) {
$output = ''; $output = '';
@ -96,7 +96,7 @@ class Certificate
/** /**
* Returns the fingerprint or digest of the certificate * Returns the fingerprint or digest of the certificate
*/ */
public function fingerprint(string $hash_algorithm = 'sha1', bool $raw_output = false)/*: string|bool*/ public function fingerprint(string $hash_algorithm = 'sha1', bool $raw_output = false): string|bool
{ {
return $this->x509 ? \openssl_x509_fingerprint($this->x509, $hash_algorithm, $raw_output) : false; return $this->x509 ? \openssl_x509_fingerprint($this->x509, $hash_algorithm, $raw_output) : false;
} }
@ -104,17 +104,17 @@ class Certificate
/** /**
* Returns the certificate information as an array * Returns the certificate information as an array
*/ */
public function info(bool $shortnames = true) /*: array|bool*/ public function info(bool $shortnames = true): array|bool
{ {
return $this->x509 ? \openssl_x509_parse($this->x509, $shortnames) : false; return $this->x509 ? \openssl_x509_parse($this->x509, $shortnames) : false;
} }
public static function getCipherMethods(bool $aliases = false) : array public static function getCipherMethods(bool $aliases = false): array
{ {
return \openssl_get_cipher_methods($aliases); return \openssl_get_cipher_methods($aliases);
} }
public function createSelfSigned(\SnappyMail\SensitiveString $passphrase, ?string $privateKey = null) : array public function createSelfSigned(\SnappyMail\SensitiveString $passphrase, ?string $privateKey = null): array
{ {
$options = array( $options = array(
'config' => __DIR__ . '/openssl.cnf', 'config' => __DIR__ . '/openssl.cnf',
@ -177,7 +177,7 @@ class Certificate
#[\SensitiveParameter] #[\SensitiveParameter]
string $pass = '', string $pass = '',
array $args = array() array $args = array()
) : string ): string
{ {
$out = ''; $out = '';
\openssl_pkcs12_export($this->x509, $out, $this->pkey, $pass, $args); \openssl_pkcs12_export($this->x509, $out, $this->pkey, $pass, $args);

View file

@ -26,12 +26,12 @@ class OpenSSL
$this->homedir = $homedir; $this->homedir = $homedir;
} }
public function getCertificate(string $filename)/* : string*/ public function getCertificate(string $filename): string|false
{ {
return \file_get_contents("{$this->homedir}/{$filename}"); return \file_get_contents("{$this->homedir}/{$filename}");
} }
public function storeCertificate(string $certificate) : bool public function storeCertificate(string $certificate): bool
{ {
$data = \openssl_x509_parse(\openssl_x509_read($certificate)); $data = \openssl_x509_parse(\openssl_x509_read($certificate));
if (!$data) { if (!$data) {
@ -51,7 +51,7 @@ class OpenSSL
return true; return true;
} }
public function certificates(bool $force = false) : array public function certificates(bool $force = false): array
{ {
$cacheFile = "{$this->homedir}/certificates.json"; $cacheFile = "{$this->homedir}/certificates.json";
$result = (!$force && \file_exists($cacheFile)) $result = (!$force && \file_exists($cacheFile))
@ -111,17 +111,17 @@ class OpenSSL
return $result; return $result;
} }
public function privateKeys() : array public function privateKeys(): array
{ {
// \glob("{$this->homedir}/*.key"); // \glob("{$this->homedir}/*.key");
} }
public static function isSupported() : bool public static function isSupported(): bool
{ {
return \defined('PKCS7_DETACHED'); return \defined('PKCS7_DETACHED');
} }
public function setCertificate(/*OpenSSLCertificate|string*/$certificate) public function setCertificate(OpenSSLCertificate|string $certificate): void
{ {
$this->certificate = \openssl_x509_read($certificate); $this->certificate = \openssl_x509_read($certificate);
if (!$this->certificate) { if (!$this->certificate) {
@ -132,7 +132,7 @@ class OpenSSL
} }
} }
public function setCertificateChain(/*string*/$certificateChain) public function setCertificateChain(?string $certificateChain): void
{ {
if ($certificateChain === "") { if ($certificateChain === "") {
$this->certificateChain = null; $this->certificateChain = null;
@ -141,9 +141,9 @@ class OpenSSL
} }
} }
public function setPrivateKey(/*OpenSSLAsymmetricKey|string*/$privateKey, public function setPrivateKey(OpenSSLAsymmetricKey|string $privateKey,
?\SnappyMail\SensitiveString $passphrase = null ?\SnappyMail\SensitiveString $passphrase = null
) : void ): void
{ {
$this->privateKey = \openssl_pkey_get_private($privateKey, $passphrase); $this->privateKey = \openssl_pkey_get_private($privateKey, $passphrase);
if (!$this->privateKey) { if (!$this->privateKey) {
@ -171,7 +171,7 @@ class OpenSSL
} }
/* /*
public function asn1parse(/*string|Temporary* / $input) : ?string public function asn1parse(string|Temporary $input): ?string
{ {
if (\is_string($input)) { if (\is_string($input)) {
$tmp = new Temporary('smimein-'); $tmp = new Temporary('smimein-');
@ -183,7 +183,7 @@ class OpenSSL
\shell_exec('openssl asn1parse -in $input->filename()'); \shell_exec('openssl asn1parse -in $input->filename()');
} }
*/ */
public function decrypt(/*string|Temporary*/ $input) : ?string public function decrypt(string|Temporary $input): ?string
{ {
if (\is_string($input)) { if (\is_string($input)) {
$tmp = new Temporary('smimein-'); $tmp = new Temporary('smimein-');
@ -204,7 +204,7 @@ class OpenSSL
return $output->getContents(); return $output->getContents();
} }
public function encrypt(/*string|Temporary*/$input, array $certificates) : ?string public function encrypt(string|Temporary $input, array $certificates): ?string
{ {
if (\is_string($input)) { if (\is_string($input)) {
$tmp = new Temporary('smimein-'); $tmp = new Temporary('smimein-');
@ -245,7 +245,7 @@ class OpenSSL
return $data; return $data;
} }
public function sign(/*string|Temporary*/$input, bool $detached = true) public function sign(string|Temporary $input, bool $detached = true): ?string
{ {
if (\is_string($input)) { if (\is_string($input)) {
$tmp = new Temporary('smimein-'); $tmp = new Temporary('smimein-');
@ -314,7 +314,7 @@ class OpenSSL
/** /**
* $opaque = true, when the message is not detached * $opaque = true, when the message is not detached
*/ */
public function verify(/*string|Temporary*/$input, ?string $signers_certificates_filename = null, bool $opaque = false) public function verify(string|Temporary $input, ?string $signers_certificates_filename = null, bool $opaque = false): ?array
{ {
if (\is_string($input)) { if (\is_string($input)) {
$tmp = new Temporary('smimein-'); $tmp = new Temporary('smimein-');

View file

@ -39,7 +39,7 @@ class TAR
$this->close(); $this->close();
} }
public function pushHttpHeaders(string $name) : void public function pushHttpHeaders(string $name): void
{ {
if ($i = \ob_get_level()) { if ($i = \ob_get_level()) {
# Clear buffers: # Clear buffers:
@ -61,7 +61,7 @@ class TAR
\MailSo\Base\Http::setContentDisposition('attachment', ['filename' => $name]); \MailSo\Base\Http::setContentDisposition('attachment', ['filename' => $name]);
} }
public function close() : void public function close(): void
{ {
if ($this->out) { if ($this->out) {
if ($this->started) { if ($this->started) {
@ -81,7 +81,7 @@ class TAR
} }
} }
public function addFile($fileinfo, ?string $name = null) : bool public function addFile($fileinfo, ?string $name = null): bool
{ {
if (!($fileinfo instanceof \SplFileInfo)) { if (!($fileinfo instanceof \SplFileInfo)) {
$fileinfo = new \SplFileInfo($fileinfo); $fileinfo = new \SplFileInfo($fileinfo);
@ -113,7 +113,7 @@ class TAR
return true; return true;
} }
public function addFromStream($resource, string $name, int $time = 0) : bool public function addFromStream($resource, string $name, int $time = 0): bool
{ {
if (\is_resource($resource)) { if (\is_resource($resource)) {
$temp = new TarTempResource(); $temp = new TarTempResource();
@ -155,7 +155,7 @@ class TAR
return true; return true;
} }
public function addFromString(string $name, string $data, int $time = 0) : bool public function addFromString(string $name, string $data, int $time = 0): bool
{ {
$this->writeEntryHeader( $this->writeEntryHeader(
\strtr($name, '\\', '/'), \strtr($name, '\\', '/'),
@ -174,7 +174,7 @@ class TAR
return true; return true;
} }
public function addDir(string $dirname, ?\SplFileInfo $fileinfo = null) : void public function addDir(string $dirname, ?\SplFileInfo $fileinfo = null): void
{ {
$this->writeEntryHeader( $this->writeEntryHeader(
\rtrim(\strtr($dirname, '\\', '/'), '/') . '/', \rtrim(\strtr($dirname, '\\', '/'), '/') . '/',
@ -187,7 +187,7 @@ class TAR
); );
} }
public function addRecursive(string $dir, string $target_dir = '', $ignore = '#/(\\.hg(/|$)|\\.hgignore)#') : void public function addRecursive(string $dir, string $target_dir = '', $ignore = '#/(\\.hg(/|$)|\\.hgignore)#'): void
{ {
if (!$this->out) { if (!$this->out) {
throw new \Exception('Stream closed'); throw new \Exception('Stream closed');
@ -217,7 +217,7 @@ class TAR
} }
} }
protected function start() protected function start(): void
{ {
if ($this->started) { if ($this->started) {
return; return;
@ -239,7 +239,7 @@ class TAR
} }
} }
protected function write($string)/* : int|bool*/ protected function write(string $string): int|bool
{ {
if (!$this->out) { if (!$this->out) {
throw new \Exception('Stream closed'); throw new \Exception('Stream closed');
@ -265,7 +265,7 @@ class TAR
return $written; return $written;
} }
protected function writeEntryHeader($name, $type, $size, $uid = 0, $gid = 0, $perm = 0, $mtime = 0, $link = '', $prefix = '') protected function writeEntryHeader($name, $type, $size, $uid = 0, $gid = 0, $perm = 0, $mtime = 0, $link = '', $prefix = ''): void
{ {
// handle long filename length // handle long filename length
$paxdata = $paxname = ''; $paxdata = $paxname = '';
@ -331,7 +331,7 @@ class TAR
} }
// Writes Pre-POSIX.1-1988 (i.e. v7) and POSIX UStar headers // Writes Pre-POSIX.1-1988 (i.e. v7) and POSIX UStar headers
protected function writeUStarEntryHeader($name, $type, $size, $uid = 0, $gid = 0, $perm = 0, $mtime = 0, $link = '', $prefix = '') protected function writeUStarEntryHeader($name, $type, $size, $uid = 0, $gid = 0, $perm = 0, $mtime = 0, $link = '', $prefix = ''): void
{ {
$data = \pack('a100a8a8a8a12A12', $data = \pack('a100a8a8a8a12A12',
$name, $name,
@ -362,10 +362,7 @@ class TAR
class TarTempResource extends \SplTempFileObject class TarTempResource extends \SplTempFileObject
{ {
#[\ReturnTypeWillChange] public function getOwner(): int|false { return 0; }
public function getOwner()/*: int|false*/ { return 0; } public function getGroup(): int|false { return 0; }
#[\ReturnTypeWillChange] public function getPerms(): int|false { return 420; }
public function getGroup()/*: int|false*/ { return 0; }
#[\ReturnTypeWillChange]
public function getPerms()/*: int|false*/ { return 420; }
} }