Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Detect Server from Email Address #863

Open
ghost opened this issue Oct 22, 2015 · 16 comments
Open

Auto Detect Server from Email Address #863

ghost opened this issue Oct 22, 2015 · 16 comments

Comments

@ghost
Copy link

ghost commented Oct 22, 2015

Hi There,

Is there any chance of setting up RainLoop as a single interface for multiple shared hosting servers (i.e. many clients with many addresses spread over multiple servers). In this case, the server name would need to be read in from the email address automatically,

For example:
info@rhysit.co.za
password

RainLoop auto detects the server name 'rhysit.co.za', and attempts to log in using
'info@rhysit.co.za' as the username,
'password' as the password,
'rhysit.co.za' as the server.

Thanks
Rhys

@ghost
Copy link

ghost commented Oct 28, 2015

Take a look at these search results. Not sure if it helps, but maybe setting * as a wildcard, will allow all domains which have an active account.

@ghost
Copy link
Author

ghost commented Oct 28, 2015

Hi There!

Thanks for the response. I did try that, however I realised it would only work if we were using one server. Due to the requirement of still having to specify the specific server to manage the wildcard domain, even though all addresses are allowed, they would all be pointed towards one imap server instead of each to their separate server :/

@ghost
Copy link
Author

ghost commented Oct 28, 2015

Oh Cool! Just discovered this from one of the links. I'll check it out!

https://github.com/RainLoop/rainloop-webmail/tree/master/plugins/override-smtp-credentials

@jas8522
Copy link

jas8522 commented Nov 8, 2015

Hey there,

I used that plugin (override-smtp-credentials) to build a custom plugin that does exactly this for IMAP and SMTP. Looking into fixing up the code a bit and possibly adding it to the plugins here on GitHub

@rhyswilliamsza
Copy link
Contributor

Hi Jas!

If you could send that my way, I would really appreciate it. I could possibly take a look and help?

Rhys

@jas8522
Copy link

jas8522 commented Nov 10, 2015

Hey Rhys,

Here's what it looks like:

/**
 * Based on:
 * https://github.com/RainLoop/rainloop-webmail/blob/master/plugins/override-smtp-credentials/index.php
 */

class OverrideServerAddressesPlugin extends \RainLoop\Plugins\AbstractPlugin
{
    public function Init()
    {
        $this->addHook('filter.smtp-credentials', 'FilterSmtpCredentials');
        $this->addHook('filter.imap-credentials', 'FilterImapCredentials');
    }

    /**
     * @param \RainLoop\Model\Account $oAccount
     * @param array $aSmtpCredentials
     */
    public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
    {
        if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aSmtpCredentials))
        {
            $sEmail = $oAccount->Email();

            // Check for mail.$DOMAIN as entered value in RL settings
            if ( $aSmtpCredentials['Host'] == "mail.%DOMAIN" || $aSmtpCredentials['Host'] == "" )
            {
                $aSmtpCredentials['Host'] = "mail." . $this->getDomainFromEmail($sEmail);
            }
        }
    }


    /**
     * @param \RainLoop\Model\Account $oAccount
     * @param array $aImapCredentials
     */
    public function FilterImapCredentials($oAccount, &$aImapCredentials)
    {
        if ($oAccount instanceof \RainLoop\Model\Account && \is_array($aImapCredentials))
                {
            $sEmail = $oAccount->Email();

            // Check for mail.$DOMAIN as entered value in RL settings
            if ( $aImapCredentials['Host'] == "mail.%DOMAIN" || $aImapCredentials['Host'] == "" )
            {
                $aImapCredentials['Host'] = "mail." . $this->getDomainFromEmail($sEmail);
            }
        }
    }


    /**
     * @param string $emailAdress
     * @return string
     */
    private function getDomainFromEmail($emailAddress){

        $parts = explode("@", trim($emailAddress));
        return $parts[1];
    }
}

I intended to add some documentation to the plugin by specifying that using wildcards like %DOMAIN would be replaced by the actual domain used in the email address, but didn't get around to it. Hopefully this can be turned into a more official plugin for allowing such functionality!

Note that this will also work with a wildcard Domain value in the RL settings even if you leave the server fields empty. Perhaps that should be tweaked...

@rhyswilliamsza
Copy link
Contributor

Awesome stuff! Looks perfect already

@rhyswilliamsza
Copy link
Contributor

Alright!

Here we go Jas. You can make a pull request with the extracted folder directly to the RainLoop plugins folder. It is all ready and works well :)

I've put usage instructions and a licence with it, so feel free to change/remove if you'd like.

https://cloud.rhysit.co.za/index.php/s/cXHQZa1PukjtYZn

Rhys

@rhyswilliamsza
Copy link
Contributor

Hi Jas,

Should I make the request?

@jas8522
Copy link

jas8522 commented Nov 18, 2015

Hey Rhys,

Looks good! Which request is that?

-J

@rhyswilliamsza
Copy link
Contributor

Pull request to the repo :) Let me know if you'd like me to.

Rhys

@jas8522
Copy link

jas8522 commented Nov 18, 2015

Ah, yes I thought that's what you meant. Go for it!

@rhyswilliamsza
Copy link
Contributor

Cool will do

@RainLoop
Copy link
Owner

👍

@RainLoop
Copy link
Owner

Small refactoring: e8fbdff

@rhyswilliamsza
Copy link
Contributor

Perfect!

Looks good. I'm sure this plugin will help a lot of those in need :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants