Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\Mail\Contracts\IAvatarService;
use OCA\Mail\Contracts\IDkimService;
use OCA\Mail\Contracts\IDkimValidator;
use OCA\Mail\Contracts\IInternalAddressService;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Contracts\IMailSearch;
use OCA\Mail\Contracts\IMailTransmission;
Expand Down Expand Up @@ -61,6 +62,7 @@
use OCA\Mail\Service\AvatarService;
use OCA\Mail\Service\DkimService;
use OCA\Mail\Service\DkimValidator;
use OCA\Mail\Service\InternalAddressService;
use OCA\Mail\Service\MailManager;
use OCA\Mail\Service\MailTransmission;
use OCA\Mail\Service\Search\MailSearch;
Expand Down Expand Up @@ -121,6 +123,7 @@ public function register(IRegistrationContext $context): void {
$context->registerServiceAlias(IMailManager::class, MailManager::class);
$context->registerServiceAlias(IMailSearch::class, MailSearch::class);
$context->registerServiceAlias(IMailTransmission::class, MailTransmission::class);
$context->registerServiceAlias(IInternalAddressService::class, InternalAddressService::class);
$context->registerServiceAlias(ITrustedSenderService::class, TrustedSenderService::class);
$context->registerServiceAlias(IUserPreferences::class, UserPreferenceService::class);
$context->registerServiceAlias(IDkimService::class, DkimService::class);
Expand Down
2 changes: 2 additions & 0 deletions lib/Contracts/IInternalAddressService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function isInternal(string $uid, string $address): bool;

public function add(string $uid, string $address, string $type, ?bool $trust = true);

public function removeInternalAddresses(string $uid): void;

/**
* @param string $uid
* @return InternalAddress[]
Expand Down
2 changes: 2 additions & 0 deletions lib/Contracts/ITrustedSenderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public function isTrusted(string $uid, string $email): bool;

public function trust(string $uid, string $email, string $type, ?bool $trust = true);

public function removeTrusted(string $uid): void;

/**
* @param string $uid
* @return TrustedSender[]
Expand Down
17 changes: 17 additions & 0 deletions lib/Db/ActionsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,22 @@ public function findAll(string $owner) {
return $this->findEntities($qb);
}

public function deleteAll(string $owner) {
$qb = $this->db->getQueryBuilder();

$actionIds = $this->db->getQueryBuilder()
->select('actions.id')
->from($this->getTableName(), 'actions')
->join('actions', 'mail_accounts', 'accounts', $qb->expr()->eq('actions.account_id', 'accounts.id'))
->where(
$qb->expr()->eq('accounts.user_id', $qb->createNamedParameter($owner, IQueryBuilder::PARAM_STR))
)
->executeQuery()->fetchAllAssociative();

$delete = $qb->delete($this->getTableName())
->where(
$qb->expr()->in('id', $qb->createNamedParameter($actionIds, IQueryBuilder::PARAM_INT_ARRAY))
);
$delete->executeStatement();
}
}
11 changes: 11 additions & 0 deletions lib/Db/InternalAddressMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\IDBConnection;

/**
Expand Down Expand Up @@ -100,4 +101,14 @@ public function find(string $uid, string $address): ?InternalAddress {
return null;
}
}

/**
* @throws Exception
*/
public function removeAll(string $uid) : void {
$qb = $this->db->getQueryBuilder();
$delete = $qb->delete($this->getTableName())
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid)));
$delete->executeStatement();
}
}
9 changes: 9 additions & 0 deletions lib/Db/TagMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ public function createDefaultTags(MailAccount $account): void {
}
}

public function deleteAll(string $userId): void {
$qb = $this->db->getQueryBuilder();
$delete = $qb->delete($this->getTableName())
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
);
$delete->executeStatement();
}

