Fixed ',2' in filename/flags + fixed file renaming when moving from 'new' to 'cur' + new functions random::getString() and maildirUtils::generateId().
This commit is contained in:
parent
3217dd9bf9
commit
706c270073
@ -343,13 +343,16 @@ void maildirFolder::scanFolder()
|
||||
for (std::vector <utility::file::path::component>::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 <utility::file> 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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user