Skip to content

Commit 0970f9c

Browse files
author
Sebastian L.
committed
Automatically add email address on IMAP backend
1 parent cc247f2 commit 0970f9c

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/Base.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public function setDisplayName($uid, $displayName) {
195195
*
196196
* @return void
197197
*/
198-
protected function storeUser($uid, $groups = []) {
198+
protected function storeUser($uid, $groups = [], $email = '') {
199199
if (!$this->userExists($uid)) {
200200
$query = $this->db->getQueryBuilder();
201201
$query->insert('users_external')
@@ -211,6 +211,11 @@ protected function storeUser($uid, $groups = []) {
211211
$this->groupManager->createGroup($group)->addUser($createduser);
212212
}
213213
}
214+
215+
if ($email) {
216+
$createduser = \OC::$server->getUserManager()->get($uid);
217+
$createduser->setSystemEMailAddress($email);
218+
}
214219
}
215220
}
216221

lib/IMAP.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function checkPassword($uid, $password) {
6464
$uid = str_replace('%40', '@', $uid);
6565
}
6666

67+
// Get email if uid is a valid email address
68+
if (filter_var($uid, FILTER_VALIDATE_EMAIL)) $email = mb_strtolower($uid);
69+
6770
$pieces = explode('@', $uid);
6871
if ($this->domain !== '') {
6972
if (count($pieces) === 1) {
@@ -107,7 +110,7 @@ public function checkPassword($uid, $password) {
107110
if ($errorcode === 0) {
108111
curl_close($ch);
109112
$uid = mb_strtolower($uid);
110-
$this->storeUser($uid, $groups);
113+
$this->storeUser($uid, $groups, $email);
111114
return $uid;
112115
} elseif ($errorcode === CURLE_COULDNT_CONNECT
113116
|| $errorcode === CURLE_SSL_CONNECT_ERROR

0 commit comments

Comments
 (0)