1717use OCA \Mail \BackgroundJob \RepairSyncJob ;
1818use OCA \Mail \BackgroundJob \SyncJob ;
1919use OCA \Mail \BackgroundJob \TrainImportanceClassifierJob ;
20+ use OCA \Mail \Db \DelegationMapper ;
2021use OCA \Mail \Db \MailAccount ;
2122use OCA \Mail \Db \MailAccountMapper ;
2223use OCA \Mail \Exception \ClientException ;
@@ -56,6 +57,7 @@ public function __construct(
5657 IMAPClientFactory $ imapClientFactory ,
5758 private readonly IConfig $ config ,
5859 private readonly ITimeFactory $ timeFactory ,
60+ private DelegationMapper $ delegationMapper ,
5961 ) {
6062 $ this ->mapper = $ mapper ;
6163 $ this ->aliasesService = $ aliasesService ;
@@ -75,6 +77,23 @@ public function findByUserId(string $currentUserId): array {
7577 return $ this ->accounts [$ currentUserId ];
7678 }
7779
80+ /**
81+ * @param string $userId
82+ * @return list<Account>
83+ */
84+ public function findDelegatedAccounts (string $ userId ): array {
85+ $ delegations = $ this ->delegationMapper ->findDelegatedAccountsForUser ($ userId );
86+ $ accounts = [];
87+ foreach ($ delegations as $ delegation ) {
88+ try {
89+ $ accounts [] = new Account ($ this ->mapper ->findById ($ delegation ->getAccountId ()));
90+ } catch (DoesNotExistException ) {
91+ // Account was deleted but delegation record remains — skip
92+ }
93+ }
94+ return $ accounts ;
95+ }
96+
7897 /**
7998 * @param int $id
8099 *
0 commit comments