Lists.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\Exceptions\InvalidParameterException;
  6. use PhpImap\Mailbox;
  7. class Lists extends RestfulController
  8. {
  9. /**
  10. * Get Method|获取数据
  11. * @return void
  12. * @throws InvalidParameterException
  13. */
  14. protected function getData()
  15. {
  16. $email=$this->getQuery()->string("u");
  17. $account = substr($email, 0, strpos($email, "@"));
  18. $domain = substr($email, strpos($email, "@") + 1);
  19. $_mail = Mail::getOne(['email' => $account, 'domain' => $domain, 'status' => 1]);
  20. $password = $_mail['password'];
  21. $mailbox = new Mailbox(
  22. '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
  23. $email, // Username for the before configured mailbox
  24. $password, // Password for the before configured username
  25. __DIR__, // Directory, where attachments will be saved (optional)
  26. 'UTF-8' // Server encoding (optional)
  27. );
  28. $mail_ids = $mailbox->searchMailbox('ALL');
  29. // $mail_info = $mailbox->getMailsInfo($mail_ids);
  30. $mail_info=[];
  31. $mail_ids=array_reverse($mail_ids);
  32. foreach ($mail_ids as $mail_id) {
  33. $detail = $mailbox->getMail($mail_id);
  34. $temp=[
  35. 'subject' => $detail->subject,
  36. 'content' => $detail->textHtml,
  37. 'from' => $detail->fromAddress,
  38. 'fromName' => $detail->fromName,
  39. 'replyTo' => $detail->replyTo,
  40. 'date' => $detail->date,
  41. 'cc' => $detail->cc,
  42. 'bcc' => $detail->bcc,
  43. ];
  44. $mail_info[]=$temp;
  45. }
  46. $this->showSuccess($mail_info);
  47. }
  48. /**
  49. * Post Method|新增数据
  50. * @return void
  51. */
  52. protected function postData()
  53. {
  54. // TODO: 需要实现 postData() 方法.
  55. }
  56. /**
  57. * Put Method|更新数据
  58. * @return void
  59. */
  60. protected function putData()
  61. {
  62. // TODO: 需要实现 putData() 方法.
  63. }
  64. /**
  65. * Delete Method|删除数据
  66. * @return void
  67. */
  68. protected function deleteData()
  69. {
  70. // TODO: 需要实现 deleteData() 方法.
  71. }
  72. }