Lists.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $mailbox = new Mailbox(
  29. '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
  30. "chen6485882@gmail.com", // Username for the before configured mailbox
  31. "chendeben6485882", // Password for the before configured username
  32. __DIR__, // Directory, where attachments will be saved (optional)
  33. 'UTF-8' // Server encoding (optional)
  34. );
  35. $mail_ids = $mailbox->searchMailbox('FROM txt.voice.google.com');
  36. // $mail_info = $mailbox->getMailsInfo($mail_ids);
  37. $mail_info=[];
  38. $mail_ids=array_reverse($mail_ids);
  39. $i=0;
  40. foreach ($mail_ids as $mail_id) {
  41. if ($i>=3){
  42. break;
  43. }
  44. $i++;
  45. $detail = $mailbox->getMail($mail_id);
  46. $txt=explode("\r\n", $detail->textPlain);
  47. $temp=[
  48. 'subject' => $detail->subject,
  49. 'content' => $txt[1],
  50. 'from' => $detail->fromAddress,
  51. 'fromName' => $detail->fromName,
  52. 'replyTo' => $detail->replyTo,
  53. 'date' => $detail->date,
  54. 'cc' => $detail->cc,
  55. 'bcc' => $detail->bcc,
  56. ];
  57. $mail_info[]=$temp;
  58. }
  59. $this->showSuccess($mail_info);
  60. }
  61. /**
  62. * Post Method|新增数据
  63. * @return void
  64. */
  65. protected function postData()
  66. {
  67. // TODO: 需要实现 postData() 方法.
  68. }
  69. /**
  70. * Put Method|更新数据
  71. * @return void
  72. */
  73. protected function putData()
  74. {
  75. // TODO: 需要实现 putData() 方法.
  76. }
  77. /**
  78. * Delete Method|删除数据
  79. * @return void
  80. */
  81. protected function deleteData()
  82. {
  83. // TODO: 需要实现 deleteData() 方法.
  84. }
  85. }