审查视图

lib/Mail/Mail.php 22.1 KB
1  
邓超 authored
1 2 3 4
<?php

namespace Lib\Mail;
x  
邓超 authored
5
use Event\syncMail;
1  
邓超 authored
6
use Lib\DbPool;
1  
邓超 authored
7
use Model\bodySql;
1  
邓超 authored
8 9
use Model\folderSql;
use Model\listsSql;
1  
邓超 authored
10
1  
邓超 authored
11 12 13 14 15 16 17 18 19 20 21
/**
 * 操作邮件
 * @author:dc
 * @time 2023/2/5 10:10
 * Class MailFun
 * @package Helper\Mail
 */
class Mail {

    /**
     * imap服务器连接实例
1  
邓超 authored
22
     * @var Imap
1  
邓超 authored
23
     */
1  
邓超 authored
24
    public Imap $client;
1  
邓超 authored
25
1  
邓超 authored
26 27 28 29
    /**
     * @var string
     */
    private string $username;
1  
邓超 authored
30 31

    /**
1  
邓超 authored
32 33 34 35 36 37 38 39 40 41 42
     * @var string
     */
    private string $password;

    /**
     * @var string
     */
    private string $server;

    /**
     * Mail constructor.
1  
邓超 authored
43 44 45
     * @param string $email
     * @param string $password
     * @param string $imap
1  
邓超 authored
46 47 48 49 50 51
     */
    public function __construct(string $email,string $password,string $imap)
    {
        $this->username = $email;
        $this->password = $password;
        $this->server = $imap;
52 53

        $this->client = new Imap();
1  
邓超 authored
54 55 56 57 58 59
    }

    /**
     * 登录imap服务器
     * @param bool $pass_err
     * @return int
1  
邓超 authored
60
     * @author:dc
1  
邓超 authored
61
     * @time 2023/3/14 10:03
1  
邓超 authored
62
     */
1  
邓超 authored
63
    public function login($pass_err=true):int {
1  
邓超 authored
64
邓超 authored
65
        // 处理url
邓超 authored
66
        $host = MailFun::getHostPort($this->server,993,'ssl://');
1  
邓超 authored
67 68
        try {
            // 是否初始成功
邓超 authored
69
            $this->client->login($host['host'].':'.$host['port'],$this->username,$this->password);
1  
邓超 authored
70
        }catch (\Throwable $e){
x  
邓超 authored
71
            logs($this->username.'===>'.$e->getMessage());
x  
邓超 authored
72
            if($pass_err){
x  
邓超 authored
73
                // 是否是密码错误
x  
邓超 authored
74
                foreach ([
x  
邓超 authored
75 76 77 78 79 80 81 82
                             'NO [ALERT] Invalid credentials (Failure)',// 登录失败
                             'NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)',// 登录失败
                             'NO [AUTHENTICATIONFAILED] Authentication failed.',// 登录失败 权限
                             'NO LOGIN Login error',// 登录失败
                             'NO LOGIN auth error',// 登录失败
                             'NO ERR.LOGIN.PASSERR',// 登录失败 密码错误
                             'NO Login fail.',// 登录失败
                             'NO LOGIN failed.', // 登录失败
x  
邓超 authored
83
//                    'NO ERR.LOGIN.REQCODE', // 未知错误
x  
邓超 authored
84
                             'NO [ALERT] Application-specific password', // 这个错误是没有提供特定的授权码
x  
邓超 authored
85
                             'NO LOGIN Login error, user name or password error'
x  
邓超 authored
86 87
                         ] as $em){
                    if(str_contains($e->getMessage(), $em)){
x  
邓超 authored
88 89 90 91 92 93 94
                        db()->update(
                            \Model\emailSql::$table,
                            ['pwd_error'=>1],
                            dbWhere(['email'=>$this->username])
                        );
                    }
                }
1  
邓超 authored
95
                // 一天中超过 3次失败说明密码错误了
邓超 authored
96
//                if(redis()->incr('email_login_error:'.md5($this->username),86400) > 10){
x  
邓超 authored
97
                // 登录失败了 ,
邓超 authored
98 99
//                    db()->update(\Model\emailSql::$table,['pwd_error'=>1],dbWhere(['email'=>$this->username]));
//                }
1  
邓超 authored
100
                return -1;
1  
邓超 authored
101 102 103
            }

            return $e->getCode() == 403 ? 0 : -1;
1  
邓超 authored
104
1  
邓超 authored
105
        }
邓超 authored
106
//        redis()->delete('email_login_error:'.md5($this->username));
1  
邓超 authored
107
1  
邓超 authored
108
        return 1;
1  
邓超 authored
109 110 111 112 113
    }


