...
|
...
|
@@ -2,7 +2,6 @@ |
|
|
|
|
|
namespace Controller;
|
|
|
|
|
|
use Lib\Mail\Mail;
|
|
|
use Model\emailSql;
|
|
|
use Model\listsSql;
|
|
|
|
...
|
...
|
@@ -14,106 +13,62 @@ use Model\listsSql; |
|
|
*/
|
|
|
class Home {
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 登录操作
|
|
|
* @return int[]
|
|
|
* @author:dc
|
|
|
* @time 2023/2/13 11:50
|
|
|
* 当前登录的邮箱
|
|
|
* @var array[]
|
|
|
*/
|
|
|
public function login(){
|
|
|
// $mail,$password,$imap,$smtp
|
|
|
$formData = app()->request(['email','password','imap','smtp']);
|
|
|
|
|
|
if(empty($formData['email']) || !preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$formData['email'])){
|
|
|
app()->e('email_verify_error');
|
|
|
}
|
|
|
|
|
|
if(empty($formData['password'])){
|
|
|
app()->e('password_verify_error');
|
|
|
}
|
|
|
|
|
|
if(empty($formData['imap'])){
|
|
|
app()->e('imap_verify_error');
|
|
|
}
|
|
|
|
|
|
if(empty($formData['smtp'])){
|
|
|
app()->e('smtp_verify_error');
|
|
|
}
|
|
|
|
|
|
// 进行远程登录,验证
|
|
|
Mail::login($formData['email'],$formData['password'],$formData['imap']);
|
|
|
|
|
|
// 是否存在
|
|
|
$id = db()->value(emailSql::hasEmail($formData['email']));
|
|
|
|
|
|
$data = [
|
|
|
'password' => base64_encode($formData['password']),
|
|
|
'imap' => $formData['imap'],
|
|
|
'smtp' => $formData['smtp'],
|
|
|
'status' => 1,
|
|
|
'pwd_error' => 0,
|
|
|
'name' => '',
|
|
|
'token' => md5($formData['email'].$formData['password'].$formData['imap']),
|
|
|
];
|
|
|
|
|
|
if($id){
|
|
|
// 修改
|
|
|
$ret = db()->update(emailSql::$table,$data,dbWhere(['id'=>$id]));
|
|
|
}else{
|
|
|
// 新增
|
|
|
$ret = db()->insert(emailSql::$table,$data);
|
|
|
|
|
|
if($ret){
|
|
|
// 增加邮件数量
|
|
|
redis()->incr('email_total');
|
|
|
// 立即处理 同步
|
|
|
redis()->lPush('sync_email_lists', $ret);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private $login_email;
|
|
|
|
|
|
if($ret){
|
|
|
app()->_json([
|
|
|
'token' => $data['token']
|
|
|
]);
|
|
|
/**
|
|
|
* 构造
|
|
|
* Home constructor.
|
|
|
*/
|
|
|
public function __construct()
|
|
|
{
|
|
|
// 获取 当前请求的 邮箱
|
|
|
$this->login_email = db()->first(emailSql::firstByToken(token()));
|
|
|
if(!$this->login_email){
|
|
|
app()->e('token_verify_notfound');
|
|
|
}
|
|
|
|
|
|
app()->e('login_error');
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 邮件列表
|
|
|
* @author:dc
|
|
|
* @time 2023/2/17 14:12
|
|
|
*/
|
|
|
public function lists(){
|
|
|
$email = db()->first(emailSql::firstByToken(token()));
|
|
|
if(!$email){
|
|
|
app()->e('token_verify_notfound');
|
|
|
}
|
|
|
|
|
|
// 分页 页数
|
|
|
$page = app()->request('page',1,'intval');
|
|
|
$page = $page ? $page : 1;
|
|
|
|
|
|
$lists = db()->all(listsSql::lists($email['id'],$page));
|
|
|
$lists = db()->all(listsSql::lists($this->login_email['id'],$page));
|
|
|
|
|
|
app()->_json(listsPage($lists,100,1,30));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 邮箱文件夹
|
|
|
* @author:dc
|
|
|
* @time 2023/2/18 10:58
|
|
|
*/
|
|
|
public function folder(){
|
|
|
|
|
|
// 查询
|
|
|
$folders = db()->all(
|
|
|
\Model\folderSql::all(
|
|
|
$this->login_email['id'],
|
|
|
'`id`,`folder`,`pid`'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
// 转tree
|
|
|
$folders = list_to_tree($folders);
|
|
|
|
|
|
app()->_json($folders);
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
|