From 92c445dd63d463aaf0ee674dcae1a192e8a50381 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 5 Apr 2012 11:46:39 +0200 Subject: Added function to retrieve sequence numbers of messages whose UID is greater or equal than a specified UID (thanks to Zahi Mashael). --- src/net/imap/IMAPFolder.cpp | 56 +++++++++++++++++++++++++++++++++++++++ src/net/maildir/maildirFolder.cpp | 6 +++++ src/net/pop3/POP3Folder.cpp | 6 +++++ 3 files changed, 68 insertions(+) (limited to 'src') 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 -- cgit