Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a69f7f4f4 | |||
| 67155faed1 |
@@ -7,6 +7,7 @@
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include "libremail/file.h"
|
||||
#include "libremail/common.h"
|
||||
|
||||
@@ -49,6 +50,57 @@ version(void)
|
||||
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
|
||||
*
|
||||
@@ -95,6 +147,14 @@ cmd_mailbox(const char *cmdlist[CMD_MAX_CNP], size_t 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");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user