作者 邓超

login

@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 ], 10 ],
11 "require": { 11 "require": {
12 "php": ">=5.5.0", 12 "php": ">=5.5.0",
  13 + "ext-mbstring": "*",
13 "pear/pear-core-minimal": "~1.10.1", 14 "pear/pear-core-minimal": "~1.10.1",
14 "pear/auth_sasl": "~1.1.0", 15 "pear/auth_sasl": "~1.1.0",
15 "pear/mail_mime": "~1.10.0", 16 "pear/mail_mime": "~1.10.0",
@@ -160,6 +160,18 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') { @@ -160,6 +160,18 @@ if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') {
160 // Login 160 // Login
161 $is_login = $auth['valid'] && !$auth['abort'] && $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck']); 161 $is_login = $auth['valid'] && !$auth['abort'] && $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'], $auth['cookiecheck']);
162 if($is_login){ 162 if($is_login){
  163 +
  164 + $_host = parse_url($auth['host'])['host'];
  165 + // 登录成功,验证是否有smtp服务器,没有就说明是新增的,需要保存邮件服务器
  166 + if(!isset($RCMAIL->config->get('smtp_server')[$_host])){
  167 + rcube_email_server_address::insert(
  168 + explode('@',$auth['user'])[1],
  169 + $_host,
  170 + str_replace('ssl://imap.','smtp.',$auth['host'])
  171 + );
  172 + }
  173 +
  174 +
163 // 登录成功,创建绑定关系 175 // 登录成功,创建绑定关系
164 $platform_user = (new rcube_platform_users())->create($_COOKIE['platform_id'],$RCMAIL->user->ID,$_COOKIE['platform_user_id']); 176 $platform_user = (new rcube_platform_users())->create($_COOKIE['platform_id'],$RCMAIL->user->ID,$_COOKIE['platform_user_id']);
165 // 创建成功 177 // 创建成功
1 <?php 1 <?php
2 2
3 /** 3 /**
4 - +-----------------------------------------------------------------------+  
5 - | This file is part of the Roundcube Webmail client |  
6 - | |  
7 - | Copyright (C) The Roundcube Dev Team |  
8 - | Copyright (C) Kolab Systems AG |  
9 - | |  
10 - | Licensed under the GNU General Public License version 3 or |  
11 - | any later version with exceptions for skins & plugins. |  
12 - | See the README file for a full license statement. |  
13 - | |  
14 - | PURPOSE: |  
15 - | Application class providing core functions and holding |  
16 - | instances of all 'global' objects like db- and imap-connections |  
17 - +-----------------------------------------------------------------------+  
18 - | Author: Thomas Bruederli <roundcube@gmail.com> |  
19 - | Author: Aleksander Machniak <alec@alec.pl> |  
20 - +-----------------------------------------------------------------------+  
21 -*/ 4 ++-----------------------------------------------------------------------+
  5 +| This file is part of the Roundcube Webmail client |
  6 +| |
  7 +| Copyright (C) The Roundcube Dev Team |
  8 +| Copyright (C) Kolab Systems AG |
  9 +| |
  10 +| Licensed under the GNU General Public License version 3 or |
  11 +| any later version with exceptions for skins & plugins. |
  12 +| See the README file for a full license statement. |
  13 +| |
  14 +| PURPOSE: |
  15 +| Application class providing core functions and holding |
  16 +| instances of all 'global' objects like db- and imap-connections |
  17 ++-----------------------------------------------------------------------+
  18 +| Author: Thomas Bruederli <roundcube@gmail.com> |
  19 +| Author: Aleksander Machniak <alec@alec.pl> |
  20 ++-----------------------------------------------------------------------+
  21 + */
22 22
23 /** 23 /**
24 * Application class of Roundcube Webmail 24 * Application class of Roundcube Webmail
@@ -989,6 +989,16 @@ class rcmail extends rcube @@ -989,6 +989,16 @@ class rcmail extends rcube
989 $key = key($default_host); 989 $key = key($default_host);
990 $host = is_numeric($key) ? $default_host[$key] : $key; 990 $host = is_numeric($key) ? $default_host[$key] : $key;
991 } 991 }
  992 +
  993 + // host再次为空,说明数据库里面没有这个服务器信息
  994 + if(empty($host)){
  995 + $post_host = parse_url($post_host);
  996 + $host = 'ssl://'.($post_host['host']??$post_host['path']??'');
  997 + // 手动填写的imap服务器
  998 + $default_host[$host] = $host;
  999 + $this->config->set('default_host',$default_host);
  1000 + }
  1001 +
992 } 1002 }
993 else if (empty($default_host)) { 1003 else if (empty($default_host)) {
994 $host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST); 1004 $host = rcube_utils::get_input_value('_host', rcube_utils::INPUT_POST);
@@ -2342,28 +2342,49 @@ EOF; @@ -2342,28 +2342,49 @@ EOF;
2342 $input_host = null; 2342 $input_host = null;
2343 $hide_host = false; 2343 $hide_host = false;
2344 2344
2345 - if (is_array($default_host) && count($default_host) > 1) {  
2346 - $input_host = new html_select(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'custom-select']);  
2347 -  
2348 - foreach ($default_host as $key => $value) {  
2349 - if (!is_array($value)) {  
2350 - $input_host->add($value, (is_numeric($key) ? $value : $key));  
2351 - }  
2352 - else {  
2353 - $input_host = null;  
2354 - break;  
2355 - }  
2356 - }  
2357 - }  
2358 - else if (is_array($default_host) && ($host = key($default_host)) !== null) {  
2359 - $hide_host = true;  
2360 - $input_host = new html_hiddenfield([  
2361 - 'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host] + $attrib);  
2362 - }  
2363 - else if (empty($default_host)) { 2345 + // 调整为手动输入模式
  2346 +// if (is_array($default_host) && count($default_host) > 1) {
  2347 +// $input_host = new html_select(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'custom-select']);
  2348 +//
  2349 +// foreach ($default_host as $key => $value) {
  2350 +// if (!is_array($value)) {
  2351 +// $input_host->add($value, (is_numeric($key) ? $value : $key));
  2352 +// }
  2353 +// else {
  2354 +// $input_host = null;
  2355 +// break;
  2356 +// }
  2357 +// }
  2358 +// }
  2359 +// else if (is_array($default_host) && ($host = key($default_host)) !== null) {
  2360 +// $hide_host = true;
  2361 +// $input_host = new html_hiddenfield([
  2362 +// 'name' => '_host', 'id' => 'rcmloginhost', 'value' => is_numeric($host) ? $default_host[$host] : $host] + $attrib);
  2363 +// }
  2364 +// else if (empty($default_host)) {
2364 $input_host = new html_inputfield(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'form-control'] 2365 $input_host = new html_inputfield(['name' => '_host', 'id' => 'rcmloginhost', 'class' => 'form-control']
2365 + $attrib + $host_attrib); 2366 + $attrib + $host_attrib);
  2367 +// }
  2368 + // 加入js来控制
  2369 + $js_default_host = rcube_email_server_address::getKeyValue();
  2370 + $_script = "<script>
  2371 +var _default_hosts = ".json_encode($js_default_host,JSON_UNESCAPED_UNICODE).";
  2372 +$(\"#rcmloginuser\").change(function() {
  2373 + auto_host($(this).val());
  2374 +});
  2375 +$(\"#rcmloginuser\").keyup(function() {
  2376 + auto_host($(this).val());
  2377 +});
  2378 +function auto_host(_user){
  2379 + _user = _user.split('@');
  2380 + if(_user[1]){
  2381 + if(_default_hosts[_user[1]]){
  2382 + $(\"#rcmloginhost\").val(_default_hosts[_user[1]]);
2366 } 2383 }
  2384 + }
  2385 +}
  2386 +</script>";
  2387 + $this->add_script(mb_substr($_script,8,-9),'foot');
2367 2388
2368 $this->add_gui_object('loginform', $form_name); 2389 $this->add_gui_object('loginform', $form_name);
2369 2390
@@ -2378,7 +2399,7 @@ EOF; @@ -2378,7 +2399,7 @@ EOF;
2378 2399
2379 // add host selection row 2400 // add host selection row
2380 if (is_object($input_host) && !$hide_host) { 2401 if (is_object($input_host) && !$hide_host) {
2381 - $table->add('title', html::label('rcmloginhost', html::quote($this->app->gettext('server')))); 2402 + $table->add('title', html::label('rcmloginhost', html::quote('imap '.$this->app->gettext('server'))));
2382 $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC))); 2403 $table->add('input', $input_host->show(rcube_utils::get_input_value('_host', rcube_utils::INPUT_GPC)));
2383 } 2404 }
2384 2405
@@ -426,9 +426,10 @@ class rcube_config @@ -426,9 +426,10 @@ class rcube_config
426 $rows = rcube_email_server_address::all($rcube->get_dbh()); 426 $rows = rcube_email_server_address::all($rcube->get_dbh());
427 427
428 foreach ($rows as $row){ 428 foreach ($rows as $row){
429 - $result['imaps'][$row['imap']] = $row['name'];  
430 -  
431 - $result['stmps'][parse_url($row['imap'])['host']] = $row['smtp']; 429 + // imap 配置
  430 + $result['imaps']['ssl://'.$row['imap']] = $row['name'] ? $row['name'] : $row['imap'];
  431 + // smtp_server
  432 + $result['stmps'][$row['imap']] = $row['smtp'];
432 } 433 }
433 434
434 $this->set('default_host',$result['imaps']??[]); 435 $this->set('default_host',$result['imaps']??[]);
@@ -82,6 +82,29 @@ class rcube_email_server_address{ @@ -82,6 +82,29 @@ class rcube_email_server_address{
82 // 82 //
83 // } 83 // }
84 84
  85 + /**
  86 + * 获取key=>val数据,
  87 + * @param string $key
  88 + * @param string $value
  89 + * @return array
  90 + * @author:dc
  91 + * @time 2022/7/25 14:12
  92 + */
  93 + public static function getKeyValue($key='mail_suffix',$value='imap'){
  94 +
  95 + $db = rcube::get_instance()->get_dbh();
  96 +
  97 + $result = $db->query("select `{$key}`,`{$value}` from ".$db->table_name('email_server_address',true));
  98 +
  99 + $key_value = [];
  100 +
  101 + foreach ($result->fetchAll(PDO::FETCH_ASSOC) as $row){
  102 + $key_value[$row[$key]] = $row[$value];
  103 + }
  104 +
  105 + return $key_value;
  106 + }
  107 +
85 108
86 public static function all($db = null) 109 public static function all($db = null)
87 { 110 {
@@ -105,7 +128,50 @@ class rcube_email_server_address{ @@ -105,7 +128,50 @@ class rcube_email_server_address{
105 return $rows; 128 return $rows;
106 } 129 }
107 130
  131 + /**
  132 + * 通过前缀获取
  133 + * @param $mail_suffix
  134 + * @param string $field
  135 + * @author:dc
  136 + * @time 2022/7/25 11:14
  137 + * @return array|bool
  138 + */
  139 + public static function firstBySuffix($mail_suffix,$field='`imap`,`smtp`'){
  140 + $db = rcube::get_instance()->get_dbh();
  141 + // 查询
  142 + $result = $db->query("select {$field} from ".$db->table_name('email_server_address',true)." where `mail_suffix` = ? limit 1",$mail_suffix);
  143 +
  144 + // 返回结果
  145 + return $db->fetch_assoc($result);
  146 + }
  147 +
  148 +
  149 + /**
  150 + * 新增数据
  151 + * @param $mail_suffix
  152 + * @param $imap
  153 + * @param $smtp
  154 + * @param string $name
  155 + * @return false|int|mixed
  156 + * @author:dc
  157 + * @time 2022/7/25 11:38
  158 + */
  159 + public static function insert($mail_suffix,$imap,$smtp,$name=' '){
108 160
  161 + $db = rcube::get_instance()->get_dbh();
  162 +
  163 + $table = $db->table_name('email_server_address',true);
  164 +
  165 + // 插入
  166 + $result = $db->query("insert into {$table} set `mail_suffix`=?,`imap`=?,`smtp`=?,`service_provider`=?",$mail_suffix,$imap,$smtp,$name);
  167 +
  168 + // 返回结果
  169 + if($result && $db->affected_rows($result) && ($id = $db->insert_id($result))){
  170 + return $id;
  171 + }
  172 +
  173 + return 0;
  174 + }
109 175
110 176
111 177