作者 邓超

1

@@ -26,7 +26,7 @@ abstract class Base { @@ -26,7 +26,7 @@ abstract class Base {
26 protected final function getEmails($filed='*'){ 26 protected final function getEmails($filed='*'){
27 static $data; 27 static $data;
28 if(empty($data)){ 28 if(empty($data)){
29 - $data = db()->all(emailSql::all(web_request_emails())); 29 + $data = db()->all(emailSql::all(dbWhere(['email'=>web_request_emails()])));
30 if(empty($data)){ 30 if(empty($data)){
31 app()->e('email_request_required'); 31 app()->e('email_request_required');
32 } 32 }
@@ -109,7 +109,7 @@ class Folder extends Base { @@ -109,7 +109,7 @@ class Folder extends Base {
109 // 远程创建 109 // 远程创建
110 $mail = new Mail( 110 $mail = new Mail(
111 $email['email'], 111 $email['email'],
112 - $email['password'], 112 + base64_decode($email['password']),
113 $email['imap'] 113 $email['imap']
114 ); 114 );
115 115
@@ -2,9 +2,11 @@ @@ -2,9 +2,11 @@
2 2
3 namespace Controller; 3 namespace Controller;
4 4
  5 +use Lib\Mail\Mail;
5 use Lib\Mail\MailFun; 6 use Lib\Mail\MailFun;
6 use Lib\Verify; 7 use Lib\Verify;
7 use Model\emailSql; 8 use Model\emailSql;
  9 +use Model\folderSql;
8 use Model\listsSql; 10 use Model\listsSql;
9 11
10 12
@@ -144,6 +146,74 @@ class Home extends Base { @@ -144,6 +146,74 @@ class Home extends Base {
144 } 146 }
145 147
146 148
  149 + /**
  150 + * 标记为已读
  151 + * @throws \Lib\Err
  152 + * @author:dc
  153 + * @time 2023/3/17 16:15
  154 + */
  155 + public function seen_2_unseen(){
  156 + $emails = $this->getEmails();
  157 +
  158 + $mail_ids = app()->request('mail_ids');
  159 + foreach ($mail_ids as $k=>$id){
  160 + if(!is_numeric($id)){
  161 + unset($mail_ids[$k]);
  162 + }
  163 + }
  164 + // 已读或未读
  165 + $seen = (int) app()->request('seen');
  166 + $seen = $seen ? 1 : 0;
  167 +
  168 + $data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')])));
  169 + if($data){
  170 + // 查询邮箱
  171 + $emails = array_column($emails,null,'id');
  172 + $uids = [];
  173 + foreach ($data as $datum){
  174 + if(empty($uids[$datum['email_id']])){
  175 + $uids[$datum['email_id']][$datum['folder_id']] = [];
  176 + }
  177 + $uids[$datum['email_id']][$datum['folder_id']][] = [
  178 + 'uid' => $datum['uid'],
  179 + 'id' => $datum['id'],
  180 + ];
  181 + }
  182 +
  183 + foreach ($uids as $eid=>$arr){
  184 + foreach ($arr as $fid=>$uid){
  185 + // 查询目录
  186 + $folder = db()->first(folderSql::first($fid));
  187 + if($folder){
  188 + // 开始远程
  189 + $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']);
  190 +
  191 + $mailInstance->login();
  192 +
  193 + $mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen);
  194 +
  195 + $mailInstance = null;
  196 + // 更新数据
  197 + db()->update(listsSql::$table,[
  198 + 'seen' => $seen
  199 + ],dbWhere([
  200 + 'id' => array_column($uid,'id')
  201 + ]));
  202 +
  203 + }
  204 + $folder = null;
  205 + }
  206 + }
  207 +
  208 + }
  209 +
  210 +
  211 + app()->_json([
  212 + 'mail_id' => $mail_ids
  213 + ]);
  214 +
  215 +
  216 + }
147 217
148 218
149 219
@@ -62,6 +62,7 @@ return [ @@ -62,6 +62,7 @@ return [
62 62
63 63
64 64
  65 + 'mail_not' => '邮件不存在'
65 66
66 67
67 68
@@ -303,5 +303,20 @@ class Mail { @@ -303,5 +303,20 @@ class Mail {
303 } 303 }
304 304
305 305
  306 + /**
  307 + * 设置为未读
  308 + * @param $uids
  309 + * @return bool
  310 + * @throws \Exception
  311 + * @author:dc
  312 + * @time 2022/10/26 17:11
  313 + */
  314 + public function seen($uids,$folder,$seen):bool{
  315 + // 选择目录
  316 + $status = $this->client->selectFolder($folder);
  317 +
  318 + return $this->client->flags($uids,[Imap::FLAGS_SEEN],$seen ? '+' : '-',true);
  319 + }
  320 +
306 321
307 } 322 }
@@ -66,14 +66,14 @@ class emailSql { @@ -66,14 +66,14 @@ class emailSql {
66 66
67 67
68 /** 68 /**
69 - * 通过邮箱查询列表  
70 - * @param $emails 69 + * 查询列表
  70 + * @param string $where
71 * @return string 71 * @return string
72 * @author:dc 72 * @author:dc
73 - * @time 2023/3/10 15:02 73 + * @time 2023/3/17 16:32
74 */ 74 */
75 - public static function all($emails){  
76 - return "select * from ".static::$table." where ".dbWhere(['email'=>$emails]); 75 + public static function all(string $where){
  76 + return "select * from ".static::$table." where ".$where;
77 } 77 }
78 78
79 79
@@ -87,6 +87,17 @@ class listsSql { @@ -87,6 +87,17 @@ class listsSql {
87 return "select `id`,`email_id`,`uuid` from `".self::$table."` where ".dbWhere(['uuid'=>$uuid]); 87 return "select `id`,`email_id`,`uuid` from `".self::$table."` where ".dbWhere(['uuid'=>$uuid]);
88 } 88 }
89 89
  90 + /**
  91 + * 根据id查询
  92 + * @param string $where
  93 + * @return string
  94 + * @author:dc
  95 + * @time 2023/3/17 16:24
  96 + */
  97 + public static function first(string $where):string {
  98 +
  99 + return "select * from `".self::$table."` where ".$where;
  100 + }
90 101
91 102
92 103
@@ -29,6 +29,8 @@ return [ @@ -29,6 +29,8 @@ return [
29 'send' => [\Controller\Home::class, 'send_mail'], 29 'send' => [\Controller\Home::class, 'send_mail'],
30 // 同步请求 30 // 同步请求
31 'sync' => [\Controller\Home::class, 'sync'], 31 'sync' => [\Controller\Home::class, 'sync'],
  32 +// 标记为已读
  33 + 'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
32 34
33 35
34 36