正在显示
7 个修改的文件
包含
143 行增加
和
24 行删除
@@ -200,7 +200,10 @@ class Home extends Base { | @@ -200,7 +200,10 @@ class Home extends Base { | ||
200 | } | 200 | } |
201 | } | 201 | } |
202 | // 移动到的文件夹 | 202 | // 移动到的文件夹 |
203 | - $folder = app()->request('folder'); | 203 | + $to_folder = app()->request('folder'); |
204 | + if(empty($to_folder)){ | ||
205 | + app()->e('folder_move_error'); | ||
206 | + } | ||
204 | 207 | ||
205 | $data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_id`')); | 208 | $data = db()->all(listsSql::first(dbWhere(['id'=>$mail_ids,'email_id'=>array_column($emails,'id')]),'`id`,`uid`,`email_id`,`folder_id`')); |
206 | if($data){ | 209 | if($data){ |
@@ -218,6 +221,9 @@ class Home extends Base { | @@ -218,6 +221,9 @@ class Home extends Base { | ||
218 | } | 221 | } |
219 | 222 | ||
220 | foreach ($uids as $eid=>$arr){ | 223 | foreach ($uids as $eid=>$arr){ |
224 | + // 查询需要移动的文件夹 | ||
225 | + $to_origin_folder = db()->first(folderSql::first(['email_id'=>$eid,'folder'=>$to_folder])); | ||
226 | + if($to_origin_folder){ | ||
221 | foreach ($arr as $fid=>$uid){ | 227 | foreach ($arr as $fid=>$uid){ |
222 | // 查询目录 | 228 | // 查询目录 |
223 | $folder = db()->first(folderSql::first($fid)); | 229 | $folder = db()->first(folderSql::first($fid)); |
@@ -226,16 +232,14 @@ class Home extends Base { | @@ -226,16 +232,14 @@ class Home extends Base { | ||
226 | $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); | 232 | $mailInstance = new Mail($emails[$eid]['email'],base64_decode($emails[$eid]['password']),$emails[$eid]['imap']); |
227 | 233 | ||
228 | if($mailInstance->login()){ | 234 | if($mailInstance->login()){ |
229 | - | ||
230 | - $mailInstance->move(); | 235 | + // TODO:: 这个过程无法保证原子性。没办法 |
236 | + // 先复制 | ||
237 | + $ret = $mailInstance->move(array_column($uid,'uid'),$folder['origin_folder'],$to_origin_folder['origin_folder']); | ||
238 | + if($ret){ | ||
239 | + $uret = db()->update(listsSql::$table,['deleted'=>1],dbWhere(['id'=>array_column($uid,'id')])); | ||
240 | + } | ||
231 | 241 | ||
232 | $mailInstance = null; | 242 | $mailInstance = null; |
233 | - // 更新数据 | ||
234 | -// db()->update(listsSql::$table,[ | ||
235 | -// $d => $fv | ||
236 | -// ],dbWhere([ | ||
237 | -// 'id' => array_column($uid,'id') | ||
238 | -// ])); | ||
239 | } | 243 | } |
240 | 244 | ||
241 | } | 245 | } |
@@ -243,6 +247,9 @@ class Home extends Base { | @@ -243,6 +247,9 @@ class Home extends Base { | ||
243 | } | 247 | } |
244 | } | 248 | } |
245 | 249 | ||
250 | + | ||
251 | + } | ||
252 | + | ||
246 | } | 253 | } |
247 | 254 | ||
248 | 255 |
@@ -143,7 +143,10 @@ function dbWhere(array $where, string $ar = 'and'):string{ | @@ -143,7 +143,10 @@ function dbWhere(array $where, string $ar = 'and'):string{ | ||
143 | foreach ($where as $f=>$v){ | 143 | foreach ($where as $f=>$v){ |
144 | if(is_array($v)){ | 144 | if(is_array($v)){ |
145 | $v = array_map(function ($n){ | 145 | $v = array_map(function ($n){ |
146 | + if (is_string($n)){ | ||
146 | return "'".addslashes($n)."'"; | 147 | return "'".addslashes($n)."'"; |
148 | + } | ||
149 | + return $n; | ||
147 | },$v); | 150 | },$v); |
148 | if(count($v)===1){ | 151 | if(count($v)===1){ |
149 | // 只有一个值时就是 = | 152 | // 只有一个值时就是 = |
@@ -153,7 +156,7 @@ function dbWhere(array $where, string $ar = 'and'):string{ | @@ -153,7 +156,7 @@ function dbWhere(array $where, string $ar = 'and'):string{ | ||
153 | } | 156 | } |
154 | 157 | ||
155 | }else{ | 158 | }else{ |
156 | - $sql[] = "`{$f}` = '".addslashes($v)."'"; | 159 | + $sql[] = "`{$f}` = '". (is_string($v) ? addslashes($v): $v) ."'"; |
157 | } | 160 | } |
158 | 161 | ||
159 | } | 162 | } |
@@ -318,6 +321,14 @@ function folderAlias($folder){ | @@ -318,6 +321,14 @@ function folderAlias($folder){ | ||
318 | 'Deleted Messages' => '回收站', | 321 | 'Deleted Messages' => '回收站', |
319 | ]; | 322 | ]; |
320 | 323 | ||
324 | + | ||
325 | + foreach ($folder_map as $key=>$name){ | ||
326 | + if(strtolower($folder) == strtolower($key)){ | ||
327 | + return $name; | ||
328 | + } | ||
329 | + } | ||
330 | + | ||
331 | + | ||
321 | return $folder_map[$folder]??$folder; | 332 | return $folder_map[$folder]??$folder; |
322 | 333 | ||
323 | } | 334 | } |
@@ -32,6 +32,7 @@ return [ | @@ -32,6 +32,7 @@ return [ | ||
32 | 'folder_delete_exist_child' => '无法删除带有子文件夹的目录', | 32 | 'folder_delete_exist_child' => '无法删除带有子文件夹的目录', |
33 | 'folder_delete_exist_mail' => '无法删除存在邮件的目录', | 33 | 'folder_delete_exist_mail' => '无法删除存在邮件的目录', |
34 | 'folder_delete_error' => '文件夹删除失败', | 34 | 'folder_delete_error' => '文件夹删除失败', |
35 | + 'folder_move_error' => '请选择目标文件夹', | ||
35 | 36 | ||
36 | 'sync_request_param_error' => '同步请求参数异常', | 37 | 'sync_request_param_error' => '同步请求参数异常', |
37 | 38 |
@@ -28,12 +28,24 @@ class DbPool { | @@ -28,12 +28,24 @@ class DbPool { | ||
28 | * @time 2023/2/13 9:12 | 28 | * @time 2023/2/13 9:12 |
29 | */ | 29 | */ |
30 | public function getClient(){ | 30 | public function getClient(){ |
31 | + if(!$this->client){ | ||
32 | + $this->connect(); | ||
33 | + } | ||
31 | return $this->client; | 34 | return $this->client; |
32 | } | 35 | } |
33 | 36 | ||
34 | 37 | ||
35 | public function __construct() | 38 | public function __construct() |
36 | { | 39 | { |
40 | + $this->connect(); | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * 连接sql | ||
45 | + * @author:dc | ||
46 | + * @time 2023/3/23 9:14 | ||
47 | + */ | ||
48 | + public function connect(){ | ||
37 | try { | 49 | try { |
38 | $this->client = new \PDO( | 50 | $this->client = new \PDO( |
39 | 'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT, | 51 | 'mysql:charset=utf8mb4;dbname='.DB_DATABASE.';host='.DB_HOST.';port='.DB_PORT, |
@@ -46,9 +58,8 @@ class DbPool { | @@ -46,9 +58,8 @@ class DbPool { | ||
46 | ] | 58 | ] |
47 | ); | 59 | ); |
48 | }catch (\PDOException $e){ | 60 | }catch (\PDOException $e){ |
49 | - | 61 | + logs($e->getMessage()); |
50 | } | 62 | } |
51 | - | ||
52 | } | 63 | } |
53 | 64 | ||
54 | 65 | ||
@@ -70,7 +81,7 @@ class DbPool { | @@ -70,7 +81,7 @@ class DbPool { | ||
70 | $timer = microtime(true); | 81 | $timer = microtime(true); |
71 | } | 82 | } |
72 | 83 | ||
73 | - $query = $this->client->prepare($sql); | 84 | + $query = $this->getClient()->prepare($sql); |
74 | 85 | ||
75 | $ret = $query->execute($params); | 86 | $ret = $query->execute($params); |
76 | 87 | ||
@@ -165,7 +176,7 @@ class DbPool { | @@ -165,7 +176,7 @@ class DbPool { | ||
165 | $query = $this->query([$sql,$data]); | 176 | $query = $this->query([$sql,$data]); |
166 | 177 | ||
167 | if($query){ | 178 | if($query){ |
168 | - return $this->client->lastInsertId(); | 179 | + return $this->getClient()->lastInsertId(); |
169 | } | 180 | } |
170 | 181 | ||
171 | return 0; | 182 | return 0; |
@@ -266,7 +277,7 @@ class DbPool { | @@ -266,7 +277,7 @@ class DbPool { | ||
266 | * @time 2023/2/17 11:35 | 277 | * @time 2023/2/17 11:35 |
267 | */ | 278 | */ |
268 | public function transaction(){ | 279 | public function transaction(){ |
269 | - $this->client->beginTransaction(); | 280 | + $this->getClient()->beginTransaction(); |
270 | } | 281 | } |
271 | 282 | ||
272 | /** | 283 | /** |
@@ -275,7 +286,7 @@ class DbPool { | @@ -275,7 +286,7 @@ class DbPool { | ||
275 | * @time 2023/2/17 11:35 | 286 | * @time 2023/2/17 11:35 |
276 | */ | 287 | */ |
277 | public function rollBack(){ | 288 | public function rollBack(){ |
278 | - $this->client->rollBack(); | 289 | + $this->getClient()->rollBack(); |
279 | } | 290 | } |
280 | 291 | ||
281 | /** | 292 | /** |
@@ -284,7 +295,7 @@ class DbPool { | @@ -284,7 +295,7 @@ class DbPool { | ||
284 | * @time 2023/2/17 11:35 | 295 | * @time 2023/2/17 11:35 |
285 | */ | 296 | */ |
286 | public function commit(){ | 297 | public function commit(){ |
287 | - $this->client->commit(); | 298 | + $this->getClient()->commit(); |
288 | } | 299 | } |
289 | 300 | ||
290 | 301 |
@@ -494,12 +494,66 @@ class Imap { | @@ -494,12 +494,66 @@ class Imap { | ||
494 | } | 494 | } |
495 | 495 | ||
496 | /** | 496 | /** |
497 | + * 复制 | ||
498 | + * @param array $uids | ||
499 | + * @param string $folder | ||
500 | + * @return bool | ||
501 | + * @throws \Exception | ||
502 | + * @author:dc | ||
503 | + * @time 2023/3/22 16:35 | ||
504 | + */ | ||
505 | + public function copy(array $uids,string $folder){ | ||
506 | + | ||
507 | + $uids = implode(',',$uids); | ||
508 | + | ||
509 | + $res = $this->request("UID COPY {$uids} \"{$folder}\""); | ||
510 | + | ||
511 | + if ($res[0] == 'ok'){ | ||
512 | + return true; | ||
513 | + } | ||
514 | + | ||
515 | + throw new \Exception("copy error:".end($res[1])); | ||
516 | + } | ||
517 | + | ||
518 | + /** | ||
497 | * 移动邮件 | 519 | * 移动邮件 |
520 | + * @param array $uids | ||
521 | + * @param string $folder | ||
522 | + * @return bool | ||
523 | + * @throws \Exception | ||
498 | * @author:dc | 524 | * @author:dc |
499 | - * @time 2023/3/21 14:55 | 525 | + * @time 2023/3/22 18:06 |
500 | */ | 526 | */ |
501 | - public function move(){ | 527 | + public function move(array $uids,string $folder){ |
528 | + | ||
529 | + $uids = implode(',',$uids); | ||
530 | + | ||
531 | + $res = $this->request("UID MOVE {$uids} \"{$folder}\""); | ||
532 | + | ||
533 | + if ($res[0] == 'ok'){ | ||
534 | + return true; | ||
535 | + } | ||
536 | + | ||
537 | + throw new \Exception("move error:".end($res[1])); | ||
538 | + } | ||
502 | 539 | ||
540 | + /** | ||
541 | + * 删除邮件 | ||
542 | + * @param array $uids | ||
543 | + * @author:dc | ||
544 | + * @time 2023/3/22 17:51 | ||
545 | + */ | ||
546 | + public function delete(array $uids){ | ||
547 | + | ||
548 | +// $uids = implode(',',$uids); | ||
549 | +// | ||
550 | +// $res = $this->request("UID DELETE {$uids} "); | ||
551 | +// | ||
552 | +// if ($res[0] == 'ok'){ | ||
553 | +// return true; | ||
554 | +// } | ||
555 | +// | ||
556 | +// throw new \Exception("delete error:".end($res[1])); | ||
503 | } | 557 | } |
504 | 558 | ||
505 | 559 |
@@ -328,23 +328,58 @@ class Mail { | @@ -328,23 +328,58 @@ class Mail { | ||
328 | } | 328 | } |
329 | 329 | ||
330 | /** | 330 | /** |
331 | - * 移动邮件, | 331 | + * 复制 |
332 | * @param $uids | 332 | * @param $uids |
333 | * @param $folder | 333 | * @param $folder |
334 | + * @param $to_folder | ||
334 | * @return bool | 335 | * @return bool |
335 | * @throws \Exception | 336 | * @throws \Exception |
336 | * @author:dc | 337 | * @author:dc |
337 | - * @time 2023/3/21 14:54 | 338 | + * @time 2023/3/22 16:38 |
339 | + */ | ||
340 | + public function copy($uids,$folder,$to_folder){ | ||
341 | + // 选择目录 | ||
342 | + $status = $this->client->selectFolder($folder); | ||
343 | + | ||
344 | + return $this->client->copy($uids,$to_folder); | ||
345 | + | ||
346 | + } | ||
347 | + | ||
348 | + /** | ||
349 | + * 移动邮件 | ||
350 | + * @param $uids | ||
351 | + * @param $folder | ||
352 | + * @param $to_folder | ||
353 | + * @return bool | ||
354 | + * @throws \Exception | ||
355 | + * @author:dc | ||
356 | + * @time 2023/3/22 18:06 | ||
338 | */ | 357 | */ |
339 | public function move($uids,$folder,$to_folder){ | 358 | public function move($uids,$folder,$to_folder){ |
340 | // 选择目录 | 359 | // 选择目录 |
341 | $status = $this->client->selectFolder($folder); | 360 | $status = $this->client->selectFolder($folder); |
342 | 361 | ||
343 | - return $this->client->folderRename($uids,[Imap::FLAGS_DELETED],$recycle ? '+' : '-',true); | 362 | + return $this->client->move($uids,$to_folder); |
344 | 363 | ||
345 | } | 364 | } |
346 | 365 | ||
347 | 366 | ||
367 | +// /** | ||
368 | +// * 删除 | ||
369 | +// * @param $uids | ||
370 | +// * @param $folder | ||
371 | +// * @return bool | ||
372 | +// * @throws \Exception | ||
373 | +// * @author:dc | ||
374 | +// * @time 2023/3/22 17:52 | ||
375 | +// */ | ||
376 | +// public function delete($uids,$folder){ | ||
377 | +// // 选择目录 | ||
378 | +// $status = $this->client->selectFolder($folder); | ||
379 | +// | ||
380 | +// return $this->client->delete($uids); | ||
381 | +// } | ||
382 | + | ||
348 | 383 | ||
349 | 384 | ||
350 | 385 |
@@ -43,9 +43,9 @@ class folderSql { | @@ -43,9 +43,9 @@ class folderSql { | ||
43 | * @author:dc | 43 | * @author:dc |
44 | * @time 2023/3/14 11:49 | 44 | * @time 2023/3/14 11:49 |
45 | */ | 45 | */ |
46 | - public static function first(array|string $where):string { | 46 | + public static function first(array|string $where,$filed = '*'):string { |
47 | $where = is_numeric($where) ? ['id'=>$where] : $where; | 47 | $where = is_numeric($where) ? ['id'=>$where] : $where; |
48 | - return "select * from `".self::$table."` where ".dbWhere($where); | 48 | + return "select {$filed} from `".self::$table."` where ".dbWhere($where)." limit 1"; |
49 | } | 49 | } |
50 | 50 | ||
51 | 51 |
-
请 注册 或 登录 后发表评论