    /**
     * 同步文件夹
1  
邓超 authored
114
     * @param int $email_id
1  
邓超 authored
115
     * @param DbPool|null $db
1  
邓超 authored
116 117 118 119
     * @return mixed
     * @author:dc
     * @time 2023/2/5 10:58
     */
1  
邓超 authored
120
    public function syncFolder($email_id,$db=null){
1  
邓超 authored
121
        $db = $db ? $db : db();
1  
邓超 authored
122
        // 读取所有文件夹,未解密
1  
邓超 authored
123
        $folders    =   $this->client->getFolder();
1  
邓超 authored
124
125 126 127 128 129 130 131
        foreach ($folders as $k=>$item){
            $pname = explode('/',$item['folder']);
            if(count($pname)>1){
                array_pop($pname);
                $pname = implode('/',$pname);
            }else{
                $pname = '';
1  
邓超 authored
132 133
            }
134 135
            $folders[$k]['pname'] = $pname;
        }
x  
邓超 authored
136
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
        $p = 0;
        $uuids = [];
        while ($folders){
            foreach ($folders as $fk=>$folder){
                $uuid = md5($email_id.$folder['folder']);
                $uuids[$uuid] = $uuid;
                // 查找/出现的次数
                if (substr_count($folder['folder'],'/') == $p){
// 查找pid
                    $pid = $db->value(folderSql::has(['uuid'=>md5($email_id.$folder['pname'])]));
                    $pid = $pid ? $pid : 0;
//                    try {
                        $folder_name = '';
                        // 已发送
                        if(in_array('Send',$folder['check'])){
                            $folder_name = folderAlias('Send');
                        }
                        // 草稿
                        elseif(in_array('Drafts',$folder['check'])){
                            $folder_name = folderAlias('Drafts');
                        }
                        // 垃圾
                        elseif(in_array('Junk',$folder['check'])){
                            $folder_name = folderAlias('Junk');
                        }
                        // 回收站
                        elseif(in_array('Trash',$folder['check'])){
                            $folder_name = folderAlias('Trash');
                        }

                        if(!$folder_name){
                            $fn = explode('/',$folder['parseFolder']);
                            $folder_name = folderAlias(end($fn));
                        }
                        if(!$db->count(folderSql::has(['uuid'=>$uuid]))){
                            $db->insert(folderSql::$table,[
                                'email_id' => $email_id,
                                'folder' => folderAlias($folder_name),
                                'origin_folder' => $folder['folder'],
                                'uuid'  =>  $uuid,
                                'pid'   =>  $pid
                            ],false);
                        }else{
                            $db->update(folderSql::$table,[
                                'email_id' => $email_id,
                                'folder' => folderAlias($folder_name),
                                'origin_folder' => $folder['folder'],
                                'uuid'  =>  $uuid,
                                'pid'   =>  $pid
                            ],dbWhere(['email_id' => $email_id,'uuid'  =>  $uuid]),false);
                        }
//                    }catch (\Throwable $e){
                        // 这里就不处理失败了
//                    }

                    unset($folders[$fk]);
邓超 authored
193 194

                }
1  
邓超 authored
195
            }
196 197
            $p++;
        }
1  
邓超 authored
198
199 200 201
        if($uuids){
            // 删除以前的
            $db->delete(folderSql::$table,['uuid.notin'=>$uuids,'email_id'=>$email_id]);
1  
邓超 authored
202 203 204 205 206 207 208 209 210 211
        }

    }


