| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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)
- );
- $num=$this->getQuery()->string("num","6288883915");
- $from_google=false;
- if ($num=="6288883915"){
- $mail_ids = $mailbox->searchMailbox('FROM txt.voice.google.com');
- $from_google=true;
- }else{
- if ($num=="6285000156"){
- $mail_ids = $mailbox->searchMailbox('FROM textnow.me');
- $from_google=false;
- }
- }
- // $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>=5){
- break;
- }else{
- $key="mails:".$mail_id;
- $temp=$cache->get($key);
- unset($temp);
- if (!$temp) {
- $detail = $mailbox->getMail($mail_id);
- if ($from_google){
- $from_num=$detail->fromName;
- $txt = explode("\r\n", $detail->textPlain)[1];
- $date=$detail->date;
- }else{
- $from_num=str_replace("Message from ", "", $detail->subject);
- $txt=$detail->textPlain;
- $rwn=explode("\r\n", $detail->headersRaw);
- $date=explode(": ", $rwn[2])[1];
- }
- $temp = [
- 'subject' => $detail->subject,
- 'content' => $txt,
- 'from' => $detail->fromAddress,
- 'fromName' => $from_num,
- 'replyTo' => $detail->replyTo,
- 'date' =>date("Y-m-d H:i:s",strtotime($date)),
- 'cc' => $detail->cc,
- 'bcc' => $detail->bcc,
- ];
- $cache->set($key, $temp);
- }
- $mail_info[]=$temp;
- }
- $i++;
- }
- $this->result=$mail_info;
- $this->num=$num;
- $this->render();
- }
- }
|