Skip to content

Commit 95925da

Browse files
committed
The message uid and message number will only be fetched if accessed and wasn't previously set Webklex#326 Webklex#285
1 parent 54eb265 commit 95925da

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Message.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,28 @@ public function __get($name) {
370370
* @param $name
371371
*
372372
* @return Attribute|mixed|null
373+
* @throws AuthFailedException
374+
* @throws ConnectionFailedException
375+
* @throws ImapBadRequestException
376+
* @throws ImapServerErrorException
377+
* @throws MessageNotFoundException
378+
* @throws RuntimeException
379+
* @throws ResponseException
373380
*/
374-
public function get($name) {
375-
if(isset($this->attributes[$name])) {
381+
public function get($name): mixed {
382+
if (isset($this->attributes[$name]) && $this->attributes[$name] !== null) {
376383
return $this->attributes[$name];
377384
}
378385

386+
switch ($name){
387+
case "uid":
388+
$this->attributes[$name] = $this->client->getConnection()->getUid($this->msgn)->validate()->integer();
389+
return $this->attributes[$name];
390+
case "msgn":
391+
$this->attributes[$name] = $this->client->getConnection()->getMessageNumber($this->uid)->validate()->integer();
392+
return $this->attributes[$name];
393+
}
394+
379395
return $this->header->get($name);
380396
}
381397

@@ -1476,7 +1492,7 @@ public function setClient($client): Message {
14761492
*/
14771493
public function setUid(int $uid): Message {
14781494
$this->uid = $uid;
1479-
$this->msgn = $this->client->getConnection()->getMessageNumber($this->uid);
1495+
$this->msgn = null;
14801496
$this->msglist = null;
14811497

14821498
return $this;
@@ -1492,7 +1508,7 @@ public function setUid(int $uid): Message {
14921508
public function setMsgn(int $msgn, int $msglist = null): Message {
14931509
$this->msgn = $msgn;
14941510
$this->msglist = $msglist;
1495-
$this->uid = $this->client->getConnection()->getUid($this->msgn);
1511+
$this->uid = null;
14961512

14971513
return $this;
14981514
}

0 commit comments

Comments
 (0)