mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 16:37:02 +03:00
CardDAV (pre-release)
This commit is contained in:
parent
7a8fffede8
commit
639d8c58f6
38 changed files with 525 additions and 207 deletions
|
|
@ -290,11 +290,12 @@ class Http
|
|||
|
||||
/**
|
||||
* @param bool $bWithRemoteUserData = false
|
||||
* @param bool $bRemoveWWW = true
|
||||
* @param bool $bWithoutWWW = true
|
||||
* @param bool $bWithoutPort = false
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function GetHost($bWithRemoteUserData = false, $bRemoveWWW = true)
|
||||
public function GetHost($bWithRemoteUserData = false, $bWithoutWWW = true, $bWithoutPort = false)
|
||||
{
|
||||
$sHost = $this->GetServer('HTTP_HOST', '');
|
||||
if (0 === \strlen($sHost))
|
||||
|
|
@ -307,7 +308,7 @@ class Http
|
|||
? $sName : $sName.':'.$iPort;
|
||||
}
|
||||
|
||||
if ($bRemoveWWW)
|
||||
if ($bWithoutWWW)
|
||||
{
|
||||
$sHost = 'www.' === \substr(\strtolower($sHost), 0, 4) ? \substr($sHost, 4) : $sHost;
|
||||
}
|
||||
|
|
@ -318,6 +319,11 @@ class Http
|
|||
$sHost = (0 < \strlen($sUser) ? $sUser.'@' : '').$sHost;
|
||||
}
|
||||
|
||||
if ($bWithoutPort)
|
||||
{
|
||||
$sHost = \preg_replace('/:[\d]+$/', '', $sHost);
|
||||
}
|
||||
|
||||
return $sHost;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -930,14 +930,35 @@ class Actions
|
|||
$oAccount = $this->getAccountFromToken(false);
|
||||
if ($oAccount instanceof \RainLoop\Account)
|
||||
{
|
||||
$oPab = $this->PersonalAddressBookProvider($oAccount);
|
||||
|
||||
|
||||
$aResult['Auth'] = true;
|
||||
$aResult['Email'] = $oAccount->Email();
|
||||
$aResult['IncLogin'] = $oAccount->IncLogin();
|
||||
$aResult['OutLogin'] = $oAccount->OutLogin();
|
||||
$aResult['AccountHash'] = $oAccount->Hash();
|
||||
$aResult['ChangePasswordIsAllowed'] = $this->ChangePasswordProvider()->PasswordChangePossibility($oAccount);
|
||||
$aResult['ContactsIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsActive();
|
||||
$aResult['ContactsSharingIsAllowed'] = $this->PersonalAddressBookProvider($oAccount)->IsSharingAllowed();
|
||||
$aResult['ContactsIsAllowed'] = $oPab->IsActive();
|
||||
$aResult['ContactsSharingIsAllowed'] = $oPab->IsSharingAllowed();
|
||||
|
||||
$aResult['ContactsSyncIsAllowed'] = (bool) $oConfig->Get('contacts', 'allow_sync', false);
|
||||
$aResult['ContactsSyncServer'] = '';
|
||||
$aResult['ContactsSyncUser'] = '';
|
||||
$aResult['ContactsSyncPassword'] = '';
|
||||
$aResult['ContactsSyncPabUrl'] = '';
|
||||
|
||||
if ($aResult['ContactsSyncIsAllowed'])
|
||||
{
|
||||
$aResult['ContactsSyncServer'] = $this->Http()->GetHost(false, true, true);
|
||||
$aResult['ContactsSyncUser'] = $oAccount->ParentEmailHelper();
|
||||
$aResult['ContactsSyncPassword'] = $oPab->GetUserHashByEmail($aResult['ContactsSyncUser'], true);
|
||||
|
||||
$sUrl = \rtrim(\trim($this->Http()->GetScheme().'://'.$this->Http()->GetHost(true, false).$this->Http()->GetPath()), '/\\');
|
||||
$sUrl = \preg_replace('/index\.php(.*)$/i', '', $sUrl);
|
||||
|
||||
$aResult['ContactsSyncPabUrl'] = $sUrl.'/index.php/dav/addressbooks/'.$oAccount->ParentEmailHelper().'/default/';
|
||||
}
|
||||
|
||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ class PdoPersonalAddressBook
|
|||
*/
|
||||
public function GetUserUidByEmail($sEmail)
|
||||
{
|
||||
$this->Sync();
|
||||
|
||||
$iId = $this->getUserId($sEmail);
|
||||
return 0 < $iId ? (string) $iId : '';
|
||||
}
|
||||
|
|
@ -98,6 +100,8 @@ class PdoPersonalAddressBook
|
|||
*/
|
||||
public function GetCtagByEmail($sEmail)
|
||||
{
|
||||
$this->Sync();
|
||||
|
||||
$sResult = '0';
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
if (0 < $iUserID)
|
||||
|
|
@ -126,11 +130,13 @@ class PdoPersonalAddressBook
|
|||
*/
|
||||
public function GetUserHashByEmail($sEmail, $bCreate = false)
|
||||
{
|
||||
$this->Sync();
|
||||
|
||||
$sHash = '';
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
if (0 < $iUserID)
|
||||
{
|
||||
$oStmt = $this->prepareAndExecute('SELECT pass_hash FROM rainloop_pab_users_hashes WHERE id_user = :id_user LIMIT 1',
|
||||
$oStmt = $this->prepareAndExecute('SELECT pass_hash FROM rainloop_pab_users WHERE id_user = :id_user LIMIT 1',
|
||||
array(':id_user' => array($iUserID, \PDO::PARAM_INT)));
|
||||
|
||||
if ($oStmt)
|
||||
|
|
@ -142,14 +148,15 @@ class PdoPersonalAddressBook
|
|||
}
|
||||
else if ($bCreate)
|
||||
{
|
||||
$this->prepareAndExecute('INSERT INTO rainloop_pab_users_hashes (id_user, pass_hash) VALUES (:id_user, :pass_hash);',
|
||||
$this->prepareAndExecute('INSERT INTO rainloop_pab_users (id_user, email, pass_hash) VALUES (:id_user, :email, :pass_hash);',
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':email' => array($sEmail, \PDO::PARAM_STR),
|
||||
':pass_hash' => array(\md5($sEmail.\microtime(true)), \PDO::PARAM_STR)
|
||||
)
|
||||
);
|
||||
|
||||
$this->GetUserHashByEmail($sEmail, false);
|
||||
$sHash = $this->GetUserHashByEmail($sEmail, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -305,6 +312,7 @@ class PdoPersonalAddressBook
|
|||
*/
|
||||
public function DeleteContacts($sEmail, $aContactIds)
|
||||
{
|
||||
$this->Sync();
|
||||
$iUserID = $this->getUserId($sEmail);
|
||||
|
||||
$aContactIds = \array_filter($aContactIds, function (&$mItem) {
|
||||
|
|
@ -1239,8 +1247,9 @@ SQLITEINITIAL;
|
|||
'ALTER TABLE rainloop_pab_contacts ADD carddav_data MEDIUMTEXT;',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash varchar(128) NOT NULL DEFAULT \'\';',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_size int UNSIGNED NOT NULL DEFAULT 0;',
|
||||
'CREATE TABLE IF NOT EXISTS rainloop_pab_users_hashes (
|
||||
'CREATE TABLE IF NOT EXISTS rainloop_pab_users (
|
||||
id_user int UNSIGNED NOT NULL,
|
||||
email varchar(128) NOT NULL,
|
||||
pass_hash varchar(128) NOT NULL
|
||||
)/*!40000 ENGINE=INNODB */;'
|
||||
)
|
||||
|
|
@ -1253,8 +1262,9 @@ SQLITEINITIAL;
|
|||
'ALTER TABLE rainloop_pab_contacts ADD carddav_data TEXT;',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash varchar(128) NOT NULL DEFAULT \'\';',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_size integer NOT NULL DEFAULT 0;',
|
||||
'CREATE TABLE rainloop_pab_users_hashes (
|
||||
'CREATE TABLE rainloop_pab_users (
|
||||
id_user integer NOT NULL,
|
||||
email varchar(128) NOT NULL,
|
||||
pass_hash varchar(128) NOT NULL
|
||||
);'
|
||||
)
|
||||
|
|
@ -1267,8 +1277,9 @@ SQLITEINITIAL;
|
|||
'ALTER TABLE rainloop_pab_contacts ADD carddav_data text;',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash text NOT NULL DEFAULT \'\';',
|
||||
'ALTER TABLE rainloop_pab_contacts ADD carddav_size integer NOT NULL DEFAULT 0;',
|
||||
'CREATE TABLE rainloop_pab_users_hashes (
|
||||
'CREATE TABLE rainloop_pab_users (
|
||||
id_user integer NOT NULL,
|
||||
email text NOT NULL,
|
||||
pass_hash text NOT NULL
|
||||
);'
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue