Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes, refactoring #564

Merged
merged 12 commits into from
May 17, 2023
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ By the way most of the common search criteria are available and functioning, bro
References:

1. https://stackoverflow.com/questions/36356715/imap-search-unknown-search-criterion-or
1. imap-2007f.tar.gz: `./src/c-client/mail.c` and `./docs/internal.txt`
2. imap-2007f.tar.gz: `./src/c-client/mail.c` and `./docs/internal.txt`

#### Message Properties and Operations

Expand All @@ -182,7 +182,7 @@ $message->isDraft();
$message->isSeen();
```

Get message headers as a [\Ddeboer\Imap\Message\Headers](/src/Ddeboer/Imap/Message/Headers.php) object:
Get message headers as a [\Ddeboer\Imap\Message\Headers](/src/Message/Headers.php) object:

```php
$message->getHeaders();
Expand Down
21 changes: 0 additions & 21 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ parameters:
count: 1
path: src/Mailbox.php

-
message: "#^Parameter \\#3 \\$reverse of function imap_sort expects bool, bool\\|int given\\.$#"
count: 1
path: src/Mailbox.php

-
message: "#^Call to function is_numeric\\(\\) with int will always evaluate to true\\.$#"
count: 1
path: src/Message.php

-
message: "#^Cannot call method getDecodedContent\\(\\) on mixed\\.$#"
count: 2
Expand Down Expand Up @@ -60,11 +50,6 @@ parameters:
count: 1
path: src/MessageIterator.php

-
message: "#^Call to function is_object\\(\\) with Ddeboer\\\\Imap\\\\MessageInterface will always evaluate to true\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Class ArrayIterator specifies template type TKey of interface Iterator as int but it's already specified as mixed\\.$#"
count: 1
Expand All @@ -75,11 +60,6 @@ parameters:
count: 1
path: src/MessageIterator.php

-
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
count: 1
path: src/MessageIterator.php

-
message: "#^Interface Iterator specifies template type TKey of interface Traversable as int but it's already specified as mixed\\.$#"
count: 2
Expand Down Expand Up @@ -164,4 +144,3 @@ parameters:
message: "#^Cannot access property \\$parts on mixed\\.$#"
count: 2
path: tests/MessageTest.php

4 changes: 0 additions & 4 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ public function getMessages(ConditionInterface $search = null, int $sortCriteria
}
$query = $search->toString();

if (\PHP_VERSION_ID < 80000) {
$descending = (int) $descending;
}

// We need to clear the stack to know whether imap_last_error()
// is related to this imap_search
\imap_errors();
Expand Down
3 changes: 1 addition & 2 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ protected function assertMessageExists(int $messageNumber): void
}
$this->messageNumberVerified = true;

$msgno = null;
\set_error_handler(static function (): bool {
return true;
});
Expand All @@ -89,7 +88,7 @@ protected function assertMessageExists(int $messageNumber): void

\restore_error_handler();

if (\is_numeric($msgno) && $msgno > 0) {
if ($msgno > 0) {
$this->imapMsgNo = $msgno;

return;
Expand Down
2 changes: 1 addition & 1 deletion src/Message/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private static function gatherAttachments(PartInterface $part): array
$attachments[] = $childPart;
}
if ($childPart->hasChildren()) {
$attachments = \array_merge($attachments, self::gatherAttachments($childPart));
$attachments = [...$attachments, ...self::gatherAttachments($childPart)];
}
}

Expand Down
13 changes: 4 additions & 9 deletions src/Message/AbstractPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private function lazyParseStructure(): void

// When the message is not multipart and the body is the attachment content
// Prevents infinite recursion
if (self::isAttachment($this->structure) && !$this instanceof Attachment) {
if (!$this instanceof Attachment && self::isAttachment($this->structure)) {
$this->parts[] = new Attachment($this->resource, $this->getNumber(), '1', $this->structure);
}

Expand All @@ -391,12 +391,11 @@ private function lazyParseStructure(): void
}
foreach ($parts as $key => $partStructure) {
$partNumber = (!$this instanceof Message) ? $this->partNumber . '.' : '';
$partNumber .= (string) ($key + 1);
$partNumber .= $key + 1;

$newPartClass = self::isAttachment($partStructure)
? Attachment::class
: SimplePart::class
;
: SimplePart::class;

$this->parts[] = new $newPartClass($this->resource, $this->getNumber(), $partNumber, $partStructure);
}
Expand Down Expand Up @@ -446,10 +445,6 @@ private static function isAttachment(\stdClass $part): bool
}
*/

if (self::SUBTYPE_RFC822 === \strtoupper($part->subtype)) {
return true;
}

return false;
return self::SUBTYPE_RFC822 === \strtoupper($part->subtype);
}
}
1 change: 0 additions & 1 deletion src/Message/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ private function parseHeader(string $key, $value)
case 'sender':
case 'return_path':
\assert(\is_array($value));
/** @var \stdClass $address */
foreach ($value as $address) {
if (isset($address->mailbox)) {
$address->host = $address->host ?? null;
Expand Down
2 changes: 1 addition & 1 deletion src/MessageIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function current(): MessageInterface
'The current value "%s" isn\'t an integer and doesn\'t represent a message;'
. ' try to cycle this "%s" with a native php function like foreach or with the method getArrayCopy(),'
. ' or check it by calling the methods valid().',
\is_object($current) ? \get_class($current) : \gettype($current),
\get_debug_type($current),
self::class
));
}
Expand Down
3 changes: 1 addition & 2 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ public function testRawHeaders(): void
{
$headers = 'From: [email protected]' . "\r\n"
. 'To: [email protected]' . "\n"
. "\r\n"
;
. "\r\n";
$originalMessage = $headers . 'Content' . "\n";

$this->mailbox->addMessage($originalMessage);
Expand Down