Skip to content

Commit 440417f

Browse files
committed
Comments and docs updated
1 parent 1774dbb commit 440417f

File tree

8 files changed

+69
-77
lines changed

8 files changed

+69
-77
lines changed

src/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public function isConnected(): bool {
370370

371371
/**
372372
* Determine if connection was established and connect if not.
373+
* Returns true if the connection was closed and has been reopened.
373374
*
374375
* @throws ConnectionFailedException
375376
* @throws AuthFailedException
@@ -659,7 +660,7 @@ public function openFolder(string $folder_path, bool $force_select = false): arr
659660

660661
/**
661662
* Create a new Folder
662-
* @param string $folder
663+
* @param string $folder_path
663664
* @param boolean $expunge
664665
*
665666
* @return Folder

src/Connection/Protocols/ImapProtocol.php

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ public function __construct(bool $cert_validation = true, mixed $encryption = fa
4848
}
4949

5050
/**
51-
* @throws ImapBadRequestException
52-
* @throws ImapServerErrorException
53-
* @throws RuntimeException
51+
* Handle the class destruction / tear down
5452
*/
5553
public function __destruct() {
5654
$this->logout();
@@ -382,12 +380,12 @@ public function requestAndResponse(string $command, array $tokens = [], bool $do
382380

383381
/**
384382
* Escape one or more literals i.e. for sendRequest
385-
* @param string|array $string the literal/-s
383+
* @param array|string $string the literal/-s
386384
*
387385
* @return string|array escape literals, literals with newline ar returned
388386
* as array('{size}', 'string');
389387
*/
390-
public function escapeString($string) {
388+
public function escapeString(array|string $string): array|string {
391389
if (func_num_args() < 2) {
392390
if (str_contains($string, "\n")) {
393391
return ['{' . strlen($string) . '}', $string];
@@ -423,7 +421,7 @@ public function escapeList(array $list): string {
423421
/**
424422
* Login to a new session.
425423
*
426-
* @param string $user username
424+
* @param string $user username
427425
* @param string $password password
428426
*
429427
* @return Response
@@ -460,7 +458,7 @@ public function authenticate(string $user, string $token): Response {
460458
$is_plus = $this->readLine($response, $tokens, '+', true);
461459
if ($is_plus) {
462460
// try to log the challenge somewhere where it can be found
463-
error_log("got an extra server challenge: $response");
461+
error_log("got an extra server challenge: $tokens");
464462
// respond with an empty response.
465463
$response->stack($this->sendRequest(''));
466464
} else {
@@ -510,18 +508,7 @@ public function logout(): Response {
510508
*/
511509
public function reset(): void {
512510
$this->stream = null;
513-
$this->uid_cache = null;
514-
515-
return $result;
516-
}
517-
518-
/**
519-
* Check if the current session is connected
520-
*
521-
* @return bool
522-
*/
523-
public function connected(): bool {
524-
return (boolean) $this->stream;
511+
$this->uid_cache = [];
525512
}
526513

527514
/**
@@ -532,6 +519,7 @@ public function connected(): bool {
532519
* @throws ImapBadRequestException
533520
* @throws ImapServerErrorException
534521
* @throws RuntimeException
522+
* @throws ResponseException
535523
*/
536524
public function getCapabilities(): Response {
537525
$response = $this->requestAndResponse('CAPABILITY');
@@ -616,8 +604,8 @@ public function examineFolder(string $folder = 'INBOX'): Response {
616604

617605
/**
618606
* Fetch one or more items of one or more messages
619-
* @param string|array $items items to fetch [RFC822.HEADER, FLAGS, RFC822.TEXT, etc]
620-
* @param int|array $from message for items or start message if $to !== null
607+
* @param array|string $items items to fetch [RFC822.HEADER, FLAGS, RFC822.TEXT, etc]
608+
* @param array|int $from message for items or start message if $to !== null
621609
* @param int|null $to if null only one message ($from) is fetched, else it's the
622610
* last message, INF means last message available
623611
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
@@ -729,7 +717,7 @@ public function fetch(array|string $items, array|int $from, mixed $to = null, in
729717

730718
/**
731719
* Fetch message headers
732-
* @param array|int $uids
720+
* @param int|array $uids
733721
* @param string $rfc
734722
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
735723
* message numbers instead.
@@ -743,7 +731,7 @@ public function content(int|array $uids, string $rfc = "RFC822", int|string $uid
743731

744732
/**
745733
* Fetch message headers
746-
* @param array|int $uids
734+
* @param int|array $uids
747735
* @param string $rfc
748736
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
749737
* message numbers instead.
@@ -757,7 +745,7 @@ public function headers(int|array $uids, string $rfc = "RFC822", int|string $uid
757745

758746
/**
759747
* Fetch message flags
760-
* @param array|int $uids
748+
* @param int|array $uids
761749
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
762750
* message numbers instead.
763751
*
@@ -825,7 +813,7 @@ public function getMessageNumber(string $id): Response {
825813
* Get a list of available folders
826814
*
827815
* @param string $reference mailbox reference for list
828-
* @param string $folder mailbox name match with wildcards
816+
* @param string $folder mailbox name match with wildcards
829817
*
830818
* @return Response folders that matched $folder as array(name => array('delimiter' => .., 'flags' => ..))
831819
*
@@ -853,15 +841,15 @@ public function folders(string $reference = '', string $folder = '*'): Response
853841
/**
854842
* Manage flags
855843
*
856-
* @param array $flags flags to set, add or remove - see $mode
857-
* @param int $from message for items or start message if $to !== null
858-
* @param null $to if null only one message ($from) is fetched, else it's the
844+
* @param array|string $flags flags to set, add or remove - see $mode
845+
* @param int $from message for items or start message if $to !== null
846+
* @param int|null $to if null only one message ($from) is fetched, else it's the
859847
* last message, INF means last message available
860-
* @param null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given
861-
* @param bool $silent if false the return values are the new flags for the wanted messages
862-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
848+
* @param string|null $mode '+' to add flags, '-' to remove flags, everything else sets the flags as given
849+
* @param bool $silent if false the return values are the new flags for the wanted messages
850+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
863851
* message numbers instead.
864-
* @param null $item command used to store a flag
852+
* @param string|null $item command used to store a flag
865853
*
866854
* @return Response new flags if $silent is false, else true or false depending on success
867855
* @throws ImapBadRequestException
@@ -898,10 +886,10 @@ public function store(
898886
/**
899887
* Append a new message to given folder
900888
*
901-
* @param string $folder name of target folder
889+
* @param string $folder name of target folder
902890
* @param string $message full message content
903-
* @param null $flags flags for new message
904-
* @param null $date date for new message
891+
* @param array|null $flags flags for new message
892+
* @param string|null $date date for new message
905893
*
906894
* @return Response
907895
*
@@ -926,11 +914,11 @@ public function appendMessage(string $folder, string $message, array $flags = nu
926914
/**
927915
* Copy a message set from current folder to another folder
928916
*
929-
* @param string $folder destination folder
917+
* @param string $folder destination folder
930918
* @param $from
931-
* @param null $to if null only one message ($from) is fetched, else it's the
919+
* @param int|null $to if null only one message ($from) is fetched, else it's the
932920
* last message, INF means last message available
933-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
921+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
934922
* message numbers instead.
935923
*
936924
* @return Response
@@ -950,8 +938,8 @@ public function copyMessage(string $folder, $from, int $to = null, int|string $u
950938
* Copy multiple messages to the target folder
951939
*
952940
* @param array $messages List of message identifiers
953-
* @param string $folder Destination folder
954-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
941+
* @param string $folder Destination folder
942+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
955943
* message numbers instead.
956944
*
957945
* @return Response Tokens if operation successful, false if an error occurred
@@ -972,11 +960,11 @@ public function copyManyMessages(array $messages, string $folder, int|string $ui
972960
/**
973961
* Move a message set from current folder to another folder
974962
*
975-
* @param string $folder destination folder
963+
* @param string $folder destination folder
976964
* @param $from
977-
* @param null $to if null only one message ($from) is fetched, else it's the
965+
* @param int|null $to if null only one message ($from) is fetched, else it's the
978966
* last message, INF means last message available
979-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
967+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
980968
* message numbers instead.
981969
*
982970
* @return Response
@@ -996,8 +984,8 @@ public function moveMessage(string $folder, $from, int $to = null, int|string $u
996984
* Move multiple messages to the target folder
997985
*
998986
* @param array $messages List of message identifiers
999-
* @param string $folder Destination folder
1000-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
987+
* @param string $folder Destination folder
988+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
1001989
* message numbers instead.
1002990
*
1003991
* @return Response
@@ -1126,7 +1114,7 @@ public function expunge(): Response {
11261114
/**
11271115
* Send noop command
11281116
*
1129-
* @return array success
1117+
* @return Response
11301118
* @throws ImapBadRequestException
11311119
* @throws ImapServerErrorException
11321120
* @throws RuntimeException
@@ -1198,7 +1186,7 @@ public function done(): bool {
11981186
* Search for matching messages
11991187
*
12001188
* @param array $params
1201-
* @param int $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
1189+
* @param int|string $uid set to IMAP::ST_UID or any string representing the UID - set to IMAP::ST_MSGN to use
12021190
* message numbers instead.
12031191
*
12041192
* @return Response message ids
@@ -1254,15 +1242,19 @@ public function overview(string $sequence, int|string $uid = IMAP::ST_UID): Resp
12541242

12551243
/**
12561244
* Enable the debug mode
1245+
*
1246+
* @return void
12571247
*/
1258-
public function enableDebug(){
1248+
public function enableDebug(): void {
12591249
$this->debug = true;
12601250
}
12611251

12621252
/**
12631253
* Disable the debug mode
1254+
*
1255+
* @return void
12641256
*/
1265-
public function disableDebug(){
1257+
public function disableDebug(): void {
12661258
$this->debug = false;
12671259
}
12681260

@@ -1273,7 +1265,7 @@ public function disableDebug(){
12731265
*
12741266
* @return int|string
12751267
*/
1276-
public function buildSet($from, $to = null) {
1268+
public function buildSet($from, $to = null): int|string {
12771269
$set = (int)$from;
12781270
if ($to !== null) {
12791271
$set .= ':' . ($to == INF ? '*' : (int)$to);

0 commit comments

Comments
 (0)