<?php

namespace Controller;

use Lib\Mail\MailFun;
use Model\emailSql;
use Model\listsSql;

/**
 * @author:dc
 * @time 2023/2/13 11:28
 * Class Home
 * @package Controller
 */
class Test {


    public function home(){



//        $urlGetSign = function ($mobile){
//            $time = time();
//            $s = 'MindrHbWGJaEfhw85oQW3LYTnUMebm4H';
//            $data = [
//                'app_id'    =>    10002415,
//                'timestamp' =>  $time
//            ];
//            $data = http_build_query($data);
//
//            $sign = md5(md5($data).$s);
//
//            return 'http://local.admin.hagro.cn/'.app()->request('route').'?iframe_sign='.
//            base64_encode($mobile.'.'.$sign.'.'.$time);
//        };
//
//
//        $url = $urlGetSign('18868868868');
//        return '<html>
//<head><title>403 您没有权限访问</title></head>
//<body>
//<div style="display: flex">
//<div style="width: 200px;">
//<p><a href="/?route=ai_search">ai搜索</a></p>
//<p><a href="/?route=ai_company_search">企业洞察</a></p>
//<p><a href="/?route=ai_keyperson">ai决策人</a></p>
//<p><a href="/?route=customer_guide">海关数据</a></p>
//<p><a href="/?route=tools/tool_mobile_verify">验证手机号</a></p>
//<p><a href="/?route=tools/tool_translate">智能翻译</a></p>
//<p><a href="/?route=tools/tool_exchange_rate">实时汇率</a></p>
//<p><a href="/?route=tools/tool_mailbox_verify">邮箱验证</a></p>
//<p><a href="/?route=tools/tool_vat">VAT查询</a></p>
//<p><a href="/?route=pro/article/31">海外社媒(AI)</a></p>
//<p><a href="/?route=pro/article/29">网站文案(AI)</a></p>
//<p><a href="/?route=pro/article/73">邮件助手(AI)</a></p>
//<p><a href="/?route=pro/article/74">企业应用(AI)</a></p>
//<p><a href="/?route=pro/e/commerce">跨境电商(AI)</a></p>
//</div>
//<iframe src="'.$url.'" frameborder="0" style="width: 100%;height: 100vh;"></iframe>
//</div>
//
//</body>
//</html>';

//        if(app()->request('sign')!='s1'){
//            http_response_code(404);
//            app()->e(404,404);
//        }
//
////        $email = db()->first(emailSql::first(app()->request('mid')));
//
//        $config = (new \Lib\Imap\ImapConfig())
//            ->setEmail('CService001@spicay-meart.com')
//            ->setPassword('5YmS77JBb7JJwuaD')
//            ->setHost('imap.exmail.qq.com');


        $imap = \Lib\Imap\ImapPool::get($config);
//$imap->debug();
        $login = $imap->login();
        if($login->isOk()) {
            $msgno = (int) app()->request('msgno');
//            foreach ($imap->getFolders()->all() as $a){
//                echo $a->folder;
//                echo '=>';
//                echo $a->getParseFolder();
//                echo '|';
//            };
            $folder = $imap->folder('INBOX');
            echo '总共有:';
            echo $folder->getTotal();
            echo "<br>";
            echo "<br>";
            echo '<a href="?msgno='.($msgno+1).'">下一个</a>';
            echo "<br>";
            echo "<hr>";

            $msgs = $folder->msg()->forPage(449)->get();
            if ($msgs) {
                $msgs->each(function ($msg){
                    echo '<p>'.$msg->uid.'==>'.$msg->header->getSubject().' =====> '.date('Y-m-d H:i:s',strtotime($msg->date)).'</p>';
                });
//                echo $msg->header->getSubject();
//                echo '<br>-------------------------------------------------<br>';
//                if($msg->body->getHtml()){
//                    echo $msg->body->getHtml();
//                }else{
//                    echo $msg->body->getText();
//                }
//                $msg->header->getRaw()
//                echo $msg->body->getAttachment();
//                foreach ($msg->body->getAttachment() as $attachment){
//                    header("Content-Type:".$attachment->getFileType());
//                    echo $attachment->getContent();
//                    break;
//                }
            }

        }else{
            echo $login->getMessage();
        }

    }



}