fix todos
This commit is contained in:
parent
56d86c8e46
commit
11a951cc37
|
@ -1,7 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
// TODO: return Either<Success,Failure>
|
|
||||||
// TODO: define return types
|
|
||||||
class ImapClient {
|
class ImapClient {
|
||||||
|
|
||||||
/*PhpImap\Mailbox */
|
/*PhpImap\Mailbox */
|
||||||
|
@ -33,15 +31,15 @@ class ImapClient {
|
||||||
* @param $mailid integer imap email id
|
* @param $mailid integer imap email id
|
||||||
* @param $user User
|
* @param $user User
|
||||||
* @internal param the $username matching username
|
* @internal param the $username matching username
|
||||||
|
* @return true if success
|
||||||
*/
|
*/
|
||||||
public function delete_email(string $mailid, User $user) {
|
public function delete_email(string $mailid, User $user): bool {
|
||||||
if ($this->_load_one_email($mailid, $user) !== null) {
|
if ($this->_load_one_email($mailid, $user) !== null) {
|
||||||
$this->mailbox->deleteMail($mailid);
|
$this->mailbox->deleteMail($mailid);
|
||||||
$this->mailbox->expungeDeletedMails();
|
$this->mailbox->expungeDeletedMails();
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// TODO: use return/throw instead
|
return false;
|
||||||
@http_response_code(404);
|
|
||||||
die('delete error: invalid username/mailid combination');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +52,7 @@ class ImapClient {
|
||||||
* @internal param the $username matching username
|
* @internal param the $username matching username
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function download_email(int $mailid, User $user) {
|
public function download_email(int $mailid, User $user): bool {
|
||||||
if ($this->_load_one_email($mailid, $user) !== null) {
|
if ($this->_load_one_email($mailid, $user) !== null) {
|
||||||
header("Content-Type: message/rfc822; charset=utf-8");
|
header("Content-Type: message/rfc822; charset=utf-8");
|
||||||
header("Content-Disposition: attachment; filename=\"" . $user->address . "-" . $mailid . ".eml\"");
|
header("Content-Disposition: attachment; filename=\"" . $user->address . "-" . $mailid . ".eml\"");
|
||||||
|
@ -62,8 +60,9 @@ class ImapClient {
|
||||||
$headers = imap_fetchheader($this->mailbox->getImapStream(), $mailid, FT_UID);
|
$headers = imap_fetchheader($this->mailbox->getImapStream(), $mailid, FT_UID);
|
||||||
$body = imap_body($this->mailbox->getImapStream(), $mailid, FT_UID);
|
$body = imap_body($this->mailbox->getImapStream(), $mailid, FT_UID);
|
||||||
print $headers . "\n" . $body;
|
print $headers . "\n" . $body;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
error(404, 'download error: invalid username/mailid combination');
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,9 @@ class DownloadEmailPage extends Page {
|
||||||
$this->if_invalid_redirect_to_random($user, $this->config_domains);
|
$this->if_invalid_redirect_to_random($user, $this->config_domains);
|
||||||
|
|
||||||
$download_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
$download_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
||||||
$imapClient->download_email($download_email_id, $user);
|
if (!$imapClient->download_email($download_email_id, $user)) {
|
||||||
|
$this->error(404, 'download error: invalid username/mailid combination');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,8 +101,11 @@ class DeleteEmailPage extends Page {
|
||||||
$this->if_invalid_redirect_to_random($user, $this->config_domains);
|
$this->if_invalid_redirect_to_random($user, $this->config_domains);
|
||||||
|
|
||||||
$delete_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
$delete_email_id = filter_var($this->email_id, FILTER_SANITIZE_NUMBER_INT);
|
||||||
$imapClient->delete_email($delete_email_id, $user);
|
if ($imapClient->delete_email($delete_email_id, $user)) {
|
||||||
header("location: ?" . $user->address);
|
header("location: ?" . $user->address);
|
||||||
|
} else {
|
||||||
|
$this->error(404, 'delete error: invalid username/mailid combination');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user