Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F120822683
D5451.1776938042.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
D5451.1776938042.diff
View Options
diff --git a/src/app/Backends/IMAP.php b/src/app/Backends/IMAP.php
--- a/src/app/Backends/IMAP.php
+++ b/src/app/Backends/IMAP.php
@@ -35,9 +35,13 @@
// Mailbox already exists
if (self::folderExists($imap, $mailbox)) {
- $imap->closeConnection();
- self::createDefaultFolders($user);
- return true;
+ // This is a special (rare) case. We delete the mailbox and re-create it
+ // to make sure no old data is accessible.
+ if (!self::deleteMailboxEx($imap, $mailbox)) {
+ \Log::error("Failed to delete mailbox {$mailbox} for re-creation");
+ $imap->closeConnection();
+ return false;
+ }
}
// Create the mailbox
@@ -132,8 +136,20 @@
$config = self::getConfig();
$imap = self::initIMAP($config);
+ $result = self::deleteMailboxEx($imap, $mailbox);
+
+ $imap->closeConnection();
+
+ return $result;
+ }
+
+ /**
+ * Execute user mailbox deletion (as cyrus-admin)
+ */
+ protected static function deleteMailboxEx($imap, $mailbox): bool
+ {
// To delete the mailbox cyrus-admin needs extra permissions
- $result = $imap->setACL($mailbox, $config['user'], 'c');
+ $result = $imap->setACL($mailbox, \config('services.imap.admin_login'), 'c');
// Ignore the error if the folder doesn't exist (maybe it was removed already).
if (
@@ -141,15 +157,11 @@
&& str_contains($imap->error, 'Mailbox does not exist')
) {
\Log::info("The mailbox to delete was already removed: {$mailbox}");
- $result = true;
- } else {
- // Delete the mailbox (no need to delete subfolders?)
- $result = $imap->deleteFolder($mailbox);
+ return true;
}
- $imap->closeConnection();
-
- return $result;
+ // Delete the mailbox (no need to delete subfolders?)
+ return $imap->deleteFolder($mailbox);
}
/**
diff --git a/src/app/Jobs/User/CreateJob.php b/src/app/Jobs/User/CreateJob.php
--- a/src/app/Jobs/User/CreateJob.php
+++ b/src/app/Jobs/User/CreateJob.php
@@ -108,6 +108,7 @@
}
$user->status |= User::STATUS_IMAP_READY;
+ $user->save();
}
// FIXME: Should we ignore exceptions on this operation or introduce DAV_READY status?
diff --git a/src/tests/Feature/Backends/IMAPTest.php b/src/tests/Feature/Backends/IMAPTest.php
--- a/src/tests/Feature/Backends/IMAPTest.php
+++ b/src/tests/Feature/Backends/IMAPTest.php
@@ -174,6 +174,12 @@
$quota = $imap->getQuota('user/' . $user->email);
$this->assertSame($expectedQuota, $quota['all']);
+ // Create the mailbox again
+ $result = IMAP::createUser($user);
+ $this->assertTrue($result);
+ $this->assertTrue(IMAP::verifyAccount($user->email));
+ $this->assertTrue(IMAP::verifyDefaultFolders($user->email));
+
// Update the mailbox (increase quota)
$user->assignSku($storage, 1, $user->wallets->first());
$expectedQuota['user/' . $user->email]['storage']['total'] = 1048576 * 2;
@@ -185,6 +191,10 @@
$this->assertSame($expectedQuota, $quota['all']);
// Delete the mailbox
+ // If we don't wait Cyrus will throw "Mailbox already exists", because
+ // we already deleted the mailbox once above. And this next delete to work
+ // we need to "bump" the timestamp
+ sleep(1);
$result = IMAP::deleteUser($user);
$this->assertTrue($result);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Apr 23, 9:54 AM (1 h, 30 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18834005
Default Alt Text
D5451.1776938042.diff (3 KB)
Attached To
Mode
D5451: Delete an existing user mailbox in IMAP::createUser()
Attached
Detach File
Event Timeline