diff --git a/appinfo/info.xml b/appinfo/info.xml
index c51cb1cd..c1295f66 100755
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -36,6 +36,7 @@ Guests users can only access files shared to them and cannot create any files ou
OCA\Guests\Migration\OwncloudGuestsMigration
+ OCA\Guests\Repair\ResetEmails
diff --git a/lib/Repair/ResetEmails.php b/lib/Repair/ResetEmails.php
new file mode 100644
index 00000000..9568b4da
--- /dev/null
+++ b/lib/Repair/ResetEmails.php
@@ -0,0 +1,38 @@
+
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OCA\Guests\Repair;
+
+use OCA\Guests\GuestManager;
+use OCP\IConfig;
+use OCP\IUserManager;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class ResetEmails implements IRepairStep {
+ public function __construct(
+ private readonly GuestManager $guestManager,
+ private readonly IUserManager $userManager,
+ private readonly IConfig $config,
+ ) {
+ }
+
+ public function getName(): string {
+ return 'Reset the email of all guest accounts';
+ }
+
+ public function run(IOutput $output) {
+ foreach ($this->guestManager->listGuests() as $guestId) {
+ $guest = $this->userManager->get($guestId);
+ if (strtolower($guest->getSystemEMailAddress()) !== strtolower($guestId)) {
+ $this->config->setUserValue($guestId, 'guests', 'old_email', $guest->getSystemEMailAddress());
+ $guest->setSystemEMailAddress(strtolower($guestId));
+ }
+ }
+ }
+}