From cec80c63355461d451d83f95ca790418167a7d07 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 21 Jul 2013 14:24:18 +0200 Subject: [PATCH] Return real message UID from IMAP server. Added function to return the current UID validity. --- src/net/imap/IMAPFolder.cpp | 19 ++++++++++----- src/net/imap/IMAPMessage.cpp | 4 ++-- src/net/imap/IMAPUtils.cpp | 44 ++--------------------------------- vmime/net/imap/IMAPFolder.hpp | 11 +++++++++ vmime/net/imap/IMAPUtils.hpp | 15 ------------ 5 files changed, 28 insertions(+), 65 deletions(-) diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp index 60133a29..3a38182e 100644 --- a/src/net/imap/IMAPFolder.cpp +++ b/src/net/imap/IMAPFolder.cpp @@ -596,10 +596,10 @@ std::vector > IMAPFolder::getMessagesByUID(const std::vector ::size_type i = 1, n = uids.size() ; i < n ; ++i) - cmd << "," << IMAPUtils::extractUIDFromGlobalUID(uids[i]); + cmd << "," << uids[i]; cmd << " UID"; @@ -639,7 +639,7 @@ std::vector > IMAPFolder::getMessagesByUID(const std::vector (messageData->number()); - message::uid msgUID, msgFullUID; + message::uid msgUID; // Find UID in message attributes const std::vector atts = messageData->msg_att()->items(); @@ -649,9 +649,7 @@ std::vector > IMAPFolder::getMessagesByUID(const std::vector type() == IMAPParser::msg_att_item::UID) { - msgFullUID = IMAPUtils::makeGlobalUID(m_status->getUIDValidity(), (*it)->unique_id()->value()); msgUID = (*it)->unique_id()->value(); - break; } } @@ -659,7 +657,7 @@ std::vector > IMAPFolder::getMessagesByUID(const std::vector thisFolder = thisRef().dynamicCast (); - messages.push_back(vmime::create (thisFolder, msgNum, msgFullUID)); + messages.push_back(vmime::create (thisFolder, msgNum, msgUID)); } } @@ -676,6 +674,15 @@ int IMAPFolder::getMessageCount() } +vmime_uint32 IMAPFolder::getUIDValidity() const +{ + if (!isOpen()) + throw exceptions::illegal_state("Folder not open"); + + return m_status->getUIDValidity(); +} + + vmime_uint64 IMAPFolder::getHighestModSequence() const { if (!isOpen()) diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp index 9ae264c0..96114e94 100644 --- a/src/net/imap/IMAPMessage.cpp +++ b/src/net/imap/IMAPMessage.cpp @@ -295,7 +295,7 @@ void IMAPMessage::extractImpl(ref p, utility::outputStream& if (m_uid.empty()) command << "FETCH " << m_num << " BODY"; else - command << "UID FETCH " << IMAPUtils::extractUIDFromGlobalUID(m_uid) << " BODY"; + command << "UID FETCH " << m_uid << " BODY"; /* BODY[] header + body @@ -393,7 +393,7 @@ int IMAPMessage::processFetchResponse } case IMAPParser::msg_att_item::UID: { - m_uid = IMAPUtils::makeGlobalUID(folder->m_status->getUIDValidity(), (*it)->unique_id()->value()); + m_uid = (*it)->unique_id()->value(); break; } case IMAPParser::msg_att_item::MODSEQ: diff --git a/src/net/imap/IMAPUtils.cpp b/src/net/imap/IMAPUtils.cpp index 2aad06a1..dc583f84 100644 --- a/src/net/imap/IMAPUtils.cpp +++ b/src/net/imap/IMAPUtils.cpp @@ -554,10 +554,10 @@ const string IMAPUtils::listToSet(const std::vector & list) std::ostringstream res; res.imbue(std::locale::classic()); - res << extractUIDFromGlobalUID(list[0]); + res << list[0]; for (std::vector ::size_type i = 1, n = list.size() ; i < n ; ++i) - res << "," << extractUIDFromGlobalUID(list[i]); + res << "," << list[i]; return res.str(); } @@ -756,46 +756,6 @@ void IMAPUtils::convertAddressList } -// static -vmime_uint32 IMAPUtils::extractUIDFromGlobalUID(const message::uid& uid) -{ - message::uid::size_type colonPos = uid.find(':'); - - if (colonPos == message::uid::npos) - { - std::istringstream iss(uid); - iss.imbue(std::locale::classic()); - - vmime_uint32 n = 0; - iss >> n; - - return n; - } - else - { - std::istringstream iss(uid.substr(colonPos + 1)); - iss.imbue(std::locale::classic()); - - vmime_uint32 n = 0; - iss >> n; - - return n; - } -} - - -// static -const message::uid IMAPUtils::makeGlobalUID(const vmime_uint32 UIDValidity, const vmime_uint32 messageUID) -{ - std::ostringstream oss; - oss.imbue(std::locale::classic()); - - oss << UIDValidity << ":" << messageUID; - - return message::uid(oss.str()); -} - - } // imap } // net } // vmime diff --git a/vmime/net/imap/IMAPFolder.hpp b/vmime/net/imap/IMAPFolder.hpp index d7ad19ee..c1d2d34a 100644 --- a/vmime/net/imap/IMAPFolder.hpp +++ b/vmime/net/imap/IMAPFolder.hpp @@ -138,6 +138,17 @@ public: int getFetchCapabilities() const; + /** Returns the UID validity of the folder for the current session. + * If the server is capable of persisting UIDs accross sessions, + * this value should never change for a folder. If the UID validity + * differs across sessions, then the UIDs obtained during a previous + * session may not correspond to the UIDs of the same messages in + * this session. + * + * @return UID validity of the folder + */ + vmime_uint32 getUIDValidity() const; + /** Returns the highest modification sequence of this folder, ie the * modification sequence of the last message that changed in this * folder. diff --git a/vmime/net/imap/IMAPUtils.hpp b/vmime/net/imap/IMAPUtils.hpp index 591db3f3..7a03fcac 100644 --- a/vmime/net/imap/IMAPUtils.hpp +++ b/vmime/net/imap/IMAPUtils.hpp @@ -130,21 +130,6 @@ public: */ static void convertAddressList(const IMAPParser::address_list& src, mailboxList& dest); - /** Extract the message UID from a globally unique UID. - * - * @param uid globally unique UID (as returned by makeGlobalUID(), for example) - * @return message UID - */ - static vmime_uint32 extractUIDFromGlobalUID(const message::uid& uid); - - /** Construct a globally unique UID from UID Validity and a message UID. - * - * @param UIDValidity UID Validity of the folder - * @param messageUID UID of the message - * @return global UID - */ - static const message::uid makeGlobalUID(const vmime_uint32 UIDValidity, const vmime_uint32 messageUID); - private: static const string buildFetchRequestImpl