diff options
-rw-r--r-- | imap4d/delete.c | 20 | ||||
-rw-r--r-- | include/mailutils/mailbox.h | 1 | ||||
-rw-r--r-- | include/mailutils/stream.h | 3 | ||||
-rw-r--r-- | include/mailutils/sys/amd.h | 2 | ||||
-rw-r--r-- | include/mailutils/sys/mailbox.h | 1 | ||||
-rw-r--r-- | libmailutils/amd.c | 115 | ||||
-rw-r--r-- | libmailutils/errors | 4 | ||||
-rw-r--r-- | libmailutils/file_stream.c | 2 | ||||
-rw-r--r-- | libmailutils/mailbox.c | 129 | ||||
-rw-r--r-- | libmailutils/tests/.gitignore | 1 | ||||
-rw-r--r-- | libmailutils/tests/Makefile.am | 5 | ||||
-rw-r--r-- | libmailutils/tests/mbdel.c | 54 | ||||
-rw-r--r-- | libproto/maildir/mbox.c | 23 | ||||
-rw-r--r-- | libproto/mbox/mbox.c | 13 | ||||
-rw-r--r-- | libproto/mh/mbox.c | 10 |
15 files changed, 327 insertions, 56 deletions
diff --git a/imap4d/delete.c b/imap4d/delete.c index b7d30ae61..11f78beea 100644 --- a/imap4d/delete.c +++ b/imap4d/delete.c @@ -37,7 +37,8 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok) const char *msg = "Completed"; const char *delim = "/"; char *name; - + mu_mailbox_t tmpbox; + if (imap4d_tokbuf_argc (tok) != 3) return io_completion_response (command, RESP_BAD, "Invalid arguments"); name = imap4d_tokbuf_getarg (tok, IMAP4_ARG_1); @@ -54,7 +55,22 @@ imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok) if (!name) return io_completion_response (command, RESP_NO, "Cannot remove"); - if (remove (name) != 0) + rc = mu_mailbox_create (&tmpbox, name); + if (rc == 0) + { + rc = mu_mailbox_remove (tmpbox); + mu_mailbox_destroy (&tmpbox); + if (rc) + mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_remove", name, rc); + } + else + { + rc = remove (name); + if (rc) + mu_diag_funcall (MU_DIAG_ERROR, "remove", name, errno); + } + + if (rc) { rc = RESP_NO; msg = "Cannot remove"; diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h index 1d1ce96ce..74d3407f2 100644 --- a/include/mailutils/mailbox.h +++ b/include/mailutils/mailbox.h @@ -49,6 +49,7 @@ extern void mu_mailbox_destroy (mu_mailbox_t *); extern int mu_mailbox_open (mu_mailbox_t, int flag); extern int mu_mailbox_close (mu_mailbox_t); +extern int mu_mailbox_remove (mu_mailbox_t mbox); extern int mu_mailbox_flush (mu_mailbox_t mbox, int expunge); extern int mu_mailbox_get_folder (mu_mailbox_t, mu_folder_t *); extern int mu_mailbox_set_folder (mu_mailbox_t, mu_folder_t); diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h index d8567ac8d..95b279007 100644 --- a/include/mailutils/stream.h +++ b/include/mailutils/stream.h @@ -27,7 +27,6 @@ enum mu_buffer_type mu_buffer_full }; - #define MU_SEEK_SET 0 #define MU_SEEK_CUR 1 #define MU_SEEK_END 2 @@ -38,8 +37,10 @@ enum mu_buffer_type #define MU_STREAM_SEEK 0x00000004 #define MU_STREAM_APPEND 0x00000008 #define MU_STREAM_CREAT 0x00000010 +/* So far used only by TCP streams. */ #define MU_STREAM_NONBLOCK 0x00000020 #define MU_STREAM_AUTOCLOSE 0x00000040 +/* Not used. Intended for mailboxes only. */ #define MU_STREAM_NONLOCK 0x00000080 #define MU_STREAM_ALLOW_LINKS 0x00000100 /* FIXME: This one affects only mailboxes */ diff --git a/include/mailutils/sys/amd.h b/include/mailutils/sys/amd.h index b72c3c1ec..52f039515 100644 --- a/include/mailutils/sys/amd.h +++ b/include/mailutils/sys/amd.h @@ -82,6 +82,7 @@ struct _amd_data int (*msg_cmp) (struct _amd_message *, struct _amd_message *); int (*message_uid) (mu_message_t msg, size_t *puid); size_t (*next_uid) (struct _amd_data *mhd); + int (*remove) (struct _amd_data *); /* List of messages: */ size_t msg_count; /* number of messages in the list */ @@ -112,5 +113,6 @@ void amd_cleanup (void *arg); struct _amd_message *_amd_get_message (struct _amd_data *amd, size_t msgno); int amd_msg_lookup (struct _amd_data *amd, struct _amd_message *msg, size_t *pret); +int amd_remove_dir (const char *name); #endif diff --git a/include/mailutils/sys/mailbox.h b/include/mailutils/sys/mailbox.h index 12af8fe48..fe362690f 100644 --- a/include/mailutils/sys/mailbox.h +++ b/include/mailutils/sys/mailbox.h @@ -54,6 +54,7 @@ struct _mu_mailbox int (*_open) (mu_mailbox_t, int); int (*_close) (mu_mailbox_t); + int (*_remove) (mu_mailbox_t); /* messages */ int (*_get_message) (mu_mailbox_t, size_t, mu_message_t *); diff --git a/libmailutils/amd.c b/libmailutils/amd.c index 3cf3dde6c..a0dec4e21 100644 --- a/libmailutils/amd.c +++ b/libmailutils/amd.c @@ -112,6 +112,7 @@ static int amd_envelope_date (mu_envelope_t envelope, char *buf, size_t len, size_t *psize); static int amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t *psize); +static int amd_remove_mbox (mu_mailbox_t mailbox); static int amd_body_stream_read (mu_stream_t str, char *buffer, @@ -309,7 +310,8 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size, mailbox->_is_updated = amd_is_updated; mailbox->_get_size = amd_get_size; - + mailbox->_remove = amd_remove_mbox; + MU_DEBUG1 (mailbox->debug, MU_DEBUG_TRACE1, "amd_init(%s)\n", amd->name); *pamd = amd; return 0; @@ -1100,6 +1102,40 @@ compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize) } static int +amd_remove_mbox (mu_mailbox_t mailbox) +{ + int rc; + struct _amd_data *amd = mailbox->data; + + if (!amd->remove) + return ENOSYS; + rc = amd->remove (amd); + if (rc == 0) + { + char *name = make_size_file_name (amd); + if (!name) + return ENOMEM; + if (unlink (name) && errno != ENOENT) + rc = errno; + free (name); + } + + if (rc == 0) + { + if (rmdir (amd->name) && errno != ENOENT) + { + rc = errno; + /* POSIX.1-2001 allows EEXIST to be returned if the directory + contained entries other than . and .. */ + if (rc == EEXIST) + rc = ENOTEMPTY; + } + } + + return rc; +} + +static int amd_expunge (mu_mailbox_t mailbox) { struct _amd_data *amd = mailbox->data; @@ -1922,4 +1958,81 @@ amd_envelope_sender (mu_envelope_t envelope, char *buf, size_t len, size_t *psiz return 0; } + +int +amd_remove_dir (const char *name) +{ + DIR *dir; + struct dirent *ent; + char *namebuf; + size_t namelen, namesize; + int rc = 0; + int has_subdirs = 0; + + namelen = strlen (name); + namesize = namelen + 128; + namebuf = malloc (namesize); + if (!namebuf) + return ENOMEM; + memcpy (namebuf, name, namelen); + if (namebuf[namelen - 1] != '/') + namebuf[namelen++] = '/'; + + dir = opendir (name); + if (!dir) + return errno; + while ((ent = readdir (dir))) + { + struct stat st; + size_t len; + + if (strcmp (ent->d_name, ".") == 0 || + strcmp (ent->d_name, "..") == 0) + continue; + len = strlen (ent->d_name); + if (namelen + len >= namesize) + { + char *p; + + namesize += len + 1; + p = realloc (namebuf, namesize); + if (!p) + { + rc = ENOMEM; + break; + } + } + strcpy (namebuf + namelen, ent->d_name); + if (stat (namebuf, &st) == 0 && S_ISDIR (st.st_mode)) + { + has_subdirs = 1; + continue; + } + + if (unlink (namebuf)) + { + rc = errno; + mu_diag_output (MU_DIAG_WARNING, + "failed to remove %s: %s", + namebuf, mu_strerror (rc)); + break; + } + } + closedir (dir); + free (namebuf); + + if (rc == 0 && !has_subdirs) + { + if (rmdir (name)) + { + rc = errno; + /* POSIX.1-2001 allows EEXIST to be returned if the directory + contained entries other than . and .. */ + if (rc == EEXIST) + rc = ENOTEMPTY; + } + } + return rc; +} + diff --git a/libmailutils/errors b/libmailutils/errors index 06eb98b48..5b4d2f112 100644 --- a/libmailutils/errors +++ b/libmailutils/errors @@ -26,6 +26,10 @@ MU_ERR_OUT_NULL _("Pointer to output null") MU_ERR_OUT_PTR_NULL _("Pointer to output pointer null") MU_ERR_MBX_NULL _("Mailbox null") +MU_ERR_MBX_REMOVED _("Mailbox removed") + +MU_ERR_NOT_OPEN _("Resource not open") +MU_ERR_OPEN _("Resource still open") MU_ERR_BAD_822_FORMAT _("Format of RFC822 object is bad") MU_ERR_EMPTY_ADDRESS _("Address contains no addr specs") diff --git a/libmailutils/file_stream.c b/libmailutils/file_stream.c index 0df1254e1..dccbd0dfe 100644 --- a/libmailutils/file_stream.c +++ b/libmailutils/file_stream.c @@ -121,7 +121,7 @@ fd_open (struct _mu_stream *str) { struct stat fdbuf, filebuf; - /* The next two stats should never fail. */ + /* The following two stats should never fail. */ if (fstat (fd, &fdbuf) == -1 || lstat (fstr->filename, &filebuf) == -1) { diff --git a/libmailutils/mailbox.c b/libmailutils/mailbox.c index e1c7b59f1..9344f01d0 100644 --- a/libmailutils/mailbox.c +++ b/libmailutils/mailbox.c @@ -44,6 +44,11 @@ #include <mailutils/sys/mailbox.h> #include <mailutils/sys/url.h> +/* Mailbox-specific flags */ +#define _MU_MAILBOX_OPEN 0x10000000 +#define _MU_MAILBOX_REMOVED 0x20000000 +#define _MU_MAILBOX_MASK 0xF0000000 + static int mailbox_folder_create (mu_mailbox_t mbox, const char *name, mu_record_t record) @@ -287,7 +292,11 @@ mu_mailbox_destroy (mu_mailbox_t *pmbox) int mu_mailbox_open (mu_mailbox_t mbox, int flag) { - if (mbox == NULL || mbox->_open == NULL) + int rc; + + if (!mbox) + return MU_ERR_MBX_NULL; + if (mbox->_open == NULL) return MU_ERR_EMPTY_VFN; if (flag & MU_STREAM_QACCESS) { @@ -296,16 +305,42 @@ mu_mailbox_open (mu_mailbox_t mbox, int flag) | MU_STREAM_APPEND | MU_STREAM_CREAT)) return EINVAL; /* FIXME: Better error code, please? */ } - return mbox->_open (mbox, flag); + rc = mbox->_open (mbox, flag); + if (rc == 0) + mbox->flags |= _MU_MAILBOX_OPEN; + return rc; } int mu_mailbox_close (mu_mailbox_t mbox) { + int rc; + + if (!mbox) + return MU_ERR_MBX_NULL; + if (!(mbox->flags & _MU_MAILBOX_OPEN)) + return MU_ERR_NOT_OPEN; if (mbox == NULL || mbox->_close == NULL) return MU_ERR_EMPTY_VFN; - return mbox->_close (mbox); + rc = mbox->_close (mbox); + if (rc == 0) + mbox->flags &= ~_MU_MAILBOX_OPEN; + return rc; +} + +int +mu_mailbox_remove (mu_mailbox_t mbox) +{ + if (!mbox) + return MU_ERR_MBX_NULL; + if (mbox->flags & _MU_MAILBOX_OPEN) + return MU_ERR_OPEN; + if (mbox->flags & _MU_MAILBOX_REMOVED) + return MU_ERR_MBX_REMOVED; + if (!mbox->_remove) + return MU_ERR_EMPTY_VFN; + return mbox->_remove (mbox); } int @@ -315,7 +350,11 @@ mu_mailbox_flush (mu_mailbox_t mbox, int expunge) int status = 0; if (!mbox) - return EINVAL; + return MU_ERR_MBX_NULL; + if (mbox->flags & _MU_MAILBOX_REMOVED) + return MU_ERR_MBX_REMOVED; + if (!(mbox->flags & _MU_MAILBOX_OPEN)) + return _MU_MAILBOX_OPEN; if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))) return 0; @@ -338,12 +377,29 @@ mu_mailbox_flush (mu_mailbox_t mbox, int expunge) return status; } +#define _MBOX_CHECK_FLAGS(mbox) \ + if (mbox == NULL) \ + return MU_ERR_MBX_NULL; \ + if (mbox->flags & _MU_MAILBOX_REMOVED) \ + return MU_ERR_MBX_REMOVED; \ + if (!(mbox->flags & _MU_MAILBOX_OPEN)) \ + return _MU_MAILBOX_OPEN + +#define _MBOX_CHECK(mbox,method) \ + _MBOX_CHECK_FLAGS(mbox); \ + if (mbox->method == NULL) \ + return MU_ERR_EMPTY_VFN + +#define _MBOX_CHECK_Q(mbox,method) \ + _MBOX_CHECK(mbox,method); \ + if (mbox->flags & MU_STREAM_QACCESS) \ + return MU_ERR_BADOP + /* messages */ int mu_mailbox_append_message (mu_mailbox_t mbox, mu_message_t msg) { - if (mbox == NULL || mbox->_append_message == NULL) - return MU_ERR_EMPTY_VFN; + _MBOX_CHECK_Q (mbox, _append_message); if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))) return EACCES; return mbox->_append_message (mbox, msg); @@ -352,10 +408,7 @@ mu_mailbox_append_message (mu_mailbox_t mbox, mu_message_t msg) int mu_mailbox_get_message (mu_mailbox_t mbox, size_t msgno, mu_message_t *pmsg) { - if (mbox == NULL || mbox->_get_message == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _get_message); return mbox->_get_message (mbox, msgno, pmsg); } @@ -363,8 +416,7 @@ int mu_mailbox_quick_get_message (mu_mailbox_t mbox, mu_message_qid_t qid, mu_message_t *pmsg) { - if (mbox == NULL || mbox->_quick_get_message == NULL) - return MU_ERR_EMPTY_VFN; + _MBOX_CHECK (mbox, _quick_get_message); if (!(mbox->flags & MU_STREAM_QACCESS)) return MU_ERR_BADOP; return mbox->_quick_get_message (mbox, qid, pmsg); @@ -373,38 +425,28 @@ mu_mailbox_quick_get_message (mu_mailbox_t mbox, mu_message_qid_t qid, int mu_mailbox_messages_count (mu_mailbox_t mbox, size_t *num) { - if (mbox == NULL || mbox->_messages_count == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _messages_count); return mbox->_messages_count (mbox, num); } int mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num) { - if (mbox == NULL || mbox->_messages_recent == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _messages_recent); return mbox->_messages_recent (mbox, num); } int mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num) { - if (mbox == NULL || mbox->_message_unseen == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _message_unseen); return mbox->_message_unseen (mbox, num); } int mu_mailbox_sync (mu_mailbox_t mbox) { - if (mbox == NULL || mbox->_sync == NULL) - return MU_ERR_EMPTY_VFN; + _MBOX_CHECK_Q (mbox, _sync); if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))) return 0; return mbox->_sync (mbox); @@ -414,18 +456,13 @@ mu_mailbox_sync (mu_mailbox_t mbox) int mu_mailbox_save_attributes (mu_mailbox_t mbox) { - if (mbox == NULL || mbox->_sync == NULL) - return MU_ERR_EMPTY_VFN; - if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))) - return EACCES; - return mbox->_sync (mbox); + return mu_mailbox_sync (mbox); } int mu_mailbox_expunge (mu_mailbox_t mbox) { - if (mbox == NULL || mbox->_expunge == NULL) - return MU_ERR_EMPTY_VFN; + _MBOX_CHECK_Q (mbox, _expunge); if (!(mbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))) return EACCES; return mbox->_expunge (mbox); @@ -434,7 +471,10 @@ mu_mailbox_expunge (mu_mailbox_t mbox) int mu_mailbox_is_updated (mu_mailbox_t mbox) { - if (mbox == NULL || mbox->_is_updated == NULL) + if (mbox == NULL || + !(mbox->flags & _MU_MAILBOX_OPEN) || + (mbox->flags & _MU_MAILBOX_REMOVED) || + mbox->_is_updated == NULL) return 1; if (mbox->flags & MU_STREAM_QACCESS) return 1; @@ -444,10 +484,7 @@ mu_mailbox_is_updated (mu_mailbox_t mbox) int mu_mailbox_scan (mu_mailbox_t mbox, size_t msgno, size_t *pcount) { - if (mbox == NULL || mbox->_scan == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _scan); return mbox->_scan (mbox, msgno, pcount); } @@ -455,8 +492,8 @@ int mu_mailbox_get_size (mu_mailbox_t mbox, mu_off_t *psize) { int status; - if (mbox == NULL) - return MU_ERR_EMPTY_VFN; + + _MBOX_CHECK_FLAGS (mbox); if (mbox->flags & MU_STREAM_QACCESS) return MU_ERR_BADOP; if (mbox->_get_size == NULL @@ -489,20 +526,14 @@ mu_mailbox_get_size (mu_mailbox_t mbox, mu_off_t *psize) int mu_mailbox_uidvalidity (mu_mailbox_t mbox, unsigned long *pvalid) { - if (mbox == NULL || mbox->_uidvalidity == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _uidvalidity); return mbox->_uidvalidity (mbox, pvalid); } int mu_mailbox_uidnext (mu_mailbox_t mbox, size_t *puidnext) { - if (mbox == NULL || mbox->_uidnext == NULL) - return MU_ERR_EMPTY_VFN; - if (mbox->flags & MU_STREAM_QACCESS) - return MU_ERR_BADOP; + _MBOX_CHECK_Q (mbox, _uidnext); return mbox->_uidnext (mbox, puidnext); } @@ -536,7 +567,7 @@ mu_mailbox_get_flags (mu_mailbox_t mbox, int *flags) return MU_ERR_MBX_NULL; if (!*flags) return MU_ERR_OUT_NULL; - *flags = mbox->flags; + *flags = mbox->flags & ~_MU_MAILBOX_MASK; return 0; } diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore index 9d3e2d83d..925b0df51 100644 --- a/libmailutils/tests/.gitignore +++ b/libmailutils/tests/.gitignore @@ -11,5 +11,6 @@ encode2047 fltst listop mailcap +mbdel mimetest url-parse diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am index f3092ce12..89ca27c3d 100644 --- a/libmailutils/tests/Makefile.am +++ b/libmailutils/tests/Makefile.am @@ -47,6 +47,7 @@ noinst_PROGRAMS = \ fltst\ listop\ mailcap\ + mbdel\ mimetest\ url-parse @@ -55,6 +56,10 @@ LDADD =\ ${MU_LIB_MBOX}\ ${MU_LIB_IMAP}\ ${MU_LIB_POP}\ + ${MU_LIB_NNTP}\ + ${MU_LIB_MH}\ + ${MU_LIB_MAILDIR}\ + ${MU_LIB_MAILER}\ ${MU_LIB_AUTH}\ @MU_AUTHLIBS@\ ${MU_LIB_MAILUTILS} diff --git a/libmailutils/tests/mbdel.c b/libmailutils/tests/mbdel.c new file mode 100644 index 000000000..802444b05 --- /dev/null +++ b/libmailutils/tests/mbdel.c @@ -0,0 +1,54 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2010 Free Software Foundation, Inc. + + GNU Mailutils is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GNU Mailutils is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <mailutils/mailutils.h> + +int +main (int argc, char **argv) +{ + int rc; + mu_mailbox_t mbox; + + if (argc != 2) + { + fprintf (stderr, "usage: %s URL\n", argv[0]); + return 1; + } + + mu_register_all_mbox_formats (); + + MU_ASSERT (mu_mailbox_create (&mbox, argv[1])); + rc = mu_mailbox_remove (mbox); + if (rc) + { + if (rc == ENOTEMPTY) + { + printf ("mailbox removed, but has subfolders\n"); + rc = 0; + } + else + fprintf (stderr, "%s\n", mu_strerror (rc)); + } + mu_mailbox_destroy (&mbox); + + return rc != 0; +} diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c index d2d7b9e78..8a8b19769 100644 --- a/libproto/maildir/mbox.c +++ b/libproto/maildir/mbox.c @@ -765,6 +765,28 @@ maildir_qfetch (struct _amd_data *amd, mu_message_qid_t qid) return 0; } + +static int +maildir_remove (struct _amd_data *amd) +{ + int i; + static char *suf[3] = { NEWSUF, CURSUF, TMPSUF }; + int rc = 0; + + for (i = 0; rc == 0 && i < 3; i++) + { + char *name = maildir_mkfilename (amd->name, suf[i], NULL); + rc = amd_remove_dir (name); + if (rc) + mu_diag_output (MU_DIAG_WARNING, + "removing contents of %s failed: %s", name, + mu_strerror (rc)); + free (name); + } + + return rc; +} + int _mailbox_maildir_init (mu_mailbox_t mailbox) @@ -788,6 +810,7 @@ _mailbox_maildir_init (mu_mailbox_t mailbox) amd->msg_cmp = maildir_message_cmp; amd->message_uid = maildir_message_uid; amd->next_uid = maildir_next_uid; + amd->remove = maildir_remove; /* Set our properties. */ { diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c index 9963c2f16..1425358b3 100644 --- a/libproto/mbox/mbox.c +++ b/libproto/mbox/mbox.c @@ -174,6 +174,16 @@ mbox_close (mu_mailbox_t mailbox) return mu_stream_close (mailbox->stream); } +static int +mbox_remove (mu_mailbox_t mailbox) +{ + mbox_data_t mud = mailbox->data; + + MU_DEBUG1 (mailbox->debug, MU_DEBUG_TRACE1, + "mbox_remove (%s)\n", mud->name); + return unlink (mud->name); +} + /* Cover function that calls the real thing, mbox_scan(), with notification set. */ static int @@ -1479,7 +1489,8 @@ _mailbox_mbox_init (mu_mailbox_t mailbox) mailbox->_open = mbox_open; mailbox->_close = mbox_close; - + mailbox->_remove = mbox_remove; + /* Overloading of the entire mailbox object methods. */ mailbox->_get_message = mbox_get_message; mailbox->_append_message = mbox_append_message; diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c index b39ce6c90..5995c5b67 100644 --- a/libproto/mh/mbox.c +++ b/libproto/mh/mbox.c @@ -353,6 +353,13 @@ _mh_msg_init (struct _amd_data *amd, struct _amd_message *amm) } +static int +mh_remove (struct _amd_data *amd) +{ + return amd_remove_dir (amd->name); +} + + int _mailbox_mh_init (mu_mailbox_t mailbox) @@ -375,7 +382,8 @@ _mailbox_mh_init (mu_mailbox_t mailbox) amd->msg_cmp = mh_message_cmp; amd->message_uid = mh_message_uid; amd->next_uid = _mh_next_seq; - + amd->remove = mh_remove; + /* Set our properties. */ { mu_property_t property = NULL; |