mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-08 00:47:04 +03:00
Added test contacts CardDAV settings
This commit is contained in:
parent
2809e75307
commit
3d55bdaf5a
7 changed files with 87 additions and 25 deletions
|
|
@ -3,13 +3,11 @@
|
|||
namespace RainLoop\Actions;
|
||||
|
||||
use RainLoop\Enumerations\Capa;
|
||||
use RainLoop\Exceptions\ClientException;
|
||||
|
||||
trait Contacts
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\AddressBook
|
||||
*/
|
||||
protected $oAddressBookProvider = null;
|
||||
protected ?\RainLoop\Providers\AddressBook $oAddressBookProvider = null;
|
||||
|
||||
public function AddressBookProvider(?\RainLoop\Model\Account $oAccount = null): \RainLoop\Providers\AddressBook
|
||||
{
|
||||
|
|
@ -61,18 +59,66 @@ trait Contacts
|
|||
return $this->DefaultResponse($bResult);
|
||||
}
|
||||
|
||||
public function DoTestContactsSyncData() : array
|
||||
{
|
||||
if (!$this->GetCapa(Capa::CONTACTS)) {
|
||||
throw new ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'Disallowed');
|
||||
}
|
||||
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
|
||||
$sPassword = $this->GetActionParam('Password', '');
|
||||
if (static::APP_DUMMY === $sPassword) {
|
||||
$mData = $this->getContactsSyncData($oAccount);
|
||||
$sPassword = isset($mData['Password']) ? $mData['Password'] : '';
|
||||
}
|
||||
$sPasswordHMAC = null;
|
||||
if ($sPassword) {
|
||||
$oMainAccount = $this->getMainAccountFromToken();
|
||||
$sPassword = \SnappyMail\Crypt::EncryptToJSON($sPassword, $oMainAccount->CryptKey());
|
||||
if ($sPassword) {
|
||||
$sPasswordHMAC = \hash_hmac('sha1', $sPassword, $oMainAccount->CryptKey());
|
||||
}
|
||||
}
|
||||
|
||||
$oDriver = $this->fabrica('address-book', $oAccount);
|
||||
if (!$oDriver) {
|
||||
throw new ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'No driver');
|
||||
}
|
||||
$oDriver->SetEmail($this->GetMainEmail($oAccount));
|
||||
$oDriver->setDAVClientConfig([
|
||||
'Mode' => 2, // readonly
|
||||
'User' => $this->GetActionParam('User', ''),
|
||||
'Password' => $sPassword,
|
||||
'Url' => $this->GetActionParam('Url', ''),
|
||||
'PasswordHMAC' => $sPasswordHMAC
|
||||
]);
|
||||
|
||||
$oClient = $oDriver->getDavClient();
|
||||
if (!$oClient) {
|
||||
throw new ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'No client');
|
||||
}
|
||||
$oClient->propFind($oClient->urlPath, [
|
||||
'{DAV:}getlastmodified',
|
||||
'{DAV:}resourcetype',
|
||||
'{DAV:}getetag'
|
||||
], 1);
|
||||
|
||||
return $this->TrueResponse();
|
||||
}
|
||||
|
||||
public function DoContactsSync() : array
|
||||
{
|
||||
$oAccount = $this->getAccountFromToken();
|
||||
$oAddressBookProvider = $this->AddressBookProvider($oAccount);
|
||||
if (!$oAddressBookProvider) {
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'No AddressBookProvider');
|
||||
throw new ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'No AddressBookProvider');
|
||||
}
|
||||
\ignore_user_abort(true);
|
||||
\SnappyMail\HTTP\Stream::start(/*$binary = false*/);
|
||||
\SnappyMail\HTTP\Stream::JSON(['messsage'=>'start']);
|
||||
if (!$oAddressBookProvider->Sync()) {
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'AddressBookProvider->Sync() failed');
|
||||
throw new ClientException(\RainLoop\Notifications::ContactsSyncError, null, 'AddressBookProvider->Sync() failed');
|
||||
}
|
||||
return $this->TrueResponse();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,7 @@ namespace RainLoop\Providers;
|
|||
|
||||
class AddressBook extends AbstractProvider
|
||||
{
|
||||
/**
|
||||
* @var \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||
*/
|
||||
private $oDriver;
|
||||
private ?AddressBook\AddressBookInterface $oDriver;
|
||||
|
||||
public function __construct(?AddressBook\AddressBookInterface $oDriver)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -265,17 +265,9 @@ trait CardDAV
|
|||
*/
|
||||
private function checkContactsPath(DAVClient $oClient, string $sPath) : bool
|
||||
{
|
||||
$aResponse = null;
|
||||
try
|
||||
{
|
||||
$aResponse = $oClient->propFind($sPath, array(
|
||||
'{DAV:}resourcetype'
|
||||
), 1);
|
||||
}
|
||||
catch (\Throwable $oException)
|
||||
{
|
||||
$this->logException($oException);
|
||||
}
|
||||
$aResponse = $oClient->propFind($sPath, array(
|
||||
'{DAV:}resourcetype'
|
||||
), 1);
|
||||
|
||||
$bGood = false;
|
||||
if (\is_array($aResponse)) {
|
||||
|
|
@ -339,7 +331,7 @@ trait CardDAV
|
|||
return $oClient;
|
||||
}
|
||||
|
||||
protected function getDavClient() : ?DAVClient
|
||||
public function getDavClient() : ?DAVClient
|
||||
{
|
||||
if (!$this->aDAVConfig['Mode']) {
|
||||
return null;
|
||||
|
|
@ -405,7 +397,11 @@ trait CardDAV
|
|||
|
||||
$bGood = $sNewPath && $this->checkContactsPath($oClient, $sNewPath);
|
||||
if (!$bGood) {
|
||||
$this->logWrite('Contacts path not found at: '.$sPath, \LOG_INFO, 'DAV');
|
||||
throw new \RainLoop\Exceptions\ClientException(
|
||||
\RainLoop\Notifications::ContactsSyncError,
|
||||
null,
|
||||
'Contacts path not found at: '.$sPath
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,12 @@ class PdoAddressBook
|
|||
return false;
|
||||
}
|
||||
|
||||
$oClient = $this->getDavClient();
|
||||
try {
|
||||
$oClient = $this->getDavClient();
|
||||
} catch (\Throwable $e) {
|
||||
\SnappyMail\Log::error('DAV', $e->getMessage());
|
||||
// $this->logException($oException);
|
||||
}
|
||||
if (!$oClient) {
|
||||
\SnappyMail\Log::warning('PdoAddressBook', 'Sync() invalid DavClient');
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -39,4 +39,9 @@
|
|||
<input type="password" autocomplete="current-password" autocorrect="off" autocapitalize="off"
|
||||
spellcheck="false" data-bind="value: syncPass">
|
||||
</div>
|
||||
<div class="control-group" data-bind="hidden: !syncUrl()">
|
||||
<label></label>
|
||||
<button class="btn" data-i18n="GLOBAL/TEST" data-bind="click: test"></button>
|
||||
</div>
|
||||
<div class="alert alert-error" data-bind="visible: syncError, text: syncError"></div>
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue