From 6c3ae90980d50bd71e212a9aabe39591f75d9320 Mon Sep 17 00:00:00 2001 From: czPechy Date: Fri, 3 Jan 2020 12:15:04 +0100 Subject: [PATCH 1/7] Typo --- src/Selection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Selection.php b/src/Selection.php index 4c76056..0c3b4ef 100644 --- a/src/Selection.php +++ b/src/Selection.php @@ -104,7 +104,7 @@ public function countMails(): int */ public function fetchAll(): array { - if ($this->mails !== NULL) { + if ($this->mails === NULL) { $this->fetchMails(); } return $this->mails; From e91cae8edaacee1a02a92dc5dc5fd6784de99ee6 Mon Sep 17 00:00:00 2001 From: Martin Pecha Date: Fri, 3 Jan 2020 12:56:33 +0100 Subject: [PATCH 2/7] fix contact creation & change getHeaders for getHeader: string --- src/Contact.php | 4 ++-- src/Drivers/ImapDriver.php | 8 ++++---- src/Mail.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Contact.php b/src/Contact.php index 4bfd9f8..0171489 100644 --- a/src/Contact.php +++ b/src/Contact.php @@ -38,12 +38,12 @@ public function getEmail(): string return $this->mailbox . '@' . $this->host; } - public function getName(): string + public function getName(): ?string { return $this->personal; } - public function getAdl(): string + public function getAdl(): ?string { return $this->adl; } diff --git a/src/Drivers/ImapDriver.php b/src/Drivers/ImapDriver.php index 083c0c0..76f5271 100644 --- a/src/Drivers/ImapDriver.php +++ b/src/Drivers/ImapDriver.php @@ -197,10 +197,10 @@ public function getHeaders(int $mailId): array $list = new ContactList; foreach ($contacts as $contact) { $list->addContact( - isset($contact->mailbox) ? $contact->mailbox : NULL, - isset($contact->host) ? $contact->host : NULL, - isset($contact->personal) ? $contact->personal : NULL, - isset($contact->adl) ? $contact->adl : NULL + $contact->mailbox ?? NULL, + $contact->host ?? NULL, + $contact->personal ?? NULL, + $contact->adl ?? NULL ); } $list->build(); diff --git a/src/Mail.php b/src/Mail.php index 8cf5600..6ea8fda 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -103,9 +103,9 @@ public function getHeader(string $name): string public function getSender(): ?Contact { - $from = $this->getHeader('from'); - if ($from) { - $contacts = $from->getContactsObjects(); + $headers = $this->getHeaders(); + if ($headers['from']) { + $contacts = $headers['from']->getContactsObjects(); return (count($contacts) ? $contacts[0] : NULL); } else { return NULL; From 9cafb9bbe42a64f299a67ebd16d024ef55629c50 Mon Sep 17 00:00:00 2001 From: Martin Pecha Date: Fri, 3 Jan 2020 13:03:21 +0100 Subject: [PATCH 3/7] add nullable return type if header nto exist --- src/Mail.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mail.php b/src/Mail.php index 6ea8fda..41e104e 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -95,7 +95,7 @@ public function getHeaders(): array return $this->headers; } - public function getHeader(string $name): string + public function getHeader(string $name): ?string { $this->headers !== NULL || $this->initializeHeaders(); return $this->headers[$this->formatHeaderName($name)]; From d8a0b9a998d1a3b40156d975c1422ba6a12b9da0 Mon Sep 17 00:00:00 2001 From: Martin Pecha Date: Fri, 3 Jan 2020 13:13:52 +0100 Subject: [PATCH 4/7] fix getIterator() if mails not fetched yet --- src/Selection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Selection.php b/src/Selection.php index 0c3b4ef..cfb1af3 100644 --- a/src/Selection.php +++ b/src/Selection.php @@ -127,7 +127,7 @@ public function count(): int public function getIterator(): ArrayIterator { - return new ArrayIterator($this->mails); + return new ArrayIterator($this->fetchAll()); } } From 59ab19982885b7a71dcd33aeb057853830b25ce7 Mon Sep 17 00:00:00 2001 From: "martin.pecha" Date: Thu, 1 May 2025 14:12:01 +0200 Subject: [PATCH 5/7] hotfixes for 8.0 --- composer.json | 6 ++-- src/Drivers/ImapDriver.php | 2 +- src/Extensions/MailLibraryExtension.php | 41 ------------------------- src/Selection.php | 23 +++++++++++++- src/loader.php | 4 --- tests/MailLibrary/Driver.filters.phpt | 2 +- 6 files changed, 28 insertions(+), 50 deletions(-) delete mode 100644 src/Extensions/MailLibraryExtension.php diff --git a/composer.json b/composer.json index b9ec1f6..af00dd1 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,10 @@ ] }, "require": { - "php": ">= 7.1.0" - }, + "php": ">= 8.0.0", + "ext-mbstring": "*", + "ext-imap": "*" + }, "require-dev": { "nette/tester": "@dev" } diff --git a/src/Drivers/ImapDriver.php b/src/Drivers/ImapDriver.php index 76f5271..24b28f1 100644 --- a/src/Drivers/ImapDriver.php +++ b/src/Drivers/ImapDriver.php @@ -162,7 +162,7 @@ public function getHeaders(int $mailId): array $headers = []; $lastHeader = NULL; foreach ($lines as $line) { - if (mb_strpos($line, ' ', 'UTF-8') === 0) { + if(mb_substr($line, 0, 1, 'UTF-8') === " ") { $headers[$lastHeader] .= $line; } else { $parts = explode(':', $line); diff --git a/src/Extensions/MailLibraryExtension.php b/src/Extensions/MailLibraryExtension.php deleted file mode 100644 index 5380bd1..0000000 --- a/src/Extensions/MailLibraryExtension.php +++ /dev/null @@ -1,41 +0,0 @@ -getConfig([ - 'imap' => [ - 'username' => '', - 'password' => '', - 'host' => 'localhost', - 'port' => 993, - 'ssl' => 'true', - ], - ]); - - $config = $config['imap']; - - $builder = $this->getContainerBuilder(); - - $builder->addDefinition($this->prefix('connection')) - ->setClass(Connection::class); - - $builder->addDefinition($this->prefix('imap')) - ->setClass(ImapDriver::class, [ - $config['username'], - $config['password'], - $config['host'], - $config['port'], - $config['ssl'], - ]); - } - -} diff --git a/src/Selection.php b/src/Selection.php index cfb1af3..91fd3c9 100644 --- a/src/Selection.php +++ b/src/Selection.php @@ -2,11 +2,12 @@ namespace PhpMailClient; +use ArrayAccess; use ArrayIterator; use Countable; use IteratorAggregate; -class Selection implements Countable, IteratorAggregate +class Selection implements Countable, IteratorAggregate, ArrayAccess { /** @var Connection */ @@ -130,4 +131,24 @@ public function getIterator(): ArrayIterator return new ArrayIterator($this->fetchAll()); } + public function offsetExists($offset): bool + { + return isset($this->fetchAll()[$offset]); + } + + public function offsetGet($offset) + { + return $this->fetchAll()[$offset] ?? NULL; + } + + public function offsetSet($offset, $value) + { + throw new \BadMethodCallException('Not implemented.'); + } + + public function offsetUnset($offset) + { + throw new \BadMethodCallException('Not implemented.'); + } + } diff --git a/src/loader.php b/src/loader.php index d7d442d..ad0d19b 100644 --- a/src/loader.php +++ b/src/loader.php @@ -6,7 +6,6 @@ use PhpMailClient\ContactList; use PhpMailClient\Drivers\IDriver; use PhpMailClient\Drivers\ImapDriver; -use PhpMailClient\Extensions\MailLibraryExtension; use PhpMailClient\Mail; use PhpMailClient\Mailbox; use PhpMailClient\Selection; @@ -25,8 +24,6 @@ class_alias(IStructure::class, '\greeny\MailLibrary\Structures\IStructure'); class_alias(ImapStructure::class, '\greeny\MailLibrary\Structures\ImapStructure'); class_alias(IDriver::class, '\greeny\MailLibrary\Drivers\IDriver'); class_alias(ImapDriver::class, '\greeny\MailLibrary\Drivers\ImapDriver'); -class_alias(MailLibraryExtension::class, '\greeny\MailLibrary\Extensions\MailLibraryExtension'); - spl_autoload_register(function ($type) { static $paths = [ @@ -41,7 +38,6 @@ class_alias(MailLibraryExtension::class, '\greeny\MailLibrary\Extensions\MailLib 'greeny\maillibrary\structures\imapstructure' => 'Structures/ImapStructure.php', 'greeny\maillibrary\drivers\idriver' => 'Drivers/IDriver.php', 'greeny\maillibrary\drivers\imapdriver' => 'Drivers/ImapDriver.php', - 'greeny\maillibrary\extensions\maillibraryextension' => 'Extensions/MailLibraryExtension.php', ]; $type = ltrim(strtolower($type), '\\'); // PHP namespace bug #49143 diff --git a/tests/MailLibrary/Driver.filters.phpt b/tests/MailLibrary/Driver.filters.phpt index 0c11410..7d88bc1 100644 --- a/tests/MailLibrary/Driver.filters.phpt +++ b/tests/MailLibrary/Driver.filters.phpt @@ -35,5 +35,5 @@ $exceptions = array( foreach($exceptions as $exception) { Assert::exception(function()use($driver, $exception){ $driver->checkFilter($exception->key, $exception->value); - }, '\\greeny\\MailLibrary\\DriverException', $exception->exception); + }, '\\PhpMailClient\\DriverException', $exception->exception); } From d7e664c76fc333382ddbddf37e5a2b15c9514d08 Mon Sep 17 00:00:00 2001 From: "martin.pecha" Date: Thu, 1 May 2025 14:15:33 +0200 Subject: [PATCH 6/7] update my bad --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index af00dd1..090c4c1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ] }, "require": { - "php": ">= 8.0.0", + "php": ">= 7.4", "ext-mbstring": "*", "ext-imap": "*" }, From 4458f087bab72114239e0a416634267ac3e11497 Mon Sep 17 00:00:00 2001 From: "martin.pecha" Date: Fri, 2 May 2025 00:49:11 +0200 Subject: [PATCH 7/7] fix move mail --- src/Drivers/ImapDriver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drivers/ImapDriver.php b/src/Drivers/ImapDriver.php index 24b28f1..a74a6ba 100644 --- a/src/Drivers/ImapDriver.php +++ b/src/Drivers/ImapDriver.php @@ -286,7 +286,7 @@ public function copyMail(int $mailId, string $toMailbox): void public function moveMail(int $mailId, string $toMailbox): void { - if (!imap_mail_move($this->resource, $mailId, $this->server . $this->encodeMailboxName($toMailbox), CP_UID)) { + if (!imap_mail_move($this->resource, $mailId, $this->encodeMailboxName($toMailbox), CP_UID)) { throw new DriverException(sprintf('Cannot copy mail to mailbox %s: %s', $toMailbox, imap_last_error())); } }