-
Notifications
You must be signed in to change notification settings - Fork 17
[WIP] Experimental fixes #14
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
Changes from all commits
6a4227d
efd4f8d
ae6e560
7a88095
8ab921d
1b615f1
ae4c5e8
2efd498
2ec0552
a169cdf
052cedc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,9 @@ | |
|
|
||
| namespace greeny\MailLibrary; | ||
|
|
||
| use greeny\MailLibrary\Structures\IStructure; | ||
| use Nette\Utils\Strings; | ||
|
|
||
| class Mail { | ||
| const ANSWERED = 'ANSWERED'; | ||
| const BCC = 'BCC'; | ||
|
|
@@ -39,10 +42,10 @@ class Mail { | |
| const ORDER_CC = SORTCC; | ||
| const ORDER_SIZE = SORTSIZE; | ||
|
|
||
| /** @var \greeny\MailLibrary\Connection */ | ||
| /** @var Connection */ | ||
| protected $connection; | ||
|
|
||
| /** @var \greeny\MailLibrary\Mailbox */ | ||
| /** @var Mailbox */ | ||
| protected $mailbox; | ||
|
|
||
| /** @var int */ | ||
|
|
@@ -51,7 +54,7 @@ class Mail { | |
| /** @var array */ | ||
| protected $headers = NULL; | ||
|
|
||
| /** @var \greeny\MailLibrary\Structures\IStructure */ | ||
| /** @var IStructure */ | ||
| protected $structure = NULL; | ||
|
|
||
| /** @var array */ | ||
|
|
@@ -78,7 +81,8 @@ public function __construct(Connection $connection, Mailbox $mailbox, $id) | |
| public function __isset($name) | ||
| { | ||
| $this->headers !== NULL || $this->initializeHeaders(); | ||
| return isset($this->headers[$this->formatHeaderName($name)]); | ||
| $key = $this->normalizeHeaderName($this->lowerCamelCaseToHeaderName($name)); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is proposal. Basic idea is that magic methods uses magic name translation into normalized header name and getHeader() is more accurate (less magic included).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment in PR |
||
| return isset($this->headers[$key]); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -89,7 +93,9 @@ public function __isset($name) | |
| */ | ||
| public function __get($name) | ||
| { | ||
| return $this->getHeader($name); | ||
| return $this->getHeader( | ||
| $this->normalizeHeaderName($this->lowerCamelCaseToHeaderName($name)) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -124,7 +130,12 @@ public function getHeaders() | |
| public function getHeader($name) | ||
| { | ||
| $this->headers !== NULL || $this->initializeHeaders(); | ||
| return $this->headers[$this->formatHeaderName($name)]; | ||
| $index = $this->normalizeHeaderName($name); | ||
| if(isset($this->headers[$index])) { | ||
| return $this->headers[$index]; | ||
| } else { | ||
| return NULL; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -230,7 +241,7 @@ protected function initializeHeaders() | |
| $this->headers = array(); | ||
| $this->connection->getDriver()->switchMailbox($this->mailbox->getName()); | ||
| foreach($this->connection->getDriver()->getHeaders($this->id) as $key => $value) { | ||
| $this->headers[$this->formatHeaderName($key)] = $value; | ||
| $this->headers[$this->normalizeHeaderName($key)] = $value; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -247,15 +258,29 @@ protected function initializeFlags() | |
| } | ||
|
|
||
| /** | ||
| * Formats header name (X-Received-From => xReceivedFrom) | ||
| * Formats header name (X-Received-From => x-recieved-from) | ||
| * | ||
| * @param string $name | ||
| * @param string $name Header name (with dashes, valid UTF-8 string) | ||
| * @return string | ||
| */ | ||
| protected function formatHeaderName($name) | ||
| protected function normalizeHeaderName($name) | ||
| { | ||
| return lcfirst(preg_replace_callback("~-.~", function($matches){ | ||
| return Strings::normalize(Strings::lower($name)); | ||
| } | ||
|
|
||
| /** | ||
| * Converts camel cased name to normalized header name (xReceivedFrom => x-recieved-from) | ||
| * | ||
| * @param string $camelCasedName | ||
| * @return string name with dashes | ||
| */ | ||
| protected function lowerCamelCaseToHeaderName($camelCasedName) { | ||
| // todo: test this | ||
| // todo: use something like this instead http://stackoverflow.com/a/1993772 | ||
| $dashedName = lcfirst(preg_replace_callback("~-.~", function($matches){ | ||
| return ucfirst(substr($matches[0], 1)); | ||
| }, $name)); | ||
| }, $camelCasedName)); | ||
|
|
||
| return $this->normalizeHeaderName($dashedName); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [PHP] | ||
| ;extension_dir = "./ext" | ||
| extension=mbstring.so | ||
| extension=imap.so | ||
| date.timezone = "Europe/Prague" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [PHP] | ||
| extension_dir = "./ext" | ||
| extension=php_mbstring.dll | ||
| extension=php_imap.dll | ||
| date.timezone = "Europe/Prague" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be some way how to configure this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment in PR