Folder deletion.
This commit is contained in:
parent
3bbffc18de
commit
6933fb8a30
@ -2,6 +2,11 @@
|
||||
VERSION 0.8.1cvs
|
||||
================
|
||||
|
||||
2006-04-23 Vincent Richard <vincent@vincent-richard.net>
|
||||
|
||||
* Added vmime::net::folder::destroy() to delete folders on IMAP and
|
||||
maildir stores.
|
||||
|
||||
2006-04-18 Vincent Richard <vincent@vincent-richard.net>
|
||||
|
||||
* Renamed 'byte' to 'byte_t' to fix compilation problems on Fedora
|
||||
|
@ -371,6 +371,43 @@ void IMAPFolder::create(const int type)
|
||||
}
|
||||
|
||||
|
||||
void IMAPFolder::destroy()
|
||||
{
|
||||
ref <IMAPStore> store = m_store.acquire();
|
||||
|
||||
if (!store)
|
||||
throw exceptions::illegal_state("Store disconnected");
|
||||
|
||||
if (isOpen())
|
||||
throw exceptions::illegal_state("Folder is open");
|
||||
|
||||
const string mailbox = IMAPUtils::pathToString
|
||||
(m_connection->hierarchySeparator(), getFullPath());
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "DELETE " << IMAPUtils::quoteString(mailbox);
|
||||
|
||||
m_connection->send(true, oss.str(), true);
|
||||
|
||||
|
||||
utility::auto_ptr <IMAPParser::response> resp(m_connection->readResponse());
|
||||
|
||||
if (resp->isBad() || resp->response_done()->response_tagged()->
|
||||
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
|
||||
{
|
||||
throw exceptions::command_error("DELETE",
|
||||
m_connection->getParser()->lastLine(), "bad response");
|
||||
}
|
||||
|
||||
// Notify folder deleted
|
||||
events::folderEvent event
|
||||
(thisRef().dynamicCast <folder>(),
|
||||
events::folderEvent::TYPE_DELETED, m_path, m_path);
|
||||
|
||||
notifyFolder(event);
|
||||
}
|
||||
|
||||
|
||||
const bool IMAPFolder::exists()
|
||||
{
|
||||
ref <IMAPStore> store = m_store.acquire();
|
||||
|
@ -242,6 +242,42 @@ void maildirFolder::create(const int /* type */)
|
||||
}
|
||||
|
||||
|
||||
void maildirFolder::destroy()
|
||||
{
|
||||
ref <maildirStore> store = m_store.acquire();
|
||||
|
||||
if (!store)
|
||||
throw exceptions::illegal_state("Store disconnected");
|
||||
else if (isOpen())
|
||||
throw exceptions::illegal_state("Folder is open");
|
||||
|
||||
// Delete 'folder' and '.folder.directory' directories
|
||||
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
|
||||
|
||||
ref <utility::file> rootDir = fsf->create
|
||||
(maildirUtils::getFolderFSPath(store, m_path, maildirUtils::FOLDER_PATH_ROOT));
|
||||
ref <utility::file> contDir = fsf->create
|
||||
(maildirUtils::getFolderFSPath(store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
|
||||
|
||||
try
|
||||
{
|
||||
maildirUtils::recursiveFSDelete(rootDir);
|
||||
maildirUtils::recursiveFSDelete(contDir);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
// Ignore exception: anyway, we can't recover from this...
|
||||
}
|
||||
|
||||
// Notify folder deleted
|
||||
events::folderEvent event
|
||||
(thisRef().dynamicCast <folder>(),
|
||||
events::folderEvent::TYPE_DELETED, m_path, m_path);
|
||||
|
||||
notifyFolder(event);
|
||||
}
|
||||
|
||||
|
||||
const bool maildirFolder::exists()
|
||||
{
|
||||
ref <maildirStore> store = m_store.acquire();
|
||||
|
@ -22,6 +22,9 @@
|
||||
|
||||
#include "vmime/utility/random.hpp"
|
||||
|
||||
#include "vmime/exception.hpp"
|
||||
#include "vmime/platformDependant.hpp"
|
||||
|
||||
|
||||
namespace vmime {
|
||||
namespace net {
|
||||
@ -212,6 +215,44 @@ const utility::file::path::component maildirUtils::generateId()
|
||||
}
|
||||
|
||||
|
||||
void maildirUtils::recursiveFSDelete(ref <utility::file> dir)
|
||||
{
|
||||
ref <utility::fileIterator> files = dir->getFiles();
|
||||
|
||||
// First, delete files and subdirectories in this directory
|
||||
while (files->hasMoreElements())
|
||||
{
|
||||
ref <utility::file> file = files->nextElement();
|
||||
|
||||
if (file->isDirectory())
|
||||
{
|
||||
maildirUtils::recursiveFSDelete(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
file->remove();
|
||||
}
|
||||
catch (exceptions::filesystem_exception&)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Then, delete this (empty) directory
|
||||
try
|
||||
{
|
||||
dir->remove();
|
||||
}
|
||||
catch (exceptions::filesystem_exception&)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// messageIdComparator
|
||||
|
@ -184,6 +184,12 @@ void POP3Folder::create(const int /* type */)
|
||||
}
|
||||
|
||||
|
||||
void POP3Folder::destroy()
|
||||
{
|
||||
throw exceptions::operation_not_supported();
|
||||
}
|
||||
|
||||
|
||||
const bool POP3Folder::exists()
|
||||
{
|
||||
ref <POP3Store> store = m_store.acquire();
|
||||
|
@ -132,18 +132,21 @@ public:
|
||||
* is not available, a more restricted mode will be selected automatically.
|
||||
* If set to true and if the requested mode is not available, the opening
|
||||
* will fail.
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void open(const int mode, bool failIfModeIsNotAvailable = false) = 0;
|
||||
|
||||
/** Close this folder.
|
||||
*
|
||||
* @param expunge if set to true, deleted messages are expunged
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void close(const bool expunge) = 0;
|
||||
|
||||
/** Create this folder.
|
||||
*
|
||||
* @param type folder type (see folder::Types)
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void create(const int type) = 0;
|
||||
|
||||
@ -153,6 +156,13 @@ public:
|
||||
*/
|
||||
virtual const bool exists() = 0;
|
||||
|
||||
/** Delete this folder.
|
||||
* The folder should be closed before attempting to delete it.
|
||||
*
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void destroy() = 0;
|
||||
|
||||
/** Test whether this folder is open.
|
||||
*
|
||||
* @return true if the folder is open, false otherwise
|
||||
@ -163,6 +173,7 @@ public:
|
||||
*
|
||||
* @param num message sequence number
|
||||
* @return a new object referencing the specified message
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual ref <message> getMessage(const int num) = 0;
|
||||
|
||||
@ -171,6 +182,7 @@ public:
|
||||
* @param from sequence number of the first message to get
|
||||
* @param to sequence number of the last message to get
|
||||
* @return new objects referencing the specified messages
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual std::vector <ref <message> > getMessages(const int from = 1, const int to = -1) = 0;
|
||||
|
||||
@ -178,6 +190,7 @@ public:
|
||||
*
|
||||
* @param nums sequence numbers of the messages to delete
|
||||
* @return new objects referencing the specified messages
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual std::vector <ref <message> > getMessages(const std::vector <int>& nums) = 0;
|
||||
|
||||
@ -191,6 +204,7 @@ public:
|
||||
*
|
||||
* @param name sub-folder name
|
||||
* @return a new object referencing the specified folder
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual ref <folder> getFolder(const folder::path::component& name) = 0;
|
||||
|
||||
@ -199,18 +213,21 @@ public:
|
||||
* @param recursive if set to true, all the descendant are returned.
|
||||
* If set to false, only the direct children are returned.
|
||||
* @return list of sub-folders
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual std::vector <ref <folder> > getFolders(const bool recursive = false) = 0;
|
||||
|
||||
/** Rename (move) this folder to another location.
|
||||
*
|
||||
* @param newPath new path of the folder
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void rename(const folder::path& newPath) = 0;
|
||||
|
||||
/** Remove a message in this folder.
|
||||
*
|
||||
* @param num sequence number of the message to delete
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void deleteMessage(const int num) = 0;
|
||||
|
||||
@ -218,12 +235,14 @@ public:
|
||||
*
|
||||
* @param from sequence number of the first message to delete
|
||||
* @param to sequence number of the last message to delete
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void deleteMessages(const int from = 1, const int to = -1) = 0;
|
||||
|
||||
/** Remove one or more messages from this folder.
|
||||
*
|
||||
* @param nums sequence numbers of the messages to delete
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void deleteMessages(const std::vector <int>& nums) = 0;
|
||||
|
||||
@ -233,6 +252,7 @@ public:
|
||||
* @param to sequence number of the last message to modify
|
||||
* @param flags set of flags (see message::Flags)
|
||||
* @param mode indicate how to treat old and new flags (see message::FlagsModes)
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET) = 0;
|
||||
|
||||
@ -241,6 +261,7 @@ public:
|
||||
* @param nums sequence numbers of the messages to modify
|
||||
* @param flags set of flags (see message::Flags)
|
||||
* @param mode indicate how to treat old and new flags (see message::FlagsModes)
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET) = 0;
|
||||
|
||||
@ -250,6 +271,7 @@ public:
|
||||
* @param flags flags for the new message
|
||||
* @param date date/time for the new message (if NULL, the current time is used)
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL) = 0;
|
||||
|
||||
@ -260,6 +282,7 @@ public:
|
||||
* @param flags flags for the new message
|
||||
* @param date date/time for the new message (if NULL, the current time is used)
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressListener* progress = NULL) = 0;
|
||||
|
||||
@ -267,6 +290,7 @@ public:
|
||||
*
|
||||
* @param dest destination folder path
|
||||
* @param num sequence number of the message to copy
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void copyMessage(const folder::path& dest, const int num) = 0;
|
||||
|
||||
@ -275,6 +299,7 @@ public:
|
||||
* @param dest destination folder path
|
||||
* @param from sequence number of the first message to copy
|
||||
* @param to sequence number of the last message to copy
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void copyMessages(const folder::path& dest, const int from = 1, const int to = -1) = 0;
|
||||
|
||||
@ -282,6 +307,7 @@ public:
|
||||
*
|
||||
* @param dest destination folder path
|
||||
* @param nums sequence numbers of the messages to copy
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void copyMessages(const folder::path& dest, const std::vector <int>& nums) = 0;
|
||||
|
||||
@ -289,10 +315,13 @@ public:
|
||||
*
|
||||
* @param count will receive the number of messages in the folder
|
||||
* @param unseen will receive the number of unseen messages in the folder
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void status(int& count, int& unseen) = 0;
|
||||
|
||||
/** Expunge deleted messages.
|
||||
*
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void expunge() = 0;
|
||||
|
||||
@ -335,6 +364,7 @@ public:
|
||||
* @param msg list of message sequence numbers
|
||||
* @param options objects to fetch (combination of folder::FetchOptions flags)
|
||||
* @param progress progress listener, or NULL if not used
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressListener* progress = NULL) = 0;
|
||||
|
||||
@ -342,6 +372,7 @@ public:
|
||||
*
|
||||
* @param msg the message
|
||||
* @param options objects to fetch (combination of folder::FetchOptions flags)
|
||||
* @throw net_exception if an error occurs
|
||||
*/
|
||||
virtual void fetchMessage(ref <message> msg, const int options) = 0;
|
||||
|
||||
|
@ -77,6 +77,8 @@ public:
|
||||
|
||||
const bool exists();
|
||||
|
||||
void destroy();
|
||||
|
||||
const bool isOpen() const;
|
||||
|
||||
ref <message> getMessage(const int num);
|
||||
|
@ -78,6 +78,8 @@ public:
|
||||
|
||||
const bool exists();
|
||||
|
||||
void destroy();
|
||||
|
||||
const bool isOpen() const;
|
||||
|
||||
ref <message> getMessage(const int num);
|
||||
|
@ -148,6 +148,12 @@ public:
|
||||
*/
|
||||
static const utility::file::path::component generateId();
|
||||
|
||||
/** Recursively delete a directory on the file system.
|
||||
*
|
||||
* @param dir directory to delete
|
||||
*/
|
||||
static void recursiveFSDelete(ref <utility::file> dir);
|
||||
|
||||
private:
|
||||
|
||||
static const vmime::word TMP_DIR;
|
||||
|
@ -76,6 +76,8 @@ public:
|
||||
|
||||
const bool exists();
|
||||
|
||||
void destroy();
|
||||
|
||||
const bool isOpen() const;
|
||||
|
||||
ref <message> getMessage(const int num);
|
||||
|
Loading…
Reference in New Issue
Block a user