From db6701bf6af5ab7bd52b452006b9c98b6d837d67 Mon Sep 17 00:00:00 2001 From: Rhyswilliamsza Date: Wed, 18 Nov 2015 19:25:36 +0200 Subject: [PATCH] Added Auto Domain Grabber Plug-in --- plugins/auto-domain-grab/LICENSE | 22 ++++++++++ plugins/auto-domain-grab/README | 14 ++++++ plugins/auto-domain-grab/VERSION | 1 + plugins/auto-domain-grab/index.php | 70 ++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 plugins/auto-domain-grab/LICENSE create mode 100644 plugins/auto-domain-grab/README create mode 100644 plugins/auto-domain-grab/VERSION create mode 100644 plugins/auto-domain-grab/index.php diff --git a/plugins/auto-domain-grab/LICENSE b/plugins/auto-domain-grab/LICENSE new file mode 100644 index 000000000..d6b23af63 --- /dev/null +++ b/plugins/auto-domain-grab/LICENSE @@ -0,0 +1,22 @@ +This plugin, written by https://github.com/jas8522 and optimised by https://github.com/rhyswilliamsza / https://github.com/rhysit/ is released under: + +The MIT License (MIT) + +Copyright (c) 2015 https://github.com/jas8522 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/plugins/auto-domain-grab/README b/plugins/auto-domain-grab/README new file mode 100644 index 000000000..c7d82ba48 --- /dev/null +++ b/plugins/auto-domain-grab/README @@ -0,0 +1,14 @@ +What is it? + +In essense, this plugin allows for multiple users across multiple servers to use one RainLoop installation, +all without the administrator needing to create each domain separately. This plugin detects the required +hostname from the inputted email address (for example, it would detect "example.com" as the hostname if +"info@example.com" is inputted). This hostname is then used for IMAP and SMTP communication. + +How to Use: + +1) Activate plugin +2) Visit Settings, and add a new wildcard domain ' * ' +3) Set your ports/ssl requirements as needed. These will not be changed by the plugin. +4) In the SMTP and/or IMAP host fields, place the single word "auto". This will be replaced when the plugin is active. +5) That's it! The plugin should now work! \ No newline at end of file diff --git a/plugins/auto-domain-grab/VERSION b/plugins/auto-domain-grab/VERSION new file mode 100644 index 000000000..d3827e75a --- /dev/null +++ b/plugins/auto-domain-grab/VERSION @@ -0,0 +1 @@ +1.0 diff --git a/plugins/auto-domain-grab/index.php b/plugins/auto-domain-grab/index.php new file mode 100644 index 000000000..303a7594b --- /dev/null +++ b/plugins/auto-domain-grab/index.php @@ -0,0 +1,70 @@ +addHook('filter.smtp-credentials', 'FilterSmtpCredentials'); + $this->addHook('filter.imap-credentials', 'FilterImapCredentials'); + } + + /** + * This function detects the IMAP Host, and if it is set to "auto", replaces it with the email domain. + * @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'] == "auto" ) + { + $aImapCredentials['Host'] = $this->getDomainFromEmail($sEmail); + } + } + } + + /** + * This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain. + * @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'] == "auto" ) + { + $aSmtpCredentials['Host'] = $this->getDomainFromEmail($sEmail); + } + } + } + + + /** + * This function extracts the domain from the email address. + * @param string $emailAdress + * @return string + */ + private function getDomainFromEmail($emailAddress){ + + $parts = explode("@", trim($emailAddress)); + return $parts[1]; + } +} + +?>