Page MenuHomePhorge

D4992.diff
No OneTemporary

D4992.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
@@ -144,7 +144,7 @@
*
* @param string $mailbox Folder name
*/
- protected static function deleteMailbox($mailbox): bool
+ public static function deleteMailbox($mailbox): bool
{
$config = self::getConfig();
$imap = self::initIMAP($config);
@@ -169,6 +169,23 @@
return $result;
}
+ /**
+ * Empty a mailbox
+ *
+ * @param string $mailbox Folder name
+ */
+ public static function clearMailbox($mailbox): bool
+ {
+ $config = self::getConfig();
+ $imap = self::initIMAP($config);
+
+ $result = $imap->clearFolder($mailbox);
+
+ $imap->closeConnection();
+
+ return $result;
+ }
+
/**
* Delete a user mailbox.
*
diff --git a/src/app/Console/Commands/Imap/DeleteCommand.php b/src/app/Console/Commands/Imap/DeleteCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/Imap/DeleteCommand.php
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Console\Commands\Imap;
+
+use App\Console\Command;
+
+class DeleteCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'imap:delete {user} {mailbox} {--clear : Clear mailbox instead}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Delete IMAP Folders";
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = $this->argument('user');
+ $mailbox = $this->argument('mailbox');
+ if ($mailbox == "*") {
+ // Reverse so subfolders are deleted before parent folders
+ foreach (array_reverse(\App\Backends\IMAP::listMailboxes($user)) as $mailbox) {
+ \App\Backends\IMAP::deleteMailbox($mailbox);
+ }
+ // Can't delete INBOX
+ \App\Backends\IMAP::clearMailbox(\App\Backends\IMAP::userMailbox($user, "INBOX"));
+ } else {
+ if ($this->option('clear')) {
+ \App\Backends\IMAP::clearMailbox(\App\Backends\IMAP::userMailbox($user, $mailbox));
+ } else {
+ \App\Backends\IMAP::deleteMailbox(\App\Backends\IMAP::userMailbox($user, $mailbox));
+ }
+ }
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 19, 1:28 PM (20 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
9877845
Default Alt Text
D4992.diff (2 KB)

Event Timeline