From de09abb036a54b4214f0092a57e057481adb9530 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 14 Nov 2004 14:31:23 +0000 Subject: [PATCH] Prevent from renaming 'INBOX' folder in IMAP (illegal_operation exception). --- src/exception.hpp | 16 ++++++++++++++++ src/messaging/IMAPFolder.cpp | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/exception.hpp b/src/exception.hpp index 815fd1d4..41e113ac 100644 --- a/src/exception.hpp +++ b/src/exception.hpp @@ -415,6 +415,22 @@ public: }; +/** Illegal operation: cannot run this operation on the object. + */ + +class illegal_operation : public messaging_exception +{ +public: + + illegal_operation(const string& msg = "") + : messaging_exception(msg.empty() + ? "Illegal operation." + : "Illegal operation: " + msg + "." + ) {} + ~illegal_operation() throw() {} +}; + + /** Command error: operation failed (this is specific to the underlying protocol). */ diff --git a/src/messaging/IMAPFolder.cpp b/src/messaging/IMAPFolder.cpp index 4aef1afe..7544dc2c 100644 --- a/src/messaging/IMAPFolder.cpp +++ b/src/messaging/IMAPFolder.cpp @@ -1228,6 +1228,8 @@ void IMAPFolder::rename(const folder::path& newPath) throw exceptions::illegal_state("Store disconnected"); else if (isOpen()) throw exceptions::illegal_state("Folder open"); + else if (m_path.getSize() == 1 && m_name.getBuffer() == "INBOX") + throw exceptions::illegal_operation("Cannot rename 'INBOX' folder"); // Build the request text std::ostringstream command;