| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace Heanup\App\Api\Controller\Mail;
- use Heanup\App\Api\Package\Database\Mail;
- use Heanup\App\Api\RestfulController;
- use PhpImap\Exceptions\InvalidParameterException;
- use PhpImap\Mailbox;
- class Lists extends RestfulController
- {
- /**
- * Get Method|获取数据
- * @return void
- * @throws InvalidParameterException
- */
- protected function getData()
- {
- $email=$this->getQuery()->string("u");
- $account = substr($email, 0, strpos($email, "@"));
- $domain = substr($email, strpos($email, "@") + 1);
- $_mail = Mail::getOne(['email' => $account, 'domain' => $domain, 'status' => 1]);
- $password = $_mail['password'];
- // $mailbox = new Mailbox(
- // '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
- // $email, // Username for the before configured mailbox
- // $password, // Password for the before configured username
- // __DIR__, // Directory, where attachments will be saved (optional)
- // 'UTF-8' // Server encoding (optional)
- // );
- $mailbox = new Mailbox(
- '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
- "chen6485882@gmail.com", // Username for the before configured mailbox
- "chendeben6485882", // Password for the before configured username
- __DIR__, // Directory, where attachments will be saved (optional)
- 'UTF-8' // Server encoding (optional)
- );
- $mail_ids = $mailbox->searchMailbox('FROM txt.voice.google.com');
- // $mail_info = $mailbox->getMailsInfo($mail_ids);
- $mail_info=[];
- $mail_ids=array_reverse($mail_ids);
- $i=0;
- foreach ($mail_ids as $mail_id) {
- if ($i>=3){
- break;
- }
- $i++;
- $detail = $mailbox->getMail($mail_id);
- $txt=explode("\r\n", $detail->textPlain);
- $temp=[
- 'subject' => $detail->subject,
- 'content' => $txt[1],
- 'from' => $detail->fromAddress,
- 'fromName' => $detail->fromName,
- 'replyTo' => $detail->replyTo,
- 'date' => $detail->date,
- 'cc' => $detail->cc,
- 'bcc' => $detail->bcc,
- ];
- $mail_info[]=$temp;
- }
- $this->showSuccess($mail_info);
- }
- /**
- * Post Method|新增数据
- * @return void
- */
- protected function postData()
- {
- // TODO: 需要实现 postData() 方法.
- }
- /**
- * Put Method|更新数据
- * @return void
- */
- protected function putData()
- {
- // TODO: 需要实现 putData() 方法.
- }
- /**
- * Delete Method|删除数据
- * @return void
- */
- protected function deleteData()
- {
- // TODO: 需要实现 deleteData() 方法.
- }
- }
|