aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/imap
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/net/imap/IMAPConnection.cpp38
-rw-r--r--src/net/imap/IMAPFolder.cpp158
-rw-r--r--src/net/imap/IMAPMessage.cpp73
-rw-r--r--src/net/imap/IMAPStore.cpp10
4 files changed, 171 insertions, 108 deletions
diff --git a/src/net/imap/IMAPConnection.cpp b/src/net/imap/IMAPConnection.cpp
index bd963f56..9683b009 100644
--- a/src/net/imap/IMAPConnection.cpp
+++ b/src/net/imap/IMAPConnection.cpp
@@ -41,11 +41,11 @@
// Helpers for service properties
#define GET_PROPERTY(type, prop) \
- (m_store->getInfos().getPropertyValue <type>(getSession(), \
- dynamic_cast <const IMAPServiceInfos&>(m_store->getInfos()).getProperties().prop))
+ (m_store.acquire()->getInfos().getPropertyValue <type>(getSession(), \
+ dynamic_cast <const IMAPServiceInfos&>(m_store.acquire()->getInfos()).getProperties().prop))
#define HAS_PROPERTY(prop) \
- (m_store->getInfos().hasProperty(getSession(), \
- dynamic_cast <const IMAPServiceInfos&>(m_store->getInfos()).getProperties().prop))
+ (m_store.acquire()->getInfos().hasProperty(getSession(), \
+ dynamic_cast <const IMAPServiceInfos&>(m_store.acquire()->getInfos()).getProperties().prop))
namespace vmime {
@@ -53,7 +53,7 @@ namespace net {
namespace imap {
-IMAPConnection::IMAPConnection(weak_ref <IMAPStore> store, ref <security::authenticator> auth)
+IMAPConnection::IMAPConnection(ref <IMAPStore> store, ref <security::authenticator> auth)
: m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL),
m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL),
m_secured(false)
@@ -88,18 +88,20 @@ void IMAPConnection::connect()
const string address = GET_PROPERTY(string, PROPERTY_SERVER_ADDRESS);
const port_t port = GET_PROPERTY(port_t, PROPERTY_SERVER_PORT);
+ ref <IMAPStore> store = m_store.acquire();
+
// Create the time-out handler
- if (m_store->getTimeoutHandlerFactory())
- m_timeoutHandler = m_store->getTimeoutHandlerFactory()->create();
+ if (store->getTimeoutHandlerFactory())
+ m_timeoutHandler = store->getTimeoutHandlerFactory()->create();
// Create and connect the socket
- m_socket = m_store->getSocketFactory()->create();
+ m_socket = store->getSocketFactory()->create();
#if VMIME_HAVE_TLS_SUPPORT
- if (m_store->isIMAPS()) // dedicated port/IMAPS
+ if (store->isIMAPS()) // dedicated port/IMAPS
{
ref <tls::TLSSession> tlsSession =
- vmime::create <tls::TLSSession>(m_store->getCertificateVerifier());
+ vmime::create <tls::TLSSession>(store->getCertificateVerifier());
ref <tls::TLSSocket> tlsSocket =
tlsSession->getSocket(m_socket);
@@ -150,7 +152,7 @@ void IMAPConnection::connect()
const bool tlsRequired = HAS_PROPERTY(PROPERTY_CONNECTION_TLS_REQUIRED)
&& GET_PROPERTY(bool, PROPERTY_CONNECTION_TLS_REQUIRED);
- if (!m_store->isSecuredConnection() && tls) // only if not IMAPS
+ if (!store->isSecuredConnection() && tls) // only if not IMAPS
{
try
{
@@ -202,7 +204,7 @@ void IMAPConnection::connect()
void IMAPConnection::authenticate()
{
- getAuthenticator()->setService(m_store.toStrong());
+ getAuthenticator()->setService(m_store.acquire());
#if VMIME_HAVE_SASL_SUPPORT
// First, try SASL authentication
@@ -448,7 +450,7 @@ void IMAPConnection::startTLS()
}
ref <tls::TLSSession> tlsSession =
- vmime::create <tls::TLSSession>(m_store->getCertificateVerifier());
+ vmime::create <tls::TLSSession>(m_store.acquire()->getCertificateVerifier());
ref <tls::TLSSocket> tlsSocket =
tlsSession->getSocket(m_socket);
@@ -693,21 +695,21 @@ ref <const IMAPParser> IMAPConnection::getParser() const
}
-weak_ref <const IMAPStore> IMAPConnection::getStore() const
+ref <const IMAPStore> IMAPConnection::getStore() const
{
- return (m_store);
+ return m_store.acquire();
}
-weak_ref <IMAPStore> IMAPConnection::getStore()
+ref <IMAPStore> IMAPConnection::getStore()
{
- return (m_store);
+ return m_store.acquire();
}
ref <session> IMAPConnection::getSession()
{
- return (m_store->getSession());
+ return m_store.acquire()->getSession();
}
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index f28fa8a3..0179620b 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -39,23 +39,25 @@ namespace net {
namespace imap {
-IMAPFolder::IMAPFolder(const folder::path& path, IMAPStore* store, const int type, const int flags)
- : m_store(store), m_connection(m_store->connection()), m_path(path),
+IMAPFolder::IMAPFolder(const folder::path& path, ref <IMAPStore> store, const int type, const int flags)
+ : m_store(store), m_connection(store->connection()), m_path(path),
m_name(path.isEmpty() ? folder::path::component("") : path.getLastComponent()), m_mode(-1),
m_open(false), m_type(type), m_flags(flags), m_messageCount(0), m_uidValidity(0)
{
- m_store->registerFolder(this);
+ store->registerFolder(this);
}
IMAPFolder::~IMAPFolder()
{
- if (m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (store)
{
if (m_open)
close(false);
- m_store->unregisterFolder(this);
+ store->unregisterFolder(this);
}
else if (m_open)
{
@@ -128,12 +130,14 @@ const folder::path IMAPFolder::getFullPath() const
void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
// Open a connection for this folder
ref <IMAPConnection> connection =
- vmime::create <IMAPConnection>(m_store, m_store->getAuthenticator());
+ vmime::create <IMAPConnection>(store, store->getAuthenticator());
try
{
@@ -270,7 +274,9 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
void IMAPFolder::close(const bool expunge)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
if (!isOpen())
@@ -292,7 +298,7 @@ void IMAPFolder::close(const bool expunge)
oldConnection->disconnect();
// Now use default store connection
- m_connection = m_store->connection();
+ m_connection = m_store.acquire()->connection();
m_open = false;
m_mode = -1;
@@ -317,13 +323,15 @@ void IMAPFolder::onClose()
void IMAPFolder::create(const int type)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (isOpen())
throw exceptions::illegal_state("Folder is open");
else if (exists())
throw exceptions::illegal_state("Folder already exists");
- else if (!m_store->isValidFolderName(m_name))
+ else if (!store->isValidFolderName(m_name))
throw exceptions::invalid_folder_name();
// Emit the "CREATE" command
@@ -365,7 +373,9 @@ void IMAPFolder::create(const int type)
const bool IMAPFolder::exists()
{
- if (!isOpen() && !m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!isOpen() && !store)
throw exceptions::illegal_state("Store disconnected");
return (testExistAndGetType() != TYPE_UNDEFINED);
@@ -458,7 +468,7 @@ ref <message> IMAPFolder::getMessage(const int num)
if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return vmime::create <IMAPMessage>(this, num);
+ return vmime::create <IMAPMessage>(thisRef().dynamicCast <IMAPFolder>(), num);
}
@@ -473,9 +483,10 @@ std::vector <ref <message> > IMAPFolder::getMessages(const int from, const int t
throw exceptions::message_not_found();
std::vector <ref <message> > v;
+ ref <IMAPFolder> thisFolder = thisRef().dynamicCast <IMAPFolder>();
for (int i = from ; i <= to2 ; ++i)
- v.push_back(vmime::create <IMAPMessage>(this, i));
+ v.push_back(vmime::create <IMAPMessage>(thisFolder, i));
return (v);
}
@@ -487,9 +498,10 @@ std::vector <ref <message> > IMAPFolder::getMessages(const std::vector <int>& nu
throw exceptions::illegal_state("Folder not open");
std::vector <ref <message> > v;
+ ref <IMAPFolder> thisFolder = thisRef().dynamicCast <IMAPFolder>();
for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- v.push_back(vmime::create <IMAPMessage>(this, *it));
+ v.push_back(vmime::create <IMAPMessage>(thisFolder, *it));
return (v);
}
@@ -506,16 +518,20 @@ const int IMAPFolder::getMessageCount()
ref <folder> IMAPFolder::getFolder(const folder::path::component& name)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
- return vmime::create <IMAPFolder>(m_path / name, m_store);
+ return vmime::create <IMAPFolder>(m_path / name, store);
}
std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
{
- if (!isOpen() && !m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!isOpen() && !store)
throw exceptions::illegal_state("Store disconnected");
// Eg. List folders in '/foo/bar'
@@ -591,7 +607,7 @@ std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
const class IMAPParser::mailbox_flag_list* mailbox_flag_list =
mailboxData->mailbox_list()->mailbox_flag_list();
- v.push_back(vmime::create <IMAPFolder>(path, m_store,
+ v.push_back(vmime::create <IMAPFolder>(path, store,
IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
}
@@ -604,7 +620,9 @@ std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int options,
utility::progressListener* progress)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -691,12 +709,14 @@ void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int opti
void IMAPFolder::fetchMessage(ref <message> msg, const int options)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- msg.dynamicCast <IMAPMessage>()->fetch(this, options);
+ msg.dynamicCast <IMAPMessage>()->fetch(thisRef().dynamicCast <IMAPFolder>(), options);
}
@@ -713,19 +733,19 @@ ref <folder> IMAPFolder::getParent()
if (m_path.isEmpty())
return NULL;
else
- return vmime::create <IMAPFolder>(m_path.getParent(), m_store);
+ return vmime::create <IMAPFolder>(m_path.getParent(), m_store.acquire());
}
-weak_ref <const store> IMAPFolder::getStore() const
+ref <const store> IMAPFolder::getStore() const
{
- return (m_store);
+ return m_store.acquire();
}
-weak_ref <store> IMAPFolder::getStore()
+ref <store> IMAPFolder::getStore()
{
- return (m_store);
+ return m_store.acquire();
}
@@ -753,7 +773,9 @@ void IMAPFolder::onStoreDisconnected()
void IMAPFolder::deleteMessage(const int num)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -802,10 +824,12 @@ void IMAPFolder::deleteMessage(const int num)
void IMAPFolder::deleteMessages(const int from, const int to)
{
+ ref <IMAPStore> store = m_store.acquire();
+
if (from < 1 || (to < from && to != -1))
throw exceptions::invalid_argument();
- if (!m_store)
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -865,10 +889,12 @@ void IMAPFolder::deleteMessages(const int from, const int to)
void IMAPFolder::deleteMessages(const std::vector <int>& nums)
{
+ ref <IMAPStore> store = m_store.acquire();
+
if (nums.empty())
throw exceptions::invalid_argument();
- if (!m_store)
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -924,10 +950,12 @@ void IMAPFolder::deleteMessages(const std::vector <int>& nums)
void IMAPFolder::setMessageFlags(const int from, const int to, const int flags, const int mode)
{
+ ref <IMAPStore> store = m_store.acquire();
+
if (from < 1 || (to < from && to != -1))
throw exceptions::invalid_argument();
- if (!m_store)
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1012,7 +1040,9 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags,
void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags, const int mode)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1142,7 +1172,9 @@ void IMAPFolder::addMessage(ref <vmime::message> msg, const int flags,
void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int flags,
vmime::datetime* date, utility::progressListener* progress)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1243,8 +1275,8 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
notifyMessageCount(event);
// Notify folders with the same path
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it) != this && (*it)->getFullPath() == m_path)
{
@@ -1261,7 +1293,9 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
void IMAPFolder::expunge()
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1330,8 +1364,8 @@ void IMAPFolder::expunge()
notifyMessageCount(event);
// Notify folders with the same path
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it) != this && (*it)->getFullPath() == m_path)
{
@@ -1349,13 +1383,15 @@ void IMAPFolder::expunge()
void IMAPFolder::rename(const folder::path& newPath)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (m_path.isEmpty() || newPath.isEmpty())
throw exceptions::illegal_operation("Cannot rename root folder");
else if (m_path.getSize() == 1 && m_name.getBuffer() == "INBOX")
throw exceptions::illegal_operation("Cannot rename 'INBOX' folder");
- else if (!m_store->isValidFolderName(newPath.getLastComponent()))
+ else if (!store->isValidFolderName(newPath.getLastComponent()))
throw exceptions::invalid_folder_name();
// Build the request text
@@ -1392,8 +1428,8 @@ void IMAPFolder::rename(const folder::path& newPath)
notifyFolder(event);
// Notify folders with the same path and sub-folders
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it) != this && (*it)->getFullPath() == oldPath)
{
@@ -1424,7 +1460,9 @@ void IMAPFolder::rename(const folder::path& newPath)
void IMAPFolder::copyMessage(const folder::path& dest, const int num)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1440,8 +1478,8 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num)
std::vector <int> nums;
nums.push_back(num);
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
@@ -1458,7 +1496,9 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num)
void IMAPFolder::copyMessages(const folder::path& dest, const int from, const int to)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1486,8 +1526,8 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
@@ -1504,7 +1544,9 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in
void IMAPFolder::copyMessages(const folder::path& dest, const std::vector <int>& nums)
{
- if (!m_store)
+ ref <IMAPStore> store = m_store.acquire();
+
+ if (!store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -1515,8 +1557,8 @@ void IMAPFolder::copyMessages(const folder::path& dest, const std::vector <int>&
// Notify message count changed
const int count = nums.size();
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
@@ -1556,6 +1598,8 @@ void IMAPFolder::copyMessages(const string& set, const folder::path& dest)
void IMAPFolder::status(int& count, int& unseen)
{
+ ref <IMAPStore> store = m_store.acquire();
+
count = 0;
unseen = 0;
@@ -1567,16 +1611,16 @@ void IMAPFolder::status(int& count, int& unseen)
command << " (MESSAGES UNSEEN)";
// Send the request
- m_store->m_connection->send(true, command.str(), true);
+ m_connection->send(true, command.str(), true);
// Get the response
- utility::auto_ptr <IMAPParser::response> resp(m_store->m_connection->readResponse());
+ 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("STATUS",
- m_store->m_connection->getParser()->lastLine(), "bad response");
+ m_connection->getParser()->lastLine(), "bad response");
}
const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList =
@@ -1588,7 +1632,7 @@ void IMAPFolder::status(int& count, int& unseen)
if ((*it)->response_data() == NULL)
{
throw exceptions::command_error("STATUS",
- m_store->m_connection->getParser()->lastLine(), "invalid response");
+ m_connection->getParser()->lastLine(), "invalid response");
}
const IMAPParser::response_data* responseData = (*it)->response_data();
@@ -1644,8 +1688,8 @@ void IMAPFolder::status(int& count, int& unseen)
notifyMessageCount(event);
// Notify folders with the same path
- for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
- it != m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = store->m_folders.begin() ;
+ it != store->m_folders.end() ; ++it)
{
if ((*it) != this && (*it)->getFullPath() == m_path)
{
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index e7778b95..e796afaf 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -53,7 +53,7 @@ public:
ref <const structure> getStructure() const;
ref <structure> getStructure();
- weak_ref <const IMAPpart> getParent() const { return (m_parent); }
+ ref <const IMAPpart> getParent() const { return m_parent.acquire(); }
const mediaType& getType() const { return (m_mediaType); }
const int getSize() const { return (m_size); }
@@ -272,18 +272,20 @@ private:
//
-IMAPMessage::IMAPMessage(IMAPFolder* folder, const int num)
+IMAPMessage::IMAPMessage(ref <IMAPFolder> folder, const int num)
: m_folder(folder), m_num(num), m_size(-1), m_flags(FLAG_UNDEFINED),
m_expunged(false), m_structure(NULL)
{
- m_folder->registerMessage(this);
+ folder->registerMessage(this);
}
IMAPMessage::~IMAPMessage()
{
- if (m_folder)
- m_folder->unregisterMessage(this);
+ ref <IMAPFolder> folder = m_folder.acquire();
+
+ if (folder)
+ folder->unregisterMessage(this);
}
@@ -359,7 +361,9 @@ ref <const header> IMAPMessage::getHeader() const
void IMAPMessage::extract(utility::outputStream& os, utility::progressListener* progress,
const int start, const int length, const bool peek) const
{
- if (!m_folder)
+ ref <const IMAPFolder> folder = m_folder.acquire();
+
+ if (!folder)
throw exceptions::folder_not_found();
extract(NULL, os, progress, start, length, false, peek);
@@ -370,7 +374,9 @@ void IMAPMessage::extractPart
(ref <const part> p, utility::outputStream& os, utility::progressListener* progress,
const int start, const int length, const bool peek) const
{
- if (!m_folder)
+ ref <const IMAPFolder> folder = m_folder.acquire();
+
+ if (!folder)
throw exceptions::folder_not_found();
extract(p, os, progress, start, length, false, peek);
@@ -379,7 +385,9 @@ void IMAPMessage::extractPart
void IMAPMessage::fetchPartHeader(ref <part> p)
{
- if (!m_folder)
+ ref <IMAPFolder> folder = m_folder.acquire();
+
+ if (!folder)
throw exceptions::folder_not_found();
std::ostringstream oss;
@@ -395,6 +403,8 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
utility::progressListener* progress, const int start,
const int length, const bool headerOnly, const bool peek) const
{
+ ref <const IMAPFolder> folder = m_folder.acquire();
+
IMAPMessage_literalHandler literalHandler(os, progress);
// Construct section identifier
@@ -402,7 +412,7 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
if (p != NULL)
{
- weak_ref <const IMAPpart> currentPart = p.dynamicCast <const IMAPpart>();
+ ref <const IMAPpart> currentPart = p.dynamicCast <const IMAPpart>();
std::vector <int> numbers;
numbers.push_back(currentPart->getNumber());
@@ -437,17 +447,17 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
command << "<" << start << "." << length << ">";
// Send the request
- m_folder->m_connection->send(true, command.str(), true);
+ folder.constCast <IMAPFolder>()->m_connection->send(true, command.str(), true);
// Get the response
utility::auto_ptr <IMAPParser::response> resp
- (m_folder->m_connection->readResponse(&literalHandler));
+ (folder.constCast <IMAPFolder>()->m_connection->readResponse(&literalHandler));
if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
{
throw exceptions::command_error("FETCH",
- m_folder->m_connection->getParser()->lastLine(), "bad response");
+ folder.constCast <IMAPFolder>()->m_connection->getParser()->lastLine(), "bad response");
}
@@ -458,9 +468,11 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
}
-void IMAPMessage::fetch(IMAPFolder* folder, const int options)
+void IMAPMessage::fetch(ref <IMAPFolder> msgFolder, const int options)
{
- if (m_folder != folder)
+ ref <IMAPFolder> folder = m_folder.acquire();
+
+ if (folder != msgFolder)
throw exceptions::folder_not_found();
// Send the request
@@ -469,16 +481,16 @@ void IMAPMessage::fetch(IMAPFolder* folder, const int options)
const string command = IMAPUtils::buildFetchRequest(list, options);
- m_folder->m_connection->send(true, command, true);
+ folder->m_connection->send(true, command, true);
// Get the response
- utility::auto_ptr <IMAPParser::response> resp(m_folder->m_connection->readResponse());
+ utility::auto_ptr <IMAPParser::response> resp(folder->m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
{
throw exceptions::command_error("FETCH",
- m_folder->m_connection->getParser()->lastLine(), "bad response");
+ folder->m_connection->getParser()->lastLine(), "bad response");
}
const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList =
@@ -490,7 +502,7 @@ void IMAPMessage::fetch(IMAPFolder* folder, const int options)
if ((*it)->response_data() == NULL)
{
throw exceptions::command_error("FETCH",
- m_folder->m_connection->getParser()->lastLine(), "invalid response");
+ folder->m_connection->getParser()->lastLine(), "invalid response");
}
const IMAPParser::message_data* messageData =
@@ -512,6 +524,8 @@ void IMAPMessage::fetch(IMAPFolder* folder, const int options)
void IMAPMessage::processFetchResponse
(const int options, const IMAPParser::msg_att* msgAtt)
{
+ ref <IMAPFolder> folder = m_folder.acquire();
+
// Get message attributes
const std::vector <IMAPParser::msg_att_item*> atts =
msgAtt->items();
@@ -531,7 +545,7 @@ void IMAPMessage::processFetchResponse
case IMAPParser::msg_att_item::UID:
{
std::ostringstream oss;
- oss << m_folder->m_uidValidity << ":" << (*it)->unique_id()->value();
+ oss << folder->m_uidValidity << ":" << (*it)->unique_id()->value();
m_uid = oss.str();
break;
@@ -681,9 +695,11 @@ void IMAPMessage::convertAddressList
void IMAPMessage::setFlags(const int flags, const int mode)
{
- if (!m_folder)
+ ref <IMAPFolder> folder = m_folder.acquire();
+
+ if (!folder)
throw exceptions::folder_not_found();
- else if (m_folder->m_mode == folder::MODE_READ_ONLY)
+ else if (folder->m_mode == folder::MODE_READ_ONLY)
throw exceptions::illegal_state("Folder is read-only");
// Build the request text
@@ -723,16 +739,16 @@ void IMAPMessage::setFlags(const int flags, const int mode)
command << *(flagList.end() - 1) << ")";
// Send the request
- m_folder->m_connection->send(true, command.str(), true);
+ folder->m_connection->send(true, command.str(), true);
// Get the response
- utility::auto_ptr <IMAPParser::response> resp(m_folder->m_connection->readResponse());
+ utility::auto_ptr <IMAPParser::response> resp(folder->m_connection->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
{
throw exceptions::command_error("STORE",
- m_folder->m_connection->getParser()->lastLine(), "bad response");
+ folder->m_connection->getParser()->lastLine(), "bad response");
}
// Update the local flags for this message
@@ -776,13 +792,12 @@ void IMAPMessage::setFlags(const int flags, const int mode)
nums.push_back(m_num);
events::messageChangedEvent event
- (m_folder->thisRef().dynamicCast <folder>(),
- events::messageChangedEvent::TYPE_FLAGS, nums);
+ (folder, events::messageChangedEvent::TYPE_FLAGS, nums);
- for (std::list <IMAPFolder*>::iterator it = m_folder->m_store->m_folders.begin() ;
- it != m_folder->m_store->m_folders.end() ; ++it)
+ for (std::list <IMAPFolder*>::iterator it = folder->m_store.acquire()->m_folders.begin() ;
+ it != folder->m_store.acquire()->m_folders.end() ; ++it)
{
- if ((*it)->getFullPath() == m_folder->m_path)
+ if ((*it)->getFullPath() == folder->m_path)
(*it)->notifyMessageChanged(event);
}
}
diff --git a/src/net/imap/IMAPStore.cpp b/src/net/imap/IMAPStore.cpp
index ba99761d..e6f82c70 100644
--- a/src/net/imap/IMAPStore.cpp
+++ b/src/net/imap/IMAPStore.cpp
@@ -63,7 +63,8 @@ ref <folder> IMAPStore::getRootFolder()
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return vmime::create <IMAPFolder>(folder::path(), this);
+ return vmime::create <IMAPFolder>(folder::path(),
+ thisRef().dynamicCast <IMAPStore>());
}
@@ -72,7 +73,8 @@ ref <folder> IMAPStore::getDefaultFolder()
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return vmime::create <IMAPFolder>(folder::path::component("INBOX"), this);
+ return vmime::create <IMAPFolder>(folder::path::component("INBOX"),
+ thisRef().dynamicCast <IMAPStore>());
}
@@ -81,7 +83,7 @@ ref <folder> IMAPStore::getFolder(const folder::path& path)
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return vmime::create <IMAPFolder>(path, this);
+ return vmime::create <IMAPFolder>(path, thisRef().dynamicCast <IMAPStore>());
}
@@ -97,7 +99,7 @@ void IMAPStore::connect()
throw exceptions::already_connected();
m_connection = vmime::create <IMAPConnection>
- (thisWeakRef().dynamicCast <IMAPStore>(), getAuthenticator());
+ (thisRef().dynamicCast <IMAPStore>(), getAuthenticator());
try
{