正在显示
1 个修改的文件
包含
39 行增加
和
31 行删除
@@ -472,55 +472,63 @@ function folder2int($folder):int { | @@ -472,55 +472,63 @@ function folder2int($folder):int { | ||
472 | * @author:dc | 472 | * @author:dc |
473 | * @time 2025/6/11 10:49 | 473 | * @time 2025/6/11 10:49 |
474 | */ | 474 | */ |
475 | -function isAiAutoMail($from,$subject,$body=''){ | 475 | +function isAiAutoMail($from,$subject,$body='',$return_keyword=false){ |
476 | // 读取fob设置的过滤词 | 476 | // 读取fob设置的过滤词 |
477 | - $temp = function ($re = false){ | ||
478 | - $filter = redis()->get('ai_email_filter_lists',[]); | 477 | + $temp = function ($type = 0){ |
478 | + $type = $type?1:0; // 是否白名单 | ||
479 | + | ||
480 | + $filter = redis()->get('fob:ai_email_filter_lists'.$type,[]); | ||
479 | $filter = is_array($filter) ? $filter : []; | 481 | $filter = is_array($filter) ? $filter : []; |
480 | - if($filter && !$re){ | ||
481 | - return $filter; | 482 | + if(!$filter){ |
483 | + try { | ||
484 | + $filter = fob_mysql()->throw()->all('select `type`,`text` from `email_filter_rule` where `is_white` = '.$type); | ||
485 | + }catch (Throwable $e){ | ||
486 | + $filter = redis()->get('fob:ai_email_filter_lists_a'.$type,[]); | ||
482 | } | 487 | } |
483 | - $redisfilter = $filter; | 488 | + // 7天过期的 |
489 | + redis()->set('fob:ai_email_filter_lists_a'.$type,$filter,86400*7); | ||
484 | 490 | ||
485 | - $filter = @file_get_contents('https://fob.ai.cc/api/mail/ai_inbox_filter/'.md5('aicc.'.date('ymdh'))); | ||
486 | - $filter = @json_decode($filter,true); | ||
487 | - if(!is_array($filter)){ | ||
488 | - if($redisfilter){ | ||
489 | - return $redisfilter; | ||
490 | - } | ||
491 | - return []; | ||
492 | - } | ||
493 | $filters = []; | 491 | $filters = []; |
494 | array_map(function ($v) use (&$filters){ | 492 | array_map(function ($v) use (&$filters){ |
495 | - $filters[] = [ | ||
496 | - $v['type'], | ||
497 | - $v['text'], | ||
498 | - ]; | ||
499 | - },$filter[0]); | ||
500 | - | 493 | + $filters[] = [$v['type'], $v['text'],]; |
494 | + },$filter); | ||
501 | if($filters){ | 495 | if($filters){ |
502 | - redis()->set('ai_email_filter_lists',$filters,86400); | 496 | + // 5分钟过期的 |
497 | + redis()->set('fob:ai_email_filter_lists'.$type,$filters,300); | ||
503 | } | 498 | } |
504 | return $filters; | 499 | return $filters; |
500 | + }else{ | ||
501 | + return $filter; | ||
502 | + } | ||
505 | }; | 503 | }; |
506 | 504 | ||
507 | // 是否是更新索引 | 505 | // 是否是更新索引 |
508 | if($from===true&&$subject===true) { | 506 | if($from===true&&$subject===true) { |
509 | - return $temp(true); | 507 | + return $temp(); |
510 | } | 508 | } |
509 | + $haystacks = [ | ||
510 | + 1 => $from, | ||
511 | + 2 => $subject, | ||
512 | + 3 => $body, | ||
513 | + ]; | ||
511 | 514 | ||
512 | - // 是否是自动回复 | ||
513 | - foreach ($temp() as $f){ | 515 | + // 是否在白名单 |
516 | + foreach ($temp(1) as $f){ | ||
514 | list($t,$str) = $f; | 517 | list($t,$str) = $f; |
515 | - $haystack = ''; | ||
516 | - if($t==2){ | ||
517 | - $haystack = $subject; | ||
518 | - }elseif ($t==1){ | ||
519 | - $haystack = $from; | ||
520 | - }elseif ($t==3&&$body){ | ||
521 | - $haystack = $body; | 518 | + $haystack = $haystacks[$t]??''; |
519 | + if($haystack && $str && stripos($haystack,$str)!==false){ | ||
520 | + return 0; | ||
521 | + } | ||
522 | } | 522 | } |
523 | + | ||
524 | + // 是否在黑名单中 | ||
525 | + foreach ($temp() as $f){ | ||
526 | + list($t,$str) = $f; | ||
527 | + $haystack = $haystacks[$t]??''; | ||
523 | if($haystack && $str && stripos($haystack,$str)!==false){ | 528 | if($haystack && $str && stripos($haystack,$str)!==false){ |
529 | + if($return_keyword){ | ||
530 | + return $str; | ||
531 | + } | ||
524 | return 1; | 532 | return 1; |
525 | } | 533 | } |
526 | } | 534 | } |
-
请 注册 或 登录 后发表评论