From 59aba28faf41d6dd62186a3d47c62d451cf127b6 Mon Sep 17 00:00:00 2001 From: Synox Date: Fri, 23 Feb 2018 22:24:12 +0100 Subject: [PATCH] add return types --- src/imap_client.php | 18 +++++++++++++----- src/index.php | 13 +------------ 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/imap_client.php b/src/imap_client.php index 1c8bdb6..843ee2d 100644 --- a/src/imap_client.php +++ b/src/imap_client.php @@ -52,7 +52,7 @@ class ImapClient { * @internal param the $username matching username */ - function download_email(string $mailid, User $user) { + function download_email(int $mailid, User $user) { if ($this->_load_one_email($mailid, $user) !== null) { header("Content-Type: message/rfc822; charset=utf-8"); header("Content-Disposition: attachment; filename=\"" . $user->address . "-" . $mailid . ".eml\""); @@ -68,11 +68,8 @@ class ImapClient { /** * Load exactly one email, the $address in TO or CC has to match. - * @param $mailid integer - * @param $user User - * @return email or null */ - function _load_one_email(string $mailid, User $user) { + function _load_one_email(int $mailid, User $user): \PhpImap\IncomingMail { // 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 = $this->_load_emails(array($mailid), $user); @@ -97,4 +94,15 @@ class ImapClient { } return $emails; } + + /** + * deletes messages older than X days. + */ + function delete_old_messages(string $delete_messages_older_than) { + $ids = $this->mailbox->searchMailbox('BEFORE ' . date('d-M-Y', strtotime($delete_messages_older_than))); + foreach ($ids as $id) { + $this->mailbox->deleteMail($id); + } + $this->mailbox->expungeDeletedMails(); + } } \ No newline at end of file diff --git a/src/index.php b/src/index.php index 9f40ae4..b28ca39 100644 --- a/src/index.php +++ b/src/index.php @@ -24,7 +24,7 @@ $imapClient = new ImapClient($config['imap']['url'], $config['imap']['username'] $page->invoke($imapClient); // delete after each request -delete_old_messages(); +$imapClient->delete_old_messages($config['delete_messages_older_than']); /** * print error and stop program. @@ -39,18 +39,7 @@ function error($status, $text) { -/** - * deletes messages older than X days. - */ -function delete_old_messages() { - global $mailbox, $config; - $ids = $mailbox->searchMailbox('BEFORE ' . date('d-M-Y', strtotime($config['delete_messages_older_than']))); - foreach ($ids as $id) { - $mailbox->deleteMail($id); - } - $mailbox->expungeDeletedMails(); -} ?> \ No newline at end of file