作者 张关杰

服务器提交

@@ -2,4 +2,17 @@ @@ -2,4 +2,17 @@
2 composer.lock 2 composer.lock
3 vendor 3 vendor
4 config.php 4 config.php
5 -public/temp  
  5 +public/temp
  6 +public/attachment
  7 +public/attachment2
  8 +public/attachment2025
  9 +index.html
  10 +eml
  11 +log
  12 +public/.user.ini
  13 +public/.well-known
  14 +public/storage
  15 +cmd/*.log
  16 +*.log
  17 +.htaccess
  18 +404.html
@@ -59,7 +59,7 @@ class AutoMail { @@ -59,7 +59,7 @@ class AutoMail {
59 if(redis()->add('auto_mail_sync2',1,60)){ 59 if(redis()->add('auto_mail_sync2',1,60)){
60 _echo('正在计算数据'); 60 _echo('正在计算数据');
61 $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); 61 $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
62 - $startId = $maxId-20000; 62 + $startId = $maxId-200000;
63 63
64 foreach (minMaxToArray($startId,$maxId) as $ids){ 64 foreach (minMaxToArray($startId,$maxId) as $ids){
65 redis()->rPush('auto_check_ids',implode(',',$ids)); 65 redis()->rPush('auto_check_ids',implode(',',$ids));
@@ -38,7 +38,7 @@ class HotMail { @@ -38,7 +38,7 @@ class HotMail {
38 if(redis()->add('hot_mail_sync2',1,60)){ 38 if(redis()->add('hot_mail_sync2',1,60)){
39 _echo( '正在计算数据'); 39 _echo( '正在计算数据');
40 $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1"); 40 $maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
41 - foreach (minMaxToArray($maxId-100000,$maxId) as $ids){ 41 + foreach (minMaxToArray($maxId-50000,$maxId) as $ids){
42 redis()->rPush('hot_check_ids',implode(',',$ids)); 42 redis()->rPush('hot_check_ids',implode(',',$ids));
43 } 43 }
44 _echo( '计算完成'); 44 _echo( '计算完成');
@@ -99,10 +99,10 @@ class HotMail { @@ -99,10 +99,10 @@ class HotMail {
99 } 99 }
100 } 100 }
101 101
102 - $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>1]),'`id`'));  
103 - foreach ($list as $item){  
104 - redis()->rPush('sync_to_es',$item['id']);  
105 - } 102 + // $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>1]),'`id`'));
  103 + // foreach ($list as $item){
  104 + // redis()->rPush('sync_to_es',$item['id']);
  105 + // }
106 } 106 }
107 107
108 108
@@ -73,7 +73,7 @@ function start(){ @@ -73,7 +73,7 @@ function start(){
73 73
74 }catch (Throwable $e){ 74 }catch (Throwable $e){
75 if(!strpos($e->getMessage(),'read time out')){ 75 if(!strpos($e->getMessage(),'read time out')){
76 - logs('sync : '.$e->getMessage()); 76 + logs('sync : '.($email['email']??'').' '.$e->getMessage());
77 } 77 }
78 } 78 }
79 79
@@ -4,6 +4,13 @@ @@ -4,6 +4,13 @@
4 4
5 require_once "../vendor/autoload.php"; 5 require_once "../vendor/autoload.php";
6 6
  7 +
  8 +if(in_array('v2',$argv)){
  9 + define('S_V2','2');
  10 +}else{
  11 + define('S_V2','');
  12 +}
  13 +
7 /** 14 /**
8 * 把mysql的数据同步到es 15 * 把mysql的数据同步到es
9 * @author:dc 16 * @author:dc
@@ -37,7 +44,12 @@ class SyncToEsCmd { @@ -37,7 +44,12 @@ class SyncToEsCmd {
37 // pcntl_signal(SIGHUP, $handler); 44 // pcntl_signal(SIGHUP, $handler);
38 45
39 46
40 - $es = es(); 47 + if(S_V2){
  48 + $es = es('email_lists');
  49 + }else{
  50 + $es = es();
  51 + }
  52 +
41 $db = db(); 53 $db = db();
42 $this->fob_db = fob_mysql(); 54 $this->fob_db = fob_mysql();
43 $startTime = time(); 55 $startTime = time();
@@ -55,14 +67,14 @@ class SyncToEsCmd { @@ -55,14 +67,14 @@ class SyncToEsCmd {
55 break; 67 break;
56 } 68 }
57 69
58 - $id = redis()->lPop('sync_to_es'); 70 + $id = redis()->lPop('sync_to_es'.S_V2);
59 $code = 500; 71 $code = 500;
60 if($id){ 72 if($id){
61 $doc_id = ''; 73 $doc_id = '';
62 try { 74 try {
63 $data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id)); 75 $data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id));
64 }catch (Throwable $e){ 76 }catch (Throwable $e){
65 - redis()->rPush('sync_to_es',$id); 77 + redis()->rPush('sync_to_es'.S_V2,$id);
66 _echo('sync to es '.$e->getMessage()); 78 _echo('sync to es '.$e->getMessage());
67 break; 79 break;
68 } 80 }
@@ -70,15 +82,20 @@ class SyncToEsCmd { @@ -70,15 +82,20 @@ class SyncToEsCmd {
70 if($data){ 82 if($data){
71 // 设置 进程 是否在运行 83 // 设置 进程 是否在运行
72 $data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0; 84 $data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
73 - // 文件夹  
74 - if(empty($this->folders[$data['folder_id']])){  
75 - $this->folders[$data['folder_id']] = $db->throw()->value(\Model\folderSql::first($data['folder_id'],'folder')); 85 + try {
  86 + // 文件夹
  87 + if(empty($this->folders[$data['folder_id']])){
  88 + $this->folders[$data['folder_id']] = $db->throw()->value(\Model\folderSql::first($data['folder_id'],'folder'));
  89 + }
  90 + // 为文件夹打标 方便查询
  91 + $data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);
  92 + // postid ai邮箱要用 这个是查询黑格
  93 + $data['postid'] = $this->getPostid($data['email_id']);
  94 + }catch (Throwable $e){
  95 + redis()->rPush('sync_to_es'.S_V2,$id);
  96 + _echo('sync to es '.$e->getMessage());
  97 + break;
76 } 98 }
77 - // 为文件夹打标 方便查询  
78 - $data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);  
79 - // postid ai邮箱要用 这个是查询黑格  
80 - $data['postid'] = $this->getPostid($data['email_id']);  
81 -  
82 99
83 $data = $this->getEsData($data); 100 $data = $this->getEsData($data);
84 $doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid']; 101 $doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];
@@ -87,7 +104,7 @@ class SyncToEsCmd { @@ -87,7 +104,7 @@ class SyncToEsCmd {
87 } 104 }
88 105
89 if($code!==200){ 106 if($code!==200){
90 - @file_put_contents(LOG_PATH.'/sync_es_fail.log',$id."\n",FILE_APPEND); 107 + @file_put_contents(LOG_PATH.'/sync_es_fail'.S_V2.'.log',$id."\n",FILE_APPEND);
91 _echo('同步es: '.$doc_id.'===>'.$code); 108 _echo('同步es: '.$doc_id.'===>'.$code);
92 } 109 }
93 110
@@ -106,9 +123,14 @@ class SyncToEsCmd { @@ -106,9 +123,14 @@ class SyncToEsCmd {
106 * @time 2025/5/20 15:44 123 * @time 2025/5/20 15:44
107 */ 124 */
108 public function getPostid($email_id){ 125 public function getPostid($email_id){
109 - $h = date('dhi');  
110 - if(empty($this->postids[$h][$email_id])){  
111 - $id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' and `source` = 2 and `deleted_at` is null order by `id` desc limit 1 "); 126 + $h = date('dh');
  127 + if(!isset($this->postids[$h][$email_id])){
  128 + // 未删除状态
  129 + $id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' and `deleted_at` is null order by `id` desc limit 1 ");
  130 + if(!$id){
  131 + // 已删状态
  132 + $id = (int) $this->fob_db->throw()->value("select `post_id` from `e_mail_binds` where `email_id` = '{$email_id}' order by `id` desc limit 1 ");
  133 + }
112 $this->postids[$h][$email_id] = $id; 134 $this->postids[$h][$email_id] = $id;
113 } 135 }
114 136
@@ -144,6 +166,8 @@ class SyncToEsCmd { @@ -144,6 +166,8 @@ class SyncToEsCmd {
144 $data['to_name'] = ''; 166 $data['to_name'] = '';
145 } 167 }
146 } 168 }
  169 + $data['description'] = str_replace(["\n"],"",$data['description']);
  170 + // unset($data['to_name']);
