作者 邓超

login

... ... @@ -10,6 +10,7 @@
],
"require": {
"php": ">=5.5.0",
"ext-mbstring": "*",
"pear/pear-core-minimal": "~1.10.1",
"pear/auth_sasl": "~1.1.0",
"pear/mail_mime": "~1.10.0",
... ...
... ... @@ -160,6 +160,18 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') {
// Login
$is_login = $auth['valid'] && !$auth['abort'] && $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck']);
if($is_login){
$_host = parse_url($auth['host'])['host'];
// 登录成功,验证是否有smtp服务器,没有就说明是新增的,需要保存邮件服务器
if(!isset($RCMAIL->config->get('smtp_server')[$_host])){
rcube_email_server_address::insert(
explode('@',$auth['user'])[1],
$_host,
str_replace('ssl://imap.','smtp.',$auth['host'])
);
}
// 登录成功,创建绑定关系
$platform_user = (new rcube_platform_users())->create($_COOKIE['platform_id'],$RCMAIL->user->ID,$_COOKIE['platform_user_id']);
// 创建成功
... ...
<?php
/**
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| Copyright (C) Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Application class providing core functions and holding |
| instances of all 'global' objects like db- and imap-connections |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
+-----------------------------------------------------------------------+
| This file is part of the Roundcube Webmail client |
| |
| Copyright (C) The Roundcube Dev Team |
| Copyright (C) Kolab Systems AG |
| |
| Licensed under the GNU General Public License version 3 or |
| any later version with exceptions for skins & plugins. |
| See the README file for a full license statement. |
| |
| PURPOSE: |
| Application class providing core functions and holding |
| instances of all 'global' objects like db- and imap-connections |
+-----------------------------------------------------------------------+
| Author: Thomas Bruederli <roundcube@gmail.com> |
| Author: Aleksander Machniak <alec@alec.pl> |
+-----------------------------------------------------------------------+
*/
/**
* Application class of Roundcube Webmail
... ... @@ -384,11 +384,11 @@ class rcmail extends rcube
}
self::raise_error([
'code' => 700,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Addressbook source ($id) not found!"
],
'code' => 700,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Addressbook source ($id) not found!"
],
true, true);
}
... ... @@ -553,9 +553,9 @@ class rcmail extends rcube
$responses = array_values($responses);
$hook = $this->plugins->exec_hook('get_compose_responses', [
'list' => $responses,
'sorted' => $sorted,
'user_only' => $user_only,
'list' => $responses,
'sorted' => $sorted,
'user_only' => $user_only,
]);
return $hook['list'];
... ... @@ -807,22 +807,22 @@ class rcmail extends rcube
if (!$user) {
self::raise_error([
'code' => 620,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Failed to create a user record. Maybe aborted by a plugin?"
],
'code' => 620,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Failed to create a user record. Maybe aborted by a plugin?"
],
true, false
);
}
}
else {
self::raise_error([
'code' => 621,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Access denied for new user $username. 'auto_create_user' is disabled"
],
'code' => 621,
'file' => __FILE__,
'line' => __LINE__,
'message' => "Access denied for new user $username. 'auto_create_user' is disabled"
],
true, false
);
}
... ... @@ -989,6 +989,16 @@ class rcmail extends rcube
$key = key($default_host);
$host = is_numeric($key) ? $default_host[$key] : $key;
}
// host再次为空,说明数据库里面没有这个服务器信息
if(empty($host)){
$post_host = parse_url($post_host);
$host = 'ssl://'.($post_host['host']??$post_host['path']??'');
// 手动填写的imap服务器
$default_host[$host] = $host;
$this->config->set('default_host',$default_host);
}
}
else if (empty($default_host)) {
$host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
... ... @@ -1340,8 +1350,8 @@ class rcmail extends rcube
}
$plugin = $this->plugins->exec_hook('contact_create', [
'record' => $contact,
'source' => $this->get_address_book_id($source),
'record' => $contact,
'source' => $this->get_address_book_id($source),
]);
$contact = $plugin['record'];
... ... @@ -1404,9 +1414,9 @@ class rcmail extends rcube
}
$plugin = $this->plugins->exec_hook('contact_exists', [
'email' => $email,
'type' => $type,
'sources' => $sources,
'email' => $email,
'type' => $type,
'sources' => $sources,
]);
if (!empty($plugin['abort'])) {
... ...
... ... @@ -2342,28 +2342,49 @@ EOF;
$input_host = null;
$hide_host = false;
if (is_array($default_host) && count($default_host) > 1) {
$input_host = new html_select(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'custom-select']);
foreach ($default_host as $key => $value) {
if (!is_array($value)) {
$input_host->add($value, (is_numeric($key) ? $value : $key));
}
else {
$input_host = null;
break;
}
}
}
else if (is_array($default_host) && ($host = key($default_host)) !== null) {
$hide_host = true;
$input_host = new html_hiddenfield([
'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host] + $attrib);
}
else if (empty($default_host)) {
// 调整为手动输入模式
// if (is_array($default_host) && count($default_host) > 1) {
// $input_host = new html_select(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'custom-select']);
//
// foreach ($default_host as $key => $value) {
// if (!is_array($value)) {
// $input_host->add($value, (is_numeric($key) ? $value : $key));
// }
// else {
// $input_host = null;
// break;
// }
// }
// }
// else if (is_array($default_host) && ($host = key($default_host)) !== null) {
// $hide_host = true;
// $input_host = new html_hiddenfield([
// 'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host] + $attrib);
// }
// else if (empty($default_host)) {
$input_host = new html_inputfield(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'form-control']
+ $attrib + $host_attrib);
// }
// 加入js来控制
$js_default_host = rcube_email_server_address::getKeyValue();
$_script = "<script>
var _default_hosts = ".json_encode($js_default_host,JSON_UNESCAPED_UNICODE).";
$(\"#rcmloginuser\").change(function() {
auto_host($(this).val());
});
$(\"#rcmloginuser\").keyup(function() {
auto_host($(this).val());
});
function auto_host(_user){
_user = _user.split('@');
if(_user[1]){
if(_default_hosts[_user[1]]){
$(\"#rcmloginhost\").val(_default_hosts[_user[1]]);
}
}
}
</script>";
$this->add_script(mb_substr($_script,8,-9),'foot');
$this->add_gui_object('loginform', $form_name);
... ... @@ -2378,7 +2399,7 @@ EOF;
// add host selection row
if (is_object($input_host) && !$hide_host) {
$table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server'))));
$table->add('title', html::label('rcmloginhost', html::quote('imap '.$this->app->gettext('server'))));
$table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
}
... ...
... ... @@ -426,9 +426,10 @@ class rcube_config
$rows = rcube_email_server_address::all($rcube->get_dbh());
foreach ($rows as $row){
$result['imaps'][$row['imap']] = $row['name'];
$result['stmps'][parse_url($row['imap'])['host']] = $row['smtp'];
// imap 配置
$result['imaps']['ssl://'.$row['imap']] = $row['name'] ? $row['name'] : $row['imap'];
// smtp_server
$result['stmps'][$row['imap']] = $row['smtp'];
}
$this->set('default_host',$result['imaps']??[]);
... ...
... ... @@ -82,6 +82,29 @@ class rcube_email_server_address{
//
// }
/**
* 获取key=>val数据,
* @param string $key
* @param string $value
* @return array
* @author:dc
* @time 2022/7/25 14:12
*/
public static function getKeyValue($key='mail_suffix',$value='imap'){
$db = rcube::get_instance()->get_dbh();
$result = $db->query("select `{$key}`,`{$value}` from ".$db->table_name('email_server_address',true));
$key_value = [];
foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row){
$key_value[$row[$key]] = $row[$value];
}
return $key_value;
}
public static function all($db = null)
{
... ... @@ -105,7 +128,50 @@ class rcube_email_server_address{
return $rows;
}
/**
* 通过前缀获取
* @param $mail_suffix
* @param string $field
* @author:dc
* @time 2022/7/25 11:14
* @return array|bool
*/
public static function firstBySuffix($mail_suffix,$field='`imap`,`smtp`'){
$db = rcube::get_instance()->get_dbh();
// 查询
$result = $db->query("select {$field} from ".$db->table_name('email_server_address',true)." where `mail_suffix` = ? limit 1",$mail_suffix);
// 返回结果
return $db->fetch_assoc($result);
}
/**
* 新增数据
* @param $mail_suffix
* @param $imap
* @param $smtp
* @param string $name
* @return false|int|mixed
* @author:dc
* @time 2022/7/25 11:38
*/
public static function insert($mail_suffix,$imap,$smtp,$name=' '){
$db = rcube::get_instance()->get_dbh();
$table = $db->table_name('email_server_address',true);
// 插入
$result = $db->query("insert into {$table} set `mail_suffix`=?,`imap`=?,`smtp`=?,`service_provider`=?",$mail_suffix,$imap,$smtp,$name);
// 返回结果
if($result && $db->affected_rows($result) && ($id = $db->insert_id($result))){
return $id;
}
return 0;
}
... ...