Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
]
},
"require": {
"php": ">= 7.1.0"
},
"php": ">= 7.4",
"ext-mbstring": "*",
"ext-imap": "*"
},
"require-dev": {
"nette/tester": "@dev"
}
Expand Down
4 changes: 2 additions & 2 deletions src/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Drivers/ImapDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()));
}
}
Expand Down
41 changes: 0 additions & 41 deletions src/Extensions/MailLibraryExtension.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ 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)];
}

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;
Expand Down
27 changes: 24 additions & 3 deletions src/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -104,7 +105,7 @@ public function countMails(): int
*/
public function fetchAll(): array
{
if ($this->mails !== NULL) {
if ($this->mails === NULL) {
$this->fetchMails();
}
return $this->mails;
Expand All @@ -127,7 +128,27 @@ public function count(): int

public function getIterator(): ArrayIterator
{
return new ArrayIterator($this->mails);
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.');
}

}
4 changes: 0 additions & 4 deletions src/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/MailLibrary/Driver.filters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}