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; }