diff --git a/appinfo/info.xml b/appinfo/info.xml
index f59eebc97dcfca1f4382b844bab0e4f547e68380..c5c7a83ba3870e661dd04930429e88cd11d8cff4 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -5,7 +5,7 @@
Email Recovery
Email Recovery App
- 10.2.0
+ 10.2.1
agpl
MURENA SAS
EmailRecovery
diff --git a/lib/Command/SpamAccountDetection.php b/lib/Command/SpamAccountDetection.php
index 72e18e6bd90c4cf61bd1999b946ef2e2b4f6de9f..0e4e2ba5af35dc3979d726be54e927b4216691e1 100644
--- a/lib/Command/SpamAccountDetection.php
+++ b/lib/Command/SpamAccountDetection.php
@@ -32,19 +32,17 @@ class SpamAccountDetection extends Command {
protected function execute(InputInterface $input, OutputInterface $output): int {
try {
- $spamUsers = $this->recoveryEmailService->getAllSpamEmails();
-
$output->writeln('Spam user list:');
- foreach ($spamUsers as $user) {
- $output->writeln($user['userId']);
- //$output->writeln("User ID: {$user['userId']}, Recovery Email: {$user['recoveryEmail']}");
- }
+
+ $this->recoveryEmailService->getAllSpamEmails(function (string $userId, string $recoveryEmail) use ($output) {
+ //$output->writeln("User ID: $userId, Recovery Email: $recoveryEmail");
+ $output->writeln($userId);
+ });
} catch (\Throwable $th) {
- $this->logger->error('Error while fetching domains. ' . $th->getMessage());
- $output->writeln('Error while fetching domains: ' . $th->getMessage());
+ $this->logger->error('Error while fetching spam email list: ' . $th->getMessage());
return Command::FAILURE;
}
-
+
return Command::SUCCESS;
}
}
diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php
index 3503419b7da410be48ce10a9ef53bc0b609fd8aa..5ecefdb6c61f17d41b15f090e8f5d0b2b0ed0568 100644
--- a/lib/Service/RecoveryEmailService.php
+++ b/lib/Service/RecoveryEmailService.php
@@ -596,54 +596,53 @@ class RecoveryEmailService {
* - Already taken by another user
* - Unverifiable or unreachable (e.g., failed MX or domain lookup)
*
- * Returns an array of spam account entries, each including:
- * - userId: the username
- * - recoveryEmail: the flagged recovery email address
+ * A callback can be passed to handle each detected spam user in real-time.
+ * This is useful for streaming output during long-running operations (e.g., CLI).
*
- * @return array
+ * @param callable $onSpamDetected A callback function with signature fn(string $userId, string $recoveryEmail): void
+ * @return void
*/
- public function getAllSpamEmails(): array {
+ public function getAllSpamEmails(callable $onSpamDetected): void {
$verifiedEmails = $this->configMapper->getAllVerifiedRecoveryEmails();
- $spamAccounts = [];
-
+
foreach ($verifiedEmails as $entry) {
$recoveryEmail = strtolower(trim($entry['configvalue']));
$userId = strtolower(trim($entry['userid']));
-
+
if ($recoveryEmail === '' || $userId === '') {
continue;
}
-
+
$user = $this->userManager->get($userId);
if ($user === null) {
continue;
}
-
+
$email = $user->getEMailAddress();
-
- if ($this->hasActiveSubscription($email)) {
- $this->logger->info("User $userId has an active subscription. Skipping spam flag for <$recoveryEmail>.");
+ if (empty($email)) {
continue;
}
-
+
+ try {
+ if ($this->hasActiveSubscription($email)) {
+ $this->logger->info("User $userId has an active subscription. Skipping spam flag for <$recoveryEmail>.");
+ continue;
+ }
+ } catch (\Throwable $e) {
+ $this->logger->error("Error checking subscription for $userId <$email>: " . $e->getMessage());
+ continue;
+ }
+
try {
if (!$this->validateRecoveryEmail($recoveryEmail, $userId)) {
- $spamAccounts[] = [
- 'userId' => $userId,
- 'recoveryEmail' => $recoveryEmail,
- ];
+ $onSpamDetected($userId, $recoveryEmail);
}
} catch (BlacklistedEmailException | InvalidRecoveryEmailException $e) {
$this->logger->info("Validation failed (spam) for $userId <$recoveryEmail>: " . $e->getMessage());
- $spamAccounts[] = [
- 'userId' => $userId,
- 'recoveryEmail' => $recoveryEmail,
- ];
+ $onSpamDetected($userId, $recoveryEmail);
} catch (\Throwable $e) {
$this->logger->info("Error while checking $userId <$recoveryEmail>: " . $e->getMessage());
}
}
-
- return $spamAccounts;
}
}