Skip to content

Commit

Permalink
Merge pull request #215 from Slamdunk/get_all_headers
Browse files Browse the repository at this point in the history
Headers now extends \ArrayIterator
Close #200
  • Loading branch information
Slamdunk authored Oct 2, 2017
2 parents 1dd0666 + b17b580 commit 4ad1cfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Message/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Collection of message headers
*/
class Headers extends Parameters
final class Headers extends Parameters
{
/**
* Constructor
Expand All @@ -23,7 +23,7 @@ public function __construct(\stdClass $headers)
$headers = array_change_key_case((array) $headers);

foreach ($headers as $key => $value) {
$this->parameters[$key] = $this->parseHeader($key, $value);
$this[$key] = $this->parseHeader($key, $value);
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/Parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace Ddeboer\Imap;

class Parameters
class Parameters extends \ArrayIterator
{
protected $parameters = [];

public function __construct(array $parameters = [])
{
$this->add($parameters);
Expand All @@ -18,17 +16,13 @@ public function add(array $parameters = [])
foreach ($parameters as $parameter) {
$key = strtolower($parameter->attribute);
$value = $this->decode($parameter->value);
$this->parameters[$key] = $value;
$this[$key] = $value;
}
}

public function get(string $key)
{
if (isset($this->parameters[$key])) {
return $this->parameters[$key];
}

return;
return $this[$key] ?? null;
}

protected function decode(string $value): string
Expand Down
17 changes: 17 additions & 0 deletions tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ public function testRawHeaders()
$this->assertSame($expectedHeaders, $message->getRawHeaders());
}

/**
* @see https://github.com/ddeboer/imap/issues/200
*/
public function testGetAllHeaders()
{
$this->mailbox->addMessage($this->getFixture('bcc'));

$message = $this->mailbox->getMessage(1);
$headers = $message->getHeaders();

$this->assertGreaterThan(9, count($headers));

$this->assertArrayHasKey('from', $headers);
$this->assertArrayHasKey('date', $headers);
$this->assertArrayHasKey('recent', $headers);
}

public function testSetFlags()
{
$this->createTestMessage($this->mailbox, 'Message A');
Expand Down

0 comments on commit 4ad1cfd

Please sign in to comment.