Last active
December 13, 2025 18:36
-
-
Save lukas-staab/d64b5dc1c4ccd6b87b3a56f96d0edfcf to your computer and use it in GitHub Desktop.
Proof of Concept Roundcube plugin for login over .well-known Mailadress to Username
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class hs_login extends rcube_plugin | |
| { | |
| public $task = 'login'; | |
| function init() | |
| { | |
| $this->add_hook('authenticate', array($this, 'translate_username')); | |
| } | |
| function translate_username($args) | |
| { | |
| $email = $args['user']; | |
| // if no @ -> its a username - do nothing | |
| if (strpos($email, '@') === false) { | |
| return $args; | |
| } | |
| list($local, $domain) = explode('@', $email); | |
| // if an email: check .well-known to figure out the username to the mail | |
| $url = "https://{$domain}/.well-known/autoconfig/mail/config-v1.1.xml?emailaddress=" . urlencode($email); | |
| $response = @file_get_contents($url, false, $context); | |
| if ($response) { | |
| $xml = @simplexml_load_string($response); | |
| if ($xml && isset($xml->emailProvider->incomingServer)) { | |
| foreach ($xml->emailProvider->incomingServer as $server) { | |
| if ((string)$server['type'] === 'imap') { | |
| $username = (string)$server->username; | |
| $username = str_replace('%EMAILADDRESS%', $email, $username); | |
| $username = str_replace('%EMAILLOCALPART%', $local, $username); | |
| // overwrite the given "username" (a mail adress) with the found and correct username | |
| $args['user'] = $username; | |
| rcube::write_log('hs_login', "Translated {$email} -> {$username}"); | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| // returned (modified) user credentials | |
| return $args; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment