|
14 | 14 |
|
15 | 15 | use Webklex\IMAP\Exceptions\ConnectionFailedException; |
16 | 16 | use Webklex\IMAP\Exceptions\GetMessagesFailedException; |
| 17 | +use Webklex\IMAP\Exceptions\InvalidImapTimeoutTypeException; |
17 | 18 | use Webklex\IMAP\Exceptions\MessageSearchValidationException; |
18 | 19 | use Webklex\IMAP\Support\FolderCollection; |
19 | 20 | use Webklex\IMAP\Support\MessageCollection; |
@@ -115,6 +116,18 @@ class Client { |
115 | 116 | */ |
116 | 117 | protected $validConfigKeys = ['host', 'port', 'encryption', 'validate_cert', 'username', 'password','protocol']; |
117 | 118 |
|
| 119 | + /** |
| 120 | + * All available timeout types |
| 121 | + * |
| 122 | + * @var array $timeout_type |
| 123 | + */ |
| 124 | + protected $timeout_type = [ |
| 125 | + 'IMAP_OPENTIMEOUT' => 1, |
| 126 | + 'IMAP_READTIMEOUT' => 2, |
| 127 | + 'IMAP_WRITETIMEOUT' => 3, |
| 128 | + 'IMAP_CLOSETIMEOUT' => 4 |
| 129 | + ]; |
| 130 | + |
118 | 131 | /** |
119 | 132 | * Client constructor. |
120 | 133 | * |
@@ -569,4 +582,43 @@ public function checkCurrentMailbox() { |
569 | 582 | $this->checkConnection(); |
570 | 583 | return imap_check($this->connection); |
571 | 584 | } |
| 585 | + |
| 586 | + /** |
| 587 | + * Set the imap timeout for a given operation type |
| 588 | + * @param $type |
| 589 | + * @param $timeout |
| 590 | + * |
| 591 | + * @return mixed |
| 592 | + * @throws InvalidImapTimeoutTypeException |
| 593 | + */ |
| 594 | + public function setTimeout($type, $timeout) { |
| 595 | + if(is_numeric($type)) { |
| 596 | + $type = (int) $type; |
| 597 | + }elseif (isset($this->timeout_type[$type])){ |
| 598 | + $type = $this->timeout_type[$type]; |
| 599 | + }else{ |
| 600 | + throw new InvalidImapTimeoutTypeException("Invalid imap timeout type provided."); |
| 601 | + } |
| 602 | + |
| 603 | + return imap_timeout($type, $timeout); |
| 604 | + } |
| 605 | + |
| 606 | + /** |
| 607 | + * Get the timeout for a certain operation |
| 608 | + * @param $type |
| 609 | + * |
| 610 | + * @return mixed |
| 611 | + * @throws InvalidImapTimeoutTypeException |
| 612 | + */ |
| 613 | + public function getTimeout($type){ |
| 614 | + if(is_numeric($type)) { |
| 615 | + $type = (int) $type; |
| 616 | + }elseif (isset($this->timeout_type[$type])){ |
| 617 | + $type = $this->timeout_type[$type]; |
| 618 | + }else{ |
| 619 | + throw new InvalidImapTimeoutTypeException("Invalid imap timeout type provided."); |
| 620 | + } |
| 621 | + |
| 622 | + return imap_timeout($type); |
| 623 | + } |
572 | 624 | } |
0 commit comments