Lists.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace Heanup\App\Api\Controller\Mail;
  3. use Heanup\App\Api\Package\Database\Mail;
  4. use Heanup\App\Api\RestfulController;
  5. use PhpImap\Mailbox;
  6. class Lists 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. $mail_ids = $mailbox->searchMailbox('ALL');
  28. // $mail_info = $mailbox->getMailsInfo($mail_ids);
  29. $mail_info=[];
  30. $mail_ids=array_reverse($mail_ids);
  31. foreach ($mail_ids as $mail_id) {
  32. $detail = $mailbox->getMail($mail_id);
  33. $temp=[
  34. 'subject' => $detail->subject,
  35. 'content' => $detail->textHtml,
  36. 'from' => $detail->fromAddress,
  37. 'fromName' => $detail->fromName,
  38. 'replyTo' => $detail->replyTo,
  39. 'date' => $detail->date,
  40. 'cc' => $detail->cc,
  41. 'bcc' => $detail->bcc,
  42. ];
  43. $mail_info[]=$temp;
  44. }
  45. $this->showSuccess($mail_info);
  46. }
  47. /**
  48. * Post Method|新增数据
  49. * @return void
  50. */
  51. protected function postData()
  52. {
  53. // TODO: 需要实现 postData() 方法.
  54. }
  55. /**
  56. * Put Method|更新数据
  57. * @return void
  58. */
  59. protected function putData()
  60. {
  61. // TODO: 需要实现 putData() 方法.
  62. }
  63. /**
  64. * Delete Method|删除数据
  65. * @return void
  66. */
  67. protected function deleteData()
  68. {
  69. // TODO: 需要实现 deleteData() 方法.
  70. }
  71. }