作者 邓超

1

... ... @@ -26,7 +26,7 @@ abstract class Base {
protected final function getEmails($filed='*'){
static $data;
if(empty($data)){
$data = db()->all(emailSql::all(web_request_emails()));
$data = db()->all(emailSql::all(dbWhere(['email'=>web_request_emails()])));
if(empty($data)){
app()->e('email_request_required');
}
... ...
... ... @@ -109,7 +109,7 @@ class Folder extends Base {
// 远程创建
$mail = new Mail(
$email['email'],
$email['password'],
base64_decode($email['password']),
$email['imap']
);
... ...
... ... @@ -2,9 +2,11 @@
namespace Controller;
use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Lib\Verify;
use Model\emailSql;
use Model\folderSql;
use Model\listsSql;
... ... @@ -144,6 +146,74 @@ class Home extends Base {
}
/**
* 标记为已读
* @throws \Lib\Err
* @author:dc
* @time 2023/3/17 16:15
*/
public function seen_2_unseen(){
$emails = $this->getEmails();
$mail_ids = app()->request('mail_ids');
foreach ($mail_ids as $k=>$id){
if(!is_numeric($id)){
unset($mail_ids[$k]);
}
}
// 已读或未读
$seen = (int) app()->request('seen');
$seen = $seen ? 1 : 0;
$data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')])));
if($data){
// 查询邮箱
$emails = array_column($emails,null,'id');
$uids = [];
foreach ($data as $datum){
if(empty($uids[$datum['email_id']])){
$uids[$datum['email_id']][$datum['folder_id']] = [];
}
$uids[$datum['email_id']][$datum['folder_id']][] = [
'uid' => $datum['uid'],
'id' => $datum['id'],
];
}
foreach ($uids as $eid=>$arr){
foreach ($arr as $fid=>$uid){
// 查询目录
$folder = db()->first(folderSql::first($fid));
if($folder){
// 开始远程
$mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']);
$mailInstance->login();
$mailInstance->seen(array_column($uid,'uid'),$folder['origin_folder'],$seen);
$mailInstance = null;
// 更新数据
db()->update(listsSql::$table,[
'seen' => $seen
],dbWhere([
'id' => array_column($uid,'id')
]));
}
$folder = null;
}
}
}
app()->_json([
'mail_id' => $mail_ids
]);
}
... ...
... ... @@ -62,6 +62,7 @@ return [
'mail_not' => '邮件不存在'
... ...
... ... @@ -303,5 +303,20 @@ class Mail {
}
/**
* 设置为未读
* @param $uids
* @return bool
* @throws \Exception
* @author:dc
* @time 2022/10/26 17:11
*/
public function seen($uids,$folder,$seen):bool{
// 选择目录
$status = $this->client->selectFolder($folder);
return $this->client->flags($uids,[Imap::FLAGS_SEEN],$seen ? '+' : '-',true);
}
}
... ...
... ... @@ -66,14 +66,14 @@ class emailSql {
/**
* 通过邮箱查询列表
* @param $emails
* 查询列表
* @param string $where
* @return string
* @author:dc
* @time 2023/3/10 15:02
* @time 2023/3/17 16:32
*/
public static function all($emails){
return "select * from ".static::$table." where ".dbWhere(['email'=>$emails]);
public static function all(string $where){
return "select * from ".static::$table." where ".$where;
}
... ...
... ... @@ -87,6 +87,17 @@ class listsSql {
return "select `id`,`email_id`,`uuid` from `".self::$table."` where ".dbWhere(['uuid'=>$uuid]);
}
/**
* 根据id查询
* @param string $where
* @return string
* @author:dc
* @time 2023/3/17 16:24
*/
public static function first(string $where):string {
return "select * from `".self::$table."` where ".$where;
}
... ...
... ... @@ -29,6 +29,8 @@ return [
'send' => [\Controller\Home::class, 'send_mail'],
// 同步请求
'sync' => [\Controller\Home::class, 'sync'],
// 标记为已读
'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
... ...