public function deleteDuplicates(): void {
$qb = $this->db->getQueryBuilder();
$qb->select('mt2.id')
Expand Down
9 changes: 9 additions & 0 deletions lib/Db/TextBlockMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,13 @@ public function findSharedWithMe(string $userId, array $groups) {
return $this->findEntities($qb);
}

public function deleteAll(string $owner) {
$qb = $this->db->getQueryBuilder();
$delete = $qb->delete($this->getTableName())
->where(
$qb->expr()->eq('owner', $qb->createNamedParameter($owner, IQueryBuilder::PARAM_STR))
);
$delete->executeStatement();
}

}
7 changes: 7 additions & 0 deletions lib/Db/TrustedSenderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,11 @@ public function findAll(string $uid): array {
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid)));
return $this->findEntities($select);
}

public function deleteAll(string $uid) {
$qb = $this->db->getQueryBuilder();
$delete = $qb->delete($this->getTableName())
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($uid)));
$delete->executeStatement();
}
}
12 changes: 9 additions & 3 deletions lib/Service/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,19 @@ public function deleteByAccountId(int $accountId): void {

/**
* @param MailAccount $newAccount
* @param bool $scheduleBackgroundJobs Optional parameter to save the mail
* account without scheduling the corresponding background jobs. This can
* be useful if further database modifications must be done before
* running any background jobs. Defaults to `true`.
* @return MailAccount
*/
public function save(MailAccount $newAccount): MailAccount {
public function save(MailAccount $newAccount, bool $scheduleBackgroundJobs = true): MailAccount {
$newAccount = $this->mapper->save($newAccount);

// Insert background jobs for this account
$this->scheduleBackgroundJobs($newAccount->getId());
if ($scheduleBackgroundJobs) {
// Insert background jobs for this account
$this->scheduleBackgroundJobs($newAccount->getId());
}

return $newAccount;
}
Expand Down
13 changes: 13 additions & 0 deletions lib/Service/AliasesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\Mail\Db\MailAccountMapper;
use OCA\Mail\Exception\ClientException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\Exception;

class AliasesService {
/** @var AliasMapper */
Expand Down Expand Up @@ -133,4 +134,16 @@ public function updateSignature(string $userId, int $aliasId, ?string $signature
$entity->setSignature($signature);
return $this->aliasMapper->update($entity);
}

/**
* Update the S/MIME certificate for alias.
*
* @throws DoesNotExistException
* @throws Exception
*/
public function updateSmimeCertificateId(string $userId, int $aliasId, ?int $smimeCertificateId = null): Alias {
$entity = $this->find($aliasId, $userId);
$entity->setSmimeCertificateId($smimeCertificateId);
return $this->aliasMapper->update($entity);
}
}
5 changes: 5 additions & 0 deletions lib/Service/InternalAddressService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function add(string $uid, string $address, string $type, ?bool $trust = t
return null;
}

#[\Override]
public function removeInternalAddresses(string $uid): void {
$this->mapper->removeAll($uid);
}

#[\Override]
public function getInternalAddresses(string $uid): array {
return $this->mapper->findAll($uid);
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/QuickActionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public function delete(int $actionId, string $userId): void {
$this->actionsMapper->delete($action);
}

public function deleteAll(string $userId): void {
$allActions = $this->actionsMapper->findAll($userId);

foreach ($allActions as $action) {
$this->actionsMapper->delete($action);
}
}

/**
* @throws DoesNotExistException
*/
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/TextBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function delete(int $textBlockId, string $userId): void {
$this->textBlockShareMapper->deleteByTextBlockId($textBlockId);
}

public function deleteAll(string $userId): void {
$this->textBlockMapper->deleteAll($userId);
}


/**
* @throws UserNotFoundException
Expand Down
4 changes: 4 additions & 0 deletions lib/Service/TrustedSenderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ public function trust(string $uid, string $email, string $type, ?bool $trust = t
public function getTrusted(string $uid): array {
return $this->mapper->findAll($uid);
}

public function removeTrusted(string $uid): void {
$this->mapper->deleteAll($uid);
}
}
Loading