作者 张关杰

服务器提交

... ... @@ -2,4 +2,17 @@
composer.lock
vendor
config.php
public/temp
\ No newline at end of file
public/temp
public/attachment
public/attachment2
public/attachment2025
index.html
eml
log
public/.user.ini
public/.well-known
public/storage
cmd/*.log
*.log
.htaccess
404.html
\ No newline at end of file
... ...
... ... @@ -59,7 +59,7 @@ class AutoMail {
if(redis()->add('auto_mail_sync2',1,60)){
_echo('正在计算数据');
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
$startId = $maxId-20000;
$startId = $maxId-200000;
foreach (minMaxToArray($startId,$maxId) as $ids){
redis()->rPush('auto_check_ids',implode(',',$ids));
... ...
... ... @@ -38,7 +38,7 @@ class HotMail {
if(redis()->add('hot_mail_sync2',1,60)){
_echo( '正在计算数据');
$maxId = $this->db->value("select `id` from `lists` order by `id` desc limit 1");
foreach (minMaxToArray($maxId-100000,$maxId) as $ids){
foreach (minMaxToArray($maxId-50000,$maxId) as $ids){
redis()->rPush('hot_check_ids',implode(',',$ids));
}
_echo( '计算完成');
... ... @@ -99,10 +99,10 @@ class HotMail {
}
}
$list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>1]),'`id`'));
foreach ($list as $item){
redis()->rPush('sync_to_es',$item['id']);
}
// $list = $this->db->all(\Model\listsSql::all(dbWhere(['id'=>$id,'is_hots'=>1]),'`id`'));
// foreach ($list as $item){
// redis()->rPush('sync_to_es',$item['id']);
// }
}
... ...
... ... @@ -73,7 +73,7 @@ function start(){
}catch (Throwable $e){
if(!strpos($e->getMessage(),'read time out')){
logs('sync : '.$e->getMessage());
logs('sync : '.($email['email']??'').' '.$e->getMessage());
}
}
... ...
... ... @@ -4,6 +4,13 @@
require_once "../vendor/autoload.php";
if(in_array('v2',$argv)){
define('S_V2','2');
}else{
define('S_V2','');
}
/**
* 把mysql的数据同步到es
* @author:dc
... ... @@ -37,7 +44,12 @@ class SyncToEsCmd {
// pcntl_signal(SIGHUP, $handler);
$es = es();
if(S_V2){
$es = es('email_lists');
}else{
$es = es();
}
$db = db();
$this->fob_db = fob_mysql();
$startTime = time();
... ... @@ -55,14 +67,14 @@ class SyncToEsCmd {
break;
}
$id = redis()->lPop('sync_to_es');
$id = redis()->lPop('sync_to_es'.S_V2);
$code = 500;
if($id){
$doc_id = '';
try {
$data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id));
}catch (Throwable $e){
redis()->rPush('sync_to_es',$id);
redis()->rPush('sync_to_es'.S_V2,$id);
_echo('sync to es '.$e->getMessage());
break;
}
... ... @@ -70,15 +82,20 @@ class SyncToEsCmd {
if($data){
// 设置 进程 是否在运行
$data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
// 文件夹
if(empty($this->folders[$data['folder_id']])){
$this->folders[$data['folder_id']] = $db->throw()->value(\Model\folderSql::first($data['folder_id'],'folder'));
try {
// 文件夹
if(empty($this->folders[$data['folder_id']])){
$this->folders[$data['folder_id']] = $db->throw()->value(\Model\folderSql::first($data['folder_id'],'folder'));
}
// 为文件夹打标 方便查询
$data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);
// postid ai邮箱要用 这个是查询黑格
$data['postid'] = $this->getPostid($data['email_id']);
}catch (Throwable $e){
redis()->rPush('sync_to_es'.S_V2,$id);
_echo('sync to es '.$e->getMessage());
break;
}
// 为文件夹打标 方便查询
$data['folder_as_int'] = folder2int($this->folders[$data['folder_id']]);
// postid ai邮箱要用 这个是查询黑格
$data['postid'] = $this->getPostid($data['email_id']);
$data = $this->getEsData($data);
$doc_id = $data['email_id'].'_'.$data['folder_id'].'_'.$data['uid'];
... ... @@ -87,7 +104,7 @@ class SyncToEsCmd {
}
if($code!==200){
@file_put_contents(LOG_PATH.'/sync_es_fail.log',$id."\n",FILE_APPEND);
@file_put_contents(LOG_PATH.'/sync_es_fail'.S_V2.'.log',$id."\n",FILE_APPEND);
_echo('同步es: '.$doc_id.'===>'.$code);
}
... ... @@ -106,9 +123,14 @@ class SyncToEsCmd {
* @time 2025/5/20 15:44
*/
public function getPostid($email_id){
$h = date('dhi');
if(empty($this->postids[$h][$email_id])){
$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 ");
$h = date('dh');
if(!isset($this->postids[$h][$email_id])){
// 未删除状态
$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 ");
if(!$id){
// 已删状态
$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 ");
}
$this->postids[$h][$email_id] = $id;
}
... ... @@ -144,6 +166,8 @@ class SyncToEsCmd {
$data['to_name'] = '';
}
}
$data['description'] = str_replace(["\n"],"",$data['description']);
// unset($data['to_name']);
if(!empty($data['created_at'])){
$data['created_at'] = date('Y-m-d\TH:i:s',strtotime($data['created_at']));
... ...
... ... @@ -11,7 +11,7 @@
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-redis": "*",
"elasticsearch/elasticsearch": "7.x",
"elasticsearch/elasticsearch": "8.1.*",
"phpmailer/phpmailer": "^6.7",
"swlib/saber": "^1.0"
},
... ...
... ... @@ -997,6 +997,12 @@ class Home extends Base {
$body = db()->first(bodySql::first($id));
if(!$body){
$body = db()->first("select * from `bodies_back` where `lists_id` = ".$id." limit 1");
// if(!$body){
// $body = @file_get_contents('http://172.19.0.5:9527?id='.$id);
// if($body){
// $body = ['lists_id'=>$id,'text_html'=>$body];
// }
// }
}
if($body && !$reload){
$data['body'] = json_decode($body['text_html'],true);
... ...
... ... @@ -17,7 +17,7 @@ class Test {
public function home(){
return 404;
// $urlGetSign = function ($mobile){
// $time = time();
... ...
... ... @@ -242,7 +242,7 @@ class MailListV2Es extends Base {
// $result = $this->es->search(['query'=>$query],($page-1) * $limit,$limit,['udate'=>"desc"]);
$result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"]);
$result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"],($where['is_hots']==1||$folder=='垃圾箱')?10000:true);
$total = $result['hits']['total']['value']??0;
... ... @@ -282,7 +282,7 @@ class MailListV2Es extends Base {
}
// 手动触发同步es
// redis()->rPush('sync_to_es',$v['id']);
redis()->rPush('sync_to_es',$v['id']);
return $v;
},$lists?:[]);
... ... @@ -489,7 +489,14 @@ class MailListV2Es extends Base {
private function countHot($body,$folder){
$body['query']['bool']['must'][] = ['term'=>['is_hots'=>1]];
$body['query']['bool']['must'][] = $this->assignSql3($folder);
return $this->es->count($body);
$key = 'hot_count:'.md5(json_encode($body));
$a = redis()->get($key);
if(!is_numeric($a)){
$a = $this->es->count($body);
redis()->set($key,$a,strtotime(date('Y-m-d',strtotime("+1 day"))) - time());
}
return $a;
// return $this->es->count($body);
}
private function countMail($body,$folder,$seen=null){
... ... @@ -518,6 +525,17 @@ class MailListV2Es extends Base {
}
$body['query']['bool']['must'][] = ['term'=>['is_hots'=>0]];
$body['query']['bool']['must'][] = $this->assignSql($folder);
if($folder=='垃圾箱'){
$key = 'laji_count:'.md5(json_encode($body));
$a = redis()->get($key);
if(!is_numeric($a)){
$a = $this->es->count($body);
redis()->set($key,$a,strtotime(date('Y-m-d',strtotime("+1 day"))) - time());
}
return $a;
}
return $this->es->count($body);
}
... ...
... ... @@ -179,6 +179,7 @@ class MailListV2Es2 extends Base {
// 软删
$where['deleted'] = 0;
$where['email_id'] = $this->getEmails('id');
$query = [
'bool'=>[
... ... @@ -233,6 +234,7 @@ class MailListV2Es2 extends Base {
}
}
logs(json_encode(['query'=>['constant_score'=>['filter'=>$query]]]));
$result = $this->es->search(['query'=>['constant_score'=>['filter'=>$query]]],($page-1) * $limit,$limit,['udate'=>"desc"]);
... ...
... ... @@ -44,7 +44,7 @@ class SyncMail {
// 不是预热邮箱
if($f=='收件箱'){
$this->auto_mail($id,$data);
// $this->auto_mail($id,$data);
// 邮件过滤 这些邮箱都是系统邮箱
... ...
... ... @@ -146,7 +146,7 @@ class Imap {
public function __destruct()
{
// 退出登录
(new Logout($this))->exec();
// (new Logout($this))->exec();
unset($this->client);
// TODO: Implement __destruct() method.
}
... ...
... ... @@ -277,11 +277,11 @@ class MailFun {
if(stripos($email['email'],'@gmail.com')){
$gmail = true;
}
$time = time();
if($gmail){
// 发送
if($mail->send()){
logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'], LOG_PATH.'/mail_send.log');
logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s', LOG_PATH.'/mail_send.log');
return [true,$mail->getLastMessageID()];
}
}else{
... ... @@ -294,7 +294,7 @@ class MailFun {
$mail->Host = empty($email['smtp_proxy'])?$ip:$email['smtp_proxy'];
// 发送成功直接返回
if($mail->send()){
logs('sendmail '.$ip.' success '.$email['email'].' to '.$data['tos'][0]['email'],LOG_PATH.'/mail_send.log');
logs('sendmail '.$ip.' success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s',LOG_PATH.'/mail_send.log');
return [true,$mail->getLastMessageID()];
}
// 只执行一次
... ... @@ -308,7 +308,7 @@ class MailFun {
}else{
// 发送成功直接返回
if($mail->send()){
logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'],LOG_PATH.'/mail_send.log');
logs('sendmail success '.$email['email'].' to '.$data['tos'][0]['email'].' '.(time()-$time).'s',LOG_PATH.'/mail_send.log');
return [true,$mail->getLastMessageID()];
}
}
... ...
<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>
\ No newline at end of file
... ...
... ... @@ -185,11 +185,15 @@ class SyncMail {
'authentication failure'
] as $em){
if(str_contains($login->getMessage(), $em)){
$this->db->update(
\Model\emailSql::$table,
['pwd_error'=>1],
dbWhere(['id'=> $this->emailId()])
);
if(redis()->incr('err_mail:'.$this->emailId(),1800)>2){
$this->db->update(
\Model\emailSql::$table,
['pwd_error'=>1],
dbWhere(['id'=> $this->emailId()])
);
}
}
}
... ... @@ -378,9 +382,9 @@ class SyncMail {
if($folder->getName() == 'INBOX'){
$this->folder_inbox_id = $folder_id;
}
if(in_array($folder->getName(),['INBOX','[Gmail]/Important','[Gmail]/Starred','星标邮件','Important'])){
$isBody = true;
}
// if(in_array($folder->getName(),['INBOX','[Gmail]/Important','[Gmail]/Starred','星标邮件','Important'])){
// $isBody = true;
// }
// 选择成功
if($folder->isOk()){
$msg = $folder->msg();
... ...