Page MenuHomePhorge

D5541.1775227255.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D5541.1775227255.diff

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
@@ -502,6 +502,38 @@
return $result;
}
+
+ /**
+ * List groupware mailboxes.
+ *
+ * @param string $user The user
+ *
+ * @return array List of mailboxes
+ *
+ * @throws \Exception
+ */
+ public static function listGroupwareMailboxes(string $user): array
+ {
+ $config = self::getConfig();
+ $imap = self::initIMAP($config);
+
+ $mailboxes = $imap->listMailboxes('', self::userMailbox($user, "*"));
+ $result = [];
+ foreach ($mailboxes as $folder) {
+ $metadata = $imap->getMetadata($folder, ['/shared/vendor/kolab/folder-type']);
+ if (!empty($metadata)) {
+ $metadata = implode(" ", $metadata[$folder]);
+ if (!empty($metadata) && !str_contains($metadata, "mail")) {
+ $result[] = $folder;
+ }
+ }
+ }
+
+ $imap->closeConnection();
+
+ return $result;
+ }
+
/**
* Convert UTF8 string to UTF7-IMAP encoding
*/
diff --git a/src/app/Console/Commands/Imap/DeleteCommand.php b/src/app/Console/Commands/Imap/DeleteCommand.php
--- a/src/app/Console/Commands/Imap/DeleteCommand.php
+++ b/src/app/Console/Commands/Imap/DeleteCommand.php
@@ -12,7 +12,7 @@
*
* @var string
*/
- protected $signature = 'imap:delete {user} {mailbox} {--clear : Clear mailbox instead}';
+ protected $signature = 'imap:delete {user} {mailbox} {--clear : Clear mailbox instead} {--groupware : Only match groupware mailboxes}';
/**
* The console command description.
@@ -31,16 +31,21 @@
$user = $this->argument('user');
$mailbox = $this->argument('mailbox');
if ($mailbox == "*") {
+ if ($this->option('groupware')) {
+ $mailboxes = IMAP::listGroupwareMailboxes($user);
+ } else {
+ $mailboxes = IMAP::listMailboxes($user);
+ // Can't delete INBOX
+ IMAP::clearMailbox(IMAP::userMailbox($user, "INBOX"));
+ }
// Reverse so subfolders are deleted before parent folders
- foreach (array_reverse(IMAP::listMailboxes($user)) as $mailbox) {
+ foreach (array_reverse($mailboxes) as $mailbox) {
if ($this->option('clear')) {
IMAP::clearMailbox($mailbox);
} else {
IMAP::deleteMailbox($mailbox);
}
}
- // Can't delete INBOX
- IMAP::clearMailbox(IMAP::userMailbox($user, "INBOX"));
} else {
if ($this->option('clear')) {
IMAP::clearMailbox(IMAP::userMailbox($user, $mailbox));
diff --git a/src/app/Console/Commands/Imap/ListCommand.php b/src/app/Console/Commands/Imap/ListCommand.php
--- a/src/app/Console/Commands/Imap/ListCommand.php
+++ b/src/app/Console/Commands/Imap/ListCommand.php
@@ -12,7 +12,7 @@
*
* @var string
*/
- protected $signature = 'imap:list {user}';
+ protected $signature = 'imap:list {user} {--groupware}';
/**
* The console command description.
@@ -29,8 +29,14 @@
public function handle()
{
$user = $this->argument('user');
- foreach (IMAP::listMailboxes($user) as $mailbox) {
- $this->info("{$mailbox}");
+ if ($this->option("groupware")) {
+ foreach (IMAP::listGroupwareMailboxes($user) as $mailbox) {
+ $this->info("{$mailbox}");
+ }
+ } else {
+ foreach (IMAP::listMailboxes($user) as $mailbox) {
+ $this->info("{$mailbox}");
+ }
}
}
}

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 2:40 PM (1 d, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18824331
Default Alt Text
D5541.1775227255.diff (3 KB)

Event Timeline