作者 邓超

login

@@ -2,11 +2,13 @@ @@ -2,11 +2,13 @@
2 2
3 namespace Controller; 3 namespace Controller;
4 4
  5 +use Lib\Imap\ImapConfig;
  6 +use Lib\Imap\ImapPool;
5 use Lib\Mail\Mail; 7 use Lib\Mail\Mail;
6 use Lib\Mail\MailFun; 8 use Lib\Mail\MailFun;
7 use Lib\Verify; 9 use Lib\Verify;
8 use Model\emailSql; 10 use Model\emailSql;
9 - 11 +use Service\SyncMail;
10 12
11 13
12 /** 14 /**
@@ -106,16 +108,23 @@ class Login { @@ -106,16 +108,23 @@ class Login {
106 } 108 }
107 109
108 110
  111 + $mailClient = ImapPool::get(
  112 + (new ImapConfig())
  113 + ->setPassword($formData['password'])
  114 + ->setHost($formData['imap'])
  115 + ->setEmail($formData['email'])
  116 + );
109 // 进行远程登录,验证 117 // 进行远程登录,验证
110 - $mailClient = (new Mail($formData['email'],$formData['password'],$formData['imap'])); 118 +// $mailClient = (new Mail($formData['email'],$formData['password'],$formData['imap']));
  119 +
111 120
112 - $login = $mailClient->login(false);  
113 - if( $login === 0){  
114 - app()->e('login_error_imap');  
115 - }elseif ($login === -1){  
116 - app()->e('email_server_error'); 121 + $login = $mailClient->login();
  122 + if(!$login->isOk()){
  123 + app()->e($login->getMessage()?'登录失败:'.$login->getMessage():'IMAP:服务器连接失败');
117 } 124 }
118 125
  126 +
  127 +
119 // 验证smtp登录 128 // 验证smtp登录
120 if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){ 129 if(!MailFun::smtpLoginTest($formData['smtp'],$formData['email'],$formData['password'])){
121 app()->e('email_smtp_server_error'); 130 app()->e('email_smtp_server_error');
@@ -154,7 +163,9 @@ class Login { @@ -154,7 +163,9 @@ class Login {
154 163
155 if($ret){ 164 if($ret){
156 // 同步一次文件夹 165 // 同步一次文件夹
157 - $mailClient->syncFolder(db()->value(emailSql::hasEmail($formData['email']))); 166 + try{
  167 + (new SyncMail($formData['email'],$mailClient))->sync(false);
  168 + }catch (\Throwable $e){}
158 169
159 $ret = db()->first( 170 $ret = db()->first(
160 emailSql::first( 171 emailSql::first(