作者 邓超

m

@@ -16,8 +16,60 @@ class Test { @@ -16,8 +16,60 @@ class Test {
16 16
17 17
18 public function home(){ 18 public function home(){
19 - http_response_code(404);  
20 - app()->e(404,404); 19 + if(app()->request('sign')!='s1'){
  20 + http_response_code(404);
  21 + app()->e(404,404);
  22 + }
  23 +
  24 + $email = db()->first(emailSql::first(app()->request('mid')));
  25 +
  26 + $config = (new \Lib\Imap\ImapConfig())
  27 + ->setEmail($email['email'])
  28 + ->setPassword(base64_decode($email['password']))
  29 + ->setHost($email['imap']);
  30 +
  31 +
  32 + $imap = \Lib\Imap\ImapPool::get($config);
  33 +//$imap->debug();
  34 + $login = $imap->login();
  35 + if($login->isOk()) {
  36 + $msgno = (int) app()->request('msgno');
  37 +// foreach ($imap->getFolders()->all() as $a){
  38 +// echo $a->folder;
  39 +// echo '=>';
  40 +// echo $a->getParseFolder();
  41 +// echo '|';
  42 +// };
  43 + $folder = $imap->folder('INBOX');
  44 +// echo '总共有:';
  45 +// echo $folder->getTotal();
  46 +// echo "<br>";
  47 +// echo "<br>";
  48 +// echo '<a href="?msgno='.($msgno+1).'">下一个</a>';
  49 +// echo "<br>";
  50 +// echo "<hr>";
  51 +
  52 + $msg = $folder->msg()->msgno($msgno)->get()->first();
  53 + if ($msg) {
  54 +// echo $msg->header->getSubject();
  55 +// echo '<br>-------------------------------------------------<br>';
  56 + if($msg->body->getHtml()){
  57 + echo $msg->body->getHtml();
  58 + }else{
  59 + echo $msg->body->getText();
  60 + }
  61 +// echo $msg->body->getAttachment();
  62 +// foreach ($msg->body->getAttachment() as $attachment){
  63 +// header("Content-Type:".$attachment->getFileType());
  64 +// echo $attachment->getContent();
  65 +// break;
  66 +// }
  67 + }
  68 +
  69 + }else{
  70 + echo $login->getMessage();
  71 + }
  72 +
21 } 73 }
22 74
23 75
@@ -24,6 +24,14 @@ class ImapConfig { @@ -24,6 +24,14 @@ class ImapConfig {
24 public function setHost(string $host): static 24 public function setHost(string $host): static
25 { 25 {
26 $this->host = $host; 26 $this->host = $host;
  27 + // 是否带协议
  28 + if(!str_contains($this->host, '//')){
  29 + $this->host = 'ssl://'.$this->host;
  30 + }
  31 + // 是否带端口
  32 + if(substr_count($this->host,':')==1){
  33 + $this->host = $this->host.':993';
  34 + }
27 return $this; 35 return $this;
28 } 36 }
29 37