aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2006-11-08 18:33:18 +0000
committerVincent Richard <[email protected]>2006-11-08 18:33:18 +0000
commitf99fc84915e4bcd2750b7fadfb24f858ccc7e5ef (patch)
treeb3c8fa78d8b145ff04aca8b17a4a74dbc348cd15
parentFixed compilation problem with GCC 3.3. (diff)
downloadvmime-f99fc84915e4bcd2750b7fadfb24f858ccc7e5ef.tar.gz
vmime-f99fc84915e4bcd2750b7fadfb24f858ccc7e5ef.zip
Imbue classic 'C' locale for the output of message parts and protocol commands.
-rw-r--r--ChangeLog5
-rw-r--r--src/dateTime.cpp2
-rw-r--r--src/messageId.cpp1
-rw-r--r--src/net/imap/IMAPFolder.cpp20
-rw-r--r--src/net/imap/IMAPMessage.cpp6
-rw-r--r--src/net/imap/IMAPUtils.cpp7
-rw-r--r--src/net/maildir/maildirUtils.cpp1
-rw-r--r--src/net/pop3/POP3Folder.cpp10
-rw-r--r--src/parameter.cpp2
-rw-r--r--src/platforms/posix/posixChildProcess.cpp2
-rw-r--r--src/platforms/posix/posixSocket.cpp2
-rw-r--r--src/security/digest/messageDigest.cpp1
-rw-r--r--src/utility/stringUtils.cpp25
-rw-r--r--src/utility/url.cpp1
-rw-r--r--vmime/utility/stream.hpp2
-rw-r--r--vmime/utility/stringUtils.hpp4
16 files changed, 86 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 1f849fb1..84c1ff26 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
VERSION 0.8.1cvs
================
+2006-11-08 Vincent Richard <[email protected]>
+
+ * Imbue classic "C" locale for the output of message parts and
+ protocol commands (thanks to Mörtsell Anders).
+
2006-10-11 Vincent Richard <[email protected]>
* Renamed 'vmime::platformDependant' to 'vmime::platform'. The old
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index 09202bdb..2bba3322 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -600,6 +600,8 @@ void datetime::generate(utility::outputStream& os, const string::size_type /* ma
const int zm = z % 60;
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+
oss << dayNames[getWeekDay()] << ", "
<< m_day << " " << monthNames[m_month - 1] << " " << m_year
<< " " << std::setfill('0') << std::setw(2) << m_hour << ":"
diff --git a/src/messageId.cpp b/src/messageId.cpp
index bfa5cd05..0f808ee9 100644
--- a/src/messageId.cpp
+++ b/src/messageId.cpp
@@ -210,6 +210,7 @@ messageId& messageId::operator=(const string& id)
messageId messageId::generateId()
{
std::ostringstream left;
+ left.imbue(std::locale::classic());
left << "vmime";
left << '.';
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 09d33b68..5796528d 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -821,6 +821,8 @@ void IMAPFolder::deleteMessage(const int num)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STORE " << num << " +FLAGS.SILENT (\\Deleted)";
// Send the request
@@ -875,6 +877,8 @@ void IMAPFolder::deleteMessages(const int from, const int to)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STORE " << from << ":";
if (to == -1) command << m_messageCount;
@@ -948,6 +952,8 @@ void IMAPFolder::deleteMessages(const std::vector <int>& nums)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STORE ";
command << IMAPUtils::listToSet(list, m_messageCount, true);
command << " +FLAGS.SILENT (\\Deleted)";
@@ -1000,6 +1006,7 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags,
throw exceptions::illegal_state("Folder is read-only");
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
if (to == -1)
oss << from << ":*";
@@ -1159,6 +1166,8 @@ void IMAPFolder::setMessageFlags(const string& set, const int flags, const int m
{
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STORE " << set;
switch (mode)
@@ -1220,6 +1229,8 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "APPEND " << IMAPUtils::quoteString(IMAPUtils::pathToString
(m_connection->hierarchySeparator(), getFullPath())) << ' ';
@@ -1433,6 +1444,8 @@ void IMAPFolder::rename(const folder::path& newPath)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "RENAME ";
command << IMAPUtils::quoteString(IMAPUtils::pathToString
(m_connection->hierarchySeparator(), getFullPath())) << " ";
@@ -1506,6 +1519,8 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num)
// Construct set
std::ostringstream set;
+ set.imbue(std::locale::classic());
+
set << num;
// Delegate message copy
@@ -1544,6 +1559,7 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in
// Construct set
std::ostringstream set;
+ set.imbue(std::locale::classic());
if (to == -1)
set << from << ":*";
@@ -1614,6 +1630,8 @@ void IMAPFolder::copyMessages(const string& set, const folder::path& dest)
{
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "COPY " << set << " ";
command << IMAPUtils::quoteString(IMAPUtils::pathToString
(m_connection->hierarchySeparator(), dest));
@@ -1642,6 +1660,8 @@ void IMAPFolder::status(int& count, int& unseen)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STATUS ";
command << IMAPUtils::quoteString(IMAPUtils::pathToString
(m_connection->hierarchySeparator(), getFullPath()));
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index 47e77de4..11c2bea2 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -409,6 +409,7 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
// Construct section identifier
std::ostringstream section;
+ section.imbue(std::locale::classic());
if (p != NULL)
{
@@ -435,6 +436,7 @@ void IMAPMessage::extract(ref <const part> p, utility::outputStream& os,
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
command << "FETCH " << m_num << " BODY";
if (peek) command << ".PEEK";
@@ -545,6 +547,8 @@ void IMAPMessage::processFetchResponse
case IMAPParser::msg_att_item::UID:
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+
oss << folder->m_uidValidity << ":" << (*it)->unique_id()->value();
m_uid = oss.str();
@@ -685,6 +689,8 @@ void IMAPMessage::setFlags(const int flags, const int mode)
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "STORE " << m_num;
switch (mode)
diff --git a/src/net/imap/IMAPUtils.cpp b/src/net/imap/IMAPUtils.cpp
index 6e3c869c..d36bd1eb 100644
--- a/src/net/imap/IMAPUtils.cpp
+++ b/src/net/imap/IMAPUtils.cpp
@@ -390,6 +390,8 @@ const string IMAPUtils::messageFlagList(const int flags)
if (!flagList.empty())
{
std::ostringstream res;
+ res.imbue(std::locale::classic());
+
res << "(";
if (flagList.size() >= 2)
@@ -426,6 +428,8 @@ const string IMAPUtils::listToSet(const std::vector <int>& list, const int max,
// Build the set
std::ostringstream res;
+ res.imbue(std::locale::classic());
+
int previous = -1, setBegin = -1;
for (std::vector <int>::const_iterator it = theList.begin() ;
@@ -483,6 +487,7 @@ const string IMAPUtils::listToSet(const std::vector <int>& list, const int max,
const string IMAPUtils::dateTime(const vmime::datetime& date)
{
std::ostringstream res;
+ res.imbue(std::locale::classic());
// date_time ::= <"> date_day_fixed "-" date_month "-" date_year
// SPACE time SPACE zone <">
@@ -608,6 +613,8 @@ const string IMAPUtils::buildFetchRequest(const std::vector <int>& list, const i
// Build the request text
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "FETCH " << listToSet(list, -1, false) << " (";
for (std::vector <string>::const_iterator it = items.begin() ;
diff --git a/src/net/maildir/maildirUtils.cpp b/src/net/maildir/maildirUtils.cpp
index 004c2553..1f0486b0 100644
--- a/src/net/maildir/maildirUtils.cpp
+++ b/src/net/maildir/maildirUtils.cpp
@@ -203,6 +203,7 @@ const utility::file::path::component maildirUtils::buildFilename
const utility::file::path::component maildirUtils::generateId()
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
oss << utility::random::getTime();
oss << ".";
diff --git a/src/net/pop3/POP3Folder.cpp b/src/net/pop3/POP3Folder.cpp
index 7ef4aa12..e19adea0 100644
--- a/src/net/pop3/POP3Folder.cpp
+++ b/src/net/pop3/POP3Folder.cpp
@@ -443,6 +443,8 @@ void POP3Folder::fetchMessage(ref <message> msg, const int options)
{
// Send the "LIST" command
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "LIST " << msg->getNumber();
store->sendRequest(command.str());
@@ -479,6 +481,8 @@ void POP3Folder::fetchMessage(ref <message> msg, const int options)
{
// Send the "UIDL" command
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "UIDL " << msg->getNumber();
store->sendRequest(command.str());
@@ -566,6 +570,8 @@ void POP3Folder::deleteMessage(const int num)
throw exceptions::illegal_state("Folder not open");
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "DELE " << num;
store->sendRequest(command.str());
@@ -615,6 +621,8 @@ void POP3Folder::deleteMessages(const int from, const int to)
for (int i = from ; i <= to2 ; ++i)
{
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "DELE " << i;
store->sendRequest(command.str());
@@ -666,6 +674,8 @@ void POP3Folder::deleteMessages(const std::vector <int>& nums)
it = nums.begin() ; it != nums.end() ; ++it)
{
std::ostringstream command;
+ command.imbue(std::locale::classic());
+
command << "DELE " << (*it);
store->sendRequest(command.str());
diff --git a/src/parameter.cpp b/src/parameter.cpp
index 9ebe7273..c7c13339 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -125,7 +125,9 @@ void parameter::parse(const std::vector <valueChunk>& chunks)
bool foundCharsetChunk = false;
charset ch(charsets::US_ASCII);
+
std::ostringstream value;
+ value.imbue(std::locale::classic());
for (std::vector <valueChunk>::size_type i = 0 ; i < chunks.size() ; ++i)
{
diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp
index bbeaa497..aded6a6e 100644
--- a/src/platforms/posix/posixChildProcess.cpp
+++ b/src/platforms/posix/posixChildProcess.cpp
@@ -376,6 +376,8 @@ void posixChildProcess::waitForFinish()
else
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+
oss << "Process exited with status " << WEXITSTATUS(wstat);
throw exceptions::system_error(oss.str());
diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp
index e63e4674..14f8f103 100644
--- a/src/platforms/posix/posixSocket.cpp
+++ b/src/platforms/posix/posixSocket.cpp
@@ -78,6 +78,8 @@ void posixSocket::connect(const vmime::string& address, const vmime::port_t port
hints.ai_socktype = SOCK_STREAM;
std::ostringstream portStr;
+ portStr.imbue(std::locale::classic());
+
portStr << port;
struct ::addrinfo* res0;
diff --git a/src/security/digest/messageDigest.cpp b/src/security/digest/messageDigest.cpp
index bba80023..4a2e8912 100644
--- a/src/security/digest/messageDigest.cpp
+++ b/src/security/digest/messageDigest.cpp
@@ -39,6 +39,7 @@ const string messageDigest::getHexDigest() const
static const unsigned char hex[] = "0123456789abcdef";
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
for (int i = 0 ; i < len ; ++i)
{
diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp
index ea9ffec4..dab01f15 100644
--- a/src/utility/stringUtils.cpp
+++ b/src/utility/stringUtils.cpp
@@ -33,10 +33,13 @@ const bool stringUtils::isStringEqualNoCase
if (s1.length() < n)
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
for (string::size_type i = 0 ; equal && i < n ; ++i)
- equal = (std::tolower(s1[i], std::locale()) == s2[i]);
+ equal = (fac.tolower(static_cast <unsigned char>(s1[i])) == s2[i]);
return (equal);
}
@@ -47,11 +50,14 @@ const bool stringUtils::isStringEqualNoCase(const string& s1, const string& s2)
if (s1.length() != s2.length())
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
const string::const_iterator end = s1.end();
for (string::const_iterator i = s1.begin(), j = s2.begin(); i != end ; ++i, ++j)
- equal = (std::tolower(*i, std::locale()) == std::tolower(*j, std::locale()));
+ equal = (fac.tolower(static_cast <unsigned char>(*i)) == fac.tolower(static_cast <unsigned char>(*j)));
return (equal);
}
@@ -64,12 +70,15 @@ const bool stringUtils::isStringEqualNoCase
if (static_cast <string::size_type>(end - begin) < n)
return (false);
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
bool equal = true;
char* c = const_cast<char*>(s);
string::size_type r = n;
for (string::const_iterator i = begin ; equal && r && *c ; ++i, ++c, --r)
- equal = (std::tolower(*i, std::locale()) == *c);
+ equal = (fac.tolower(static_cast <unsigned char>(*i)) == static_cast <unsigned char>(*c));
return (r == 0 && equal);
}
@@ -77,11 +86,14 @@ const bool stringUtils::isStringEqualNoCase
const string stringUtils::toLower(const string& str)
{
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
string out;
out.resize(str.size());
for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
- out[i] = std::tolower(str[i], std::locale());
+ out[i] = fac.tolower(static_cast <unsigned char>(str[i]));
return out;
}
@@ -89,11 +101,14 @@ const string stringUtils::toLower(const string& str)
const string stringUtils::toUpper(const string& str)
{
+ const std::ctype <unsigned char>& fac =
+ std::use_facet <std::ctype <unsigned char> >(std::locale::classic());
+
string out;
out.resize(str.size());
for (string::size_type i = 0, len = str.length() ; i < len ; ++i)
- out[i] = std::toupper(str[i], std::locale());
+ out[i] = fac.toupper(static_cast <unsigned char>(str[i]));
return out;
}
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index dede3208..69782c1b 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -95,6 +95,7 @@ url::operator string() const
const string url::build() const
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
oss << m_protocol << "://";
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index edde8444..60b4ecce 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -164,6 +164,8 @@ template <typename T>
outputStream& operator<<(outputStream& os, const T& t)
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic()); // no formatting
+
oss << t;
os << oss.str();
diff --git a/vmime/utility/stringUtils.hpp b/vmime/utility/stringUtils.hpp
index 77566752..71253a13 100644
--- a/vmime/utility/stringUtils.hpp
+++ b/vmime/utility/stringUtils.hpp
@@ -113,6 +113,8 @@ public:
static const string toString(const TYPE& value)
{
std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+
oss << value;
return (oss.str());
@@ -130,6 +132,8 @@ public:
TYPE ret;
std::istringstream iss(value);
+ iss.imbue(std::locale::classic());
+
iss >> ret;
return (ret);