diff --git a/plugins/nextcloud/LICENSE b/plugins/nextcloud/LICENSE new file mode 100644 index 000000000..9e5e56cdd --- /dev/null +++ b/plugins/nextcloud/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2022 SnappyMail + +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/nextcloud/NextCloudContactsSuggestions.php b/plugins/nextcloud/NextCloudContactsSuggestions.php new file mode 100644 index 000000000..4e6061ff5 --- /dev/null +++ b/plugins/nextcloud/NextCloudContactsSuggestions.php @@ -0,0 +1,74 @@ +getContactsManager(); + if (!$cm || !$cm->isEnabled()) { + return []; + } + + $aSearchResult = $cm->search($sQuery, array('FN', 'NICKNAME', 'TITLE', 'EMAIL')); + + //$this->oLogger->WriteDump($aSearchResult); + + if (\is_array($aSearchResult) && 0 < \count($aSearchResult)) { + $iInputLimit = $iLimit; + $aResult = array(); + foreach ($aSearchResult as $aContact) { + if (0 >= $iLimit) { + break; + } + if (!empty($aContact['UID'])) { + $sUid = $aContact['UID']; + $mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : ''; + + $sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : ''; + if (empty($sFullName) && isset($aContact['NICKNAME'])) { + $sFullName = \trim($aContact['NICKNAME']); + } + + if (!\is_array($mEmails)) { + $mEmails = array($mEmails); + } + + foreach ($mEmails as $sEmail) { + $sHash = $sFullName.'|'.$sEmail; + if (!isset($aResult[$sHash])) { + $aResult[$sHash] = array($sEmail, $sFullName); + --$iLimit; + } + } + } + } + return \array_slice(\array_values($aResult), 0, $iInputLimit); + } + } + catch (\Exception $oException) + { + if ($this->oLogger) { + $this->oLogger->WriteException($oException); + } + } + + return []; + } + + public function SetLogger(\MailSo\Log\Logger $oLogger) + { + $this->oLogger = $oLogger; + } +} diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php new file mode 100644 index 000000000..d58d31051 --- /dev/null +++ b/plugins/nextcloud/index.php @@ -0,0 +1,47 @@ +addHook('main.fabrica', 'MainFabrica'); + } + + public function Supported() : string + { + return static::IsIntegrated() ? '' : 'Not running inside Nextcloud'; + } + + public static function IsIntegrated() + { +// return !empty($_ENV['RAINLOOP_OWNCLOUD']) && + return \class_exists('OC') && isset(\OC::$server); + } + + public static function IsLoggedIn() + { + return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn(); + } + + /** + * @param mixed $mResult + */ + public function MainFabrica(string $sName, &$mResult) + { + if ('suggestions' === $sName) { + if (!\is_array($mResult)) { + $mResult = array(); + } + include_once __DIR__ . '/NextcloudContactsSuggestions.php'; + $mResult[] = new NextcloudContactsSuggestions(); + } + } +} diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions/ISuggestions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions/ISuggestions.php index 25c3f2c49..7cadcc10d 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions/ISuggestions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Providers/Suggestions/ISuggestions.php @@ -5,4 +5,5 @@ namespace RainLoop\Providers\Suggestions; interface ISuggestions { public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20) : array; +// public function SetLogger(\MailSo\Log\Logger $oLogger) : void }