作者 邓超

1

... ... @@ -93,7 +93,11 @@ class Folder extends Base {
$origin_folder = $parent['origin_folder'].'/'.$origin_folder;
}
$formData['folder'] = str_replace(["'",'"','/','\\','&','*','(',')'],'',$formData['folder']);
$formData['folder'] = str_replace(
["'",'"','/','\\','&','*','(',')','{','}','|','$','@','!','#','%','^','<','>','?','`','~','[',']'],
'',
$formData['folder']
);
// 判断文件夹是否存在
$has = db()->count(folderSql::has(
... ... @@ -132,14 +136,22 @@ class Folder extends Base {
'folder' => $formData['folder'],
'origin_folder' => $origin_folder,
'uuid' => md5($email['id'].$origin_folder),
]);
],false);
if(!$id){
app()->e('folder_create_save_error');
}
// 返回数据
app()->_json(db()->first(folderSql::first($id)));
// 查询
$folders = db()->all(
\Model\folderSql::all(
$email['id'],
'`id`,`folder`,`pid`,`exsts`,`unseen`,`email_id`'
)
);
return list_to_tree($folders);
}
... ...
... ... @@ -186,17 +186,81 @@ class Home extends Base {
/**
* 邮件回收站,进行回收,恢复邮件
* 邮件移动
* @author:dc
* @time 2023/3/21 11:41
*/
public function recycle(){
$this->setFlags('deleted');
public function move(){
$emails = $this->getEmails();
$mail_ids = app()->request('mail_ids');
foreach ($mail_ids as $k=>$id){
if(!is_numeric($id)){
unset($mail_ids[$k]);
}
}
// 移动到的文件夹
$folder = app()->request('folder');
$data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_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']);
if($mailInstance->login()){
$mailInstance->move();
$mailInstance = null;
// 更新数据
// db()->update(listsSql::$table,[
// $d => $fv
// ],dbWhere([
// 'id' => array_column($uid,'id')
// ]));
}
}
$folder = null;
}
}
}
app()->_json([
'mail_id' => $mail_ids
]);
}
/**
* 远程标签
* @param $d
* @throws \Lib\Err
* @author:dc
* @time 2023/3/21 14:28
*/
private function setFlags($d){
$emails = $this->getEmails();
... ... @@ -210,7 +274,7 @@ class Home extends Base {
$fv = (int) app()->request($d);
$fv = $fv ? 1 : 0;
$data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')])));
$data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_id`'));
if($data){
// 查询邮箱
$emails = array_column($emails,null,'id');
... ... @@ -241,10 +305,10 @@ class Home extends Base {
break;
}
// 回收站,已删 未删,软删
case 'deleted':{
$mailInstance->recycle(array_column($uid,'uid'),$folder['origin_folder'],$fv);
break;
}
// case 'deleted':{
// $mailInstance->recycle(array_column($uid,'uid'),$folder['origin_folder'],$fv);
// break;
// }
}
$mailInstance = null;
... ...
... ... @@ -301,9 +301,26 @@ function start_now_mail(){
}
/**
* 固定文件夹的名称,统一
* @param $folder
* @return string
* @author:dc
* @time 2023/3/21 16:00
*/
function folderAlias($folder){
$folder_map = [
'INBOX' => '收件箱',
// qq的
'Sent Messages' => '发件箱',
'Drafts' => '草稿箱',
'Junk' => '垃圾箱',
'Deleted Messages' => '回收站',
];
return $folder_map[$folder]??$folder;
}
... ...
... ... @@ -493,6 +493,15 @@ class Imap {
}
/**
* 移动邮件
* @author:dc
* @time 2023/3/21 14:55
*/
public function move(){
}
/**
* 获取邮件头,并解析
... ...
... ... @@ -65,8 +65,12 @@ class Mail {
$this->client->login("ssl://{$this->server}:993",$this->username,$this->password);
}catch (\Throwable $e){
if($pass_err && $e->getCode() == 403){
// 一天中超过 3次失败说明密码错误了
if(redis()->incr('email_login_error:'.md5($this->username),86400) > 3){
// 登录失败了 ,
db()->update(\Model\emailSql::$table,['pwd_error'=>1],dbWhere(['email'=>$this->username]));
}
return -1;
}else{
logs($e->getMessage());
}
... ... @@ -74,6 +78,8 @@ class Mail {
return $e->getCode() == 403 ? 0 : -1;
}
redis()->delete('email_login_error:'.md5($this->username));
return 1;
}
... ... @@ -106,10 +112,11 @@ class Mail {
$folder['parseFolder'] = explode('/',$folder['parseFolder'])[1];
}
if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
try {
$db->insert(folderSql::$table,[
'email_id' => $email_id,
'folder' => $folder['parseFolder'],
'folder' => folderAlias($folder['parseFolder']),
'origin_folder' => $folder['folder'],
'uuid' => $uuid,
'pid' => $pid
... ... @@ -117,6 +124,8 @@ class Mail {
}catch (\Throwable $e){
// 这里就不处理失败了
}
}
}
// $db->commit();
... ... @@ -319,20 +328,24 @@ class Mail {
}
/**
* 回收站
* 移动邮件,
* @param $uids
* @param $folder
* @param $recycle
* @return bool
* @throws \Exception
* @author:dc
* @time 2023/3/21 13:41
* @time 2023/3/21 14:54
*/
public function recycle($uids,$folder,$recycle){
public function move($uids,$folder,$to_folder){
// 选择目录
$status = $this->client->selectFolder($folder);
return $this->client->flags($uids,[Imap::FLAGS_DELETED],$recycle ? '+' : '-',true);
return $this->client->folderRename($uids,[Imap::FLAGS_DELETED],$recycle ? '+' : '-',true);
}
}
... ...
... ... @@ -94,9 +94,9 @@ class listsSql {
* @author:dc
* @time 2023/3/17 16:24
*/
public static function first(string $where):string {
public static function first(string $where,$filed='*'):string {
return "select * from `".self::$table."` where ".$where;
return "select {$filed} from `".self::$table."` where ".$where;
}
... ...
... ... @@ -31,8 +31,8 @@ return [
'sync' => [\Controller\Home::class, 'sync'],
// 标记为已读
'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
// 回收站,邮件删除,非真实删除
'recycle' => [\Controller\Home::class, 'recycle'],
// 邮件移动文件夹
'move' => [\Controller\Home::class, 'move'],
... ...