mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-08 14:14:26 +08:00
Clear autocreated contacts on create/update contact
This commit is contained in:
parent
3a4867abea
commit
43f094220c
2 changed files with 44 additions and 0 deletions
|
@ -82,4 +82,21 @@ class Contact
|
|||
|
||||
$this->DisplayInList = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function GetEmails()
|
||||
{
|
||||
$aResult = array();
|
||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
||||
{
|
||||
if ($oProperty && $oProperty->IsEmail())
|
||||
{
|
||||
$aResult[] = $oProperty->Value;
|
||||
}
|
||||
}
|
||||
|
||||
return \array_unique($aResult);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,33 @@ class MySqlPersonalAddressBook
|
|||
$oContact->UpdateDependentValues();
|
||||
$oContact->Changed = \time();
|
||||
|
||||
if (\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO != $oContact->Type)
|
||||
{
|
||||
$aEmail = $oContact->GetEmails();
|
||||
if (0 < \count($aEmail))
|
||||
{
|
||||
$aEmail = \array_map(function ($mItem) {
|
||||
return \strtolower(\trim($mItem));
|
||||
}, $aEmail);
|
||||
|
||||
$aEmail = \array_filter($aEmail, function ($mItem) {
|
||||
return !empty($mItem);
|
||||
});
|
||||
|
||||
if (0 < \strlen($aEmail))
|
||||
{
|
||||
// clear autocreated contacts
|
||||
$this->prepareAndExecute(
|
||||
'DELETE FROM `rainloop_pab_contacts` WHERE `id_user` = :id_user AND `type` = :type AND `display_in_list` IN ('.\implode(',', $aEmail).')',
|
||||
array(
|
||||
':id_user' => array($iUserID, \PDO::PARAM_INT),
|
||||
':type' => array(\RainLoop\Providers\PersonalAddressBook\Enumerations\ContactType::AUTO, \PDO::PARAM_INT)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->beginTransaction();
|
||||
|
|
Loading…
Add table
Reference in a new issue