From 421dd028cea8102550f6b0140a088c588880a28d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 5 Mar 2022 13:08:09 +0000 Subject: [PATCH 1/4] Fix storing mail settings --- mod/settings.php | 2 +- src/Protocol/Email.php | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/mod/settings.php b/mod/settings.php index 2c9dcac126..41a1436e69 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -108,7 +108,7 @@ function settings_post(App $a) 'port' => $mail_port, 'ssltype' => $mail_ssl, 'user' => $mail_user, - `action` => $mail_action, + 'action' => $mail_action, 'movetofolder' => $mail_movetofolder, 'mailbox' => 'INBOX', 'reply_to' => $mail_replyto, diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index 09792935e0..18af77b3fe 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -27,6 +27,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Model\Item; use Friendica\Util\Strings; +use \IMAP\Connection; /** * Email class @@ -37,7 +38,7 @@ class Email * @param string $mailbox The mailbox name * @param string $username The username * @param string $password The password - * @return resource + * @return Connection * @throws \Exception */ public static function connect($mailbox, $username, $password) @@ -50,7 +51,7 @@ class Email $errors = imap_errors(); if (!empty($errors)) { - Logger::notice('IMAP Errors occured', ['errora' => $errors]); + Logger::notice('IMAP Errors occured', ['errors' => $errors]); } $alerts = imap_alerts(); @@ -62,8 +63,8 @@ class Email } /** - * @param resource $mbox mailbox - * @param string $email_addr email + * @param Connection $mbox mailbox + * @param string $email_addr email * @return array * @throws \Exception */ @@ -112,8 +113,8 @@ class Email } /** - * @param resource $mbox mailbox - * @param integer $uid user id + * @param Connection $mbox mailbox + * @param integer $uid user id * @return mixed */ public static function messageMeta($mbox, $uid) @@ -123,9 +124,9 @@ class Email } /** - * @param resource $mbox mailbox - * @param integer $uid user id - * @param string $reply reply + * @param Connection $mbox mailbox + * @param integer $uid user id + * @param string $reply reply * @return array * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ @@ -210,11 +211,11 @@ class Email /** * fetch the specified message part number with the specified subtype * - * @param resource $mbox mailbox - * @param integer $uid user id - * @param object $p parts - * @param integer $partno part number - * @param string $subtype sub type + * @param Connection $mbox mailbox + * @param integer $uid user id + * @param object $p parts + * @param integer $partno part number + * @param string $subtype sub type * @return string */ private static function messageGetPart($mbox, $uid, $p, $partno, $subtype) From 1ec1adf9048968c7aa9ae5450a979e6bd0e147c1 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 6 Mar 2022 05:49:49 +0100 Subject: [PATCH 2/4] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Protocol/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index 18af77b3fe..22d8aca235 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -41,7 +41,7 @@ class Email * @return Connection * @throws \Exception */ - public static function connect($mailbox, $username, $password) + public static function connect($mailbox, $username, $password): Connection { if (!function_exists('imap_open')) { return false; @@ -117,7 +117,7 @@ class Email * @param integer $uid user id * @return mixed */ - public static function messageMeta($mbox, $uid) + public static function messageMeta(Connection $mbox, $uid) { $ret = (($mbox && $uid) ? @imap_fetch_overview($mbox, $uid, FT_UID) : [[]]); // POSSIBLE CLEANUP --> array(array()) is probably redundant now return (count($ret)) ? $ret : []; @@ -218,7 +218,7 @@ class Email * @param string $subtype sub type * @return string */ - private static function messageGetPart($mbox, $uid, $p, $partno, $subtype) + private static function messageGetPart(Connection $mbox, $uid, $p, $partno, $subtype) { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple global $htmlmsg,$plainmsg,$charset,$attachments; From 31dbdd36771aea90e4330132db335a7238a45790 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Mar 2022 12:21:27 +0000 Subject: [PATCH 3/4] variable type for the return value is added --- src/Protocol/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index 22d8aca235..f3a3736ad3 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -68,7 +68,7 @@ class Email * @return array * @throws \Exception */ - public static function poll($mbox, $email_addr) + public static function poll($mbox, $email_addr): array { if (!$mbox || !$email_addr) { return []; @@ -130,7 +130,7 @@ class Email * @return array * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function getMessage($mbox, $uid, $reply, $item) + public static function getMessage($mbox, $uid, $reply, $item): array { $ret = $item; From acba7d25a02827e46298bbb380b96b8ef4e19ca4 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 6 Mar 2022 14:15:59 +0100 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Protocol/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Protocol/Email.php b/src/Protocol/Email.php index f3a3736ad3..4221dfb6db 100644 --- a/src/Protocol/Email.php +++ b/src/Protocol/Email.php @@ -68,7 +68,7 @@ class Email * @return array * @throws \Exception */ - public static function poll($mbox, $email_addr): array + public static function poll(Connection $mbox, $email_addr): array { if (!$mbox || !$email_addr) { return []; @@ -130,7 +130,7 @@ class Email * @return array * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function getMessage($mbox, $uid, $reply, $item): array + public static function getMessage(Connection $mbox, $uid, $reply, $item): array { $ret = $item;