From 0a69f7f4f4ff0f20cbf76ead8ab1c5d1c4940116 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sun, 3 May 2026 02:05:20 -0400 Subject: [PATCH] tools: mailutil: Add mailbox remove command Signed-off-by: Ian Moffett --- tools/mailutil/core/mailutil.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/mailutil/core/mailutil.c b/tools/mailutil/core/mailutil.c index 57b9f6b..b1f3589 100644 --- a/tools/mailutil/core/mailutil.c +++ b/tools/mailutil/core/mailutil.c @@ -73,6 +73,34 @@ cmd_mailbox_list(void) return 0; } +/* + * Parse a "mailbox rm" command + * + * @cmdlist: Command list to parse + * @count: Number of entries inside command list + * + * Returns zero on success + */ +static int +cmd_mailbox_rm(const char *cmdlist[CMD_MAX_CNP], size_t count) +{ + char pathbuf[64]; + + ASSERT_COUNT_N(count, 3); + + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", + MAILBOX_PREFIX, cmdlist[2]); + + /* Destroy the mailbox */ + if (rmdir(pathbuf) < 0) { + perror("rmdir"); + return -1; + } + + printf("deleted mailbox '%s'\n", cmdlist[2]); + return 0; +} + /* * Parse a "mailbox create" command * @@ -123,6 +151,10 @@ cmd_mailbox(const char *cmdlist[CMD_MAX_CNP], size_t count) return cmd_mailbox_list(); } + if (strcmp(cmdlist[1], "rm") == 0) { + return cmd_mailbox_rm(cmdlist, count); + } + printf("error: bad parameter\n"); return -1; }