Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

NFR: Misc updates to imap authentication

未关闭
#199 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
php

调研方向

Start in lib/IMAP.php and review the constructor and authentication flow against the proposed addEmail and authSeparator settings. Verify the username, Nextcloud user ID, email, and domain-group behavior for each objective; completion requires addressing the three listed objectives, though no test file or IMAP test server is provided.

由索引模型根据 Issue 内容生成。

描述

0. Needs triage enhancement

Objectives:

Summary:

Add two new config variables

  • $addEmail (arg6) true: create email address matching login if login contains '@'
  • $authSeparator (arg7) replace '@' with '$authSeparator' when authenticating to the IMAP server
    (Note: I don't have any server to test this against...)

update lib/IMAP.php

Collect the new variables

diff -u IMAP.php  apps/user_external/lib/IMAP.php 
--- IMAP.php	2022-04-29 09:29:43.573148672 -0400
+++ apps/user_external/lib/IMAP.php	2022-04-29 09:41:59.878674898 -0400
@@ -25,6 +25,8 @@
 	private $domain;
 	private $stripeDomain;
 	private $groupDomain;
+        private $addEmail;
+        private $authSeparator;
 
 	/**
 	 * Create new IMAP authentication provider
@@ -36,7 +38,7 @@
 	 * @param boolean $stripeDomain (whether to stripe the domain part from the username or not)
 	 * @param boolean $groupDomain (whether to add the usere to a group corresponding to the domain of the address)
 	 */
-	public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) {
+	public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false, $addEmail = false, $authSeparator = null) {
 		parent::__construct($mailbox);
 		$this->mailbox = $mailbox;
 		$this->port = $port === null ? 143 : $port;

@@ -44,6 +46,8 @@
 		$this->domain = $domain === null ? '' : $domain;
 		$this->stripeDomain = $stripeDomain;
 		$this->groupDomain = $groupDomain;
+                $this->addEmail = $addEmail;
+                $this->authSeparator = $authSeparator;
 	}

Look for the configured authSeparator in the login field and replace it with an '@' to be used for the NC username and email.

 	/**
@@ -61,12 +65,21 @@
 			$uid = str_replace("%40", "@", $uid);
 		}
 
+                $authseparator = strlen($this->authSeparator) == 1 ? $this->authSeparator : '@';
+
+                // Replace $authseparator with '@' in case the user used the wrong separator...
+                if (!(strpos($uid, '@') !== false) && (strpos($uid, $authseparator) !== false)) {
+                        $uid = str_replace($authseparator, "@", $uid);
+                }
+

Set $useremail whenever we set $username. Use $authSeparator in $username for authentication to the IMAP server (addresses [Bug 150] (https://github.com/nextcloud/user_external/issues/150), but I have no server to test against )

 		$pieces = explode('@', $uid);
 		if ($this->domain !== '') {
 			if (count($pieces) === 1) {
-				$username = $uid . '@' . $this->domain;
+				$username = $pieces[0] . $authseparator . $this->domain;
+                                $useremail = $pieces[0] . '@' . $this->domain;
 			} elseif (count($pieces) === 2 && $pieces[1] === $this->domain) {
-				$username = $uid;
+                                $username = $pieces[0] . $authseparator . $pieces[1];
+				$useremail = $pieces[0] . '@' . $pieces[1];
 				if ($this->stripeDomain) {
 					$uid = $pieces[0];
 				}
@@ -79,8 +92,14 @@
 			}
 		} else {
 			$username = $uid;
+                        $useremail = $uid;
 		}

Force the NC user id to match the full email (addresses Bug 128 )

-
+                if ($this->stripeDomain) {
+                    $uid = $pieces[0];
+                } else {
+                    $uid = $useremail;
+                }
+                    
 		$groups = [];
 		if ($this->groupDomain && $pieces[1]) {
 			$groups[] = $pieces[1];

Save the user's email in NC config if there's an '@' in it and $addEmail is true

@@ -104,6 +123,10 @@
 			curl_close($ch);
 			$uid = mb_strtolower($uid);
 			$this->storeUser($uid, $groups);
+                        if ($this->addEmail && (strpos($useremail,'@') !== false) ) {
+                           $config = \OC::$server->getConfig();
+                           $config->setUserValue( $uid, 'settings', 'email', $useremail);
+                        }
 			return $uid;
 		} else {
 			\OC::$server->getLogger()->error(
主要语言
JavaScript
星标
120
派生
72
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nextcloud/user_external 的其他 Issue

查看 nextcloud/user_external 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。