| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Heanup\App\Api\Controller;
- use Heanup\App\Api\Controller;
- use Heanup\Library\Redis;
- use PhpImap\Mailbox;
- class Msg extends Controller
- {
- /**
- * Get Method|获取数据
- * @return void
- */
- protected function main()
- {
- $mailbox = new Mailbox(
- '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
- "gv@a4sky.com", // Username for the before configured mailbox
- "6485882", // Password for the before configured username
- __DIR__, // Directory, where attachments will be saved (optional)
- 'UTF-8' // Server encoding (optional)
- );
- $mail_ids = $mailbox->searchMailbox('ALL');
- // $mail_info = $mailbox->getMailsInfo($mail_ids);
- $mail_info=[];
- $mail_ids=array_reverse($mail_ids);
- $i=0;
- // $cache = new FileCache([
- // 'root' => APP_DIR.'/cache', // Cache root
- // 'ttl' => 0, // Time to live
- // 'compress' => false, // Compress data with gzcompress or not
- // 'serialize' => 'json', // How to serialize data: json, php, raw
- // ]);
- $cache=Redis::instance();
- foreach ($mail_ids as $mail_id) {
- if ($i>=10){
- // $mailbox->deleteMail($mail_id);
- break;
- }else{
- $key="mails:".$mail_id;
- $temp=$cache->get($key);
- if (!$temp) {
- $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,
- ];
- $cache->set($key, $temp);
- }
- $mail_info[]=$temp;
- }
- $i++;
- }
- $this->result=$mail_info;
- $this->render();
- }
- }
|