作者 邓超

1

... ... @@ -4,6 +4,7 @@ namespace Controller;
use Lib\Mail\Mail;
use Lib\Mail\MailFun;
use Lib\UploadFile;
use Lib\Verify;
use Model\bodySql;
use Model\emailSql;
... ... @@ -209,6 +210,24 @@ class Home extends Base {
}
}
}
// 远程路径,云文件
$attachmentUrl = app()->request('attachmentUrl');
if(is_array($attachmentUrl)){
foreach ($attachmentUrl as $file){
$file = is_array($file) ? $file : json_decode($file,true);
if(!empty($file['url']) && !empty($file['name'])){
$file = new UploadFile($file['name'],$file['url']);
if($file->move()){
// 添加到邮箱中
$mail->addAttachment($file->savePath.$file->saveName, $file->name); //Add attachments
}else{
app()->e(['attachment_upload_error',$file->name]);
}
}
}
}
// 回执,阅读后收回执的邮箱
if(!empty($formData['receipt'])){
... ... @@ -288,6 +307,9 @@ class Home extends Base {
$emails = $this->getEmails();
$mail_ids = app()->request('mail_ids');
if(!($mail_ids && is_array($mail_ids))){
app()->e('param_request_error');
}
foreach ($mail_ids as $k=>$id){
if(!is_numeric($id)){
unset($mail_ids[$k]);
... ... @@ -366,6 +388,9 @@ class Home extends Base {
$emails = $this->getEmails();
$mail_ids = app()->request('mail_ids');
if(!($mail_ids && is_array($mail_ids))){
app()->e('param_request_error');
}
foreach ($mail_ids as $k=>$id){
if(!is_numeric($id)){
unset($mail_ids[$k]);
... ...
... ... @@ -75,10 +75,11 @@ return [
'mail_not' => '邮件不存在',
'mail_body_error' => '邮件内容拉取失败',
'tos_verify_error' => '收件人邮箱地址错误 %s'
'tos_verify_error' => '收件人邮箱地址错误 %s',
'upload_file_load_error' => '上传文件加载失败'
... ...
... ... @@ -252,8 +252,13 @@ class App {
public function e($message,$status=400){
if(is_array($message)){
$this->data['error_message'] = __($message[0]);
if(is_array($message[1])){
$this->data['error_message'] = sprintf($this->data['error_message'],...$message[1]);
}else{
unset($message[0]);
$this->data['error_message'] = sprintf($this->data['error_message'],...$message);
}
}else{
$this->data['error_message'] = __($message);
}
$this->data['status'] = $status;
... ...
... ... @@ -2,6 +2,7 @@
namespace Lib;
/**
* 文件
* @author:dc
... ... @@ -44,6 +45,11 @@ class UploadFile
public string $savePath = '';
/**
* @var bool
*/
private $isUpload = true;
/**
* UploadFile constructor.
* @param $name
* @param $tempFile
... ... @@ -53,6 +59,37 @@ class UploadFile
$this->name = $name;
// 不是临时文件
if(!is_file($tempFile)){
$this->isUpload = false;
// 是不是远程路径
if(str_starts_with($tempFile, 'http://') || str_starts_with($tempFile, 'https://')){
$content = @file_get_contents($tempFile);
}
// 以文件内容的形式保存
else{
$content = $tempFile;
}
if(!$content){
throw new Err('upload_file_load_error',600);
}
// 临时路径
$tempFile = PUBLIC_PATH.'/temp/'.md5($tempFile);
if(!is_dir(dirname($tempFile))){
@mkdir(dirname($tempFile),0775,true);
}
// 保存失败
if(!@file_put_contents($tempFile,$content)){
throw new Err('upload_file_load_error',601);
}
}
$this->tempFile = $tempFile;
// kb
... ... @@ -83,7 +120,13 @@ class UploadFile
// 保存的文件
$this->saveName = $name ? $name : md5_file($this->tempFile).'.'.$this->ext;
if($this->isUpload){
return move_uploaded_file($this->tempFile,$this->savePath.$this->saveName);
}else{
$ret = copy($this->tempFile,$this->savePath.$this->saveName);
@unlink($this->tempFile);
return $ret;
}
}
... ...
... ... @@ -34,7 +34,7 @@ return [
// 标记为已读
'seen_2_unseen' => [\Controller\Home::class, 'seen_2_unseen'],
// 标记为已回复/未回复
'answered_2_unanswered' => [\Controller\Home::class, 'seen_2_unseen'],
'answered_2_unanswered' => [\Controller\Home::class, 'answered_2_unanswered'],
// 邮件移动文件夹
'move' => [\Controller\Home::class, 'move'],
// 检查邮箱状态
... ...