From 7589f76250a60991a0d70cd117b53a812c2655be Mon Sep 17 00:00:00 2001 From: Synox Date: Fri, 23 Feb 2018 22:17:51 +0100 Subject: [PATCH] _load_emails --- src/imap_client.php | 23 +++++++++++++++++++++-- src/index.php | 19 ------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/imap_client.php b/src/imap_client.php index d016da3..1c8bdb6 100644 --- a/src/imap_client.php +++ b/src/imap_client.php @@ -22,7 +22,7 @@ class ImapClient { $mailsIdsCc = imap_sort($this->mailbox->getImapStream(), SORTARRIVAL, true, SE_UID, 'CC "' . $user->address . '"'); $mail_ids = array_merge($mailsIdsTo, $mailsIdsCc); - $emails = _load_emails($mail_ids, $user); + $emails = $this->_load_emails($mail_ids, $user); return $emails; } @@ -75,7 +75,26 @@ class ImapClient { function _load_one_email(string $mailid, User $user) { // in order to avoid https://www.owasp.org/index.php/Top_10_2013-A4-Insecure_Direct_Object_References // the recipient in the email has to match the $address. - $emails = _load_emails(array($mailid), $user); + $emails = $this->_load_emails(array($mailid), $user); return count($emails) === 1 ? $emails[0] : null; } + + + /** + * Load emails using the $mail_ids, the mails have to match the $address in TO or CC. + * @param $mail_ids array of integer ids + * @param $user User + * @return array of emails + */ + function _load_emails(array $mail_ids, User $user) { + $emails = array(); + foreach ($mail_ids as $id) { + $mail = $this->mailbox->getMail($id); + // imap_search also returns partials matches. The mails have to be filtered again: + if (array_key_exists($user->address, $mail->to) || array_key_exists($user->address, $mail->cc)) { + $emails[] = $mail; + } + } + return $emails; + } } \ No newline at end of file diff --git a/src/index.php b/src/index.php index 19b822f..07fd6c1 100644 --- a/src/index.php +++ b/src/index.php @@ -43,25 +43,6 @@ function error($status, $text) { -/** - * Load emails using the $mail_ids, the mails have to match the $address in TO or CC. - * @param $mail_ids array of integer ids - * @param $user User - * @return array of emails - */ -function _load_emails($mail_ids, $user) { - global $mailbox; - - $emails = array(); - foreach ($mail_ids as $id) { - $mail = $mailbox->getMail($id); - // imap_search also returns partials matches. The mails have to be filtered again: - if (array_key_exists($user->address, $mail->to) || array_key_exists($user->address, $mail->cc)) { - $emails[] = $mail; - } - } - return $emails; -} /** * Remove illegal characters from address.