正在显示
5 个修改的文件
包含
78 行增加
和
4 行删除
@@ -4,6 +4,7 @@ namespace Controller; | @@ -4,6 +4,7 @@ namespace Controller; | ||
4 | 4 | ||
5 | use Lib\Mail\Mail; | 5 | use Lib\Mail\Mail; |
6 | use Lib\Mail\MailFun; | 6 | use Lib\Mail\MailFun; |
7 | +use Lib\UploadFile; | ||
7 | use Lib\Verify; | 8 | use Lib\Verify; |
8 | use Model\bodySql; | 9 | use Model\bodySql; |
9 | use Model\emailSql; | 10 | use Model\emailSql; |
@@ -209,6 +210,24 @@ class Home extends Base { | @@ -209,6 +210,24 @@ class Home extends Base { | ||
209 | } | 210 | } |
210 | } | 211 | } |
211 | } | 212 | } |
213 | + // 远程路径,云文件 | ||
214 | + $attachmentUrl = app()->request('attachmentUrl'); | ||
215 | + | ||
216 | + if(is_array($attachmentUrl)){ | ||
217 | + foreach ($attachmentUrl as $file){ | ||
218 | + $file = is_array($file) ? $file : json_decode($file,true); | ||
219 | + if(!empty($file['url']) && !empty($file['name'])){ | ||
220 | + $file = new UploadFile($file['name'],$file['url']); | ||
221 | + if($file->move()){ | ||
222 | + // 添加到邮箱中 | ||
223 | + $mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments | ||
224 | + }else{ | ||
225 | + app()->e(['attachment_upload_error',$file->name]); | ||
226 | + } | ||
227 | + } | ||
228 | + | ||
229 | + } | ||
230 | + } | ||
212 | 231 | ||
213 | // 回执,阅读后收回执的邮箱 | 232 | // 回执,阅读后收回执的邮箱 |
214 | if(!empty($formData['receipt'])){ | 233 | if(!empty($formData['receipt'])){ |
@@ -288,6 +307,9 @@ class Home extends Base { | @@ -288,6 +307,9 @@ class Home extends Base { | ||
288 | $emails = $this->getEmails(); | 307 | $emails = $this->getEmails(); |
289 | 308 | ||
290 | $mail_ids = app()->request('mail_ids'); | 309 | $mail_ids = app()->request('mail_ids'); |
310 | + if(!($mail_ids && is_array($mail_ids))){ | ||
311 | + app()->e('param_request_error'); | ||
312 | + } | ||
291 | foreach ($mail_ids as $k=>$id){ | 313 | foreach ($mail_ids as $k=>$id){ |
292 | if(!is_numeric($id)){ | 314 | if(!is_numeric($id)){ |
293 | unset($mail_ids[$k]); | 315 | unset($mail_ids[$k]); |
@@ -366,6 +388,9 @@ class Home extends Base { | @@ -366,6 +388,9 @@ class Home extends Base { | ||
366 | $emails = $this->getEmails(); | 388 | $emails = $this->getEmails(); |
367 | 389 | ||
368 | $mail_ids = app()->request('mail_ids'); | 390 | $mail_ids = app()->request('mail_ids'); |
391 | + if(!($mail_ids && is_array($mail_ids))){ | ||
392 | + app()->e('param_request_error'); | ||
393 | + } | ||
369 | foreach ($mail_ids as $k=>$id){ | 394 | foreach ($mail_ids as $k=>$id){ |
370 | if(!is_numeric($id)){ | 395 | if(!is_numeric($id)){ |
371 | unset($mail_ids[$k]); | 396 | unset($mail_ids[$k]); |
@@ -75,10 +75,11 @@ return [ | @@ -75,10 +75,11 @@ return [ | ||
75 | 'mail_not' => '邮件不存在', | 75 | 'mail_not' => '邮件不存在', |
76 | 'mail_body_error' => '邮件内容拉取失败', | 76 | 'mail_body_error' => '邮件内容拉取失败', |
77 | 77 | ||
78 | - 'tos_verify_error' => '收件人邮箱地址错误 %s' | 78 | + 'tos_verify_error' => '收件人邮箱地址错误 %s', |
79 | 79 | ||
80 | 80 | ||
81 | 81 | ||
82 | + 'upload_file_load_error' => '上传文件加载失败' | ||
82 | 83 | ||
83 | 84 | ||
84 | 85 |
@@ -252,7 +252,12 @@ class App { | @@ -252,7 +252,12 @@ class App { | ||
252 | public function e($message,$status=400){ | 252 | public function e($message,$status=400){ |
253 | if(is_array($message)){ | 253 | if(is_array($message)){ |
254 | $this->data['error_message'] = __($message[0]); | 254 | $this->data['error_message'] = __($message[0]); |
255 | - $this->data['error_message'] = sprintf($this->data['error_message'],...$message[1]); | 255 | + if(is_array($message[1])){ |
256 | + $this->data['error_message'] = sprintf($this->data['error_message'],...$message[1]); | ||
257 | + }else{ | ||
258 | + unset($message[0]); | ||
259 | + $this->data['error_message'] = sprintf($this->data['error_message'],...$message); | ||
260 | + } | ||
256 | }else{ | 261 | }else{ |
257 | $this->data['error_message'] = __($message); | 262 | $this->data['error_message'] = __($message); |
258 | } | 263 | } |
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | 2 | ||
3 | namespace Lib; | 3 | namespace Lib; |
4 | 4 | ||
5 | + | ||
5 | /** | 6 | /** |
6 | * 文件 | 7 | * 文件 |
7 | * @author:dc | 8 | * @author:dc |
@@ -44,6 +45,11 @@ class UploadFile | @@ -44,6 +45,11 @@ class UploadFile | ||
44 | public string $savePath = ''; | 45 | public string $savePath = ''; |
45 | 46 | ||
46 | /** | 47 | /** |
48 | + * @var bool | ||
49 | + */ | ||
50 | + private $isUpload = true; | ||
51 | + | ||
52 | + /** | ||
47 | * UploadFile constructor. | 53 | * UploadFile constructor. |
48 | * @param $name | 54 | * @param $name |
49 | * @param $tempFile | 55 | * @param $tempFile |
@@ -53,6 +59,37 @@ class UploadFile | @@ -53,6 +59,37 @@ class UploadFile | ||
53 | 59 | ||
54 | $this->name = $name; | 60 | $this->name = $name; |
55 | 61 | ||
62 | + // 不是临时文件 | ||
63 | + if(!is_file($tempFile)){ | ||
64 | + $this->isUpload = false; | ||
65 | + // 是不是远程路径 | ||
66 | + if(str_starts_with($tempFile, 'http://') || str_starts_with($tempFile, 'https://')){ | ||
67 | + $content = @file_get_contents($tempFile); | ||
68 | + } | ||
69 | + // 以文件内容的形式保存 | ||
70 | + else{ | ||
71 | + $content = $tempFile; | ||
72 | + } | ||
73 | + | ||
74 | + if(!$content){ | ||
75 | + throw new Err('upload_file_load_error',600); | ||
76 | + } | ||
77 | + | ||
78 | + // 临时路径 | ||
79 | + $tempFile = PUBLIC_PATH.'/temp/'.md5($tempFile); | ||
80 | + | ||
81 | + if(!is_dir(dirname($tempFile))){ | ||
82 | + @mkdir(dirname($tempFile),0775,true); | ||
83 | + } | ||
84 | + | ||
85 | + // 保存失败 | ||
86 | + if(!@file_put_contents($tempFile,$content)){ | ||
87 | + throw new Err('upload_file_load_error',601); | ||
88 | + } | ||
89 | + | ||
90 | + } | ||
91 | + | ||
92 | + | ||
56 | $this->tempFile = $tempFile; | 93 | $this->tempFile = $tempFile; |
57 | 94 | ||
58 | // kb | 95 | // kb |
@@ -83,7 +120,13 @@ class UploadFile | @@ -83,7 +120,13 @@ class UploadFile | ||
83 | // 保存的文件 | 120 | // 保存的文件 |
84 | $this->saveName = $name ? $name : md5_file($this->tempFile).'.'.$this->ext; | 121 | $this->saveName = $name ? $name : md5_file($this->tempFile).'.'.$this->ext; |
85 | 122 | ||
86 | - return move_uploaded_file($this->tempFile,$this->savePath.$this->saveName); | 123 | + if($this->isUpload){ |
124 | + return move_uploaded_file($this->tempFile,$this->savePath.$this->saveName); | ||
125 | + }else{ | ||
126 | + $ret = copy($this->tempFile,$this->savePath.$this->saveName); | ||
127 | + @unlink($this->tempFile); | ||
128 | + return $ret; | ||
129 | + } | ||
87 | 130 | ||
88 | } | 131 | } |
89 | 132 |
@@ -34,7 +34,7 @@ return [ | @@ -34,7 +34,7 @@ return [ | ||
34 | // 标记为已读 | 34 | // 标记为已读 |
35 | 'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'], | 35 | 'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'], |
36 | // 标记为已回复/未回复 | 36 | // 标记为已回复/未回复 |
37 | - 'answered_2_unanswered' => [\Controller\Home::class, 'seen_2_unseen'], | 37 | + 'answered_2_unanswered' => [\Controller\Home::class, 'answered_2_unanswered'], |
38 | // 邮件移动文件夹 | 38 | // 邮件移动文件夹 |
39 | 'move' => [\Controller\Home::class, 'move'], | 39 | 'move' => [\Controller\Home::class, 'move'], |
40 | // 检查邮箱状态 | 40 | // 检查邮箱状态 |
-
请 注册 或 登录 后发表评论