add return types

This commit is contained in:
Synox 2018-02-23 22:24:12 +01:00
parent 68493c4401
commit 59aba28faf
2 changed files with 14 additions and 17 deletions

View File

@ -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();
}
}

View File

@ -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();
}
?>