作者 邓超

1

... ... @@ -5,7 +5,7 @@ error_reporting(E_ERROR | E_NOTICE | E_WARNING);
ini_set('display_errors',0);
// 开启4个进程
define('WORKER_NUM',10);
define('WORKER_NUM',1);
// 开启最大1000个协程
define('COROUTINE_MAX_NUM',5000);
// 是否继续运行
... ...
... ... @@ -42,19 +42,35 @@ class Home extends Base {
}
}
// 邮件文件夹的id
$folder_id = (int) app()->request('folder_id');
// 附件
$attachment = app()->request('attachment');
// 已读/未读
$seen = app()->request('seen',-1,'intval');
// 软删
$deleted = app()->request('deleted',0,'intval');
$where = ['email_id'=>$this->getEmails('id')];
// 目录
$folder = app()->request('folder','INBOX');
$folderList = db()->all(folderSql::all($where['email_id']));
$folder_id = [];
// 文件夹id
if($folderList){
foreach ($folderList as $item){
if($item['folder'] == $folder){
$folder_id[] = $item['id'];
}
}
}
//目录
if($folder_id) $where['folder_id'] = $folder_id;
if($ids) $where['id'] = $ids;
if($attachment) $where['is_file'] = 1; //附件
// 软删
$where['deleted'] = $deleted;
// 已读/未读
if(in_array($seen,[0,1])){
$where['seen'] = $seen;
... ... @@ -164,6 +180,24 @@ class Home extends Base {
* @time 2023/3/17 16:15
*/
public function seen_2_unseen(){
$this->setFlags('seen');
}
/**
* 邮件回收站,进行回收,恢复邮件
* @author:dc
* @time 2023/3/21 11:41
*/
public function recycle(){
$this->setFlags('deleted');
}
private function setFlags($d){
$emails = $this->getEmails();
$mail_ids = app()->request('mail_ids');
... ... @@ -173,8 +207,8 @@ class Home extends Base {
}
}
// 已读或未读
$seen = (int) app()->request('seen');
$seen = $seen ? 1 : 0;
$fv = (int) app()->request($d);
$fv = $fv ? 1 : 0;
$data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')])));
if($data){
... ... @@ -200,12 +234,23 @@ class Home extends Base {
$mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']);
if($mailInstance->login()){
$mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen);
switch ($d){
// 已读 未读
case 'seen':{
$mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$fv);
break;
}
// 回收站,已删 未删,软删
case 'deleted':{
$mailInstance->recycle(array_column($uid,'uid'),$folder['origin_folder'],$fv);
break;
}
}
$mailInstance = null;
// 更新数据
db()->update(listsSql::$table,[
'seen' => $seen
$d => $fv
],dbWhere([
'id' => array_column($uid,'id')
]));
... ... @@ -223,7 +268,6 @@ class Home extends Base {
'mail_id' => $mail_ids
]);
}
... ...
... ... @@ -147,7 +147,7 @@ function dbWhere(array $where, string $ar = 'and'):string{
},$v);
if(count($v)===1){
// 只有一个值时就是 =
$sql[] = "`{$f}` = ".$v;
$sql[] = "`{$f}` = ".$v[0];
}elseif (count($v) > 1){
$sql[] = "`{$f}` in (".implode(',',$v).")";
}
... ...
... ... @@ -80,7 +80,7 @@ class DbPool {
$timer2 = microtime(true);
// todo:: 记录日志,生产请注释
$sql = '['.substr($timer2-$timer,0,8).'ms] '.$sql;
$sql = '['.substr(($timer2-$timer)*1000,0,6).'ms] '.$sql;
logs(
$params ? [$sql,$params] : $sql,
LOG_PATH.'/'.date('Y-m-d').'.sql.log'
... ...
... ... @@ -318,5 +318,21 @@ class Mail {
return $this->client->flags($uids,[Imap::FLAGS_SEEN],$seen ? '+' : '-',true);
}
/**
* 回收站
* @param $uids
* @param $folder
* @param $recycle
* @author:dc
* @time 2023/3/21 13:41
*/
public function recycle($uids,$folder,$recycle){
// 选择目录
$status = $this->client->selectFolder($folder);
return $this->client->flags($uids,[Imap::FLAGS_DELETED],$recycle ? '+' : '-',true);
}
}
... ...
... ... @@ -29,7 +29,7 @@ class listsSql {
*/
public static function lists(string $where, int $p, int $size){
$filed = '`id`,`uid`,`msgno`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`';
$filed = '`id`,`uid`,`msgno`,`subject`,`from`,`from_name`,`to`,`date`,`size`,`recent`,`flagged`,`answered`,`deleted`,`seen`,`draft`,`udate`,`folder_id`,`is_file`,`cc`,`bcc`,`description`,`email_id`';
return "select {$filed} from `".static::$table."` where ".$where." order by `udate` desc limit {$size} offset ".(($p-1)*$size);
... ...
... ... @@ -31,6 +31,8 @@ return [
'sync' => [\Controller\Home::class, 'sync'],
// 标记为已读
'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
// 回收站,邮件删除,非真实删除
'recycle' => [\Controller\Home::class, 'recycle'],
... ...