147 171
148 if(!empty($data['created_at'])){ 172 if(!empty($data['created_at'])){
149 $data['created_at'] = date('Y-m-d\TH:i:s',strtotime($data['created_at'])); 173 $data['created_at'] = date('Y-m-d\TH:i:s',strtotime($data['created_at']));
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 "ext-mbstring": "*", 11 "ext-mbstring": "*",
12 "ext-pdo": "*", 12 "ext-pdo": "*",
13 "ext-redis": "*", 13 "ext-redis": "*",
14 - "elasticsearch/elasticsearch": "7.x", 14 + "elasticsearch/elasticsearch": "8.1.*",
15 "phpmailer/phpmailer": "^6.7", 15 "phpmailer/phpmailer": "^6.7",
16 "swlib/saber": "^1.0" 16 "swlib/saber": "^1.0"
17 }, 17 },
@@ -997,6 +997,12 @@ class Home extends Base { @@ -997,6 +997,12 @@ class Home extends Base {
997 $body = db()->first(bodySql::first($id)); 997 $body = db()->first(bodySql::first($id));
998 if(!$body){ 998 if(!$body){
999 $body = db()->first("select * from `bodies_back` where `lists_id` = ".$id." limit 1"); 999 $body = db()->first("select * from `bodies_back` where `lists_id` = ".$id." limit 1");
  1000 + // if(!$body){
  1001 + // $body = @file_get_contents('http://172.19.0.5:9527?id='.$id);
  1002 + // if($body){
  1003 + // $body = ['lists_id'=>$id,'text_html'=>$body];
  1004 + // }
  1005 + // }
1000 } 1006 }
1001 if($body && !$reload){ 1007 if($body && !$reload){
1002 $data['body'] = json_decode($body['text_html'],true); 1008 $data['body'] = json_decode($body['text_html'],true);
@@ -17,7 +17,7 @@ class Test { @@ -17,7 +17,7 @@ class Test {
17 17
18 public function home(){ 18 public function home(){
19 19
20 - 20 +return 404;
21 21
22 // $urlGetSign = function ($mobile){ 22 // $urlGetSign = function ($mobile){
23 // $time = time(); 23 // $time = time();
@@ -242,7 +242,7 @@ class MailListV2Es extends Base { @@ -242,7 +242,7 @@ class MailListV2Es extends Base {
242 242
243 243
244 // $result = $this->es->search(['query'=>$query],($page-1) * $limit,$limit,['udate'=>"desc"]); 244 // $result = $this->es->search(['query'=>$query],($page-1) * $limit,$limit,['udate'=>"desc"]);
245 - $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"]); 245 + $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"],($where['is_hots']==1||$folder=='垃圾箱')?10000:true);
246 246
247 247
248 $total = $result['hits']['total']['value']??0; 248 $total = $result['hits']['total']['value']??0;
@@ -282,7 +282,7 @@ class MailListV2Es extends Base { @@ -282,7 +282,7 @@ class MailListV2Es extends Base {
282 } 282 }
283 283
284 // 手动触发同步es 284 // 手动触发同步es
285 -// redis()->rPush('sync_to_es',$v['id']); 285 + redis()->rPush('sync_to_es',$v['id']);
286 286
287 return $v; 287 return $v;
288 },$lists?:[]); 288 },$lists?:[]);
@@ -489,7 +489,14 @@ class MailListV2Es extends Base { @@ -489,7 +489,14 @@ class MailListV2Es extends Base {
489 private function countHot($body,$folder){ 489 private function countHot($body,$folder){
490 $body['query']['bool']['must'][] = ['term'=>['is_hots'=>1]]; 490 $body['query']['bool']['must'][] = ['term'=>['is_hots'=>1]];
491 $body['query']['bool']['must'][] = $this->assignSql3($folder); 491 $body['query']['bool']['must'][] = $this->assignSql3($folder);
492 - return $this->es->count($body); 492 + $key = 'hot_count:'.md5(json_encode($body));
  493 + $a = redis()->get($key);
  494 + if(!is_numeric($a)){
  495 + $a = $this->es->count($body);
  496 + redis()->set($key,$a,strtotime(date('Y-m-d',strtotime("+1 day"))) - time());
  497 + }
  498 + return $a;
  499 + // return $this->es->count($body);
493 } 500 }
494 501
495 private function countMail($body,$folder,$seen=null){ 502 private function countMail($body,$folder,$seen=null){
@@ -518,6 +525,17 @@ class MailListV2Es extends Base { @@ -518,6 +525,17 @@ class MailListV2Es extends Base {
518 } 525 }
519 $body['query']['bool']['must'][] = ['term'=>['is_hots'=>0]]; 526 $body['query']['bool']['must'][] = ['term'=>['is_hots'=>0]];
520 $body['query']['bool']['must'][] = $this->assignSql($folder); 527 $body['query']['bool']['must'][] = $this->assignSql($folder);
  528 +
  529 + if($folder=='垃圾箱'){
  530 + $key = 'laji_count:'.md5(json_encode($body));
  531 + $a = redis()->get($key);
  532 + if(!is_numeric($a)){
  533 + $a = $this->es->count($body);
  534 + redis()->set($key,$a,strtotime(date('Y-m-d',strtotime("+1 day"))) - time());
  535 + }
  536 + return $a;
  537 + }
  538 +
521 return $this->es->count($body); 539 return $this->es->count($body);
522 } 540 }
523 541
@@ -179,6 +179,7 @@ class MailListV2Es2 extends Base { @@ -179,6 +179,7 @@ class MailListV2Es2 extends Base {
179 179
180 // 软删 180 // 软删
181 $where['deleted'] = 0; 181 $where['deleted'] = 0;
  182 + $where['email_id'] = $this->getEmails('id');
182 183
183 $query = [ 184 $query = [
184 'bool'=>[ 185 'bool'=>[
@@ -233,6 +234,7 @@ class MailListV2Es2 extends Base { @@ -233,6 +234,7 @@ class MailListV2Es2 extends Base {
233 } 234 }
234 } 235 }
235 236
  237 + logs(json_encode(['query'=>['constant_score'=>['filter'=>$query]]]));
236 $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"]); 238 $result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"]);
237 239
238 240
@@ -44,7 +44,7 @@ class SyncMail { @@ -44,7 +44,7 @@ class SyncMail {
44 // 不是预热邮箱 44 // 不是预热邮箱
45 if($f=='收件箱'){ 45 if($f=='收件箱'){
46 46
47 - $this->auto_mail($id,$data); 47 + // $this->auto_mail($id,$data);
48 48
49 49
50 // 邮件过滤 这些邮箱都是系统邮箱 50 // 邮件过滤 这些邮箱都是系统邮箱
@@ -146,7 +146,7 @@ class Imap { @@ -146,7 +146,7 @@ class Imap {
146 public function __destruct() 146 public function __destruct()
147 { 147 {
148 // 退出登录 148 // 退出登录
149 - (new Logout($this))->exec(); 149 + // (new Logout($this))->exec();
150 unset($this->client); 150 unset($this->client);
151 // TODO: Implement __destruct() method. 151 // TODO: Implement __destruct() method.
152 } 152 }
@@ -277,11 +277,11 @@ class MailFun { @@ -277,11 +277,11 @@ class MailFun {
277 if(stripos($email['email'],'@gmail.com')){ 277 if(stripos($email['email'],'@gmail.com')){
278 $gmail = true; 278 $gmail = true;
279 } 279 }
280 - 280 + $time = time();
281 if($gmail){ 281 if($gmail){
282 // 发送 282 // 发送
283 if($mail->send()){ 283 if($mail->send()){
284 - logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'], LOG_PATH.'/mail_send.log'); 284 + logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s', LOG_PATH.'/mail_send.log');
285 return [true,$mail->getLastMessageID()]; 285 return [true,$mail->getLastMessageID()];
286 } 286 }
287 }else{ 287 }else{
@@ -294,7 +294,7 @@ class MailFun { @@ -294,7 +294,7 @@ class MailFun {
294 $mail->Host = empty($email['smtp_proxy'])?$ip:$email['smtp_proxy']; 294 $mail->Host = empty($email['smtp_proxy'])?$ip:$email['smtp_proxy'];
295 // 发送成功直接返回 295 // 发送成功直接返回
296 if($mail->send()){ 296 if($mail->send()){
297 - logs('sendmail '.$ip.' success '.$email['email'].' to '.$data['tos'][0]['email'],LOG_PATH.'/mail_send.log'); 297 + logs('sendmail '.$ip.' success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s',LOG_PATH.'/mail_send.log');
298 return [true,$mail->getLastMessageID()]; 298 return [true,$mail->getLastMessageID()];
299 } 299 }
300 // 只执行一次 300 // 只执行一次
@@ -308,7 +308,7 @@ class MailFun { @@ -308,7 +308,7 @@ class MailFun {
308 }else{ 308 }else{
309 // 发送成功直接返回 309 // 发送成功直接返回
310 if($mail->send()){ 310 if($mail->send()){
311 - logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'],LOG_PATH.'/mail_send.log'); 311 + logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s',LOG_PATH.'/mail_send.log');
312 return [true,$mail->getLastMessageID()]; 312 return [true,$mail->getLastMessageID()];
313 } 313 }
314 } 314 }
  1 +<svg class="icon" style="width: 1em;height: 1em;vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1661"><path d="M877.8 560.2c-4.8-18.6-23.8-29.8-42.5-25.1-18.7 4.8-29.9 23.9-25.1 42.5l29.2 112.9H188L214.8 587c4.8-18.7-6.4-37.7-25.1-42.5-18.6-4.8-37.7 6.4-42.5 25.1L98 760v4.4c0 55.5 45.2 100.7 100.7 100.7h630c55.5 0 100.7-45.2 100.7-100.7V760l-51.6-199.8zM481.6 628c6.8 6.8 15.7 10.2 24.7 10.2 1.8 0 3.5-0.2 5.3-0.5 1.7 0.3 3.5 0.5 5.3 0.5 8.9 0 17.9-3.4 24.7-10.2l216.3-216.3c13.6-13.6 13.6-35.7 0-49.4-13.6-13.6-35.7-13.6-49.4 0L547.4 523.5V148.9c0-19.3-15.6-34.9-34.9-34.9-19.3 0-34.9 15.6-34.9 34.9v376.4l-162.9-163c-13.6-13.6-35.7-13.6-49.4 0-13.6 13.6-13.6 35.7 0 49.4L481.6 628z" p-id="1662"></path></svg>
@@ -185,11 +185,15 @@ class SyncMail { @@ -185,11 +185,15 @@ class SyncMail {
185 'authentication failure' 185 'authentication failure'
186 ] as $em){ 186 ] as $em){
187 if(str_contains($login->getMessage(), $em)){ 187 if(str_contains($login->getMessage(), $em)){
188 - $this->db->update(  
189 - \Model\emailSql::$table,  
190 - ['pwd_error'=>1],  
191 - dbWhere(['id'=> $this->emailId()])  
192 - ); 188 +
  189 + if(redis()->incr('err_mail:'.$this->emailId(),1800)>2){
  190 + $this->db->update(
  191 + \Model\emailSql::$table,
  192 + ['pwd_error'=>1],
  193 + dbWhere(['id'=> $this->emailId()])
  194 + );
  195 + }
  196 +
193 } 197 }
194 } 198 }
195 199
@@ -378,9 +382,9 @@ class SyncMail { @@ -378,9 +382,9 @@ class SyncMail {
378 if($folder->getName() == 'INBOX'){ 382 if($folder->getName() == 'INBOX'){
379 $this->folder_inbox_id = $folder_id; 383 $this->folder_inbox_id = $folder_id;
380 } 384 }
381 - if(in_array($folder->getName(),['INBOX','[Gmail]/Important','[Gmail]/Starred','星标邮件','Important'])){  
382 - $isBody = true;  
383 - } 385 + // if(in_array($folder->getName(),['INBOX','[Gmail]/Important','[Gmail]/Starred','星标邮件','Important'])){
  386 + // $isBody = true;
  387 + // }
384 // 选择成功 388 // 选择成功
385 if($folder->isOk()){ 389 if($folder->isOk()){
386 $msg = $folder->msg(); 390 $msg = $folder->msg();