    /**
     * 同步邮件
     * @param $email_id
     * @param $folder_id
     * @param string $folder
1  
邓超 authored
212
     * @param null|DbPool $db
x  
邓超 authored
213
     * @return bool|array
1  
邓超 authored
214
     * @throws \Exception
1  
邓超 authored
215
     * @author:dc
1  
邓超 authored
216
     * @time 2023/2/18 9:54
1  
邓超 authored
217
     */
x  
邓超 authored
218
    public function syncMail($email_id,$folder_id,$folder='INBOX') {
1  
邓超 authored
219 220 221
        if(empty($folder)){
            return 0;
        }
1  
邓超 authored
222
//        _echo('正在同步文件夹:'.$folder);
x  
邓超 authored
223
        $db = db();
1  
邓超 authored
224
        // 选择文件夹
x  
邓超 authored
225 226 227 228 229 230
        try {
            $status =   $this->client->selectFolder($folder);
        }catch (\Throwable $e){
            return 0;
        }
1  
邓超 authored
231
1  
邓超 authored
232
        // 是否有邮件
1  
邓超 authored
233
        if (!is_array($status) || !isset($status['EXISTS']) || !$status['EXISTS']){
1  
邓超 authored
234 235 236 237
            return true;
        }

        // 更新数量
238 239 240 241 242
        $upFolderData = ['exsts'=>$status['EXISTS'],'last_sync_time' => time()];
        // 谷歌 不返未读数量 谢特
        if(isset($status['UNSEEN'])){
            $upFolderData['unseen'] = $status['UNSEEN'];
        }
1  
邓超 authored
243 244
        $db->update(
            folderSql::$table,
245
            $upFolderData,
1  
邓超 authored
246 247
            dbWhere(['id'=>$folder_id]),
            false
1  
邓超 authored
248 249
        );
邓超 authored
250 251 252 253 254 255 256
        // 读取黑名单
        $blacklist = redis()->get('blacklist:'.$email_id);
        $blackFolder = '';
        if($blacklist){
            $blackFolder = $db->value(folderSql::originFolder($email_id,'垃圾箱'));
        }
邓超 authored
257 258 259
        //
        $nu = 100;
        $msgno = 1;
x  
邓超 authored
260
        $success_uid = [];
邓超 authored
261
        while (true){
邓超 authored
262 263 264 265 266 267

            // 结束操作了
            if(redis()->get(SYNC_RUNNING_REDIS_KEY) == 'stop'){
                break;
            }
邓超 authored
268 269 270 271
            // 是否结束了
            if($status['EXISTS'] < $msgno){
                break;
            }
x  
邓超 authored
272 273 274 275 276 277
            // 是否超过了最大数量
            $maxmsgno = ($msgno-1)+$nu;
            if($maxmsgno > $status['EXISTS']){
                $maxmsgno = $status['EXISTS'];
            }
            $uids = $this->client->fetch(range($msgno,$maxmsgno),'UID');
邓超 authored
278 279 280
            if(!$uids){
                break;
            }
x  
邓超 authored
281
x  
邓超 authored
282
邓超 authored
283
            $uids = array_column($uids,'UID');
邓超 authored
284
            $existsUids = $db->all(listsSql::getUids($email_id,$folder_id,$uids));
x  
邓超 authored
285
            if($existsUids){
邓超 authored
286
                $existsUids = array_column($existsUids,'uid');
x  
邓超 authored
287 288
                // 获取不存在数据库的uid
                $uids = array_diff($uids,$existsUids);
邓超 authored
289
            }
x  
邓超 authored
290
邓超 authored
291 292 293 294 295

            $msgno += $nu;

            // 开始同步
            if($uids){
邓超 authored
296 297 298 299 300 301 302 303 304
                $this->syncUidEmail(
                    $uids,
                    $email_id,
                    $folder,
                    $folder_id,
                    $blacklist,
                    $blackFolder,
                    $db
                );
x  
邓超 authored
305
                $success_uid = array_merge($success_uid,$uids);
x  
邓超 authored
306 307
            }
1  
邓超 authored
308
        }
1  
邓超 authored
309
邓超 authored
310
        // 更新数量
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
        if(!isset($status['UNSEEN'])){
            // 统计未读数量
            $unseen = $db->count(listsSql::listCount(dbWhere([
                'seen'  => 0,
                'deleted'  => 0,
                'email_id'  => $email_id,
                'folder_id'  => $folder_id,
            ])));
            $db->update(
                folderSql::$table,
                ['unseen' => $unseen],
                dbWhere(['id'=>$folder_id]),
                false
            );
        }
邓超 authored
327
x  
邓超 authored
328
        return $success_uid;
1  
邓超 authored
329 330 331

    }
邓超 authored
332 333 334 335 336 337 338 339
    /**
     * 同步邮件 只通过 uid获取
     * @param array $uids
     * @param $email_id
     * @param $folder
     * @param $folder_id
     * @param $blacklist
     * @param $blackFolder
x  
邓超 authored
340
     * @param \Lib\DbPool $db
邓超 authored
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
     * @throws \Exception
     * @author:dc
     * @time 2023/8/2 15:35
     */
    public function syncUidEmail(array $uids,$email_id,$folder,$folder_id,$blacklist,$blackFolder,$db){
        $results = $this->client->fetchHeader($uids,true);

        if($results && is_array($results)){
            // 表示已存在新邮件
            if($folder == 'INBOX') redis()->incr('have_new_mail_'.$email_id,120);

            // 批量插入
            foreach ($results as $key=>$result){
                $header = $result['HEADER.FIELDS'];

                foreach ($result['FLAGS'] as $k=>$FLAG){
                    $result['FLAGS'][$k] = strtolower(str_replace('\\','',$FLAG));
                }
                try {
x  
邓超 authored
361 362 363 364
                    foreach ($header as $k=>$item){
                        $header[strtolower($k)] = $item;
                    }
邓超 authored
365
                    // 没有收件人
x  
邓超 authored
366
                    $header['to'] = MailFun::toOrFrom($header['to']??'');
x  
邓超 authored
367
邓超 authored
368
x  
邓超 authored
369
                    $header['from'] = MailFun::toOrFrom($header['from']);
邓超 authored
370 371 372
                    // 抄送 ,密送
                    $cc = [];
                    $bcc = [];
x  
邓超 authored
373 374
                    if($header['cc']??''){
                        $cc = MailFun::toOrFrom($header['cc']);
邓超 authored
375
                    }
x  
邓超 authored
376 377
                    if($header['bcc']??''){
                        $bcc = MailFun::toOrFrom($header['bcc']);
邓超 authored
378 379 380 381 382
                    }


                    $data   =   [
                        'uid'   =>  $result['UID'],
x  
邓超 authored
383
                        'subject'   =>  $header['subject']??($header['Subject']??($header['SUBJECT']??'')),
邓超 authored
384 385
                        'cc'    =>  $cc,
                        'bcc'    =>  $bcc,
x  
邓超 authored
386 387 388 389 390 391
                        'from'   =>  $header['from'][0]['email']??'',
                        'from_name'   =>  $header['from'][0]['name']??'',
                        'to'   =>  $header['to']?implode(',',array_column($header['to'],'email')):'',
                        'to_name'   =>  json_encode($header['to']),
                        'date'   =>  strtotime(is_array($header['date']??'') ? $header['date'][0] : $header['date']??''),
                        'message_id'   =>  $header['message-id']??'',
邓超 authored
392 393 394 395 396 397 398 399 400 401 402 403 404 405
                        'udate'   =>  strtotime($result['INTERNALDATE']),
                        'size'   =>  $result['RFC822.SIZE']??0,
                        'recent'   =>  in_array('recent',$result['FLAGS']) ? 1 : 0,
                        'seen'   =>  in_array('seen',$result['FLAGS']) ? 1 : 0,
                        'draft'   =>  in_array('draft',$result['FLAGS']) ? 1 : 0,
                        'flagged'   =>  in_array('flagged',$result['FLAGS']) ? 1 : 0,
                        'answered'   =>  in_array('answered',$result['FLAGS']) ? 1 : 0,
                        'folder_id'   =>  $folder_id,
                        'email_id'    =>  $email_id,
                        'is_file'  =>  MailFun::isFile($result['BODYSTRUCTURE']??'') ? 1: 0 //是否附件
                    ];
                    $data['date'] = $data['date'] ? : 0;

                    // 验证是否存在黑名单中
x  
邓超 authored
406
                    if($blacklist && $blackFolder!=$folder){
邓超 authored
407 408 409 410 411 412 413 414 415 416 417 418
                        // 邮箱是否在黑名单中
                        $isBlacklist = false;
                        if (!empty($blacklist['emails']) && is_array($blacklist['emails']) && in_array($data['from'],$blacklist['emails'])){
                            $isBlacklist = true;
                        }
                        // 域是否存在
                        if (!empty($blacklist['domain']) && is_array($blacklist['domain']) && in_array(explode('@',$data['from'])[1],$blacklist['domain'])){
                            $isBlacklist = true;
                        }

                        if($isBlacklist && $blackFolder){
                            // 移入垃圾箱
x  
邓超 authored
419
                            try {
x  
邓超 authored
420
                                $this->client->move([$result['UID']],$blackFolder);
x  
邓超 authored
421 422 423 424
                            }catch (\Throwable $e){
                                logs('移动邮件失败 '.$result['UID'].':'.$e->getMessage().$e->getTraceAsString());
                            }
邓超 authored
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
                            continue;
                        }
                    }


                }catch (\Throwable $e){
                    logs(
                        '邮件解析失败:'.PHP_EOL.$e->getMessage().PHP_EOL.print_r($result,true),
                        LOG_PATH.'/imap/mail/'.$email_id.'/'.$result['UID'].'.log'
                    );
                    unset($results[$key]);
                    continue;
                }

                // 插入数据库
x  
邓超 authored
440 441
                // 主题太长了就截取掉
                $data['subject'] = mb_substr($data['subject'],0,3500);
邓超 authored
442
                try {
x  
邓超 authored
443
                    $id = $db->throw()->insert(listsSql::$table,$data);
x  
邓超 authored
444
                    if($id){
x  
邓超 authored
445 446 447 448 449 450 451 452
                        try {
                            go(function ($id,$header,$data){
                                new syncMail($id,$header,$data);
                            },...[$id,$header,$data]);
                        }catch (\Throwable $e){
                            logs($e->getMessage());
                        }
x  
邓超 authored
453 454
                    }
邓超 authored
455
                }catch (\Throwable $e){
x  
邓超 authored
456 457 458 459 460 461
                    // 插入失败,尝试更新
                    $db->update(listsSql::$table,$data,dbWhere([
                        'email_id'=> $data['email_id'],
                        'folder_id' =>  $data['folder_id'],
                        'uid'   =>  $data['uid']
                    ]));
邓超 authored
462 463
                }
x  
邓超 authored
464
邓超 authored
465 466 467 468 469
                $results[$key] = [];
            }
        }
    }
1  
邓超 authored
470 471 472 473

