Skip to content

Commit

Permalink
The message uid and message number will only be fetched if accessed a…
Browse files Browse the repository at this point in the history
…nd wasn't previously set #326 #285
  • Loading branch information
Webklex committed Jan 2, 2023
1 parent 54eb265 commit 95925da
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,28 @@ public function __get($name) {
* @param $name
*
* @return Attribute|mixed|null
* @throws AuthFailedException
* @throws ConnectionFailedException
* @throws ImapBadRequestException
* @throws ImapServerErrorException
* @throws MessageNotFoundException
* @throws RuntimeException
* @throws ResponseException
*/
public function get($name) {
if(isset($this->attributes[$name])) {
public function get($name): mixed {
if (isset($this->attributes[$name]) && $this->attributes[$name] !== null) {
return $this->attributes[$name];
}

switch ($name){
case "uid":
$this->attributes[$name] = $this->client->getConnection()->getUid($this->msgn)->validate()->integer();
return $this->attributes[$name];
case "msgn":
$this->attributes[$name] = $this->client->getConnection()->getMessageNumber($this->uid)->validate()->integer();
return $this->attributes[$name];
}

return $this->header->get($name);
}

Expand Down Expand Up @@ -1476,7 +1492,7 @@ public function setClient($client): Message {
*/
public function setUid(int $uid): Message {
$this->uid = $uid;
$this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
$this->msgn = null;
$this->msglist = null;

return $this;
Expand All @@ -1492,7 +1508,7 @@ public function setUid(int $uid): Message {
public function setMsgn(int $msgn, int $msglist = null): Message {
$this->msgn = $msgn;
$this->msglist = $msglist;
$this->uid = $this->client->getConnection()->getUid($this->msgn);
$this->uid = null;

return $this;
}
Expand Down

0 comments on commit 95925da

Please sign in to comment.