mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-10-04 02:44:22 +08:00
MySQL pab driver implementation (part 4)
This commit is contained in:
parent
ad708be88a
commit
3a4867abea
7 changed files with 255 additions and 86 deletions
|
@ -3790,10 +3790,10 @@ class Actions
|
|||
|
||||
$this->Plugins()->RunHook('filter.smtp-credentials', array($oAccount, &$aSmtpCredentials));
|
||||
|
||||
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = false;
|
||||
$bHookConnect = $bHookAuth = $bHookFrom = $bHookFrom = $bHookTo = $bHookData = $bHookLogoutAndDisconnect = false;
|
||||
$this->Plugins()->RunHook('filter.smtp-connect', array($oAccount, $aSmtpCredentials,
|
||||
&$oSmtpClient, $oMessage, &$oRcpt,
|
||||
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData));
|
||||
&$bHookConnect, &$bHookAuth, &$bHookFrom, &$bHookTo, &$bHookData, &$bHookLogoutAndDisconnect));
|
||||
|
||||
if (!$bHookConnect)
|
||||
{
|
||||
|
@ -3839,7 +3839,10 @@ class Actions
|
|||
$oSmtpClient->DataWithStream($rMessageStream);
|
||||
}
|
||||
|
||||
$oSmtpClient->LogoutAndDisconnect();
|
||||
if (!$bHookLogoutAndDisconnect)
|
||||
{
|
||||
$oSmtpClient->LogoutAndDisconnect();
|
||||
}
|
||||
}
|
||||
catch (\MailSo\Net\Exceptions\ConnectionException $oException)
|
||||
{
|
||||
|
|
|
@ -93,14 +93,49 @@ abstract class PdoAbstract
|
|||
return $oPdo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sName = null
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function lastInsertId($sName = null)
|
||||
{
|
||||
return $this->getPDO()->lastInsertId($sName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return nool
|
||||
*/
|
||||
protected function beginTransaction()
|
||||
{
|
||||
return $this->getPDO()->beginTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return nool
|
||||
*/
|
||||
protected function commit()
|
||||
{
|
||||
return $this->getPDO()->commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return nool
|
||||
*/
|
||||
protected function rollBack()
|
||||
{
|
||||
return $this->getPDO()->rollBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param string $sSql
|
||||
* @param array $aParams
|
||||
* @param bool $bMultParams = false
|
||||
*
|
||||
* @return \PDOStatement|null
|
||||
*/
|
||||
protected function prepareAndExecute($sSql, $aParams = array())
|
||||
protected function prepareAndExecute($sSql, $aParams = array(), $bMultParams = false)
|
||||
{
|
||||
$mResult = null;
|
||||
|
||||
|
@ -108,12 +143,16 @@ abstract class PdoAbstract
|
|||
$oStmt = $this->getPDO()->prepare($sSql);
|
||||
if ($oStmt)
|
||||
{
|
||||
foreach ($aParams as $sName => $aValue)
|
||||
$aRootParams = $bMultParams ? $aParams : array($aParams);
|
||||
foreach ($aRootParams as $aSubParams)
|
||||
{
|
||||
$oStmt->bindValue($sName, $aValue[0], $aValue[1]);
|
||||
}
|
||||
foreach ($aSubParams as $sName => $aValue)
|
||||
{
|
||||
$oStmt->bindValue($sName, $aValue[0], $aValue[1]);
|
||||
}
|
||||
|
||||
$mResult = $oStmt->execute() ? $oStmt : null;
|
||||
$mResult = $oStmt->execute() && !$bMultParams ? $oStmt : null;
|
||||
}
|
||||
}
|
||||
|
||||
return $mResult;
|
||||
|
|
|
@ -9,11 +9,6 @@ class Contact
|
|||
*/
|
||||
public $IdContact;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $IdUser;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -66,7 +61,7 @@ class Contact
|
|||
$sDisplayName = '';
|
||||
$sDisplayEmail = '';
|
||||
|
||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ $oProperty)
|
||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
||||
{
|
||||
if ($oProperty)
|
||||
{
|
||||
|
|
|
@ -6,21 +6,6 @@ use RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
|
|||
|
||||
class Property
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $IdProperty;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $IdContact;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $IdUser;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -53,10 +38,6 @@ class Property
|
|||
|
||||
public function Clear()
|
||||
{
|
||||
$this->IdProperty = 0;
|
||||
$this->IdContact = 0;
|
||||
$this->IdUser = 0;
|
||||
|
||||
$this->Type = PropertyType::UNKNOWN;
|
||||
$this->TypeCustom = '';
|
||||
|
||||
|
|
|
@ -21,14 +21,41 @@ class MySqlPersonalAddressBook
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param int $iUserID
|
||||
* @param int $iIdContact
|
||||
*
|
||||
* @return \RainLoop\Providers\PersonalAddressBook\Classes\Contact|null
|
||||
* @return array
|
||||
*/
|
||||
public function GetContactById($oAccount, $iIdContact)
|
||||
private function getContactFreq($iUserID, $iIdContact)
|
||||
{
|
||||
return null;
|
||||
$aResult = array();
|
||||
|
||||
$sTypes = \implode(',', array(
|
||||
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
||||
));
|
||||
|
||||
$sSql = 'SELECT `value`, `frec` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `id_contact` = :id_contact AND `type` IN ('.$sTypes.')';
|
||||
$aParams = array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':id_contact' => array($iIdContact, \PDO::PARAM_INT)
|
||||
);
|
||||
|
||||
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||
if ($oStmt)
|
||||
{
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (\is_array($aFetch))
|
||||
{
|
||||
foreach ($aFetch as $aItem)
|
||||
{
|
||||
if ($aItem && !empty($aItem['value']) && !empty($aItem['frec']))
|
||||
{
|
||||
$aResult[$aItem['value']] = (int) $aItem['frec'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,20 +64,105 @@ class MySqlPersonalAddressBook
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function CreateContact($oAccount, &$oContact)
|
||||
public function SetContact($oAccount, &$oContact)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||
$bUpdate = 0 < $oContact->IdContact;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function UpdateContact($oAccount, &$oContact)
|
||||
{
|
||||
return false;
|
||||
$oContact->UpdateDependentValues();
|
||||
$oContact->Changed = \time();
|
||||
|
||||
try
|
||||
{
|
||||
$this->beginTransaction();
|
||||
|
||||
$aFreq = array();
|
||||
if ($bUpdate)
|
||||
{
|
||||
$aFreq = $this->getContactFreq($iUserID, $oContact->IdContact);
|
||||
|
||||
$sSql = 'UPDATE `rainloop_pab_contacts` SET `display_in_list` = :display_in_list, '.
|
||||
'`type` = :type, `changed` = :changed WHERE id_user = :id_user AND `id_contact` = :id_contact';
|
||||
|
||||
$this->prepareAndExecute($sSql,
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT),
|
||||
':display_in_list' => array($oContact->DisplayInList, \PDO::PARAM_STR),
|
||||
':type' => array($oContact->Type, \PDO::PARAM_INT),
|
||||
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
|
||||
)
|
||||
);
|
||||
|
||||
// clear previos props
|
||||
$this->prepareAndExecute(
|
||||
'DELETE FROM `rainloop_pab_prop` WHERE `id_user` = :id_user AND `id_contact` = :id_contact',
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSql = 'INSERT INTO `rainloop_pab_contacts` '.
|
||||
'(`id_user`, `display_in_list`, `type`, `changed`) VALUES '.
|
||||
'(:id_user, :display_in_list, :type, :changed)';
|
||||
|
||||
$this->prepareAndExecute($sSql,
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':display_in_list' => array($oContact->DisplayInList, \PDO::PARAM_STR),
|
||||
':type' => array($oContact->Type, \PDO::PARAM_INT),
|
||||
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
|
||||
$sLast = $this->lastInsertId('id_contact');
|
||||
if (\is_numeric($sLast) && 0 < (int) $sLast)
|
||||
{
|
||||
$oContact->IdContact = (int) $sLast;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 < $oContact->IdContact)
|
||||
{
|
||||
$aParams = array();
|
||||
foreach ($oContact->Properties as /* @var $oProp \RainLoop\Providers\PersonalAddressBook\Classes\Property */ $oProp)
|
||||
{
|
||||
$iFreq = $oProp->Frec;
|
||||
if ($oProp->IsEmail() && isset($aFreq[$oProp->Value]))
|
||||
{
|
||||
$iFreq = $aFreq[$oProp->Value];
|
||||
}
|
||||
|
||||
$aParams[] = array(
|
||||
':id_contact' => array($oContact->IdContact, \PDO::PARAM_INT),
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':type' => array($oProp->Type, \PDO::PARAM_INT),
|
||||
':type_custom' => array($oProp->TypeCustom, \PDO::PARAM_STR),
|
||||
':value' => array($oProp->Value, \PDO::PARAM_STR),
|
||||
':value_custom' => array($oProp->ValueClear, \PDO::PARAM_STR),
|
||||
':frec' => array($iFreq, \PDO::PARAM_INT),
|
||||
);
|
||||
}
|
||||
|
||||
$sSql = 'INSERT INTO `rainloop_pab_prop` '.
|
||||
'(`id_contact`, `id_user`, `type`, `type_custom`, `value`, `value_custom`, `frec`) VALUES '.
|
||||
'(:id_contact, :id_user, :type, :type_custom, :value, :value_custom, :frec)';
|
||||
|
||||
$this->prepareAndExecute($sSql, $aParams, true);
|
||||
}
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
$this->rollBack();
|
||||
throw $oException;
|
||||
}
|
||||
|
||||
$this->commit();
|
||||
|
||||
return 0 < $oContact->IdContact;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,7 +251,6 @@ class MySqlPersonalAddressBook
|
|||
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
||||
|
||||
$oContact->IdContact = $iIdContact;
|
||||
$oContact->IdUser = $iUserID;
|
||||
$oContact->DisplayInList = isset($aItem['display_in_list']) ? (string) $aItem['display_in_list'] : '';
|
||||
$oContact->Type = isset($aItem['type']) ? (int) $aItem['type'] :
|
||||
\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::DEFAULT_;
|
||||
|
@ -175,10 +286,6 @@ class MySqlPersonalAddressBook
|
|||
if (0 < $iId && isset($aContacts[$iIdContact]))
|
||||
{
|
||||
$oProperty = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||
|
||||
$oProperty->IdProperty = (int) $aItem['id_prop'];
|
||||
$oProperty->IdContact = $iIdContact;
|
||||
$oProperty->IdUser = $iUserID;
|
||||
$oProperty->Type = (int) $aItem['type'];
|
||||
$oProperty->TypeCustom = isset($aItem['type_custom']) ? (string) $aItem['type_custom'] : '';
|
||||
$oProperty->Value = (string) $aItem['value'];
|
||||
|
@ -234,8 +341,9 @@ class MySqlPersonalAddressBook
|
|||
':search' => array($this->specialConvertSearchValue($sSearch, '='), \PDO::PARAM_STR)
|
||||
);
|
||||
|
||||
$sSql .= ' ORDER BY `frec` ASC LIMIT :limit';
|
||||
$sSql .= ' ORDER BY `frec` DESC LIMIT :limit';
|
||||
|
||||
$aResult = array();
|
||||
$oStmt = $this->prepareAndExecute($sSql, $aParams);
|
||||
if ($oStmt)
|
||||
{
|
||||
|
@ -249,6 +357,7 @@ class MySqlPersonalAddressBook
|
|||
if (0 < $iIdContact)
|
||||
{
|
||||
$aIdContacts[] = $iIdContact;
|
||||
$aResult[$iIdContact] = array('', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -259,7 +368,7 @@ class MySqlPersonalAddressBook
|
|||
{
|
||||
$oStmt->closeCursor();
|
||||
|
||||
$sTypes = implode(',', array(
|
||||
$sTypes = \implode(',', array(
|
||||
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
|
||||
));
|
||||
|
||||
|
@ -273,7 +382,6 @@ class MySqlPersonalAddressBook
|
|||
if ($oStmt)
|
||||
{
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$aResult = array();
|
||||
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||
{
|
||||
foreach ($aFetch as $aItem)
|
||||
|
@ -281,19 +389,17 @@ class MySqlPersonalAddressBook
|
|||
if ($aItem && isset($aItem['id_contact'], $aItem['type'], $aItem['value']))
|
||||
{
|
||||
$iId = $aItem['id_contact'];
|
||||
if (!isset($aResult[$iId]))
|
||||
if (isset($aResult[$iId]))
|
||||
{
|
||||
$aResult[$iId] = array('', '');
|
||||
}
|
||||
|
||||
if ('' === $aResult[$iId][0] && \in_array((int) $aItem['type'],
|
||||
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
|
||||
{
|
||||
$aResult[$iId][0] = $aItem['value'];
|
||||
}
|
||||
else if ('' === $aResult[$iId][1] && \in_array((int) $aItem['type'], array(PropertyType::FULLNAME)))
|
||||
{
|
||||
$aResult[$iId][1] = $aItem['value'];
|
||||
if ('' === $aResult[$iId][0] && \in_array((int) $aItem['type'],
|
||||
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
|
||||
{
|
||||
$aResult[$iId][0] = $aItem['value'];
|
||||
}
|
||||
else if ('' === $aResult[$iId][1] && \in_array((int) $aItem['type'], array(PropertyType::FULLNAME)))
|
||||
{
|
||||
$aResult[$iId][1] = $aItem['value'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,31 +430,76 @@ class MySqlPersonalAddressBook
|
|||
$iUserID = $this->getUserId($oAccount->ParentEmailHelper());
|
||||
|
||||
$self = $this;
|
||||
$aEmails = \array_filter($aEmails, function (&$mItem) use ($self) {
|
||||
$mItem = \strtolower(\trim($mItem));
|
||||
if (0 < \strlen($mItem))
|
||||
{
|
||||
$mItem = $self->quoteValue($mItem);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
$aEmails = \array_map(function ($mItem) {
|
||||
return \strtolower(\trim($mItem));
|
||||
}, $aEmails);
|
||||
|
||||
$aEmails = \array_filter($aEmails, function ($mItem) {
|
||||
return 0 < \strlen($mItem);
|
||||
});
|
||||
|
||||
if (0 === \count($aEmails))
|
||||
{
|
||||
throw new \InvalidArgumentException('Empty Emails argument');
|
||||
}
|
||||
|
||||
$sSql = 'UPDATE `rainloop_pab_prop` SET `frec` = `frec` + 1 WHERE id_user = :id_user AND `type` IN ('.
|
||||
\implode(',', array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER));
|
||||
|
||||
if (1 === \count($aEmails))
|
||||
$sTypes = \implode(',', array(
|
||||
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
||||
));
|
||||
|
||||
$sSql = 'SELECT `value` FROM `rainloop_pab_prop` WHERE id_user = :id_user AND `type` IN ('.$sTypes.')';
|
||||
$oStmt = $this->prepareAndExecute($sSql, array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT)
|
||||
));
|
||||
|
||||
$aExists = array();
|
||||
if ($oStmt)
|
||||
{
|
||||
$sSql .= ') AND `value` = '.$aEmails[0];
|
||||
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||
{
|
||||
foreach ($aFetch as $aItem)
|
||||
{
|
||||
if ($aItem && !empty($aItem['value']))
|
||||
{
|
||||
$aExists[] = \strtolower(\trim($aItem['value']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aEmailsToCreate = \array_diff($aEmails, $aExists);
|
||||
if (0 < \count($aEmailsToCreate))
|
||||
{
|
||||
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
||||
foreach ($aEmailsToCreate as $sEmailToCreate)
|
||||
{
|
||||
$oContact->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO;
|
||||
|
||||
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
||||
$oProp->Type = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::EMAIl_PERSONAL;
|
||||
$oProp->Value = $sEmailToCreate;
|
||||
|
||||
$oContact->Properties[] = $oProp;
|
||||
|
||||
$this->SetContact($oAccount, $oContact);
|
||||
$oContact->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
$sSql = 'UPDATE `rainloop_pab_prop` SET `frec` = `frec` + 1 WHERE id_user = :id_user AND `type` IN ('.$sTypes;
|
||||
|
||||
$aEmailsQuoted = \array_map(function ($mItem) use ($self) {
|
||||
return $self->quoteValue($mItem);
|
||||
}, $aEmails);
|
||||
|
||||
if (1 === \count($aEmailsQuoted))
|
||||
{
|
||||
$sSql .= ') AND `value` = '.$aEmailsQuoted[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
$sSql .= ') AND `value` IN ('.\implode(',', $aEmails).')';
|
||||
$sSql .= ') AND `value` IN ('.\implode(',', $aEmailsQuoted).')';
|
||||
}
|
||||
|
||||
return !!$this->prepareAndExecute($sSql, array(
|
||||
|
|
|
@ -8060,7 +8060,7 @@ PopupsComposeViewModel.prototype.sendMessageResponse = function (sResult, oData)
|
|||
else
|
||||
{
|
||||
this.sendError(true);
|
||||
window.alert(Utils.getNotification(oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
||||
window.alert(Utils.getNotification(oData && oData.ErrorCode ? oData.ErrorCode : Enums.Notification.CantSendMessage));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
2
rainloop/v/0.0.0/static/js/app.min.js
vendored
2
rainloop/v/0.0.0/static/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue