作者 张关杰

serversubmit

... ... @@ -41,7 +41,26 @@ class AutoMail {
$not_must[] = ["match_phrase"=>["from.email"=>$str]];
}
}
echo json_encode([
"_source" => ["uuid"],
"query"=>[
"bool"=>[
"must"=>[
["term"=>["folder_as_int" => 1]], // 收件箱
["term"=>["is_auto" => 0]], // 非auto
["term"=>["is_hots" => 0]], // 非预热
["term"=>["deleted" => 0]], // 非删除
// 自动关键字
[
"bool" => [
"should"=> $not_must,
"minimum_should_match" => 1
]
]
]
]
]
]);exit;
// 查询自动回的邮件
$lists = $es->search([
"_source" => ["uuid"],
... ...
... ... @@ -100,13 +100,15 @@ class SyncToEsCmd {
public function handler(){
$es = es(); // 第一个库,即将丢弃
$es2 = es('email_lists'); // 第二个库 新
$es2 = es('email_lists_copy'); // 第二个库 新
while (!$this->isStop()){
$id = redis()->lPop('sync_to_es');
$code = 500;
if($id){
// redis()->rPush('sync_to_es2',$id);
$doc_id = '';
try {
$data = $this->db->throw()->first(\Model\listsSql::first('`id` = '.$id));
... ...
... ... @@ -45,7 +45,7 @@ class SyncToEsCmd {
if(S_V2){
$es = es('email_lists');
$es = es('email_lists_copy');
}else{
$es = es();
}
... ... @@ -76,7 +76,10 @@ class SyncToEsCmd {
if($id){
$doc_id = '';
try {
$data = $db->throw()->first(\Model\listsSql::first('`id` = '.$id));
$data = $db->throw()->first('select * from `lists_hot` where `id` = '.$id);
if(!$data){
$data = $db->throw()->first('select * from `lists` where `id` = '.$id);
}
}catch (Throwable $e){
redis()->rPush('sync_to_es'.S_V2,$id);
_echo('sync to es '.$e->getMessage());
... ... @@ -89,7 +92,7 @@ class SyncToEsCmd {
continue;
}
// 设置 进程 是否在运行
$data['is_auto']=$db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
$data['is_auto'] = $db->count('select count(*) from `lists_auto` where `list_id` = '.$data['id']) ? 1 : 0;
try {
// 文件夹
if(empty($this->folders[$data['folder_id']])){
... ... @@ -137,7 +140,10 @@ class SyncToEsCmd {
@file_put_contents(LOG_PATH.'/sync_es_fail'.S_V2.'.log',$id."\n",FILE_APPEND);
_echo('同步es: '.$doc_id.'===>'.$code);
}
// _echo('同步es: '.$doc_id.'===>'.$code);
// print_r($data);
// var_dump($id);
// exit;
}else{
sleep(1);
}
... ...
... ... @@ -13,9 +13,11 @@ use Model\listsSql;
* @package Controller
*/
class Test {
public function home(){
return 404;
}
public function a(){
return 404;
... ... @@ -67,19 +69,20 @@ return 404;
// app()->e(404,404);
// }
//
//// $email = db()->first(emailSql::first(app()->request('mid')));
$email = db()->first(emailSql::first(app()->request('mid')));
//
// $config = (new \Lib\Imap\ImapConfig())
// ->setEmail('CService001@spicay-meart.com')
// ->setPassword('5YmS77JBb7JJwuaD')
// ->setHost('imap.exmail.qq.com');
$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');
$uid = (int) app()->request('uid');
$page = (int) app()->request('page',1);
// foreach ($imap->getFolders()->all() as $a){
// echo $a->folder;
// echo '=>';
... ... @@ -87,18 +90,27 @@ return 404;
// echo '|';
// };
$folder = $imap->folder('INBOX');
if($uid){
$msg = $folder->msg()->uid([$uid])->get()->first();
return $msg->body->getHtml();
}
echo '总共有:';
echo $folder->getTotal();
echo "<br>";
echo "<br>";
echo '<a href="?msgno='.($msgno+1).'">下一个</a>';
echo '<a href="?mid='.$email['id'].'&page='.($page+1).'">下一页</a>';
echo "<br>";
echo "<hr>";
$msgs = $folder->msg()->forPage(449)->get();
$msgs = $folder->msg()->forPage($page)->get();
if ($msgs) {
$msgs->each(function ($msg){
echo '<p>'.$msg->uid.'==>'.$msg->header->getSubject().' =====> '.date('Y-m-d H:i:s',strtotime($msg->date)).'</p>';
$msgs->each(function ($msg) use($email){
echo '<p><a href="?mid='.$email['id'].'&uid='.$msg->uid.'">'.$msg->uid.'==>'.$msg->header->getSubject().' =====> '.date('Y-m-d H:i:s',strtotime($msg->date)).'</a></p>';
});
// echo $msg->header->getSubject();
// echo '<br>-------------------------------------------------<br>';
... ...
... ... @@ -293,7 +293,7 @@ class MailListV2Es extends Base {
}
// 手动触发同步es
if(empty($v['is_auto']) && $v['folder_name']=='收件箱') redis()->rPush('sync_to_es',$v['id']);
// if(empty($v['is_auto']) && $v['folder_name']=='收件箱') redis()->rPush('sync_to_es',$v['id']);
return $v;
},$lists?:[]);
... ...
... ... @@ -31,54 +31,6 @@ class MailListV2Es2 extends Base {
$this->es = \es('email_lists');
}
/**
* 当前邮箱下指定的文件夹
* @param string $folder
* @return array
* @throws \Lib\Err
* @author:dc
* @time 2024/7/19 11:37
*/
private function getFolderId(string $folder,$emails=[]){
if(!$emails){
$emails = $this->getEmails('id');
}
$k = md5(json_encode($emails));
// 查询 文件夹
static $folderList;
if(empty($folderList[$k])){
$folderList[$k] = db()->all(folderSql::all($emails));
}
$folder_id = [];
// 文件夹id
if($folderList[$k]){
foreach ($folderList[$k] as $item){
if(folderAlias($item['folder']) == $folder){
$folder_id[] = $item['id'];
}
}
}
if(!$folder_id){
app()->e('folder_not_fount');
}
return $folder_id;
}
/**
* 处理like条件
* @param $str
* @return string
* @author:dc
* @time 2024/9/4 11:14
*/
private function getLikeStr($str){
if(str_starts_with($str, '^')){
return addslashes(mb_substr($str,1,99)).'%%';
}
return '%%'.addslashes($str).'%%';
}
/**
* 邮件列表
... ... @@ -276,7 +228,7 @@ class MailListV2Es2 extends Base {
}
// 手动触发同步es
redis()->rPush('sync_to_es',$v['id']);
// redis()->rPush('sync_to_es',$v['id']);
return $v;
},$lists?:[]);
... ... @@ -488,6 +440,8 @@ class MailListV2Es2 extends Base {
*/
private function countFlagged($body){
$body['query']['bool']['must'][] = ['term'=>['flagged'=>1]];
$body['query']['bool']['must'][] = ['terms'=>['folder_as_int'=>[1,2,3,4,5]]];
if($this->assignSql('收件箱'))
$body['query']['bool']['must'][] = $this->assignSql('收件箱');
return $this->es->count($body);
... ...