diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp index 0122d217..50a2f2ba 100644 --- a/src/net/imap/IMAPFolder.cpp +++ b/src/net/imap/IMAPFolder.cpp @@ -1772,6 +1772,62 @@ void IMAPFolder::status(int& count, int& unseen) } +std::vector IMAPFolder::getMessageNumbersStartingOnUID(const message::uid& uid) +{ + std::vector v; + + std::ostringstream command; + command.imbue(std::locale::classic()); + + command << "SEARCH UID " << uid; + + // Send the request + m_connection->send(true, command.str(), true); + + // Get the response + utility::auto_ptr resp(m_connection->readResponse()); + + if (resp->isBad() || + resp->response_done()->response_tagged()->resp_cond_state()->status() != IMAPParser::resp_cond_state::OK) + { + throw exceptions::command_error("SEARCH", + m_connection->getParser()->lastLine(), "bad response"); + } + + const std::vector & respDataList = resp->continue_req_or_response_data(); + + for (std::vector ::const_iterator + it = respDataList.begin() ; it != respDataList.end() ; ++it) + { + if ((*it)->response_data() == NULL) + { + throw exceptions::command_error("SEARCH", + m_connection->getParser()->lastLine(), "invalid response"); + } + + const IMAPParser::mailbox_data* mailboxData = + (*it)->response_data()->mailbox_data(); + + // We are only interested in responses of type "SEARCH" + if (mailboxData == NULL || + mailboxData->type() != IMAPParser::mailbox_data::SEARCH) + { + continue; + } + + for (std::vector ::const_iterator + it = mailboxData->search_nz_number_list().begin() ; + it != mailboxData->search_nz_number_list().end(); + ++it) + { + v.push_back((*it)->value()); + } + } + + return v; +} + + } // imap } // net } // vmime diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp index dd680c9c..d11ae3b8 100644 --- a/src/net/maildir/maildirFolder.cpp +++ b/src/net/maildir/maildirFolder.cpp @@ -1363,6 +1363,12 @@ const utility::file::path maildirFolder::getMessageFSPath(const int number) cons } +std::vector maildirFolder::getMessageNumbersStartingOnUID(const message::uid& /* uid */) +{ + throw exceptions::operation_not_supported(); +} + + } // maildir } // net } // vmime diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp index d5fc6874..e0856090 100644 --- a/src/net/pop3/POP3Folder.cpp +++ b/src/net/pop3/POP3Folder.cpp @@ -843,6 +843,12 @@ void POP3Folder::expunge() } +std::vector POP3Folder::getMessageNumbersStartingOnUID(const message::uid& /* uid */) +{ + throw exceptions::operation_not_supported(); +} + + } // pop3 } // net } // vmime diff --git a/vmime/net/folder.hpp b/vmime/net/folder.hpp index b20e9c95..df9cbaf5 100644 --- a/vmime/net/folder.hpp +++ b/vmime/net/folder.hpp @@ -383,6 +383,13 @@ public: */ virtual int getFetchCapabilities() const = 0; + /** Return the sequence numbers of messages whose UID equal or greater than uid + * + * @param uid the uid of the first message + * @throw net_exception if an error occurs + */ + virtual std::vector getMessageNumbersStartingOnUID(const message::uid& uid) = 0; + // Event listeners void addMessageChangedListener(events::messageChangedListener* l); void removeMessageChangedListener(events::messageChangedListener* l); diff --git a/vmime/net/imap/IMAPFolder.hpp b/vmime/net/imap/IMAPFolder.hpp index dec3878e..cc52596f 100644 --- a/vmime/net/imap/IMAPFolder.hpp +++ b/vmime/net/imap/IMAPFolder.hpp @@ -120,6 +120,8 @@ public: int getFetchCapabilities() const; + std::vector getMessageNumbersStartingOnUID(const message::uid& uid); + private: void registerMessage(IMAPMessage* msg); diff --git a/vmime/net/maildir/maildirFolder.hpp b/vmime/net/maildir/maildirFolder.hpp index 7474b1aa..68b5b898 100644 --- a/vmime/net/maildir/maildirFolder.hpp +++ b/vmime/net/maildir/maildirFolder.hpp @@ -121,6 +121,8 @@ public: int getFetchCapabilities() const; + std::vector getMessageNumbersStartingOnUID(const message::uid& uid); + private: void scanFolder(); diff --git a/vmime/net/pop3/POP3Folder.hpp b/vmime/net/pop3/POP3Folder.hpp index abaa8eb1..c4829085 100644 --- a/vmime/net/pop3/POP3Folder.hpp +++ b/vmime/net/pop3/POP3Folder.hpp @@ -119,6 +119,8 @@ public: int getFetchCapabilities() const; + std::vector getMessageNumbersStartingOnUID(const message::uid& uid); + private: void registerMessage(POP3Message* msg);