作者 邓超

1

... ... @@ -20,6 +20,8 @@ define('APP_LANG','zh');
define('ROOT_PATH',__DIR__);
// 对外的web目录
define('PUBLIC_PATH',ROOT_PATH.'/public');
// 邮件存储目录
define('MAIL_ATTACHMENT_PATH', PUBLIC_PATH.'/attachment/');
// redis
... ... @@ -39,6 +41,9 @@ define('DB_PASSWORD','pKnXKwhAFRpwcZAM');
// 调试
define('APP_DEBUG',true);
// 当前的访问域名
define('APP_HOST','http://www.mail.cn');
... ...
... ... @@ -121,13 +121,32 @@ class Home extends Base {
$email = $this->getEmail();
$yzemail = function(&$value,$field){
if($value){
if(!is_array($value)){
if(@json_decode($value,true)){
$value = json_decode($value,true);
}else{
$value = [['email'=>$value,'name'=>'']];
}
}
foreach ($value as $item){
if(!Verify::sEmail($item['email'])){
app()->e([$field.'_verify_error',$item['email']]);
}
}
}
};
$formData = Verify::checks([
'nickname|'.__('nickname') => ['required','max'=>50],
'subject|'.__('subject') => ['required','max'=>150],
'body|'.__('body_email') => ['required'],
'to|'.__('to_email') => ['required','array|string','email'],
'tos|'.__('to_email') => ['required',$yzemail],
'cc|'.__('to_cc') => [$yzemail],
'bcc|'.__('to_bcc') => [$yzemail],
'priority|'.__('priority_email') => ['in'=>[1,3,5]],
'files|'.__('files_email') => [
'attachment|'.__('files_email') => [
'file'=>[
'ext' => [],
'size' => 500,
... ... @@ -144,10 +163,10 @@ class Home extends Base {
$email['email'],
base64_decode($email['password']),
$formData['nickname']??'',
$formData['to'],
$formData['tos'],
$formData['subject'],
$formData['body'],
$formData['files']??'',
$formData['attachment']??'',
$formData['receipt']??'',
$formData['priority']??3,
);
... ... @@ -377,6 +396,34 @@ class Home extends Base {
$body = db()->first(bodySql::first($id));
if($body){
$data['body'] = json_decode($body['text_html'],true);
$charset = '';
foreach ($data['body'] as $bd){
if(!empty($bd['charset'])){
$charset = $bd['charset'];
break;
}
}
foreach ($data['body'] as $bdk=>$bd){
if(!empty($bd['path'])){
if($charset){
$data['body'][$bdk]['name'] = @iconv($charset,'utf-8',@base64_decode($bd['name']));
$data['body'][$bdk]['filename'] = @iconv($charset,'utf-8',@base64_decode($bd['filename']));
}
$data['body'][$bdk]['size'] = 0;
$data['body'][$bdk]['url'] = '';
if(is_file($bd['path'])){
// 文件大小
$data['body'][$bdk]['size'] = filesize($bd['path']);
// 文件访问地址
$data['body'][$bdk]['url'] = APP_HOST.str_replace(PUBLIC_PATH,'',$bd['path']);
}
unset($data['body'][$bdk]['path']);
}
}
return [
'data' => $data
];
... ...
... ... @@ -64,12 +64,18 @@ return [
'body_email' => '邮件内容',
'files_email' => '邮件附件',
'receipt_email' => '邮件回执',
'to_cc' => '抄送',
'to_bcc' => '密送',
'cc_verify_error' => '抄送人邮箱地址错误 %s',
'bcc_verify_error' => '密送人邮箱地址错误 %s',
'mail_not' => '邮件不存在',
'mail_body_error' => '邮件内容拉取失败',
'tos_verify_error' => '收件人邮箱地址错误 %s'
... ...
... ... @@ -318,6 +318,9 @@ class App {
$data['error_message'] = $last_error['message'];
$data['status'] = 502;
if($app->debug){
$data['debug'] = $last_error;
}
self::echo($data,502);
... ...
... ... @@ -375,7 +375,7 @@ class Body {
mkdir($data['path'],0775,true);
}
$data['signName'] = md5($content).($ext ? '.'.$ext : '');
$data['path'] = $data['path'].'/'.$data['signName'];
$data['path'] = realpath($data['path'].'/'.$data['signName']);
// 保存文件
@file_put_contents($data['path'],$content);
}
... ...
... ... @@ -320,7 +320,7 @@ class Mail {
// 选择文件夹
$this->client->selectFolder($folder_name);
$body = $this->client->fetchBody([$uid],PUBLIC_PATH.'/attachment/',true);
$body = $this->client->fetchBody([$uid],MAIL_ATTACHMENT_PATH,true);
$body = array_values($body);
$body = $body[0]['RFC822.TEXT']??'';
... ...
... ... @@ -84,21 +84,23 @@ class Verify {
}
/**
* 验证数据
* @param array $rule
* @param array $message
* @return array|false|float|int|mixed|null
* @param array $data
* @return array|false|float|int
* @throws Err
* @author:dc
* @time 2023/3/10 17:56
* @time 2023/4/6 10:27
*/
public static function checks(array $rule, array $message=[]){
public static function checks(array $rule, array $message=[], array $data = []){
$verify = new static();
$verify->message = $message;
if(!$data){
$data= app()->request();
}
if(is_array($data)){
$verify->data = &$data;
}
... ... @@ -109,10 +111,16 @@ class Verify {
$verify->alias[$key[0]] = $key[1]??$key[0];
// 验证规则
foreach ($item as $ak=>$av){
if(is_numeric($ak)){
// 是否是匿名函数
if($av instanceof \Closure){
$av($data[$key[0]], $key[0]);
continue;
}
else if(is_numeric($ak)){
$param = [$key[0]];
$ak = $av;
}else{
}
else{
$param = [$key[0],$av];
}
... ...