Skip to content

Commit

Permalink
Merge branch 'pu/ccheng/test_sieve_update_fix' into '2024.11'
Browse files Browse the repository at this point in the history
fix(Felamimail/Controller): check account status before create adblist sieve script

See merge request tine20/tine20!5615
  • Loading branch information
pschuele committed Jul 11, 2024
2 parents eb1d144 + 6221fcd commit 45af2b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tests/tine20/Felamimail/Controller/SieveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public function testAdbMailinglistSieveRuleForwardOnlyMembers()

public function testAdbMailinglistSieveRuleForwardOnlyEnabledMembers()
{
Addressbook_Config::getInstance()->set(Addressbook_Config::CONTACT_HIDDEN_CRITERIA, 'never');

$this->_setFeatureForTest(Addressbook_Config::getInstance(), Addressbook_Config::FEATURE_MAILINGLIST);
$this->_testNeedsTransaction();

Expand All @@ -148,6 +150,7 @@ public function testAdbMailinglistSieveRuleForwardOnlyEnabledMembers()

$sclever = Tinebase_User::getInstance()->getFullUserByLoginName('sclever');
$raii = new Tinebase_RAII(function() use($sclever) {
Addressbook_Config::getInstance()->set(Addressbook_Config::CONTACT_HIDDEN_CRITERIA, 'disabled');
$sclever->accountStatus = Tinebase_Model_FullUser::ACCOUNT_STATUS_ENABLED;
Tinebase_User::getInstance()->updateUserInSqlBackend($sclever);
});
Expand All @@ -161,7 +164,7 @@ public function testAdbMailinglistSieveRuleForwardOnlyEnabledMembers()
$sieve = $script->getSieve();
self::assertStringContainsString('if address :is :all "from" ["' . $this->_originalTestUser->accountEmailAddress . '"]', $sieve);
self::assertStringContainsString('reject "Your email has been rejected"', $sieve);

unset($raii);
}

Expand Down
8 changes: 5 additions & 3 deletions tine20/Felamimail/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,14 @@ protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)
if ($_eventObject->account->accountStatus !== $_eventObject->oldAccount->accountStatus) {
$lists = Addressbook_Controller_List::getInstance()->search(
Tinebase_Model_Filter_FilterGroup::getFilterForModel(Addressbook_Model_List::class, [
['field' => 'showHidden', 'operator' => 'equals', 'value' => TRUE],
['field' => 'showHidden', 'operator' => 'equals', 'value' => TRUE],
['field' => 'xprops', 'operator' => 'contains', 'value' => Addressbook_Model_List::XPROP_USE_AS_MAILINGLIST],
]));

foreach ($lists as $list) {
$members = $list['members'];

$listToUpdate[] = [$list['email'] => $list->toArray()];
if (in_array($_eventObject->account->contact_id, $members)) {
$listToUpdate[] = [$list['email'] => $list['id']];
$transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
try {
Tinebase_TransactionManager::getInstance()->registerAfterCommitCallback(function($list) {
Expand All @@ -140,6 +138,10 @@ protected function _handleEvent(Tinebase_Event_Abstract $_eventObject)

Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
$transactionId = null;
} catch (Exception $e) {
Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__
. ' Could not pdate sieve script for adb lists: ' . $e);
throw new Tinebase_Exception_Backend($e->getMessage());
} finally {
if (null !== $transactionId) {
Tinebase_TransactionManager::getInstance()->rollBack();
Expand Down
10 changes: 9 additions & 1 deletion tine20/Felamimail/Sieve/AdbList.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,16 @@ static public function createFromList(Addressbook_Model_List $_list)
foreach ($receivers as $receiver) {
/** @var Addressbook_Model_Contact $receiver */
$email = $receiver->getPreferredEmailAddress();

if ($email) {
$sieveRule->_receiverList[] = $email;
if ($receiver->type === Addressbook_Model_Contact::CONTACTTYPE_USER) {
$accountStatus = Tinebase_User::getInstance()->getFullUserById($receiver->account_id)->accountStatus;
if ($accountStatus === Tinebase_Model_User::ACCOUNT_STATUS_ENABLED) {
$sieveRule->_receiverList[] = $email;
}
} else {
$sieveRule->_receiverList[] = $email;
}
}
}

Expand Down

0 comments on commit 45af2b0

Please sign in to comment.