    /**
     * 同步 邮件 内容 body
     * @param $folder_name
邓超 authored
474 475 476
     * @param $uid
     * @param $id
     * @param null $db
1  
邓超 authored
477 478 479
     * @return bool
     * @throws \Exception
     * @author:dc
邓超 authored
480
     * @time 2023/4/23 17:40
1  
邓超 authored
481
     */
1  
邓超 authored
482
    public function syncBody($folder_name, $uid , $id, $db=null):bool {
1  
邓超 authored
483 484 485
        if(empty($folder_name)){
            return 0;
        }
1  
邓超 authored
486
        $db = $db ? $db : db();
1  
邓超 authored
487
        // 选择文件夹
1  
邓超 authored
488 489
        $this->client->selectFolder($folder_name);
1  
邓超 authored
490
        $body = $this->client->fetchBody([$uid],MAIL_ATTACHMENT_PATH,true);
1  
邓超 authored
491
1  
邓超 authored
492 493
        $body = array_values($body);
        $body = $body[0]['RFC822.TEXT']??'';
1  
邓超 authored
494
1  
邓超 authored
495
        if(!empty($body)){
1  
邓超 authored
496
            $description = '';
1  
邓超 authored
497
            foreach ($body as $key=>$item){
x  
邓超 authored
498 499 500 501 502 503 504

                if(!empty($item['body'])){
                    // 过滤二进制
                    $item['body'] = preg_replace('/<0x[a-f\d]+>/','',$item['body']);
                    $body[$key]['body'] = base64_encode($item['body']);
                }
1  
邓超 authored
505 506
                if(!$description && in_array($item['type']??'',['text/html','text/plain'])){
1  
邓超 authored
507
                    if(!empty($item['charset'])){
x  
邓超 authored
508 509
                        $value = @iconv($item['charset'],'utf-8',$item['body']);
                        $value = $value ? $value : $item['body'];
1  
邓超 authored
510 511
                    }else{
                        $value = $item['body'];
1  
邓超 authored
512
                    }
邓超 authored
513
                    $value = @html_entity_decode($value, ENT_COMPAT, 'UTF-8');
1  
邓超 authored
514 515 516
                    $value=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$value); //过滤script标签
                    $value=preg_replace("/<(\/?script.*?)>/si","",$value); //过滤script标签
                    $value=preg_replace("/javascript/si","Javascript",$value); //过滤script标签
1  
邓超 authored
517 518 519
                    $value=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$value); //过滤style标签
                    $value=preg_replace("/<(\/?style.*?)>/si","",$value); //过滤style标签
1  
邓超 authored
520
                    $value = strip_tags($value);
1  
邓超 authored
521
                    $value = str_replace(["\n","\\n","&nbsp;"],'',$value);
1  
邓超 authored
522
                    $description = mb_substr(trim($value),0,190);
1  
邓超 authored
523
1  
邓超 authored
524
                }
1  
邓超 authored
525
x  
邓超 authored
526
1  
邓超 authored
527 528 529 530 531 532 533 534 535

                if(!empty($body[$key]['filename'])){
                    $body[$key]['filename'] = base64_encode($body[$key]['filename']);
                }

                if(!empty($body[$key]['name'])){
                    $body[$key]['name'] = base64_encode($body[$key]['name']);
                }
1  
邓超 authored
536 537
            }
x  
邓超 authored
538
            bodySql::insertOrUpdate([
1  
邓超 authored
539 540 541
                'lists_id'    =>  $id,
                'text_html'  =>  $body // todo::因为邮件会出现多编码问题,会导致数据库写不进去
            ]);
1  
邓超 authored
542 543

1  
邓超 authored
544
            // 更新描述
邓超 authored
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
            try {
                $db->update(listsSql::$table,[
                    'description'  =>  @base64_encode($description) ? $description : '',
                    'is_file'   =>  MailFun::isBodyFile($body)
                ],dbWhere([
                    'id'    =>  $id
                ]));
            }catch (\Throwable $e){
                $db->update(listsSql::$table,[
                    'is_file'   =>  MailFun::isBodyFile($body)
                ],dbWhere([
                    'id'    =>  $id
                ]));
            }
1  
邓超 authored
560 561 562 563 564 565 566
        }

        return true;

    }

