Skip to content

Commit

Permalink
Upgrade to latest version of PHPIMAP from the fork https://github.com…
Browse files Browse the repository at this point in the history
…/campbell-m/php-imap, fixing deprecation notices running under PHP 8.4 (https://github.com/Webklex/php-imap seems not to be maintained).
  • Loading branch information
campbell-m committed Nov 1, 2024
1 parent 16538ca commit b2cc074
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions web/lib/Webklex/PHPIMAP/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ public function getFolderByPath($folder_path, bool $utf7 = false, bool $soft_fai
* @throws ResponseException
* @throws RuntimeException
*/
public function getFolders(bool $hierarchical = true, string $parent_folder = null, bool $soft_fail = false): FolderCollection {
public function getFolders(bool $hierarchical = true, ?string $parent_folder = null, bool $soft_fail = false): FolderCollection {
$this->checkConnection();
$folders = FolderCollection::make([]);

Expand Down Expand Up @@ -618,7 +618,7 @@ public function getFolders(bool $hierarchical = true, string $parent_folder = nu
* @throws RuntimeException
* @throws ResponseException
*/
public function getFoldersWithStatus(bool $hierarchical = true, string $parent_folder = null, bool $soft_fail = false): FolderCollection {
public function getFoldersWithStatus(bool $hierarchical = true, ?string $parent_folder = null, bool $soft_fail = false): FolderCollection {
$this->checkConnection();
$folders = FolderCollection::make([]);

Expand Down Expand Up @@ -793,7 +793,7 @@ public function getFolderPath(): string {
* @throws RuntimeException
* @throws ResponseException
*/
public function Id(array $ids = null): array {
public function Id(?array $ids = null): array {
$this->checkConnection();
return $this->connection->ID($ids)->validatedData();
}
Expand Down
2 changes: 1 addition & 1 deletion web/lib/Webklex/PHPIMAP/ClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function make(array $config): Client {
* @return Client
* @throws Exceptions\MaskNotFoundException
*/
public function account(string $name = null): Client {
public function account(?string $name = null): Client {
$name = $name ?: $this->config->getDefaultAccount();

// If the connection has not been resolved we will resolve it now as all
Expand Down
12 changes: 6 additions & 6 deletions web/lib/Webklex/PHPIMAP/Connection/Protocols/ImapProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __destruct() {
*
* @throws ConnectionFailedException
*/
public function connect(string $host, int $port = null): bool {
public function connect(string $host, ?int $port = null): bool {
$transport = 'tcp';
$encryption = '';

Expand Down Expand Up @@ -362,7 +362,7 @@ private function stringifyArray(array $arr): string {
* @return Response
* @throws RuntimeException
*/
public function sendRequest(string $command, array $tokens = [], string &$tag = null): Response {
public function sendRequest(string $command, array $tokens = [], ?string &$tag = null): Response {
if (!$tag) {
$this->noun++;
$tag = 'TAG' . $this->noun;
Expand Down Expand Up @@ -955,7 +955,7 @@ public function folders(string $reference = '', string $folder = '*'): Response
* @throws RuntimeException
*/
public function store(
array|string $flags, int $from, int $to = null, string $mode = null, bool $silent = true, int|string $uid = IMAP::ST_UID, string $item = null
array|string $flags, int $from, ?int $to = null, ?string $mode = null, bool $silent = true, int|string $uid = IMAP::ST_UID, ?string $item = null
): Response {
$flags = $this->escapeList(is_array($flags) ? $flags : [$flags]);
$set = $this->buildSet($from, $to);
Expand Down Expand Up @@ -995,7 +995,7 @@ public function store(
* @throws ImapServerErrorException
* @throws RuntimeException
*/
public function appendMessage(string $folder, string $message, array $flags = null, string $date = null): Response {
public function appendMessage(string $folder, string $message, ?array $flags = null, ?string $date = null): Response {
$tokens = [];
$tokens[] = $this->escapeString($folder);
if ($flags !== null) {
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public function appendMessage(string $folder, string $message, array $flags = nu
* @throws ImapServerErrorException
* @throws RuntimeException
*/
public function copyMessage(string $folder, $from, int $to = null, int|string $uid = IMAP::ST_UID): Response {
public function copyMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response {
$set = $this->buildSet($from, $to);
$command = $this->buildUIDCommand("COPY", $uid);

Expand Down Expand Up @@ -1071,7 +1071,7 @@ public function copyManyMessages(array $messages, string $folder, int|string $ui
* @throws ImapServerErrorException
* @throws RuntimeException
*/
public function moveMessage(string $folder, $from, int $to = null, int|string $uid = IMAP::ST_UID): Response {
public function moveMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response {
$set = $this->buildSet($from, $to);
$command = $this->buildUIDCommand("MOVE", $uid);

Expand Down
12 changes: 6 additions & 6 deletions web/lib/Webklex/PHPIMAP/Connection/Protocols/LegacyProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __destruct() {
* @param string $host
* @param int|null $port
*/
public function connect(string $host, int $port = null): void {
public function connect(string $host, ?int $port = null): void {
if ($this->encryption) {
$encryption = strtolower($this->encryption);
if ($encryption == "ssl") {
Expand Down Expand Up @@ -359,7 +359,7 @@ public function sizes(int|array $uids, int|string $uid = IMAP::ST_UID): Response
*
* @return Response message number for given message or all messages as array
*/
public function getUid(int $id = null): Response {
public function getUid(?int $id = null): Response {
return $this->response()->wrap(function($response) use ($id) {
/** @var Response $response */
if ($id === null) {
Expand Down Expand Up @@ -454,7 +454,7 @@ public function folders(string $reference = '', string $folder = '*'): Response
*
* @return Response new flags if $silent is false, else true or false depending on success
*/
public function store(array|string $flags, int $from, int $to = null, string $mode = null, bool $silent = true, int|string $uid = IMAP::ST_UID, string $item = null): Response {
public function store(array|string $flags, int $from, ?int $to = null, ?string $mode = null, bool $silent = true, int|string $uid = IMAP::ST_UID, ?string $item = null): Response {
$flag = trim(is_array($flags) ? implode(" ", $flags) : $flags);

return $this->response()->wrap(function($response) use ($mode, $from, $flag, $uid, $silent) {
Expand Down Expand Up @@ -490,7 +490,7 @@ public function store(array|string $flags, int $from, int $to = null, string $mo
*
* @return Response
*/
public function appendMessage(string $folder, string $message, array $flags = null, mixed $date = null): Response {
public function appendMessage(string $folder, string $message, ?array $flags = null, mixed $date = null): Response {
return $this->response("imap_append")->wrap(function($response) use ($folder, $message, $flags, $date) {
/** @var Response $response */
if ($date != null) {
Expand Down Expand Up @@ -521,7 +521,7 @@ public function appendMessage(string $folder, string $message, array $flags = nu
*
* @return Response
*/
public function copyMessage(string $folder, $from, int $to = null, int|string $uid = IMAP::ST_UID): Response {
public function copyMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response {
return $this->response("imap_mail_copy")->wrap(function($response) use ($from, $folder, $uid) {
/** @var Response $response */

Expand Down Expand Up @@ -571,7 +571,7 @@ public function copyManyMessages(array $messages, string $folder, int|string $ui
*
* @return Response success
*/
public function moveMessage(string $folder, $from, int $to = null, int|string $uid = IMAP::ST_UID): Response {
public function moveMessage(string $folder, $from, ?int $to = null, int|string $uid = IMAP::ST_UID): Response {
return $this->response("imap_mail_move")->wrap(function($response) use ($from, $folder, $uid) {
if (\imap_mail_move($this->stream, $from, $this->getAddress() . $folder, $uid ? IMAP::ST_UID : IMAP::NIL)) {
return [
Expand Down
2 changes: 1 addition & 1 deletion web/lib/Webklex/PHPIMAP/EncodingAliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class EncodingAliases {
*
* @return string
*/
public static function get(?string $encoding, string $fallback = null): string {
public static function get(?string $encoding, ?string $fallback = null): string {
if (isset(self::$aliases[strtolower($encoding ?? '')])) {
return self::$aliases[strtolower($encoding ?? '')];
}
Expand Down
4 changes: 2 additions & 2 deletions web/lib/Webklex/PHPIMAP/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public function move(string $new_name, bool $expunge = true): array {
* @throws MessageNotFoundException
* @throws ResponseException
*/
public function overview(string $sequence = null): array {
public function overview(?string $sequence = null): array {
$this->client->openFolder($this->path);
$sequence = $sequence === null ? "1:*" : $sequence;
$uid = $this->client->getConfig()->get('options.sequence', IMAP::ST_MSGN);
Expand All @@ -353,7 +353,7 @@ public function overview(string $sequence = null): array {
* @throws AuthFailedException
* @throws ResponseException
*/
public function appendMessage(string $message, array $options = null, Carbon|string $internal_date = null): array {
public function appendMessage(string $message, ?array $options = null, Carbon|string|null $internal_date = null): array {
/**
* Check if $internal_date is parsed. If it is null it should not be set. Otherwise, the message can't be stored.
* If this parameter is set, it will set the INTERNALDATE on the appended message. The parameter should be a
Expand Down
18 changes: 9 additions & 9 deletions web/lib/Webklex/PHPIMAP/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Message {
* @throws RuntimeException
* @throws ResponseException
*/
public function __construct(int $uid, ?int $msglist, Client $client, int $fetch_options = null, bool $fetch_body = false, bool $fetch_flags = false, int $sequence = null) {
public function __construct(int $uid, ?int $msglist, Client $client, ?int $fetch_options = null, bool $fetch_body = false, bool $fetch_flags = false, ?int $sequence = null) {
$this->boot($client->getConfig());

$default_mask = $client->getDefaultMessageMask();
Expand Down Expand Up @@ -319,7 +319,7 @@ public static function make(int $uid, ?int $msglist, Client $client, string $raw
* @throws ResponseException
* @throws RuntimeException
*/
public static function fromFile(string $filename, Config $config = null): Message {
public static function fromFile(string $filename, ?Config $config = null): Message {
$blob = file_get_contents($filename);
if ($blob === false) {
throw new RuntimeException("Unable to read file");
Expand All @@ -344,7 +344,7 @@ public static function fromFile(string $filename, Config $config = null): Messag
* @throws ResponseException
* @throws RuntimeException
*/
public static function fromString(string $blob, Config $config = null): Message {
public static function fromString(string $blob, ?Config $config = null): Message {
$reflection = new ReflectionClass(self::class);
/** @var Message $instance */
$instance = $reflection->newInstanceWithoutConstructor();
Expand Down Expand Up @@ -375,7 +375,7 @@ public static function fromString(string $blob, Config $config = null): Message
* Boot a new instance
* @param ?Config $config
*/
public function boot(Config $config = null): void {
public function boot(?Config $config = null): void {
$this->attributes = [];
$this->client = null;
$this->config = $config ?? Config::make();
Expand Down Expand Up @@ -985,7 +985,7 @@ public function getFolder(): ?Folder {
* @throws RuntimeException
* @throws ResponseException
*/
public function thread(Folder $sent_folder = null, MessageCollection &$thread = null, Folder $folder = null): MessageCollection {
public function thread(?Folder $sent_folder = null, ?MessageCollection &$thread = null, ?Folder $folder = null): MessageCollection {
$thread = $thread ?: MessageCollection::make();
$folder = $folder ?: $this->getFolder();
$sent_folder = $sent_folder ?: $this->client->getFolderByPath($this->config->get("options.common_folders.sent", "INBOX/Sent"));
Expand Down Expand Up @@ -1205,7 +1205,7 @@ protected function fetchNewMail(Folder $folder, int $next_uid, string $event, bo
* @throws RuntimeException
* @throws ResponseException
*/
public function delete(bool $expunge = true, string $trash_path = null, bool $force_move = false): bool {
public function delete(bool $expunge = true, ?string $trash_path = null, bool $force_move = false): bool {
$status = $this->setFlag("Deleted");
if ($force_move) {
$trash_path = $trash_path === null ? $this->config["common_folders"]["trash"] : $trash_path;
Expand Down Expand Up @@ -1480,7 +1480,7 @@ public function getStructure(): ?Structure {
* @param null|Message $message
* @return boolean
*/
public function is(Message $message = null): bool {
public function is(?Message $message = null): bool {
if (is_null($message)) {
return false;
}
Expand Down Expand Up @@ -1687,7 +1687,7 @@ public function setUid(int $uid): Message {
*
* @return Message
*/
public function setMsgn(int $msgn, int $msglist = null): Message {
public function setMsgn(int $msgn, ?int $msglist = null): Message {
$this->msgn = $msgn;
$this->msglist = $msglist;
$this->uid = null;
Expand Down Expand Up @@ -1718,7 +1718,7 @@ public function getSequenceId(): int {
* @param $uid
* @param int|null $msglist
*/
public function setSequenceId($uid, int $msglist = null): void {
public function setSequenceId($uid, ?int $msglist = null): void {
if ($this->getSequence() === IMAP::ST_UID) {
$this->setUid($uid);
$this->setMsglist($msglist);
Expand Down
2 changes: 1 addition & 1 deletion web/lib/Webklex/PHPIMAP/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class Part {
*
* @throws InvalidMessageDateException
*/
public function __construct(string $raw_part, Config $config, Header $header = null, int $part_number = 0) {
public function __construct(string $raw_part, Config $config, ?Header $header = null, int $part_number = 0) {
$this->raw = $raw_part;
$this->config = $config;
$this->header = $header;
Expand Down
4 changes: 2 additions & 2 deletions web/lib/Webklex/PHPIMAP/Query/WhereQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function push_search_criteria(string $criteria, mixed $value): void {
*
* @return $this
*/
public function orWhere(Closure $closure = null): static {
public function orWhere(?Closure $closure = null): static {
$this->query->push(['OR']);
if ($closure !== null) $closure($this);

Expand All @@ -183,7 +183,7 @@ public function orWhere(Closure $closure = null): static {
*
* @return $this
*/
public function andWhere(Closure $closure = null): static {
public function andWhere(?Closure $closure = null): static {
$this->query->push(['AND']);
if ($closure !== null) $closure($this);

Expand Down

0 comments on commit b2cc074

Please sign in to comment.