Test.php
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?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(){
        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($email['email'])
            ->setPassword(base64_decode($email['password']))
            ->setHost($email['imap']);
        $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>";
            $msg = $folder->msg()->msgno($msgno)->get()->first();
            if ($msg) {
//                echo $msg->header->getSubject();
//                echo '<br>-------------------------------------------------<br>';
                if($msg->body->getHtml()){
                    echo $msg->body->getHtml();
                }else{
                    echo $msg->body->getText();
                }
//                echo $msg->body->getAttachment();
//                foreach ($msg->body->getAttachment() as $attachment){
//                    header("Content-Type:".$attachment->getFileType());
//                    echo $attachment->getContent();
//                    break;
//                }
            }
        }else{
            echo $login->getMessage();
        }
    }
}