diff --git a/src/imap_client.php b/src/imap_client.php index 44a1fde..ab6052f 100644 --- a/src/imap_client.php +++ b/src/imap_client.php @@ -24,4 +24,21 @@ class ImapClient { $emails = _load_emails($mail_ids, $user); return $emails; } + + + /** + * deletes emails by id and username. The address must match the recipient in the email. + * + * @param $mailid integer imap email id + * @param $user User + * @internal param the $username matching username + */ + function delete_email(string $mailid, User $user) { + if (_load_one_email($mailid, $user) !== null) { + $this->mailbox->deleteMail($mailid); + $this->mailbox->expungeDeletedMails(); + } else { + error(404, 'delete error: invalid username/mailid combination'); + } + } } \ No newline at end of file diff --git a/src/index.php b/src/index.php index b3f3bab..4cbd5b8 100644 --- a/src/index.php +++ b/src/index.php @@ -40,23 +40,6 @@ function error($status, $text) { -/** - * deletes emails by id and username. The address must match the recipient in the email. - * - * @param $mailid integer imap email id - * @param $user User - * @internal param the $username matching username - */ -function delete_email($mailid, $user) { - global $mailbox; - - if (_load_one_email($mailid, $user) !== null) { - $mailbox->deleteMail($mailid); - $mailbox->expungeDeletedMails(); - } else { - error(404, 'delete error: invalid username/mailid combination'); - } -} /** * download email by id and username. The $address must match the recipient in the email. diff --git a/src/pages.php b/src/pages.php index 8e09a5e..a5140e5 100644 --- a/src/pages.php +++ b/src/pages.php @@ -67,7 +67,7 @@ class DeleteEmailPage extends Page { $this->if_invalid_redirect_to_random($user, $this->config_domains); $delete_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT); - delete_email($delete_email_id, $user); + $imapClient->delete_email($delete_email_id, $user); header("location: ?" . $user->address); } }