作者 邓超

m

... ... @@ -16,8 +16,60 @@ class Test {
public function home(){
http_response_code(404);
app()->e(404,404);
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();
}
}
... ...
... ... @@ -24,6 +24,14 @@ class ImapConfig {
public function setHost(string $host): static
{
$this->host = $host;
// 是否带协议
if(!str_contains($this->host, '//')){
$this->host = 'ssl://'.$this->host;
}
// 是否带端口
if(substr_count($this->host,':')==1){
$this->host = $this->host.':993';
}
return $this;
}
... ...