1  
邓超 authored
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
    /**
     * 设置为未读
     * @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);
    }
1  
邓超 authored
582
    /**
邓超 authored
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
     * 删除标记
     * @param $uids
     * @param $folder
     * @param $del
     * @return bool
     * @throws \Exception
     * @author:dc
     * @time 2024/3/9 16:50
     */
    public function deleted($uids,$folder,$del=true):bool{
        // 选择目录
        $status =   $this->client->selectFolder($folder);

        return $this->client->flags($uids,[Imap::FLAGS_DELETED],$del ? '+' : '-',true);
    }

    /**
1  
邓超 authored
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615
     * 回复标记
     * @param $uids
     * @param $folder
     * @param $seen
     * @return bool
     * @throws \Exception
     * @author:dc
     * @time 2023/4/6 17:10
     */
    public function answered($uids,$folder,$seen):bool{
        // 选择目录
        $status =   $this->client->selectFolder($folder);

        return $this->client->flags($uids,[Imap::FLAGS_ANSWERED],$seen ? '+' : '-',true);
    }
邓超 authored
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
    /**
     * 回复标记
     * @param $uids
     * @param $folder
     * @param $flagged
     * @return bool
     * @throws \Exception
     * @author:dc
     * @time 2023/4/6 17:10
     */
    public function flagged($uids,$folder,$flagged):bool{
        // 选择目录
        $status =   $this->client->selectFolder($folder);

        return $this->client->flags($uids,[Imap::FLAGS_FLAGGED],$flagged ? '+' : '-',true);
    }
