diff options
Diffstat (limited to 'src/messaging')
44 files changed, 972 insertions, 550 deletions
diff --git a/src/messaging/IMAPConnection.cpp b/src/messaging/IMAPConnection.cpp index 007cf353..63c96841 100644 --- a/src/messaging/IMAPConnection.cpp +++ b/src/messaging/IMAPConnection.cpp @@ -59,24 +59,24 @@ void IMAPConnection::connect() m_state = STATE_NONE; m_hierarchySeparator = '\0'; - const string address = m_store->session().properties()[m_store->infos().propertyPrefix() + "server.address"]; - const port_t port = m_store->session().properties().get(m_store->infos().propertyPrefix() + "server.port", m_store->infos().defaultPort()); + const string address = m_store->getSession()->getProperties()[m_store->getInfos().getPropertyPrefix() + "server.address"]; + const port_t port = m_store->getSession()->getProperties().getProperty(m_store->getInfos().getPropertyPrefix() + "server.port", m_store->getInfos().getDefaultPort()); // Create the time-out handler - if (session().properties().exists - (m_store->infos().propertyPrefix() + "timeout.factory")) + if (m_store->getSession()->getProperties().hasProperty + (m_store->getInfos().getPropertyPrefix() + "timeout.factory")) { timeoutHandlerFactory* tof = platformDependant::getHandler()-> - getTimeoutHandlerFactory(session().properties() - [m_store->infos().propertyPrefix() + "timeout.factory"]); + getTimeoutHandlerFactory(m_store->getSession()->getProperties() + [m_store->getInfos().getPropertyPrefix() + "timeout.factory"]); m_timeoutHandler = tof->create(); } // Create and connect the socket socketFactory* sf = platformDependant::getHandler()->getSocketFactory - (m_store->session().properties().get - (m_store->infos().propertyPrefix() + "server.socket-factory", string("default"))); + (m_store->getSession()->getProperties().getProperty + (m_store->getInfos().getPropertyPrefix() + "server.socket-factory", string("default"))); m_socket = sf->create(); m_socket->connect(address, port); @@ -109,8 +109,8 @@ void IMAPConnection::connect() // TODO: other authentication methods - send(true, "LOGIN " + IMAPUtils::quoteString(auth.username()) - + " " + IMAPUtils::quoteString(auth.password()), true); + send(true, "LOGIN " + IMAPUtils::quoteString(auth.getUsername()) + + " " + IMAPUtils::quoteString(auth.getPassword()), true); utility::auto_ptr <IMAPParser::response> resp(m_parser->readResponse()); diff --git a/src/messaging/IMAPConnection.hpp b/src/messaging/IMAPConnection.hpp index ae92f1e3..0cd9b144 100644 --- a/src/messaging/IMAPConnection.hpp +++ b/src/messaging/IMAPConnection.hpp @@ -72,11 +72,11 @@ public: IMAPParser::response* readResponse(IMAPParser::literalHandler* lh = NULL); - const IMAPTag* tag() const { return (m_tag); } - const IMAPParser* parser() const { return (m_parser); } + const IMAPTag* getTag() const { return (m_tag); } + const IMAPParser* getParser() const { return (m_parser); } - const IMAPStore* store() const { return (m_store); } - IMAPStore* store() { return (m_store); } + const IMAPStore* getStore() const { return (m_store); } + IMAPStore* getStore() { return (m_store); } private: diff --git a/src/messaging/IMAPFolder.cpp b/src/messaging/IMAPFolder.cpp index 717e4817..4aef1afe 100644 --- a/src/messaging/IMAPFolder.cpp +++ b/src/messaging/IMAPFolder.cpp @@ -38,7 +38,7 @@ namespace messaging { 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), - m_name(path.last()), m_mode(-1), m_open(false), m_type(type), m_flags(flags), + m_name(path.getLastComponent()), m_mode(-1), m_open(false), m_type(type), m_flags(flags), m_messageCount(0), m_uidValidity(0) { m_store->registerFolder(this); @@ -62,7 +62,7 @@ IMAPFolder::~IMAPFolder() } -const int IMAPFolder::mode() const +const int IMAPFolder::getMode() const { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); @@ -71,13 +71,13 @@ const int IMAPFolder::mode() const } -const int IMAPFolder::type() +const int IMAPFolder::getType() { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); // Root folder - if (m_path.empty()) + if (m_path.isEmpty()) { return (TYPE_CONTAINS_FOLDERS); } @@ -91,13 +91,13 @@ const int IMAPFolder::type() } -const int IMAPFolder::flags() +const int IMAPFolder::getFlags() { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); // Root folder - if (m_path.empty()) + if (m_path.isEmpty()) { return (FLAG_CHILDREN | FLAG_NO_OPEN); } @@ -111,13 +111,13 @@ const int IMAPFolder::flags() } -const folder::path::component IMAPFolder::name() const +const folder::path::component IMAPFolder::getName() const { return (m_name); } -const folder::path IMAPFolder::fullPath() const +const folder::path IMAPFolder::getFullPath() const { return (m_path); } @@ -155,7 +155,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable) oss << "SELECT "; oss << IMAPUtils::quoteString(IMAPUtils::pathToString - (connection->hierarchySeparator(), fullPath())); + (connection->hierarchySeparator(), getFullPath())); connection->send(true, oss.str(), true); @@ -166,7 +166,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("SELECT", - connection->parser()->lastLine(), "bad response"); + connection->getParser()->lastLine(), "bad response"); } const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList = @@ -178,7 +178,7 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable) if ((*it)->response_data() == NULL) { throw exceptions::command_error("SELECT", - connection->parser()->lastLine(), "invalid response"); + connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::response_data* responseData = (*it)->response_data(); @@ -332,7 +332,7 @@ void IMAPFolder::create(const int type) // S: A004 OK CREATE completed string mailbox = IMAPUtils::pathToString - (m_connection->hierarchySeparator(), fullPath()); + (m_connection->hierarchySeparator(), getFullPath()); if (type & TYPE_CONTAINS_FOLDERS) mailbox += m_connection->hierarchySeparator(); @@ -349,7 +349,7 @@ void IMAPFolder::create(const int type) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("CREATE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Notify folder created @@ -393,7 +393,7 @@ const int IMAPFolder::testExistAndGetType() std::ostringstream oss; oss << "LIST \"\" "; oss << IMAPUtils::quoteString(IMAPUtils::pathToString - (m_connection->hierarchySeparator(), fullPath())); + (m_connection->hierarchySeparator(), getFullPath())); m_connection->send(true, oss.str(), true); @@ -404,7 +404,7 @@ const int IMAPFolder::testExistAndGetType() resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("LIST", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Check whether the result mailbox list contains this folder @@ -417,7 +417,7 @@ const int IMAPFolder::testExistAndGetType() if ((*it)->response_data() == NULL) { throw exceptions::command_error("LIST", - m_connection->parser()->lastLine(), "invalid response"); + m_connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::mailbox_data* mailboxData = @@ -518,7 +518,7 @@ std::vector <folder*> IMAPFolder::getFolders(const bool recursive) std::ostringstream oss; oss << "LIST "; oss << IMAPUtils::quoteString - (IMAPUtils::pathToString(m_connection->hierarchySeparator(), fullPath())); + (IMAPUtils::pathToString(m_connection->hierarchySeparator(), getFullPath())); if (recursive) oss << " *"; @@ -533,7 +533,7 @@ std::vector <folder*> IMAPFolder::getFolders(const bool recursive) if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { - throw exceptions::command_error("LIST", m_connection->parser()->lastLine(), "bad response"); + throw exceptions::command_error("LIST", m_connection->getParser()->lastLine(), "bad response"); } const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList = @@ -550,7 +550,7 @@ std::vector <folder*> IMAPFolder::getFolders(const bool recursive) if ((*it)->response_data() == NULL) { throw exceptions::command_error("LIST", - m_connection->parser()->lastLine(), "invalid response"); + m_connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::mailbox_data* mailboxData = @@ -638,19 +638,19 @@ const int IMAPFolder::getFetchCapabilities() const folder* IMAPFolder::getParent() { - return (m_path.empty() ? NULL : new IMAPFolder(m_path.parent(), m_store)); + return (m_path.isEmpty() ? NULL : new IMAPFolder(m_path.getParent(), m_store)); } -const class store& IMAPFolder::store() const +const store* IMAPFolder::getStore() const { - return (*m_store); + return (m_store); } -class store& IMAPFolder::store() +store* IMAPFolder::getStore() { - return (*m_store); + return (m_store); } @@ -695,14 +695,14 @@ void IMAPFolder::deleteMessage(const int num) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STORE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Update local flags for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if ((*it)->number() == num && + if ((*it)->getNumber() == num && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags |= message::FLAG_DELETED; @@ -750,7 +750,7 @@ void IMAPFolder::deleteMessages(const int from, const int to) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STORE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Update local flags @@ -760,7 +760,7 @@ void IMAPFolder::deleteMessages(const int from, const int to) for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if ((*it)->number() >= from && (*it)->number() <= to2 && + if ((*it)->getNumber() >= from && (*it)->getNumber() <= to2 && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags |= message::FLAG_DELETED; @@ -816,14 +816,14 @@ void IMAPFolder::deleteMessages(const std::vector <int>& nums) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STORE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Update local flags for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if (std::binary_search(list.begin(), list.end(), (*it)->number())) + if (std::binary_search(list.begin(), list.end(), (*it)->getNumber())) { if ((*it)->m_flags != message::FLAG_UNDEFINED) (*it)->m_flags |= message::FLAG_DELETED; @@ -869,7 +869,7 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if ((*it)->number() >= from && (*it)->number() <= to2 && + if ((*it)->getNumber() >= from && (*it)->getNumber() <= to2 && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags |= flags; @@ -883,7 +883,7 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if ((*it)->number() >= from && (*it)->number() <= to2 && + if ((*it)->getNumber() >= from && (*it)->getNumber() <= to2 && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags &= ~flags; @@ -898,7 +898,7 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if ((*it)->number() >= from && (*it)->number() <= to2 && + if ((*it)->getNumber() >= from && (*it)->getNumber() <= to2 && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags = flags; @@ -951,7 +951,7 @@ void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if (std::binary_search(list.begin(), list.end(), (*it)->number()) && + if (std::binary_search(list.begin(), list.end(), (*it)->getNumber()) && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags |= flags; @@ -965,7 +965,7 @@ void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if (std::binary_search(list.begin(), list.end(), (*it)->number()) && + if (std::binary_search(list.begin(), list.end(), (*it)->getNumber()) && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags &= ~flags; @@ -980,7 +980,7 @@ void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags, for (std::vector <IMAPMessage*>::iterator it = m_messages.begin() ; it != m_messages.end() ; ++it) { - if (std::binary_search(list.begin(), list.end(), (*it)->number()) && + if (std::binary_search(list.begin(), list.end(), (*it)->getNumber()) && (*it)->m_flags != message::FLAG_UNDEFINED) { (*it)->m_flags = flags; @@ -1029,7 +1029,7 @@ void IMAPFolder::setMessageFlags(const string& set, const int flags, const int m resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STORE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } } } @@ -1063,7 +1063,7 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int // Build the request text std::ostringstream command; command << "APPEND " << IMAPUtils::quoteString(IMAPUtils::pathToString - (m_connection->hierarchySeparator(), fullPath())) << ' '; + (m_connection->hierarchySeparator(), getFullPath())) << ' '; const string flagList = IMAPUtils::messageFlagList(flags); @@ -1101,7 +1101,7 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int if (!ok) { throw exceptions::command_error("APPEND", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Send message data @@ -1139,7 +1139,7 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("APPEND", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Notify message added @@ -1172,7 +1172,7 @@ void IMAPFolder::expunge() resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("EXPUNGE", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Update the numbering of the messages @@ -1187,7 +1187,7 @@ void IMAPFolder::expunge() if ((*it)->response_data() == NULL) { throw exceptions::command_error("EXPUNGE", - m_connection->parser()->lastLine(), "invalid response"); + m_connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::message_data* messageData = @@ -1233,7 +1233,7 @@ void IMAPFolder::rename(const folder::path& newPath) std::ostringstream command; command << "RENAME "; command << IMAPUtils::quoteString(IMAPUtils::pathToString - (m_connection->hierarchySeparator(), fullPath())) << " "; + (m_connection->hierarchySeparator(), getFullPath())) << " "; command << IMAPUtils::quoteString(IMAPUtils::pathToString (m_connection->hierarchySeparator(), newPath)); @@ -1247,14 +1247,14 @@ void IMAPFolder::rename(const folder::path& newPath) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("RENAME", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } // Notify folder renamed folder::path oldPath(m_path); m_path = newPath; - m_name = newPath.last(); + m_name = newPath.getLastComponent(); events::folderEvent event(this, events::folderEvent::TYPE_RENAMED, oldPath, newPath); notifyFolder(event); @@ -1284,7 +1284,7 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num) for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == dest) + if ((*it)->getFullPath() == dest) { (*it)->m_messageCount++; (*it)->notifyMessageCount(event); @@ -1328,7 +1328,7 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == dest) + if ((*it)->getFullPath() == dest) { (*it)->m_messageCount += count; (*it)->notifyMessageCount(event); @@ -1355,7 +1355,7 @@ void IMAPFolder::copyMessages(const folder::path& dest, const std::vector <int>& for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == dest) + if ((*it)->getFullPath() == dest) { (*it)->m_messageCount += count; (*it)->notifyMessageCount(event); @@ -1382,7 +1382,7 @@ void IMAPFolder::copyMessages(const string& set, const folder::path& dest) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("COPY", - m_connection->parser()->lastLine(), "bad response"); + m_connection->getParser()->lastLine(), "bad response"); } } @@ -1396,7 +1396,7 @@ void IMAPFolder::status(int& count, int& unseen) std::ostringstream command; command << "STATUS "; command << IMAPUtils::quoteString(IMAPUtils::pathToString - (m_connection->hierarchySeparator(), fullPath())); + (m_connection->hierarchySeparator(), getFullPath())); command << "(MESSAGES UNSEEN)"; // Send the request @@ -1409,7 +1409,7 @@ void IMAPFolder::status(int& count, int& unseen) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STATUS", - m_store->m_connection->parser()->lastLine(), "bad response"); + m_store->m_connection->getParser()->lastLine(), "bad response"); } const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList = @@ -1421,7 +1421,7 @@ void IMAPFolder::status(int& count, int& unseen) if ((*it)->response_data() == NULL) { throw exceptions::command_error("STATUS", - m_store->m_connection->parser()->lastLine(), "invalid response"); + m_store->m_connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::response_data* responseData = (*it)->response_data(); @@ -1475,7 +1475,7 @@ void IMAPFolder::status(int& count, int& unseen) for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == m_path) + if ((*it)->getFullPath() == m_path) { (*it)->m_messageCount = count; (*it)->notifyMessageCount(event); diff --git a/src/messaging/IMAPFolder.hpp b/src/messaging/IMAPFolder.hpp index bbedb030..fae0a302 100644 --- a/src/messaging/IMAPFolder.hpp +++ b/src/messaging/IMAPFolder.hpp @@ -42,7 +42,7 @@ class IMAPConnection; class IMAPFolder : public folder { -protected: +private: friend class IMAPStore; friend class IMAPMessage; @@ -55,14 +55,14 @@ protected: public: - const int mode() const; + const int getMode() const; - const int type(); + const int getType(); - const int flags(); + const int getFlags(); - const folder::path::component name() const; - const folder::path fullPath() const; + const folder::path::component getName() const; + const folder::path getFullPath() const; void open(const int mode, bool failIfModeIsNotAvailable = false); void close(const bool expunge); @@ -102,8 +102,8 @@ public: folder* getParent(); - const class store& store() const; - class store& store(); + const store* getStore() const; + store* getStore(); void fetchMessages(std::vector <message*>& msg, const int options, progressionListener* progress = NULL); diff --git a/src/messaging/IMAPMessage.cpp b/src/messaging/IMAPMessage.cpp index 056c0304..56a3287f 100644 --- a/src/messaging/IMAPMessage.cpp +++ b/src/messaging/IMAPMessage.cpp @@ -66,16 +66,16 @@ private: public: - const class structure& structure() const; - class structure& structure(); + const structure& getStructure() const; + structure& getStructure(); - const IMAPpart* parent() const { return (m_parent); } + const IMAPpart* getParent() const { return (m_parent); } - const mediaType& type() const { return (m_mediaType); } - const int size() const { return (m_size); } - const int number() const { return (m_number); } + const mediaType& getType() const { return (m_mediaType); } + const int getSize() const { return (m_size); } + const int getNumber() const { return (m_number); } - const class header& header() const; + const header& getHeader() const; static IMAPpart* create(IMAPpart* parent, const int number, const IMAPParser::body* body) @@ -150,7 +150,7 @@ public: return (*m_parts[x - 1]); } - const int count() const + const int getCount() const { return (m_parts.size()); } @@ -213,7 +213,7 @@ IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_ty } -const class header& IMAPpart::header() const +const class header& IMAPpart::getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); @@ -222,7 +222,7 @@ const class header& IMAPpart::header() const } -const class structure& IMAPpart::structure() const +const class structure& IMAPpart::getStructure() const { if (m_structure != NULL) return (*m_structure); @@ -231,7 +231,7 @@ const class structure& IMAPpart::structure() const } -class structure& IMAPpart::structure() +class structure& IMAPpart::getStructure() { if (m_structure != NULL) return (*m_structure); @@ -307,19 +307,19 @@ void IMAPMessage::onFolderClosed() } -const int IMAPMessage::number() const +const int IMAPMessage::getNumber() const { return (m_num); } -const message::uid IMAPMessage::uniqueId() const +const message::uid IMAPMessage::getUniqueId() const { return (m_uid); } -const int IMAPMessage::size() const +const int IMAPMessage::getSize() const { if (m_size == -1) throw exceptions::unfetched_object(); @@ -334,7 +334,7 @@ const bool IMAPMessage::isExpunged() const } -const int IMAPMessage::flags() const +const int IMAPMessage::getFlags() const { if (m_flags == FLAG_UNDEFINED) throw exceptions::unfetched_object(); @@ -343,7 +343,7 @@ const int IMAPMessage::flags() const } -const class structure& IMAPMessage::structure() const +const structure& IMAPMessage::getStructure() const { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -352,7 +352,7 @@ const class structure& IMAPMessage::structure() const } -class structure& IMAPMessage::structure() +structure& IMAPMessage::getStructure() { if (m_structure == NULL) throw exceptions::unfetched_object(); @@ -361,7 +361,7 @@ class structure& IMAPMessage::structure() } -const class header& IMAPMessage::header() const +const header& IMAPMessage::getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); @@ -418,13 +418,13 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os, progressionL const IMAPpart* currentPart = static_cast <const IMAPpart*>(p); std::vector <int> numbers; - numbers.push_back(currentPart->number()); - currentPart = currentPart->parent(); + numbers.push_back(currentPart->getNumber()); + currentPart = currentPart->getParent(); while (currentPart != NULL) { - numbers.push_back(currentPart->number()); - currentPart = currentPart->parent(); + numbers.push_back(currentPart->getNumber()); + currentPart = currentPart->getParent(); } numbers.erase(numbers.end() - 1); @@ -458,7 +458,7 @@ void IMAPMessage::extract(const part* p, utility::outputStream& os, progressionL resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("FETCH", - m_folder->m_connection->parser()->lastLine(), "bad response"); + m_folder->m_connection->getParser()->lastLine(), "bad response"); } @@ -532,7 +532,7 @@ void IMAPMessage::fetch(IMAPFolder* folder, const int options) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("FETCH", - m_folder->m_connection->parser()->lastLine(), "bad response"); + m_folder->m_connection->getParser()->lastLine(), "bad response"); } const std::vector <IMAPParser::continue_req_or_response_data*>& respDataList = @@ -544,7 +544,7 @@ void IMAPMessage::fetch(IMAPFolder* folder, const int options) if ((*it)->response_data() == NULL) { throw exceptions::command_error("FETCH", - m_folder->m_connection->parser()->lastLine(), "invalid response"); + m_folder->m_connection->getParser()->lastLine(), "invalid response"); } const IMAPParser::message_data* messageData = @@ -598,54 +598,54 @@ void IMAPMessage::processFetchResponse vmime::header& hdr = getOrCreateHeader(); // Date - hdr.fields.Date() = env->env_date()->value(); + hdr.Date().setValue(env->env_date()->value()); // Subject text subject; decodeAndUnfoldText(env->env_subject()->value(), subject); - hdr.fields.Subject() = subject; + hdr.Subject().setValue(subject); // From mailboxList from; convertAddressList(*(env->env_from()), from); - if (!from.empty()) - hdr.fields.From() = *(from.begin()); + if (!from.isEmpty()) + hdr.From().setValue(*(from.getMailboxAt(0))); // To mailboxList to; convertAddressList(*(env->env_to()), to); - hdr.fields.To() = to; + hdr.To().setValue(to); // Sender mailboxList sender; convertAddressList(*(env->env_sender()), sender); - if (!sender.empty()) - hdr.fields.Sender() = *(sender.begin()); + if (!sender.isEmpty()) + hdr.Sender().setValue(*(sender.getMailboxAt(0))); // Reply-to mailboxList replyTo; convertAddressList(*(env->env_reply_to()), replyTo); - if (!replyTo.empty()) - hdr.fields.ReplyTo() = *(replyTo.begin()); + if (!replyTo.isEmpty()) + hdr.ReplyTo().setValue(*(replyTo.getMailboxAt(0))); // Cc mailboxList cc; convertAddressList(*(env->env_cc()), cc); - if (!cc.empty()) - hdr.fields.Cc() = cc; + if (!cc.isEmpty()) + hdr.Cc().setValue(cc); // Bcc mailboxList bcc; convertAddressList(*(env->env_bcc()), bcc); - if (!bcc.empty()) - hdr.fields.Bcc() = bcc; + if (!bcc.isEmpty()) + hdr.Bcc().setValue(bcc); } break; @@ -678,11 +678,12 @@ void IMAPMessage::processFetchResponse tempHeader.parse((*it)->nstring()->value()); vmime::header& hdr = getOrCreateHeader(); + std::vector <headerField*> fields = tempHeader.getFieldList(); - for (header::const_iterator jt = tempHeader.fields.begin() ; - jt != tempHeader.fields.end() ; ++jt) + for (std::vector <headerField*>::const_iterator jt = fields.begin() ; + jt != fields.end() ; ++jt) { - hdr.fields.append(*jt); + hdr.appendField((*jt)->clone()); } } } @@ -728,7 +729,7 @@ void IMAPMessage::convertAddressList string email = addr.addr_mailbox()->value() + "@" + addr.addr_host()->value(); - dest.append(mailbox(name, email)); + dest.appendMailbox(new mailbox(name, email)); } } @@ -786,7 +787,7 @@ void IMAPMessage::setFlags(const int flags, const int mode) resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { throw exceptions::command_error("STORE", - m_folder->m_connection->parser()->lastLine(), "bad response"); + m_folder->m_connection->getParser()->lastLine(), "bad response"); } // Update the local flags for this message @@ -834,7 +835,7 @@ void IMAPMessage::setFlags(const int flags, const int mode) for (std::list <IMAPFolder*>::iterator it = m_folder->m_store->m_folders.begin() ; it != m_folder->m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == m_folder->m_path) + if ((*it)->getFullPath() == m_folder->m_path) (*it)->notifyMessageChanged(event); } } diff --git a/src/messaging/IMAPMessage.hpp b/src/messaging/IMAPMessage.hpp index 74c7a36f..0bf874b9 100644 --- a/src/messaging/IMAPMessage.hpp +++ b/src/messaging/IMAPMessage.hpp @@ -39,7 +39,7 @@ class IMAPstructure; class IMAPMessage : public message { -protected: +private: friend class IMAPFolder; @@ -50,20 +50,20 @@ protected: public: - const int number() const; + const int getNumber() const; - const uid uniqueId() const; + const uid getUniqueId() const; - const int size() const; + const int getSize() const; const bool isExpunged() const; - const class structure& structure() const; - class structure& structure(); + const structure& getStructure() const; + structure& getStructure(); - const class header& header() const; + const header& getHeader() const; - const int flags() const; + const int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, progressionListener* progress = NULL, const int start = 0, const int length = -1) const; diff --git a/src/messaging/IMAPParser.hpp b/src/messaging/IMAPParser.hpp index 2e4a56ab..ed61b72f 100644 --- a/src/messaging/IMAPParser.hpp +++ b/src/messaging/IMAPParser.hpp @@ -26,6 +26,7 @@ #include "../charset.hpp" #include "../exception.hpp" #include "../utility/smartPtr.hpp" +#include "../utility/stringUtils.hpp" #include "../encoderB64.hpp" #include "../encoderQP.hpp" @@ -1145,7 +1146,7 @@ public: { // Quoted-printable theEncoder = new encoderQP; - theEncoder->properties()["rfc2047"] = true; + theEncoder->getProperties()["rfc2047"] = true; } else if (theEncoding->value()[0] == 'b' || theEncoding->value()[0] == 'B') { @@ -1229,7 +1230,7 @@ public: else { atom* at = parser.get <atom>(line, &pos); - const string name = toLower(at->value()); + const string name = stringUtils::toLower(at->value()); delete (at); if (name == "answered") @@ -1401,7 +1402,7 @@ public: parser.check <one_char <'\\'> >(line, &pos); atom* at = parser.get <atom>(line, &pos); - const string name = toLower(at->value()); + const string name = stringUtils::toLower(at->value()); delete (at); if (name == "marked") @@ -1800,7 +1801,7 @@ public: DEBUG_ENTER_COMPONENT("auth_type"); atom* at = parser.get <atom>(line, currentPos); - m_name = toLower(at->value()); + m_name = stringUtils::toLower(at->value()); delete (at); if (m_name == "kerberos_v4") @@ -2109,21 +2110,21 @@ public: parser.check <one_char <'"'> >(line, &pos); - m_datetime.hour() = std::min(std::max(nh->value(), 0u), 23u); - m_datetime.minute() = std::min(std::max(nmi->value(), 0u), 59u); - m_datetime.second() = std::min(std::max(ns->value(), 0u), 59u); + m_datetime.setHour(std::min(std::max(nh->value(), 0u), 23u)); + m_datetime.setMinute(std::min(std::max(nmi->value(), 0u), 59u)); + m_datetime.setSecond(std::min(std::max(ns->value(), 0u), 59u)); const int zone = static_cast <int>(nz->value()); const int zh = zone / 100; // hour offset const int zm = zone % 100; // minute offset - m_datetime.zone() = ((zh * 60) + zm) * sign; + m_datetime.setZone(((zh * 60) + zm) * sign); - m_datetime.day() = std::min(std::max(nd->value(), 1u), 31u); - m_datetime.year() = ny->value(); + m_datetime.setDay(std::min(std::max(nd->value(), 1u), 31u)); + m_datetime.setYear(ny->value()); - const string month(vmime::toLower(amo->value())); - vmime::datetime::comp_t mon = vmime::datetime::JANUARY; + const string month(stringUtils::toLower(amo->value())); + int mon = vmime::datetime::JANUARY; if (month.length() >= 3) { @@ -2177,7 +2178,7 @@ public: } } - m_datetime.month() = mon; + m_datetime.setMonth(mon); *currentPos = pos; } diff --git a/src/messaging/IMAPStore.cpp b/src/messaging/IMAPStore.cpp index 7d2bc823..bf15b705 100644 --- a/src/messaging/IMAPStore.cpp +++ b/src/messaging/IMAPStore.cpp @@ -72,8 +72,8 @@ private: // IMAPStore // -IMAPStore::IMAPStore(class session& sess, class authenticator* auth) - : store(sess, infosInstance(), auth), +IMAPStore::IMAPStore(session* sess, authenticator* auth) + : store(sess, getInfosInstance(), auth), m_connection(NULL), m_oneTimeAuth(NULL) { } @@ -92,7 +92,7 @@ authenticator* IMAPStore::oneTimeAuthenticator() } -const string IMAPStore::protocolName() const +const string IMAPStore::getProtocolName() const { return "imap"; } @@ -130,7 +130,7 @@ void IMAPStore::connect() if (isConnected()) throw exceptions::already_connected(); - m_oneTimeAuth = new IMAPauthenticator(&authenticator()); + m_oneTimeAuth = new IMAPauthenticator(getAuthenticator()); m_connection = new IMAPConnection(this, m_oneTimeAuth); @@ -189,7 +189,7 @@ void IMAPStore::noop() if (resp->isBad() || resp->response_done()->response_tagged()-> resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) { - throw exceptions::command_error("NOOP", m_connection->parser()->lastLine()); + throw exceptions::command_error("NOOP", m_connection->getParser()->lastLine()); } } @@ -220,19 +220,31 @@ void IMAPStore::unregisterFolder(IMAPFolder* folder) IMAPStore::_infos IMAPStore::sm_infos; -const port_t IMAPStore::_infos::defaultPort() const +const serviceInfos& IMAPStore::getInfosInstance() +{ + return (sm_infos); +} + + +const serviceInfos& IMAPStore::getInfos() const +{ + return (sm_infos); +} + + +const port_t IMAPStore::_infos::getDefaultPort() const { return (143); } -const string IMAPStore::_infos::propertyPrefix() const +const string IMAPStore::_infos::getPropertyPrefix() const { return "store.imap."; } -const std::vector <string> IMAPStore::_infos::availableProperties() const +const std::vector <string> IMAPStore::_infos::getAvailableProperties() const { std::vector <string> list; diff --git a/src/messaging/IMAPStore.hpp b/src/messaging/IMAPStore.hpp index cab9419f..67145896 100644 --- a/src/messaging/IMAPStore.hpp +++ b/src/messaging/IMAPStore.hpp @@ -48,17 +48,17 @@ class IMAPStore : public store public: - IMAPStore(class session& sess, class authenticator* auth); + IMAPStore(session* sess, authenticator* auth); ~IMAPStore(); - const string protocolName() const; + const string getProtocolName() const; folder* getDefaultFolder(); folder* getRootFolder(); folder* getFolder(const folder::path& path); - static const serviceInfos& infosInstance() { return (sm_infos); } - const serviceInfos& infos() const { return (sm_infos); } + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; void connect(); const bool isConnected() const; @@ -95,10 +95,10 @@ private: { public: - const port_t defaultPort() const; + const port_t getDefaultPort() const; - const string propertyPrefix() const; - const std::vector <string> availableProperties() const; + const string getPropertyPrefix() const; + const std::vector <string> getAvailableProperties() const; }; static _infos sm_infos; diff --git a/src/messaging/IMAPUtils.cpp b/src/messaging/IMAPUtils.cpp index 2413c86d..a0fdfb8a 100644 --- a/src/messaging/IMAPUtils.cpp +++ b/src/messaging/IMAPUtils.cpp @@ -110,7 +110,7 @@ const string IMAPUtils::pathToString { string result; - for (int i = 0 ; i < path.size() ; ++i) + for (int i = 0 ; i < path.getSize() ; ++i) { if (i > 0) result += hierarchySeparator; result += toModifiedUTF7(hierarchySeparator, path[i]); @@ -497,8 +497,8 @@ const string IMAPUtils::dateTime(const vmime::datetime& date) res << '"'; // Date - if (date.day() < 10) res << ' '; - res << date.day(); + if (date.getDay() < 10) res << ' '; + res << date.getDay(); res << '-'; @@ -506,33 +506,33 @@ const string IMAPUtils::dateTime(const vmime::datetime& date) { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - res << monthNames[std::min(std::max(date.month() - 1, 0), 11)]; + res << monthNames[std::min(std::max(date.getMonth() - 1, 0), 11)]; res << '-'; - if (date.year() < 10) res << '0'; - if (date.year() < 100) res << '0'; - if (date.year() < 1000) res << '0'; - res << date.year(); + if (date.getYear() < 10) res << '0'; + if (date.getYear() < 100) res << '0'; + if (date.getYear() < 1000) res << '0'; + res << date.getYear(); res << ' '; // Time - if (date.hour() < 10) res << '0'; - res << date.hour() << ':'; + if (date.getHour() < 10) res << '0'; + res << date.getHour() << ':'; - if (date.minute() < 10) res << '0'; - res << date.minute() << ':'; + if (date.getMinute() < 10) res << '0'; + res << date.getMinute() << ':'; - if (date.second() < 10) res << '0'; - res << date.second(); + if (date.getSecond() < 10) res << '0'; + res << date.getSecond(); res << ' '; // Zone - const int zs = (date.zone() < 0 ? -1 : 1); - const int zh = (date.zone() * zs) / 60; - const int zm = (date.zone() * zs) % 60; + const int zs = (date.getZone() < 0 ? -1 : 1); + const int zh = (date.getZone() * zs) / 60; + const int zm = (date.getZone() * zs) % 60; res << (zs < 0 ? '-' : '+'); diff --git a/src/messaging/POP3Folder.cpp b/src/messaging/POP3Folder.cpp index 663d03b5..e820ab3f 100644 --- a/src/messaging/POP3Folder.cpp +++ b/src/messaging/POP3Folder.cpp @@ -30,7 +30,7 @@ namespace messaging { POP3Folder::POP3Folder(const folder::path& path, POP3Store* store) - : m_store(store), m_path(path), m_name(path.last()), m_mode(-1), m_open(false) + : m_store(store), m_path(path), m_name(path.getLastComponent()), m_mode(-1), m_open(false) { m_store->registerFolder(this); } @@ -52,7 +52,7 @@ POP3Folder::~POP3Folder() } -const int POP3Folder::mode() const +const int POP3Folder::getMode() const { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); @@ -61,33 +61,33 @@ const int POP3Folder::mode() const } -const int POP3Folder::type() +const int POP3Folder::getType() { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - if (m_path.empty()) + if (m_path.isEmpty()) return (TYPE_CONTAINS_FOLDERS); - else if (m_path.size() == 1 && m_path[0].buffer() == "INBOX") + else if (m_path.getSize() == 1 && m_path[0].getBuffer() == "INBOX") return (TYPE_CONTAINS_MESSAGES); else throw exceptions::folder_not_found(); } -const int POP3Folder::flags() +const int POP3Folder::getFlags() { return (0); } -const folder::path::component POP3Folder::name() const +const folder::path::component POP3Folder::getName() const { return (m_name); } -const folder::path POP3Folder::fullPath() const +const folder::path POP3Folder::getFullPath() const { return (m_path); } @@ -98,7 +98,7 @@ void POP3Folder::open(const int mode, bool failIfModeIsNotAvailable) if (!m_store) throw exceptions::illegal_state("Store disconnected"); - if (m_path.empty()) + if (m_path.isEmpty()) { if (mode != MODE_READ_ONLY && failIfModeIsNotAvailable) throw exceptions::operation_not_supported(); @@ -108,7 +108,7 @@ void POP3Folder::open(const int mode, bool failIfModeIsNotAvailable) m_messageCount = 0; } - else if (m_path.size() == 1 && m_path[0].buffer() == "INBOX") + else if (m_path.getSize() == 1 && m_path[0].getBuffer() == "INBOX") { m_store->sendRequest("STAT"); @@ -178,7 +178,7 @@ const bool POP3Folder::exists() if (!m_store) throw exceptions::illegal_state("Store disconnected"); - return (m_path.empty() || (m_path.size() == 1 && m_path[0].buffer() == "INBOX")); + return (m_path.isEmpty() || (m_path.getSize() == 1 && m_path[0].getBuffer() == "INBOX")); } @@ -275,7 +275,7 @@ std::vector <folder*> POP3Folder::getFolders(const bool /* recursive */) if (!m_store) throw exceptions::illegal_state("Store disconnected"); - if (m_path.empty()) + if (m_path.isEmpty()) { std::vector <folder*> v; v.push_back(new POP3Folder(folder::path::component("INBOX"), m_store)); @@ -438,25 +438,25 @@ const int POP3Folder::getFetchCapabilities() const folder* POP3Folder::getParent() { - return (m_path.empty() ? NULL : new POP3Folder(m_path.parent(), m_store)); + return (m_path.isEmpty() ? NULL : new POP3Folder(m_path.getParent(), m_store)); } -const class store& POP3Folder::store() const +const store* POP3Folder::getStore() const { - return (*m_store); + return (m_store); } -class store& POP3Folder::store() +store* POP3Folder::getStore() { - return (*m_store); + return (m_store); } void POP3Folder::registerMessage(POP3Message* msg) { - m_messages.insert(MessageMap::value_type(msg, msg->number())); + m_messages.insert(MessageMap::value_type(msg, msg->getNumber())); } @@ -639,7 +639,7 @@ void POP3Folder::status(int& count, int& unseen) for (std::list <POP3Folder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == m_path) + if ((*it)->getFullPath() == m_path) { (*it)->m_messageCount = count; (*it)->notifyMessageCount(event); diff --git a/src/messaging/POP3Folder.hpp b/src/messaging/POP3Folder.hpp index cfb83bef..7afaaa1d 100644 --- a/src/messaging/POP3Folder.hpp +++ b/src/messaging/POP3Folder.hpp @@ -42,7 +42,7 @@ class POP3Message; class POP3Folder : public folder { -protected: +private: friend class POP3Store; friend class POP3Message; @@ -54,14 +54,14 @@ protected: public: - const int mode() const; + const int getMode() const; - const int type(); + const int getType(); - const int flags(); + const int getFlags(); - const folder::path::component name() const; - const folder::path fullPath() const; + const folder::path::component getName() const; + const folder::path getFullPath() const; void open(const int mode, bool failIfModeIsNotAvailable = false); void close(const bool expunge); @@ -101,8 +101,8 @@ public: folder* getParent(); - const class store& store() const; - class store& store(); + const store* getStore() const; + store* getStore(); void fetchMessages(std::vector <message*>& msg, const int options, progressionListener* progress = NULL); diff --git a/src/messaging/POP3Message.cpp b/src/messaging/POP3Message.cpp index 66b3f466..d072fdc8 100644 --- a/src/messaging/POP3Message.cpp +++ b/src/messaging/POP3Message.cpp @@ -63,19 +63,19 @@ void POP3Message::onFolderClosed() } -const int POP3Message::number() const +const int POP3Message::getNumber() const { return (m_num); } -const message::uid POP3Message::uniqueId() const +const message::uid POP3Message::getUniqueId() const { return (m_uid); } -const int POP3Message::size() const +const int POP3Message::getSize() const { if (!m_folder) throw exceptions::illegal_state("Folder closed"); @@ -93,25 +93,25 @@ const bool POP3Message::isExpunged() const } -const int POP3Message::flags() const +const int POP3Message::getFlags() const { return (FLAG_RECENT); } -const class structure& POP3Message::structure() const +const structure& POP3Message::getStructure() const { throw exceptions::operation_not_supported(); } -class structure& POP3Message::structure() +structure& POP3Message::getStructure() { throw exceptions::operation_not_supported(); } -const class header& POP3Message::header() const +const header& POP3Message::getHeader() const { if (m_header == NULL) throw exceptions::unfetched_object(); diff --git a/src/messaging/POP3Message.hpp b/src/messaging/POP3Message.hpp index 193624b8..96c1f78e 100644 --- a/src/messaging/POP3Message.hpp +++ b/src/messaging/POP3Message.hpp @@ -35,7 +35,7 @@ namespace messaging { class POP3Message : public message { -protected: +private: friend class POP3Folder; @@ -46,20 +46,20 @@ protected: public: - const int number() const; + const int getNumber() const; - const uid uniqueId() const; + const uid getUniqueId() const; - const int size() const; + const int getSize() const; const bool isExpunged() const; - const class structure& structure() const; - class structure& structure(); + const structure& getStructure() const; + structure& getStructure(); - const class header& header() const; + const header& getHeader() const; - const int flags() const; + const int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, progressionListener* progress = NULL, const int start = 0, const int length = -1) const; @@ -77,7 +77,7 @@ private: int m_num; uid m_uid; - class header* m_header; + header* m_header; }; diff --git a/src/messaging/POP3Store.cpp b/src/messaging/POP3Store.cpp index c105bc4b..6d762997 100644 --- a/src/messaging/POP3Store.cpp +++ b/src/messaging/POP3Store.cpp @@ -33,8 +33,8 @@ namespace vmime { namespace messaging { -POP3Store::POP3Store(class session& sess, class authenticator* auth) - : store(sess, infosInstance(), auth), m_socket(NULL), +POP3Store::POP3Store(session* sess, authenticator* auth) + : store(sess, getInfosInstance(), auth), m_socket(NULL), m_authentified(false), m_timeoutHandler(NULL) { } @@ -49,7 +49,7 @@ POP3Store::~POP3Store() } -const string POP3Store::protocolName() const +const string POP3Store::getProtocolName() const { return "pop3"; } @@ -87,23 +87,23 @@ void POP3Store::connect() if (isConnected()) throw exceptions::already_connected(); - const string address = session().properties()[sm_infos.propertyPrefix() + "server.address"]; - const port_t port = session().properties().get(sm_infos.propertyPrefix() + "server.port", sm_infos.defaultPort()); + const string address = getSession()->getProperties()[sm_infos.getPropertyPrefix() + "server.address"]; + const port_t port = getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "server.port", sm_infos.getDefaultPort()); // Create the time-out handler - if (session().properties().exists - (sm_infos.propertyPrefix() + "timeout.factory")) + if (getSession()->getProperties().hasProperty + (sm_infos.getPropertyPrefix() + "timeout.factory")) { timeoutHandlerFactory* tof = platformDependant::getHandler()-> - getTimeoutHandlerFactory(session().properties() - [sm_infos.propertyPrefix() + "timeout.factory"]); + getTimeoutHandlerFactory(getSession()->getProperties() + [sm_infos.getPropertyPrefix() + "timeout.factory"]); m_timeoutHandler = tof->create(); } // Create and connect the socket socketFactory* sf = platformDependant::getHandler()->getSocketFactory - (session().properties().get(sm_infos.propertyPrefix() + "server.socket-factory", string("default"))); + (getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "server.socket-factory", string("default"))); m_socket = sf->create(); m_socket->connect(address, port); @@ -120,7 +120,7 @@ void POP3Store::connect() { bool authentified = false; - const authenticationInfos auth = authenticator().requestAuthInfos(); + const authenticationInfos auth = getAuthenticator()->requestAuthInfos(); // Secured authentication with APOP (if requested and if available) // @@ -128,13 +128,13 @@ void POP3Store::connect() // --- S: +OK vincent is a valid mailbox messageId mid(response); - if (session().properties().get(sm_infos.propertyPrefix() + "options.apop", false)) + if (getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "options.apop", false)) { - if (mid.left().length() && mid.right().length()) + if (mid.getLeft().length() && mid.getRight().length()) { // <digest> is the result of MD5 applied to "<message-id>password" - sendRequest("APOP " + auth.username() + " " - + utility::md5(mid.generate() + auth.password()).hex()); + sendRequest("APOP " + auth.getUsername() + " " + + utility::md5(mid.generate() + auth.getPassword()).hex()); readResponse(response, false); if (isSuccessResponse(response)) @@ -143,7 +143,7 @@ void POP3Store::connect() } else { - if (session().properties().get(sm_infos.propertyPrefix() + + if (getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "options.apop.fallback", false) == false) { internalDisconnect(); @@ -154,7 +154,7 @@ void POP3Store::connect() else { // APOP not supported - if (session().properties().get(sm_infos.propertyPrefix() + + if (getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "options.apop.fallback", false) == false) { // Can't fallback on basic authentification @@ -174,12 +174,12 @@ void POP3Store::connect() // C: PASS couic // S: +OK vincent's maildrop has 2 messages (320 octets) - sendRequest("USER " + auth.username()); + sendRequest("USER " + auth.getUsername()); readResponse(response, false); if (isSuccessResponse(response)) { - sendRequest("PASS " + auth.password()); + sendRequest("PASS " + auth.getPassword()); readResponse(response, false); if (!isSuccessResponse(response)) @@ -565,19 +565,31 @@ void POP3Store::unregisterFolder(POP3Folder* folder) POP3Store::_infos POP3Store::sm_infos; -const port_t POP3Store::_infos::defaultPort() const +const serviceInfos& POP3Store::getInfosInstance() +{ + return (sm_infos); +} + + +const serviceInfos& POP3Store::getInfos() const +{ + return (sm_infos); +} + + +const port_t POP3Store::_infos::getDefaultPort() const { return (110); } -const string POP3Store::_infos::propertyPrefix() const +const string POP3Store::_infos::getPropertyPrefix() const { return "store.pop3."; } -const std::vector <string> POP3Store::_infos::availableProperties() const +const std::vector <string> POP3Store::_infos::getAvailableProperties() const { std::vector <string> list; diff --git a/src/messaging/POP3Store.hpp b/src/messaging/POP3Store.hpp index b9d6bd87..ae0f9fd4 100644 --- a/src/messaging/POP3Store.hpp +++ b/src/messaging/POP3Store.hpp @@ -42,17 +42,17 @@ class POP3Store : public store public: - POP3Store(class session& sess, class authenticator* auth); + POP3Store(session* sess, authenticator* auth); ~POP3Store(); - const string protocolName() const; + const string getProtocolName() const; folder* getDefaultFolder(); folder* getRootFolder(); folder* getFolder(const folder::path& path); - static const serviceInfos& infosInstance() { return (sm_infos); } - const serviceInfos& infos() const { return (sm_infos); } + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; void connect(); const bool isConnected() const; @@ -93,10 +93,10 @@ private: { public: - const port_t defaultPort() const; + const port_t getDefaultPort() const; - const string propertyPrefix() const; - const std::vector <string> availableProperties() const; + const string getPropertyPrefix() const; + const std::vector <string> getAvailableProperties() const; }; static _infos sm_infos; diff --git a/src/messaging/SMTPTransport.cpp b/src/messaging/SMTPTransport.cpp index 309f3e06..d0401a51 100644 --- a/src/messaging/SMTPTransport.cpp +++ b/src/messaging/SMTPTransport.cpp @@ -31,8 +31,8 @@ namespace vmime { namespace messaging { -SMTPTransport::SMTPTransport(class session& sess, class authenticator* auth) - : transport(sess, infosInstance(), auth), m_socket(NULL), +SMTPTransport::SMTPTransport(session* sess, authenticator* auth) + : transport(sess, getInfosInstance(), auth), m_socket(NULL), m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL) { } @@ -47,7 +47,7 @@ SMTPTransport::~SMTPTransport() } -const string SMTPTransport::protocolName() const +const string SMTPTransport::getProtocolName() const { return "smtp"; } @@ -58,23 +58,23 @@ void SMTPTransport::connect() if (isConnected()) throw exceptions::already_connected(); - const string address = session().properties()[sm_infos.propertyPrefix() + "server.address"]; - const port_t port = session().properties().get(sm_infos.propertyPrefix() + "server.port", sm_infos.defaultPort()); + const string address = getSession()->getProperties()[sm_infos.getPropertyPrefix() + "server.address"]; + const port_t port = getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "server.port", sm_infos.getDefaultPort()); // Create the time-out handler - if (session().properties().exists - (sm_infos.propertyPrefix() + "timeout.factory")) + if (getSession()->getProperties().hasProperty + (sm_infos.getPropertyPrefix() + "timeout.factory")) { timeoutHandlerFactory* tof = platformDependant::getHandler()-> - getTimeoutHandlerFactory(session().properties() - [sm_infos.propertyPrefix() + "timeout.factory"]); + getTimeoutHandlerFactory(getSession()->getProperties() + [sm_infos.getPropertyPrefix() + "timeout.factory"]); m_timeoutHandler = tof->create(); } // Create and connect the socket socketFactory* sf = platformDependant::getHandler()->getSocketFactory - (session().properties().get(sm_infos.propertyPrefix() + "server.socket-factory", string("default"))); + (getSession()->getProperties().getProperty(sm_infos.getPropertyPrefix() + "server.socket-factory", string("default"))); m_socket = sf->create(); m_socket->connect(address, port); @@ -126,8 +126,8 @@ void SMTPTransport::connect() } // Authentication - if (session().properties().get - (sm_infos.propertyPrefix() + "options.need-authentication", false) == true) + if (getSession()->getProperties().getProperty + (sm_infos.getPropertyPrefix() + "options.need-authentication", false) == true) { if (!m_extendedSMTP) { @@ -135,7 +135,7 @@ void SMTPTransport::connect() throw exceptions::command_error("AUTH", "ESMTP not supported."); } - const authenticationInfos auth = authenticator().requestAuthInfos(); + const authenticationInfos auth = getAuthenticator()->requestAuthInfos(); bool authentified = false; enum AuthMethods @@ -169,9 +169,9 @@ void SMTPTransport::connect() base64.decode(in, out); } - hmac_md5(challenge, auth.password(), challengeHex); + hmac_md5(challenge, auth.getPassword(), challengeHex); - string decoded = auth.username() + " " + challengeHex; + string decoded = auth.getUsername() + " " + challengeHex; string encoded; { @@ -259,10 +259,12 @@ void SMTPTransport::noop() static void extractMailboxes (mailboxList& recipients, const addressList& list) { - for (addressList::const_iterator it = list.begin() ; - it != list.end() ; ++it) + for (int i = 0 ; i < list.getAddressCount() ; ++i) { - recipients.append((*it)); + mailbox* mbox = dynamic_cast <mailbox*>(list.getAddressAt(i)->clone()); + + if (mbox != NULL) + recipients.appendMailbox(mbox); } } @@ -275,8 +277,8 @@ void SMTPTransport::send(vmime::message* msg, progressionListener* progress) try { const mailboxField& from = dynamic_cast <const mailboxField&> - (msg->header().fields.find(headerField::From)); - expeditor = from.value(); + (*msg->getHeader()->findField(fields::FROM)); + expeditor = from.getValue(); } catch (exceptions::no_such_field&) { @@ -289,24 +291,24 @@ void SMTPTransport::send(vmime::message* msg, progressionListener* progress) try { const addressListField& to = dynamic_cast <const addressListField&> - (msg->header().fields.find(headerField::To)); - extractMailboxes(recipients, to.value()); + (*msg->getHeader()->findField(fields::TO)); + extractMailboxes(recipients, to.getValue()); } catch (exceptions::no_such_field&) { } try { const addressListField& cc = dynamic_cast <const addressListField&> - (msg->header().fields.find(headerField::Cc)); - extractMailboxes(recipients, cc.value()); + (*msg->getHeader()->findField(fields::CC)); + extractMailboxes(recipients, cc.getValue()); } catch (exceptions::no_such_field&) { } try { const addressListField& bcc = dynamic_cast <const addressListField&> - (msg->header().fields.find(headerField::Bcc)); - extractMailboxes(recipients, bcc.value()); + (*msg->getHeader()->findField(fields::BCC)); + extractMailboxes(recipients, bcc.getValue()); } catch (exceptions::no_such_field&) { } @@ -330,15 +332,15 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients progressionListener* progress) { // If no recipient/expeditor was found, throw an exception - if (recipients.empty()) + if (recipients.isEmpty()) throw exceptions::no_recipient(); - else if (expeditor.empty()) + else if (expeditor.isEmpty()) throw exceptions::no_expeditor(); // Emit the "MAIL" command string response; - sendRequest("MAIL FROM: <" + expeditor.email() + ">"); + sendRequest("MAIL FROM: <" + expeditor.getEmail() + ">"); readResponse(response); if (responseCode(response) != 250) @@ -348,10 +350,11 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients } // Emit a "RCPT TO" command for each recipient - for (mailboxList::const_iterator it = recipients.begin() ; - it != recipients.end() ; ++it) + for (int i = 0 ; i < recipients.getMailboxCount() ; ++i) { - sendRequest("RCPT TO: <" + (*it).email() + ">"); + const mailbox& mbox = *recipients.getMailboxAt(i); + + sendRequest("RCPT TO: <" + mbox.getEmail() + ">"); readResponse(response); if (responseCode(response) != 250) @@ -538,19 +541,31 @@ void SMTPTransport::readResponse(string& buffer) SMTPTransport::_infos SMTPTransport::sm_infos; -const port_t SMTPTransport::_infos::defaultPort() const +const serviceInfos& SMTPTransport::getInfosInstance() +{ + return (sm_infos); +} + + +const serviceInfos& SMTPTransport::getInfos() const +{ + return (sm_infos); +} + + +const port_t SMTPTransport::_infos::getDefaultPort() const { return (25); } -const string SMTPTransport::_infos::propertyPrefix() const +const string SMTPTransport::_infos::getPropertyPrefix() const { return "transport.smtp."; } -const std::vector <string> SMTPTransport::_infos::availableProperties() const +const std::vector <string> SMTPTransport::_infos::getAvailableProperties() const { std::vector <string> list; diff --git a/src/messaging/SMTPTransport.hpp b/src/messaging/SMTPTransport.hpp index fa5abfcf..b63da5c3 100644 --- a/src/messaging/SMTPTransport.hpp +++ b/src/messaging/SMTPTransport.hpp @@ -38,13 +38,13 @@ class SMTPTransport : public transport { public: - SMTPTransport(class session& sess, class authenticator* auth); + SMTPTransport(session* sess, authenticator* auth); ~SMTPTransport(); - const string protocolName() const; + const string getProtocolName() const; - static const serviceInfos& infosInstance() { return (sm_infos); } - const serviceInfos& infos() const { return (sm_infos); } + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; void connect(); const bool isConnected() const; @@ -78,10 +78,10 @@ private: { public: - const port_t defaultPort() const; + const port_t getDefaultPort() const; - const string propertyPrefix() const; - const std::vector <string> availableProperties() const; + const string getPropertyPrefix() const; + const std::vector <string> getAvailableProperties() const; }; static _infos sm_infos; diff --git a/src/messaging/authenticationInfos.cpp b/src/messaging/authenticationInfos.cpp index 3c5acca7..70579ff1 100644 --- a/src/messaging/authenticationInfos.cpp +++ b/src/messaging/authenticationInfos.cpp @@ -36,5 +36,17 @@ authenticationInfos::authenticationInfos(const authenticationInfos& infos) } +const string& authenticationInfos::getUsername() const +{ + return (m_username); +} + + +const string& authenticationInfos::getPassword() const +{ + return (m_password); +} + + } // messaging } // vmime diff --git a/src/messaging/authenticationInfos.hpp b/src/messaging/authenticationInfos.hpp index fd2da2fa..ff049419 100644 --- a/src/messaging/authenticationInfos.hpp +++ b/src/messaging/authenticationInfos.hpp @@ -42,13 +42,13 @@ public: * * @return account name */ - const string& username() const { return (m_username); } + const string& getUsername() const; /** Return the user account password. * * @return account password */ - const string& password() const { return (m_password); } + const string& getPassword() const; private: diff --git a/src/messaging/folder.hpp b/src/messaging/folder.hpp index 574ac1b0..0e92d50c 100644 --- a/src/messaging/folder.hpp +++ b/src/messaging/folder.hpp @@ -37,6 +37,9 @@ namespace vmime { namespace messaging { +class store; + + /** Abstract representation of a folder in a message store. */ @@ -90,31 +93,31 @@ public: * * @return folder type (see folder::Types) */ - virtual const int type() = 0; + virtual const int getType() = 0; /** Return the flags of this folder. * * @return folder flags (see folder::Flags) */ - virtual const int flags() = 0; + virtual const int getFlags() = 0; /** Return the mode in which the folder has been open. * * @return folder opening mode (see folder::Modes) */ - virtual const int mode() const = 0; + virtual const int getMode() const = 0; /** Return the name of this folder. * * @return folder name */ - virtual const folder::path::component name() const = 0; + virtual const folder::path::component getName() const = 0; /** Return the fully qualified path name of this folder. * * @return absolute path of the folder */ - virtual const folder::path fullPath() const = 0; + virtual const folder::path getFullPath() const = 0; /** Open this folder. * @@ -297,13 +300,13 @@ public: * * @return the store object to which this folder is attached */ - virtual const class store& store() const = 0; + virtual const store* getStore() const = 0; /** Return a reference to the store to which this folder belongs. * * @return the store object to which this folder is attached */ - virtual class store& store() = 0; + virtual store* getStore() = 0; /** Possible fetchable objects. */ diff --git a/src/messaging/maildirFolder.cpp b/src/messaging/maildirFolder.cpp index 903de91d..155b48fc 100644 --- a/src/messaging/maildirFolder.cpp +++ b/src/messaging/maildirFolder.cpp @@ -32,7 +32,7 @@ namespace messaging { maildirFolder::maildirFolder(const folder::path& path, maildirStore* store) - : m_store(store), m_path(path), m_name(path.last()), m_mode(-1), m_open(false) + : m_store(store), m_path(path), m_name(path.getLastComponent()), m_mode(-1), m_open(false) { m_store->registerFolder(this); } @@ -60,7 +60,7 @@ void maildirFolder::onStoreDisconnected() } -const int maildirFolder::mode() const +const int maildirFolder::getMode() const { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); @@ -69,16 +69,16 @@ const int maildirFolder::mode() const } -const int maildirFolder::type() +const int maildirFolder::getType() { - if (m_path.empty()) + if (m_path.isEmpty()) return (TYPE_CONTAINS_FOLDERS); else return (TYPE_CONTAINS_FOLDERS | TYPE_CONTAINS_MESSAGES); } -const int maildirFolder::flags() +const int maildirFolder::getFlags() { int flags = 0; @@ -104,13 +104,13 @@ const int maildirFolder::flags() } -const folder::path::component maildirFolder::name() const +const folder::path::component maildirFolder::getName() const { return (m_name); } -const folder::path maildirFolder::fullPath() const +const folder::path maildirFolder::getFullPath() const { return (m_path); } @@ -132,13 +132,40 @@ void maildirFolder::open(const int mode, bool /* failIfModeIsNotAvailable */) void maildirFolder::close(const bool expunge) { - // TODO + if (!m_store) + throw exceptions::illegal_state("Store disconnected"); + + if (!isOpen()) + throw exceptions::illegal_state("Folder not open"); + + m_open = false; + m_mode = -1; + + onClose(); } void maildirFolder::onClose() { - // TODO + for (std::vector <maildirMessage*>::iterator it = m_messages.begin() ; + it != m_messages.end() ; ++it) + { + (*it)->onFolderClosed(); + } + + m_messages.clear(); +} + + +void maildirFolder::registerMessage(maildirMessage* msg) +{ + m_messages.push_back(msg); +} + + +void maildirFolder::unregisterMessage(maildirMessage* msg) +{ + std::remove(m_messages.begin(), m_messages.end(), msg); } @@ -152,14 +179,14 @@ void maildirFolder::create(const int type) throw exceptions::illegal_state("Folder already exists"); // Folder name cannot start with '.' - if (!m_path.empty()) + if (!m_path.isEmpty()) { - const path::component& comp = m_path.last(); + const path::component& comp = m_path.getLastComponent(); - const int length = comp.buffer().length(); + const int length = comp.getBuffer().length(); int pos = 0; - while ((pos < length) && (comp.buffer()[pos] == '.')) + while ((pos < length) && (comp.getBuffer()[pos] == '.')) ++pos; if (pos != 0) @@ -246,7 +273,7 @@ void maildirFolder::scanFolder() while (nit->hasMoreElements()) { utility::auto_ptr <utility::file> file = nit->nextElement(); - unreadMessageFilenames.push_back(file->fullPath().last()); + unreadMessageFilenames.push_back(file->fullPath().getLastComponent()); } // Seen messages (cur/) @@ -256,7 +283,7 @@ void maildirFolder::scanFolder() while (cit->hasMoreElements()) { utility::auto_ptr <utility::file> file = cit->nextElement(); - messageFilenames.push_back(file->fullPath().last()); + messageFilenames.push_back(file->fullPath().getLastComponent()); } // TODO: update m_messageFilenames @@ -384,7 +411,7 @@ void maildirFolder::listFolders(std::vector <folder*>& list, const bool recursiv if (maildirUtils::isSubfolderDirectory(*file)) { - const utility::path subPath = m_path / file->fullPath().last(); + const utility::path subPath = m_path / file->fullPath().getLastComponent(); maildirFolder* subFolder = new maildirFolder(subPath, m_store); list.push_back(subFolder); @@ -494,10 +521,12 @@ void maildirFolder::status(int& count, int& unseen) for (std::list <maildirFolder*>::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { - if ((*it)->fullPath() == m_path) + if ((*it)->getFullPath() == m_path) { (*it)->m_messageCount = count; (*it)->notifyMessageCount(event); + + (*it)->scanFolder(); } } } @@ -512,19 +541,19 @@ void maildirFolder::expunge() folder* maildirFolder::getParent() { - return (m_path.empty() ? NULL : new maildirFolder(m_path.parent(), m_store)); + return (m_path.isEmpty() ? NULL : new maildirFolder(m_path.getParent(), m_store)); } -const class store& maildirFolder::store() const +const store* maildirFolder::getStore() const { - return (*m_store); + return (m_store); } -class store& maildirFolder::store() +store* maildirFolder::getStore() { - return (*m_store); + return (m_store); } diff --git a/src/messaging/maildirFolder.hpp b/src/messaging/maildirFolder.hpp index 37578157..65835219 100644 --- a/src/messaging/maildirFolder.hpp +++ b/src/messaging/maildirFolder.hpp @@ -40,7 +40,7 @@ class maildirStore; class maildirFolder : public folder { -protected: +private: friend class maildirStore; friend class maildirMessage; @@ -53,14 +53,14 @@ protected: public: - const int mode() const; + const int getMode() const; - const int type(); + const int getType(); - const int flags(); + const int getFlags(); - const folder::path::component name() const; - const folder::path fullPath() const; + const folder::path::component getName() const; + const folder::path getFullPath() const; void open(const int mode, bool failIfModeIsNotAvailable = false); void close(const bool expunge); @@ -100,8 +100,8 @@ public: folder* getParent(); - const class store& store() const; - class store& store(); + const store* getStore() const; + store* getStore(); void fetchMessages(std::vector <message*>& msg, const int options, progressionListener* progress = NULL); @@ -111,6 +111,18 @@ public: private: + void scanFolder(); + + void listFolders(std::vector <folder*>& list, const bool recursive); + + void registerMessage(maildirMessage* msg); + void unregisterMessage(maildirMessage* msg); + + void onStoreDisconnected(); + + void onClose(); + + maildirStore* m_store; folder::path m_path; @@ -125,15 +137,7 @@ private: std::vector <folder::path::component> m_unreadMessageFilenames; std::vector <folder::path::component> m_messageFilenames; - void scanFolder(); - - void listFolders(std::vector <folder*>& list, const bool recursive); - - - - void onStoreDisconnected(); - - void onClose(); + std::vector <maildirMessage*> m_messages; }; diff --git a/src/messaging/maildirMessage.cpp b/src/messaging/maildirMessage.cpp index c14831c3..65d41447 100644 --- a/src/messaging/maildirMessage.cpp +++ b/src/messaging/maildirMessage.cpp @@ -18,11 +18,92 @@ // #include "maildirMessage.hpp" +#include "maildirFolder.hpp" namespace vmime { namespace messaging { +maildirMessage::maildirMessage(maildirFolder* folder, const int num) + : m_folder(folder), m_num(num) +{ + m_folder->registerMessage(this); +} + + +maildirMessage::~maildirMessage() +{ + if (m_folder) + m_folder->unregisterMessage(this); +} + + +void maildirMessage::onFolderClosed() +{ + m_folder = NULL; +} + + +const int maildirMessage::getNumber() const +{ +} + + +const message::uid maildirMessage::getUniqueId() const +{ +} + + +const int maildirMessage::getSize() const +{ +} + + +const bool maildirMessage::isExpunged() const +{ +} + + +const structure& maildirMessage::getStructure() const +{ +} + + +structure& maildirMessage::getStructure() +{ +} + + +const header& maildirMessage::getHeader() const +{ +} + + +const int maildirMessage::getFlags() const +{ +} + + +void maildirMessage::setFlags(const int flags, const int mode) +{ +} + + +void maildirMessage::extract(utility::outputStream& os, progressionListener* progress, const int start, const int length) const +{ +} + + +void maildirMessage::extractPart(const part& p, utility::outputStream& os, progressionListener* progress, const int start, const int length) const +{ +} + + +void maildirMessage::fetchPartHeader(part& p) +{ +} + + } // messaging } // vmime diff --git a/src/messaging/maildirMessage.hpp b/src/messaging/maildirMessage.hpp index 3ea6afbf..83e7758f 100644 --- a/src/messaging/maildirMessage.hpp +++ b/src/messaging/maildirMessage.hpp @@ -39,7 +39,7 @@ class maildirMessage : public message { friend class maildirFolder; -protected: +private: maildirMessage(maildirFolder* folder, const int num); maildirMessage(const maildirMessage&) : message() { } @@ -48,26 +48,35 @@ protected: public: - const int number() const; + const int getNumber() const; - const uid uniqueId() const; + const uid getUniqueId() const; - const int size() const; + const int getSize() const; const bool isExpunged() const; - const class structure& structure() const; - class structure& structure(); + const structure& getStructure() const; + structure& getStructure(); - const class header& header() const; + const header& getHeader() const; - const int flags() const; + const int getFlags() const; void setFlags(const int flags, const int mode = FLAG_MODE_SET); void extract(utility::outputStream& os, progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void extractPart(const part& p, utility::outputStream& os, progressionListener* progress = NULL, const int start = 0, const int length = -1) const; void fetchPartHeader(part& p); + +protected: + + void onFolderClosed(); + + + maildirFolder* m_folder; + + int m_num; }; diff --git a/src/messaging/maildirStore.cpp b/src/messaging/maildirStore.cpp index 520e6bbb..e4df0e68 100644 --- a/src/messaging/maildirStore.cpp +++ b/src/messaging/maildirStore.cpp @@ -29,8 +29,8 @@ namespace vmime { namespace messaging { -maildirStore::maildirStore(class session& sess, class authenticator* auth) - : store(sess, infosInstance(), auth), m_connected(false) +maildirStore::maildirStore(session* sess, authenticator* auth) + : store(sess, getInfosInstance(), auth), m_connected(false) { } @@ -42,7 +42,7 @@ maildirStore::~maildirStore() } -const string maildirStore::protocolName() const +const string maildirStore::getProtocolName() const { return "maildir"; } @@ -81,7 +81,7 @@ void maildirStore::connect() throw exceptions::already_connected(); m_fsPath = platformDependant::getHandler()->getFileSystemFactory()-> - stringToPath(session().properties()[infos().propertyPrefix() + "server.rootpath"]); + stringToPath(getSession()->getProperties()[getInfos().getPropertyPrefix() + "server.rootpath"]); m_connected = true; } @@ -139,19 +139,31 @@ const utility::path& maildirStore::getFileSystemPath() const maildirStore::_infos maildirStore::sm_infos; -const port_t maildirStore::_infos::defaultPort() const +const serviceInfos& maildirStore::getInfosInstance() +{ + return (sm_infos); +} + + +const serviceInfos& maildirStore::getInfos() const +{ + return (sm_infos); +} + + +const port_t maildirStore::_infos::getDefaultPort() const { return (0); } -const string maildirStore::_infos::propertyPrefix() const +const string maildirStore::_infos::getPropertyPrefix() const { return "store.maildir."; } -const std::vector <string> maildirStore::_infos::availableProperties() const +const std::vector <string> maildirStore::_infos::getAvailableProperties() const { std::vector <string> list; diff --git a/src/messaging/maildirStore.hpp b/src/messaging/maildirStore.hpp index 62acb13e..b1a56329 100644 --- a/src/messaging/maildirStore.hpp +++ b/src/messaging/maildirStore.hpp @@ -47,17 +47,17 @@ class maildirStore : public store public: - maildirStore(class session& sess, class authenticator* auth); + maildirStore(session* sess, authenticator* auth); ~maildirStore(); - const string protocolName() const; + const string getProtocolName() const; folder* getDefaultFolder(); folder* getRootFolder(); folder* getFolder(const folder::path& path); - static const serviceInfos& infosInstance() { return (sm_infos); } - const serviceInfos& infos() const { return (sm_infos); } + static const serviceInfos& getInfosInstance(); + const serviceInfos& getInfos() const; void connect(); const bool isConnected() const; @@ -85,10 +85,10 @@ private: { public: - const port_t defaultPort() const; + const port_t getDefaultPort() const; - const string propertyPrefix() const; - const std::vector <string> availableProperties() const; + const string getPropertyPrefix() const; + const std::vector <string> getAvailableProperties() const; }; static _infos sm_infos; diff --git a/src/messaging/maildirUtils.cpp b/src/messaging/maildirUtils.cpp index 28df6902..2d294c0f 100644 --- a/src/messaging/maildirUtils.cpp +++ b/src/messaging/maildirUtils.cpp @@ -25,9 +25,9 @@ namespace vmime { namespace messaging { -const vmime::word maildirUtils::TMP_DIR("tmp"); // ensure reliable delivery (not to be listed) -const vmime::word maildirUtils::CUR_DIR("cur"); // no longer new messages -const vmime::word maildirUtils::NEW_DIR("new"); // unread messages +const vmime::word maildirUtils::TMP_DIR("tmp", vmime::charset(vmime::charsets::US_ASCII)); // ensure reliable delivery (not to be listed) +const vmime::word maildirUtils::CUR_DIR("cur", vmime::charset(vmime::charsets::US_ASCII)); // no longer new messages +const vmime::word maildirUtils::NEW_DIR("new", vmime::charset(vmime::charsets::US_ASCII)); // unread messages const utility::file::path maildirUtils::getFolderFSPath @@ -35,7 +35,9 @@ const utility::file::path maildirUtils::getFolderFSPath { // Root path utility::file::path path(store->getFileSystemPath()); - const int count = (mode == FOLDER_PATH_CONTAINER ? folderPath.size() : folderPath.size() - 1); + + const int count = (mode == FOLDER_PATH_CONTAINER + ? folderPath.getSize() : folderPath.getSize() - 1); // Parent folders for (int i = 0 ; i < count ; ++i) @@ -43,16 +45,16 @@ const utility::file::path maildirUtils::getFolderFSPath utility::file::path::component comp(folderPath[i]); // TODO: may not work with all encodings... - comp.buffer() = "." + comp.buffer() + ".directory"; + comp.setBuffer("." + comp.getBuffer() + ".directory"); path /= comp; } // Last component - if (folderPath.size() != 0 && + if (folderPath.getSize() != 0 && mode != FOLDER_PATH_CONTAINER) { - path /= folderPath.last(); + path /= folderPath.getLastComponent(); switch (mode) { @@ -73,8 +75,8 @@ const bool maildirUtils::isSubfolderDirectory(const utility::file& file) // A directory which name does not start with '.' // is listed as a sub-folder... if (file.isDirectory() && - file.fullPath().last().buffer().size() >= 1 && - file.fullPath().last().buffer()[0] != '.') + file.fullPath().getLastComponent().getBuffer().length() >= 1 && + file.fullPath().getLastComponent().getBuffer()[0] != '.') { return (true); } @@ -83,5 +85,36 @@ const bool maildirUtils::isSubfolderDirectory(const utility::file& file) } +/* +const int maildirUtils::extractFlags(const utility::file::path::component& comp) +{ + string::size_type sep = comp.buffer().rfind(':'); + if (sep == string::npos) return (0); + + const string flagsString(comp.buffer().begin() + sep + 1, comp.buffer().end()); + const string::size_type count = flagsString.length(); + + int flags = 0; + + for (string::size_type i = 0 ; i < count ; ++i) + { + switch (flagsString[i]) + { + case 'S': case 's': flags |= message::FLAG_SEEN; break; + case 'R': case 'r': flags |= message::FLAG_REPLIED; break; + } + } + + return (flags); +} + + +const utility::file::component maildirUtils::changeFlags + (const utility::file::component& comp, const int flags) +{ +} +*/ + + } // messaging } // vmime diff --git a/src/messaging/message.cpp b/src/messaging/message.cpp index 0bb1aaca..871799c3 100644 --- a/src/messaging/message.cpp +++ b/src/messaging/message.cpp @@ -26,19 +26,19 @@ namespace messaging { const part& part::operator[](const int x) const { - return (structure()[x]); + return (getStructure()[x]); } part& part::operator[](const int x) { - return (structure()[x]); + return (getStructure()[x]); } -const int part::count() const +const int part::getCount() const { - return (structure().count()); + return (getStructure().getCount()); } diff --git a/src/messaging/message.hpp b/src/messaging/message.hpp index 120aca27..825e1021 100644 --- a/src/messaging/message.hpp +++ b/src/messaging/message.hpp @@ -30,6 +30,9 @@ namespace vmime { namespace messaging { +class structure; + + /** A MIME part in a message. */ @@ -48,38 +51,38 @@ public: * * @return structure of the part */ - virtual const class structure& structure() const = 0; + virtual const structure& getStructure() const = 0; /** Return the structure of this part. * * @return structure of the part */ - virtual class structure& structure() = 0; + virtual structure& getStructure() = 0; /** Return the header section for this part (you must fetch header * before using this function: see message::fetchPartHeader). * * @return header section */ - virtual const class header& header() const = 0; + virtual const header& getHeader() const = 0; /** Return the media-type of the content in this part. * * @return content media type */ - virtual const mediaType& type() const = 0; + virtual const mediaType& getType() const = 0; /** Return the size of this part. * * @return size of the part (in bytes) */ - virtual const int size() const = 0; + virtual const int getSize() const = 0; /** Return the part sequence number (index) * * @return part number */ - virtual const int number() const = 0; // begin at 1 + virtual const int getNumber() const = 0; // begin at 1 /** Return the sub-part at the specified position. * This provide easy access to parts: @@ -103,7 +106,7 @@ public: * * @return number of sub-parts */ - const int count() const; + const int getCount() const; }; @@ -139,7 +142,7 @@ public: * * @return number of parts */ - virtual const int count() const = 0; + virtual const int getCount() const = 0; }; @@ -165,38 +168,38 @@ public: * * @return MIME structure of the message */ - virtual const class structure& structure() const = 0; + virtual const structure& getStructure() const = 0; /** Return the MIME structure of the message (must fetch before). * * @return MIME structure of the message */ - virtual class structure& structure() = 0; + virtual structure& getStructure() = 0; /** Return a reference to the header fields of the message (must fetch before). * * @return header section of the message */ - virtual const class header& header() const = 0; + virtual const header& getHeader() const = 0; /** Return the sequence number of this message. This number is * used to reference the message in the folder. * * @return sequence number of the message */ - virtual const int number() const = 0; + virtual const int getNumber() const = 0; /** Return the unique identified of this message (must fetch before). * * @return UID of the message */ - virtual const uid uniqueId() const = 0; + virtual const uid getUniqueId() const = 0; /** Return the size of the message (must fetch before). * * @return size of the message (in bytes) */ - virtual const int size() const = 0; + virtual const int getSize() const = 0; /** Check whether this message has been expunged * (ie: definitively deleted). @@ -233,7 +236,7 @@ public: * * @return flags of the message */ - virtual const int flags() const = 0; + virtual const int getFlags() const = 0; /** Set the flags of this message. * @@ -244,7 +247,7 @@ public: /** Extract the whole message data (header + contents). * - * WARNING: partial fetch might not be supported by the underlying protocol. + * \warning Partial fetch might not be supported by the underlying protocol. * * @param os output stream in which to write message data * @param progress progression listener, or NULL if not used @@ -256,7 +259,7 @@ public: /** Extract the specified (MIME) part of the message (header + contents). * - * WARNING: partial fetch might not be supported by the underlying protocol. + * \warning Partial fetch might not be supported by the underlying protocol. * * @param p part to extract * @param os output stream in which to write part data diff --git a/src/messaging/service.cpp b/src/messaging/service.cpp index 5a55fb4f..5f69600d 100644 --- a/src/messaging/service.cpp +++ b/src/messaging/service.cpp @@ -26,9 +26,9 @@ namespace vmime { namespace messaging { -service::service(class session& sess, const serviceInfos& infos, class authenticator* auth) +service::service(session* sess, const serviceInfos& infos, authenticator* auth) : m_deleteAuth(auth == NULL), m_session(sess), m_auth(auth ? auth : - new defaultAuthenticator(sess.properties(), infos.propertyPrefix())) + new defaultAuthenticator(sess->getProperties(), infos.getPropertyPrefix())) { } @@ -40,5 +40,29 @@ service::~service() } +const session* service::getSession() const +{ + return (m_session); +} + + +session* service::getSession() +{ + return (m_session); +} + + +const authenticator* service::getAuthenticator() const +{ + return (m_auth); +} + + +authenticator* service::getAuthenticator() +{ + return (m_auth); +} + + } // messaging } // vmime diff --git a/src/messaging/service.hpp b/src/messaging/service.hpp index d4a59c7f..cfab3611 100644 --- a/src/messaging/service.hpp +++ b/src/messaging/service.hpp @@ -39,7 +39,7 @@ class service { protected: - service(class session& sess, const serviceInfos& infos, class authenticator* auth); + service(session* sess, const serviceInfos& infos, authenticator* auth); public: @@ -56,31 +56,31 @@ public: * * @return type of service */ - virtual const Type type() const = 0; + virtual const Type getType() const = 0; /** Return the protocol name of this service. * * @return protocol name */ - virtual const string protocolName() const = 0; + virtual const string getProtocolName() const = 0; /** Return the session object associated with this service instance. * * @return session object */ - const class session& session() const { return (m_session); } + const session* getSession() const; /** Return the session object associated with this service instance. * * @return session object */ - class session& session() { return (m_session); } + session* getSession(); /** Return information about this service. * * @return information about the service */ - virtual const serviceInfos& infos() const = 0; + virtual const serviceInfos& getInfos() const = 0; /** Connect to service. */ @@ -106,13 +106,13 @@ public: * * @return authenticator object */ - const class authenticator& authenticator() const { return (*m_auth); } + const authenticator* getAuthenticator() const; /** Return the authenticator object used with this service instance. * * @return authenticator object */ - class authenticator& authenticator() { return (*m_auth); } + authenticator* getAuthenticator(); // Basic service registerer template <class S> @@ -123,7 +123,7 @@ public: initializer(const string& protocol) { serviceFactory::getInstance()-> - template registerName <S>(protocol); + template registerServiceByProtocol <S>(protocol); } }; @@ -131,8 +131,8 @@ private: bool m_deleteAuth; - class session& m_session; - class authenticator* m_auth; + session* m_session; + authenticator* m_auth; }; diff --git a/src/messaging/serviceFactory.cpp b/src/messaging/serviceFactory.cpp index 35ff3a98..b6a69313 100644 --- a/src/messaging/serviceFactory.cpp +++ b/src/messaging/serviceFactory.cpp @@ -37,65 +37,83 @@ serviceFactory::serviceFactory() serviceFactory::~serviceFactory() { - for (ProtoMap::iterator it = m_protoMap.begin() ; it != m_protoMap.end() ; ++it) - delete ((*it).second); + for (std::vector <registeredService*>::const_iterator it = m_services.begin() ; + it != m_services.end() ; ++it) + { + delete (*it); + } } service* serviceFactory::create - (session& sess, const string& protocol, authenticator* auth) + (session* sess, const string& protocol, authenticator* auth) { - ProtoMap::const_iterator pos = m_protoMap.find(toLower(protocol)); - - if (pos != m_protoMap.end()) - { - return ((*pos).second)->create(sess, auth); - } - else - { - throw exceptions::no_service_available(); - return (NULL); - } + return (getServiceByProtocol(protocol)->create(sess, auth)); } service* serviceFactory::create - (session& sess, const url& u, authenticator* auth) + (session* sess, const url& u, authenticator* auth) { - service* serv = create(sess, u.protocol(), auth); + service* serv = create(sess, u.getProtocol(), auth); - sess.properties()[serv->infos().propertyPrefix() + "server.address"] = u.host(); + sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.address"] = u.getHost(); - if (u.port() != url::UNSPECIFIED_PORT) - sess.properties()[serv->infos().propertyPrefix() + "server.port"] = u.port(); + if (u.getPort() != url::UNSPECIFIED_PORT) + sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.port"] = u.getPort(); // Path portion of the URL is used to point a specific folder (empty = root) //if (!u.path().empty()) - // sess.properties()[serv->infos().propertyPrefix() + "server.path"] = u.path(); + // sess->properties()[serv->getInfos().getPropertyPrefix() + "server.path"] = u.getPath(); - if (!u.username().empty()) + if (!u.getUsername().empty()) { - sess.properties()[serv->infos().propertyPrefix() + "auth.username"] = u.username(); - sess.properties()[serv->infos().propertyPrefix() + "auth.password"] = u.password(); + sess->getProperties()[serv->getInfos().getPropertyPrefix() + "auth.username"] = u.getUsername(); + sess->getProperties()[serv->getInfos().getPropertyPrefix() + "auth.password"] = u.getPassword(); } return (serv); } -const serviceFactory::registeredService& serviceFactory::operator[] - (const string& protocol) const +const serviceFactory::registeredService* serviceFactory::getServiceByProtocol(const string& protocol) const { - ProtoMap::const_iterator pos = m_protoMap.find(toLower(protocol)); + const string name(stringUtils::toLower(protocol)); - if (pos != m_protoMap.end()) + for (std::vector <registeredService*>::const_iterator it = m_services.begin() ; + it != m_services.end() ; ++it) { - return *((*pos).second); + if ((*it)->getName() == name) + return (*it); } - else + + throw exceptions::no_service_available(); +} + + +const int serviceFactory::getServiceCount() const +{ + return (m_services.size()); +} + + +const serviceFactory::registeredService* serviceFactory::getServiceAt(const int pos) const +{ + return (m_services[pos]); +} + + +const std::vector <const serviceFactory::registeredService*> serviceFactory::getServiceList() const +{ + std::vector <const registeredService*> res; + + for (std::vector <registeredService*>::const_iterator it = m_services.begin() ; + it != m_services.end() ; ++it) { - throw exceptions::no_service_available(); + res.push_back(*it); } + + return (res); } diff --git a/src/messaging/serviceFactory.hpp b/src/messaging/serviceFactory.hpp index 9aa8e46a..2ade7e69 100644 --- a/src/messaging/serviceFactory.hpp +++ b/src/messaging/serviceFactory.hpp @@ -26,6 +26,7 @@ #include "../types.hpp" #include "../base.hpp" #include "../utility/singleton.hpp" +#include "../utility/stringUtils.hpp" #include "serviceInfos.hpp" #include "authenticator.hpp" @@ -49,13 +50,14 @@ class serviceFactory : public utility::singleton <serviceFactory> { friend class utility::singleton <serviceFactory>; -protected: +private: serviceFactory(); ~serviceFactory(); public: + /** Information about a registered service. */ class registeredService { friend class serviceFactory; @@ -66,10 +68,10 @@ public: public: - virtual service* create(session& sess, authenticator* auth) = 0; + virtual service* create(session* sess, authenticator* auth) const = 0; - virtual const string& name() const = 0; - virtual const serviceInfos& infos() const = 0; + virtual const string& getName() const = 0; + virtual const serviceInfos& getInfos() const = 0; }; private: @@ -82,23 +84,23 @@ private: protected: registeredServiceImpl(const string& name) - : m_name(name), m_servInfos(S::infosInstance()) + : m_name(name), m_servInfos(S::getInfosInstance()) { } public: - service* create(session& sess, authenticator* auth) + service* create(session* sess, authenticator* auth) const { return new S(sess, auth); } - const serviceInfos& infos() const + const serviceInfos& getInfos() const { return (m_servInfos); } - const string& name() const + const string& getName() const { return (m_name); } @@ -109,94 +111,71 @@ private: const serviceInfos& m_servInfos; }; - typedef std::map <string, registeredService*> ProtoMap; - ProtoMap m_protoMap; + std::vector <registeredService*> m_services; public: + /** Register a new service by its protocol name. + * + * @param protocol protocol name + */ template <class S> - void registerName(const string& protocol) + void registerServiceByProtocol(const string& protocol) { - const string name = vmime::toLower(protocol); - m_protoMap.insert(ProtoMap::value_type(name, - new registeredServiceImpl <S>(name))); + const string name = stringUtils::toLower(protocol); + m_services.push_back(new registeredServiceImpl <S>(name)); } - service* create(session& sess, const string& protocol, authenticator* auth = NULL); - service* create(session& sess, const url& u, authenticator* auth = NULL); - - const registeredService& operator[](const string& protocol) const; - - - class iterator; - - class const_iterator - { - friend class serviceFactory; - - public: - - const_iterator() { } - const_iterator(const const_iterator& it) : m_it(it.m_it) { } - const_iterator(const iterator& it) : m_it(it.m_it) { } - - const_iterator& operator=(const const_iterator& it) { m_it = it.m_it; return (*this); } - - const registeredService& operator*() const { return (*(*m_it).second); } - const registeredService* operator->() const { return ((*m_it).second); } - - const_iterator& operator++() { ++m_it; return (*this); } - const_iterator operator++(int) { return (m_it++); } - - const_iterator& operator--() { --m_it; return (*this); } - const_iterator operator--(int) { return (m_it--); } - - const bool operator==(const const_iterator& it) const { return (m_it == it.m_it); } - const bool operator!=(const const_iterator& it) const { return (m_it != it.m_it); } - - private: - - const_iterator(const ProtoMap::const_iterator it) : m_it(it) { } - - ProtoMap::const_iterator m_it; - }; - - class iterator - { - friend class serviceFactory; - friend class serviceFactory::const_iterator; - - public: - - iterator() { } - iterator(const iterator& it) : m_it(it.m_it) { } - - iterator& operator=(const iterator& it) { m_it = it.m_it; return (*this); } - - registeredService& operator*() const { return (*(*m_it).second); } - registeredService* operator->() const { return ((*m_it).second); } - - iterator& operator++() { ++m_it; return (*this); } - iterator operator++(int) { return (m_it++); } - - iterator& operator--() { --m_it; return (*this); } - iterator operator--(int) { return (m_it--); } - - const bool operator==(const iterator& it) const { return (m_it == it.m_it); } - const bool operator!=(const iterator& it) const { return (m_it != it.m_it); } - - private: - - iterator(const ProtoMap::iterator it) : m_it(it) { } - - ProtoMap::iterator m_it; - }; - - iterator begin() { return iterator(m_protoMap.begin()); } - iterator end() { return iterator(m_protoMap.end()); } - - const_iterator begin() const { return const_iterator(m_protoMap.begin()); } - const_iterator end() const { return const_iterator(m_protoMap.end()); } + /** Create a new service instance from a protocol name. + * + * @param sess session + * @param protocol protocol name (eg. "pop3") + * @param auth authenticator used to provide credentials (can be NULL if not used) + * @return a new service instance for the specified protocol + * @throw exceptions::no_service_available if no service is registered + * for this protocol + */ + service* create(session* sess, const string& protocol, authenticator* auth = NULL); + + /** Create a new service instance from a URL. + * + * @param sess session + * @param u full URL with at least protocol and server (you can also specify + * port, username and password) + * @param auth authenticator used to provide credentials (can be NULL if not used) + * @return a new service instance for the specified protocol + * @throw exceptions::no_service_available if no service is registered + * for this protocol + */ + service* create(session* sess, const url& u, authenticator* auth = NULL); + + /** Return information about a registered protocol. + * + * @param protocol protocol name + * @return information about this protocol + * @throw exceptions::no_service_available if no service is registered + * for this protocol + */ + const registeredService* getServiceByProtocol(const string& protocol) const; + + /** Return the number of registered services. + * + * @return number of registered services + */ + const int getServiceCount() const; + + /** Return the registered service at the specified position. + * + * @param pos position of the registered service to return + * @return registered service at the specified position + */ + const registeredService* getServiceAt(const int pos) const; + + /** Return a list of all registered services. + * + * @return list of registered services + */ + const std::vector <const registeredService*> getServiceList() const; }; diff --git a/src/messaging/serviceInfos.hpp b/src/messaging/serviceInfos.hpp index 9da5ab26..3215ab7d 100644 --- a/src/messaging/serviceInfos.hpp +++ b/src/messaging/serviceInfos.hpp @@ -51,20 +51,20 @@ public: * * @return default port number */ - virtual const port_t defaultPort() const = 0; + virtual const port_t getDefaultPort() const = 0; /** Return the property prefix used by this service. * Use this to set/get properties in the session object. * * @return property prefix */ - virtual const string propertyPrefix() const = 0; + virtual const string getPropertyPrefix() const = 0; /** Return a list of available properties for this service. * * @return list of property names */ - virtual const std::vector <string> availableProperties() const = 0; + virtual const std::vector <string> getAvailableProperties() const = 0; }; diff --git a/src/messaging/session.cpp b/src/messaging/session.cpp index be1d8206..54f65c95 100644 --- a/src/messaging/session.cpp +++ b/src/messaging/session.cpp @@ -52,9 +52,9 @@ transport* session::getTransport(authenticator* auth) transport* session::getTransport(const string& protocol, authenticator* auth) { - service* sv = serviceFactory::getInstance()->create(*this, protocol, auth); + service* sv = serviceFactory::getInstance()->create(this, protocol, auth); - if (sv->type() != service::TYPE_TRANSPORT) + if (sv->getType() != service::TYPE_TRANSPORT) { delete (sv); throw exceptions::no_service_available(); @@ -72,9 +72,9 @@ store* session::getStore(authenticator* auth) store* session::getStore(const string& protocol, authenticator* auth) { - service* sv = serviceFactory::getInstance()->create(*this, protocol, auth); + service* sv = serviceFactory::getInstance()->create(this, protocol, auth); - if (sv->type() != service::TYPE_STORE) + if (sv->getType() != service::TYPE_STORE) { delete (sv); throw exceptions::no_service_available(); @@ -84,5 +84,17 @@ store* session::getStore(const string& protocol, authenticator* auth) } +const propertySet& session::getProperties() const +{ + return (m_props); +} + + +propertySet& session::getProperties() +{ + return (m_props); +} + + } // messaging } // vmime diff --git a/src/messaging/session.hpp b/src/messaging/session.hpp index 43bbe0b1..ad521fc3 100644 --- a/src/messaging/session.hpp +++ b/src/messaging/session.hpp @@ -94,11 +94,11 @@ public: /** Properties for the session and for the services. */ - const propertySet& properties() const { return (m_props); } + const propertySet& getProperties() const; /** Properties for the session and for the services. */ - propertySet& properties() { return (m_props); } + propertySet& getProperties(); private: diff --git a/src/messaging/simpleAuthenticator.cpp b/src/messaging/simpleAuthenticator.cpp index 557efd63..878e5aea 100644 --- a/src/messaging/simpleAuthenticator.cpp +++ b/src/messaging/simpleAuthenticator.cpp @@ -41,5 +41,29 @@ const authenticationInfos simpleAuthenticator::getAuthInfos() const } +const string& simpleAuthenticator::getUsername() const +{ + return (m_username); +} + + +void simpleAuthenticator::setUsername(const string& username) +{ + m_username = username; +} + + +const string& simpleAuthenticator::getPassword() const +{ + return (m_password); +} + + +void simpleAuthenticator::setPassword(const string& password) +{ + m_password = password; +} + + } // messaging } // vmime diff --git a/src/messaging/simpleAuthenticator.hpp b/src/messaging/simpleAuthenticator.hpp index 9d19f4c6..4fbbbf0a 100644 --- a/src/messaging/simpleAuthenticator.hpp +++ b/src/messaging/simpleAuthenticator.hpp @@ -37,11 +37,11 @@ public: public: - const string& username() const { return (m_username); } - string& username() { return (m_username); } + const string& getUsername() const; + void setUsername(const string& username); - const string& password() const { return (m_password); } - string& password() { return (m_password); } + const string& getPassword() const; + void setPassword(const string& password); private: diff --git a/src/messaging/store.hpp b/src/messaging/store.hpp index 687975d3..43890977 100644 --- a/src/messaging/store.hpp +++ b/src/messaging/store.hpp @@ -37,7 +37,7 @@ class store : public service { protected: - store(class session& sess, const serviceInfos& infos, class authenticator* auth) + store(session* sess, const serviceInfos& infos, authenticator* auth) : service(sess, infos, auth) { } public: @@ -64,7 +64,7 @@ public: virtual folder* getFolder(const folder::path& path) = 0; - const Type type() const { return (TYPE_STORE); } + const Type getType() const { return (TYPE_STORE); } }; diff --git a/src/messaging/transport.hpp b/src/messaging/transport.hpp index 588eb24b..bb3306c2 100644 --- a/src/messaging/transport.hpp +++ b/src/messaging/transport.hpp @@ -42,7 +42,7 @@ class transport : public service { protected: - transport(class session& sess, const serviceInfos& infos, class authenticator* auth) + transport(session* sess, const serviceInfos& infos, authenticator* auth) : service(sess, infos, auth) { } public: @@ -65,7 +65,7 @@ public: virtual void send(const mailbox& expeditor, const mailboxList& recipients, utility::inputStream& is, const utility::stream::size_type size, progressionListener* progress = NULL) = 0; - const Type type() const { return (TYPE_TRANSPORT); } + const Type getType() const { return (TYPE_TRANSPORT); } }; diff --git a/src/messaging/url.cpp b/src/messaging/url.cpp index cd38c656..9bedb150 100644 --- a/src/messaging/url.cpp +++ b/src/messaging/url.cpp @@ -131,7 +131,7 @@ void url::parse(const string& str) if (protoEnd == string::npos) throw exceptions::malformed_url("No protocol separator"); const string proto = - toLower(string(str.begin(), str.begin() + protoEnd)); + stringUtils::toLower(string(str.begin(), str.begin() + protoEnd)); // Username/password string::size_type slashPos = str.find('/', protoEnd + 3); @@ -222,5 +222,77 @@ void url::parse(const string& str) } +const string& url::getProtocol() const +{ + return (m_protocol); +} + + +void url::setProtocol(const string& protocol) +{ + m_protocol = protocol; +} + + +const string& url::getUsername() const +{ + return (m_username); +} + + +void url::setUsername(const string& username) +{ + m_username = username; +} + + +const string& url::getPassword() const +{ + return (m_password); +} + + +void url::setPassword(const string& password) +{ + m_password = password; +} + + +const string& url::getHost() const +{ + return (m_host); +} + + +void url::setHost(const string& host) +{ + m_host = host; +} + + +const port_t url::getPort() const +{ + return (m_port); +} + + +void url::setPort(const port_t port) +{ + m_port = port; +} + + +const string& url::getPath() const +{ + return (m_path); +} + + +void url::setPath(const string& path) +{ + m_path = path; +} + + } // messaging } // vmime diff --git a/src/messaging/url.hpp b/src/messaging/url.hpp index 8cef2d16..15c9d402 100644 --- a/src/messaging/url.hpp +++ b/src/messaging/url.hpp @@ -37,12 +37,16 @@ class url { public: - /** Means "port not specified" (use default port). - */ + /** Means "port not specified" (use default port). */ static const port_t UNSPECIFIED_PORT = static_cast <port_t>(-1); + /** Standard name for FILE protocol (local file-system). */ static const string PROTOCOL_FILE; + + /** Standard name for HTTP protocol. */ static const string PROTOCOL_HTTP; + + /** Standard name for FTP protocol. */ static const string PROTOCOL_FTP; @@ -71,23 +75,82 @@ public: const string& path = "", const string& username = "", const string& password = ""); - const string& protocol() const { return (m_protocol); } - string& protocol() { return (m_protocol); } + /** Return the protocol of the URL (eg: "http"). + * + * @return protocol of the URL + */ + const string& getProtocol() const; - const string& username() const { return (m_username); } - string& username() { return (m_username); } + /** Set the protocol of the URL. + * + * @param protocol new protocol (eg: "http") + */ + void setProtocol(const string& protocol); - const string& password() const { return (m_password); } - string& password() { return (m_password); } + /** Return the username specified in the URL + * or empty if not specified. + * + * @return user name + */ + const string& getUsername() const; - const string& host() const { return (m_host); } - string& host() { return (m_host); } + /** Set the username of the URL. + * + * @param username user name + */ + void setUsername(const string& username); + + /** Return the password specified in the URL + * or empty if not specified. + * + * @return user password + */ + const string& getPassword() const; - const port_t port() const { return (m_port); } - port_t& port() { return (m_port); } + /** Set the password of the URL. + * + * @param password user password + */ + void setPassword(const string& password); - const string& path() const { return (m_path); } - string& path() { return (m_path); } + /** Return the host name of the URL (server name or IP address). + * + * @return host name + */ + const string& getHost() const; + + /** Set the host name of the URL. + * + * @param host server name or IP address + */ + void setHost(const string& host); + + /** Return the port of the URL, or url::UNSPECIFIED_PORT if + * the default port if used. + * + * @return server port + */ + const port_t getPort() const; + + /** Set the port of the URL. + * + * @param port server port or url::UNSPECIFIED_PORT to + * use the default port of the protocol + */ + void setPort(const port_t port); + + /** Return the path portion of the URL, + * or empty if not specified. + * + * @return path + */ + const string& getPath() const; + + /** Set the part portion of the URL. + * + * @param path path + */ + void setPath(const string& path); /** Build a string URL from this object. diff --git a/src/messaging/urlUtils.hpp b/src/messaging/urlUtils.hpp index 135d508e..c6296805 100644 --- a/src/messaging/urlUtils.hpp +++ b/src/messaging/urlUtils.hpp @@ -29,6 +29,9 @@ namespace vmime { namespace messaging { +/** Miscellaneous functions related to URLs. + */ + class urlUtils { public: |