|
1 | 1 | <?php |
2 | | - |
3 | 2 | /** |
4 | 3 | * Copyright 2013-2026 Horde LLC (http://www.horde.org/) |
5 | 4 | * |
@@ -101,13 +100,42 @@ public function getConfig() |
101 | 100 | * running from CLI with 'user_admin' registry flag, which sets |
102 | 101 | * the authentication name but not the credentials. */ |
103 | 102 | if (strcasecmp($transport, 'smtp') === 0) { |
104 | | - if ($registry->isAuthenticated() |
105 | | - && strlen((string) ($auth = $registry->getAuth()))) { |
106 | | - if (!empty($params['username_auth'])) { |
107 | | - $params['username'] = $auth; |
108 | | - } |
109 | | - if (!empty($params['password_auth'])) { |
110 | | - $params['password'] = $registry->getAuthCredential('password'); |
| 103 | + if ($registry->isAuthenticated() && |
| 104 | + strlen((string) ($auth = $registry->getAuth()))) { |
| 105 | + /* Try to get SMTP credentials via hook (e.g. for XOAUTH2 support). */ |
| 106 | + try { |
| 107 | + $hooks = $this->_injector->getInstance('Horde_Core_Hooks'); |
| 108 | + $smtp_creds = $hooks->callHook('smtp_credentials', 'horde', [$auth]); |
| 109 | + |
| 110 | + // Hook returned XOAUTH2 credentials |
| 111 | + if (isset($smtp_creds['xoauth2_token'])) { |
| 112 | + $params['xoauth2_token'] = $smtp_creds['xoauth2_token']; |
| 113 | + if (isset($smtp_creds['username'])) { |
| 114 | + $params['username'] = $smtp_creds['username']; |
| 115 | + } |
| 116 | + // Don't set password when using XOAUTH2 |
| 117 | + } else { |
| 118 | + // Hook returned regular credentials |
| 119 | + if (isset($smtp_creds['username'])) { |
| 120 | + $params['username'] = $smtp_creds['username']; |
| 121 | + } elseif (!empty($params['username_auth'])) { |
| 122 | + $params['username'] = $auth; |
| 123 | + } |
| 124 | + |
| 125 | + if (isset($smtp_creds['password'])) { |
| 126 | + $params['password'] = $smtp_creds['password']; |
| 127 | + } elseif (!empty($params['password_auth'])) { |
| 128 | + $params['password'] = $registry->getAuthCredential('password'); |
| 129 | + } |
| 130 | + } |
| 131 | + } catch (Horde_Exception_HookNotSet $e) { |
| 132 | + // No hook defined, use default username/password |
| 133 | + if (!empty($params['username_auth'])) { |
| 134 | + $params['username'] = $auth; |
| 135 | + } |
| 136 | + if (!empty($params['password_auth'])) { |
| 137 | + $params['password'] = $registry->getAuthCredential('password'); |
| 138 | + } |
111 | 139 | } |
112 | 140 | } |
113 | 141 |
|
|
0 commit comments