Unread.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace Heanup\App\Api\Controller\Mail\Count;
  3. use Heanup\App\Api\Package\Database\Mail;
  4. use Heanup\App\Api\RestfulController;
  5. use PhpImap\Mailbox;
  6. class Unread extends RestfulController
  7. {
  8. /**
  9. * Get Method|获取数据
  10. * @return void
  11. * @throws \PhpImap\Exceptions\InvalidParameterException
  12. */
  13. protected function getData()
  14. {
  15. $email=$this->getQuery()->string("u");
  16. $account = substr($email, 0, strpos($email, "@"));
  17. $domain = substr($email, strpos($email, "@") + 1);
  18. $_mail = Mail::getOne(['email' => $account, 'domain' => $domain, 'status' => 1]);
  19. $password = $_mail['password'];
  20. $mailbox = new Mailbox(
  21. '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
  22. $email, // Username for the before configured mailbox
  23. $password, // Password for the before configured username
  24. __DIR__, // Directory, where attachments will be saved (optional)
  25. 'UTF-8' // Server encoding (optional)
  26. );
  27. $count=$mailbox->searchMailbox("UNSEEN");
  28. $this->showSuccess(count($count));
  29. }
  30. /**
  31. * Post Method|新增数据
  32. * @return void
  33. */
  34. protected function postData()
  35. {
  36. // TODO: 需要实现 postData() 方法.
  37. }
  38. /**
  39. * Put Method|更新数据
  40. * @return void
  41. */
  42. protected function putData()
  43. {
  44. // TODO: 需要实现 putData() 方法.
  45. }
  46. /**
  47. * Delete Method|删除数据
  48. * @return void
  49. */
  50. protected function deleteData()
  51. {
  52. // TODO: 需要实现 deleteData() 方法.
  53. }
  54. }