diff --git a/src/messaging/maildirFolder.cpp b/src/messaging/maildirFolder.cpp index 54d35989..21b97016 100644 --- a/src/messaging/maildirFolder.cpp +++ b/src/messaging/maildirFolder.cpp @@ -343,13 +343,16 @@ void maildirFolder::scanFolder() for (std::vector ::const_iterator it = newMessageFilenames.begin() ; it != newMessageFilenames.end() ; ++it) { + const utility::file::path::component newFilename = + maildirUtils::buildFilename(maildirUtils::extractId(*it), 0); + // Move messages from 'new' to 'cur' utility::auto_ptr file = fsf->create(newDirPath / *it); - file->rename(curDirPath / *it); + file->rename(curDirPath / newFilename); // Append to message list messageInfos msgInfos; - msgInfos.path = *it; + msgInfos.path = newFilename; msgInfos.type = messageInfos::TYPE_CUR; m_messageInfos.push_back(msgInfos); diff --git a/src/messaging/maildirUtils.cpp b/src/messaging/maildirUtils.cpp index e620ce0a..aba91372 100644 --- a/src/messaging/maildirUtils.cpp +++ b/src/messaging/maildirUtils.cpp @@ -20,6 +20,8 @@ #include "maildirUtils.hpp" #include "maildirStore.hpp" +#include "../utility/random.hpp" + namespace vmime { namespace messaging { @@ -125,7 +127,9 @@ const int maildirUtils::extractFlags(const utility::file::path::component& comp) const utility::file::path::component maildirUtils::buildFlags(const int flags) { string str; - str.reserve(6); + str.reserve(8); + + str += "2,"; if (flags & message::FLAG_MARKED) str += "F"; if (flags & message::FLAG_PASSED) str += "P"; @@ -151,6 +155,20 @@ const utility::file::path::component maildirUtils::buildFilename } +const utility::file::path::component maildirUtils::generateId() +{ + std::ostringstream oss; + + oss << utility::random::getTime(); + oss << "."; + oss << utility::random::getProcess(); + oss << "."; + oss << utility::random::getString(6); + + return (utility::file::path::component(oss.str())); +} + + // // messageIdComparator diff --git a/src/messaging/maildirUtils.hpp b/src/messaging/maildirUtils.hpp index d65e5d3e..6d5f0628 100644 --- a/src/messaging/maildirUtils.hpp +++ b/src/messaging/maildirUtils.hpp @@ -128,6 +128,12 @@ public: */ static const utility::file::path::component buildFilename(const utility::file::path::component& id, const int flags); + /** Generate a new unique message identifier. + * + * @return unique message id + */ + static const utility::file::path::component generateId(); + private: static const vmime::word TMP_DIR; diff --git a/src/utility/random.cpp b/src/utility/random.cpp index b2a935d8..cefaea3e 100644 --- a/src/utility/random.cpp +++ b/src/utility/random.cpp @@ -55,5 +55,25 @@ const unsigned int random::getProcess() } +const string random::getString(const int length, const string& randomChars) +{ + string res; + res.resize(length); + + const unsigned int x = randomChars.length(); + int c = 0; + + while (c < length) + { + for (unsigned int n = random::getNext() ; n != 0 ; n /= x) + { + res[c++] = randomChars[n % x]; + } + } + + return (res); +} + + } // utility } // vmime diff --git a/src/utility/random.hpp b/src/utility/random.hpp index 70ae6716..442905a5 100644 --- a/src/utility/random.hpp +++ b/src/utility/random.hpp @@ -21,6 +21,9 @@ #define VMIME_UTILITY_RANDOM_HPP_INCLUDED +#include "types.hpp" + + namespace vmime { namespace utility { @@ -52,6 +55,15 @@ public: */ static const unsigned int getProcess(); + /** Return a random character string with the specified length. + * + * @param length length of the string to generate + * @param randomChars list of characters to use + * @return random string + */ + static const string getString(const int length, const string& randomChars + = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); + protected: static unsigned int m_next;