Compare commits

...

2 Commits

Author SHA1 Message Date
chloe 0a69f7f4f4 tools: mailutil: Add mailbox remove command
Signed-off-by: Ian Moffett <ian@mirocom.org>
2026-05-03 02:05:37 -04:00
chloe 67155faed1 tools: mailutil: Add mailbox list command
Signed-off-by: Ian Moffett <ian@mirocom.org>
2026-05-03 02:01:42 -04:00
+60
View File
@@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h>
#include "libremail/file.h" #include "libremail/file.h"
#include "libremail/common.h" #include "libremail/common.h"
@@ -49,6 +50,57 @@ version(void)
printf("Version v%s\n", MAILUTIL_VERSION); printf("Version v%s\n", MAILUTIL_VERSION);
} }
static int
cmd_mailbox_list(void)
{
DIR *dir;
struct dirent *dirent;
if ((dir = opendir(MAILBOX_PREFIX)) == NULL) {
perror("opendir");
return -1;
}
while ((dirent = readdir(dir)) != NULL) {
if (dirent->d_name[0] == '.') {
continue;
}
printf("[mailbox] :: %s\n", dirent->d_name);
}
closedir(dir);
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 * Parse a "mailbox create" command
* *
@@ -95,6 +147,14 @@ cmd_mailbox(const char *cmdlist[CMD_MAX_CNP], size_t count)
return cmd_mailbox_create(cmdlist, count); return cmd_mailbox_create(cmdlist, count);
} }
if (strcmp(cmdlist[1], "list") == 0) {
return cmd_mailbox_list();
}
if (strcmp(cmdlist[1], "rm") == 0) {
return cmd_mailbox_rm(cmdlist, count);
}
printf("error: bad parameter\n"); printf("error: bad parameter\n");
return -1; return -1;
} }