1  
邓超 authored
633 634

    /**
1  
邓超 authored
635
     * 复制
1  
邓超 authored
636 637
     * @param $uids
     * @param $folder
1  
邓超 authored
638
     * @param $to_folder
1  
邓超 authored
639 640
     * @return bool
     * @throws \Exception
1  
邓超 authored
641
     * @author:dc
1  
邓超 authored
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
     * @time 2023/3/22 16:38
     */
    public function copy($uids,$folder,$to_folder){
        // 选择目录
        $status =   $this->client->selectFolder($folder);

        return $this->client->copy($uids,$to_folder);

    }

    /**
     * 移动邮件
     * @param $uids
     * @param $folder
     * @param $to_folder
     * @return bool
     * @throws \Exception
     * @author:dc
     * @time 2023/3/22 18:06
1  
邓超 authored
661
     */
1  
邓超 authored
662
    public function move($uids,$folder,$to_folder){
1  
邓超 authored
663 664 665
        // 选择目录
        $status =   $this->client->selectFolder($folder);
1  
邓超 authored
666
        return $this->client->move($uids,$to_folder);
1  
邓超 authored
667 668 669

    }
邓超 authored
670 671 672 673 674 675 676 677 678
    /**
     * 清空标记为已删除的邮件,不可还原邮件
     * @author:dc
     * @time 2024/3/14 14:11
     */
    public function expunge(){
        return $this->client->expunge();
    }
1  
邓超 authored
679
1  
邓超 authored
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
//    /**
//     * 删除
//     * @param $uids
//     * @param $folder
//     * @return bool
//     * @throws \Exception
//     * @author:dc
//     * @time 2023/3/22 17:52
//     */
//    public function delete($uids,$folder){
//        // 选择目录
//        $status =   $this->client->selectFolder($folder);
//
//        return $this->client->delete($uids);
//    }
1  
邓超 authored
696 697 698


1  
邓超 authored
699
}