aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/platforms/windows/windowsHandler.cpp72
-rw-r--r--src/utility/url.cpp17
-rw-r--r--src/utility/urlUtils.cpp37
3 files changed, 110 insertions, 16 deletions
diff --git a/src/platforms/windows/windowsHandler.cpp b/src/platforms/windows/windowsHandler.cpp
index 6b84f59f..bbdcc1b6 100644
--- a/src/platforms/windows/windowsHandler.cpp
+++ b/src/platforms/windows/windowsHandler.cpp
@@ -18,11 +18,17 @@
//
#include "vmime/platforms/windows/windowsHandler.hpp"
+#include "vmime/config.hpp"
#include <time.h>
#include <locale.h>
#include <process.h>
-#include <mlang.h>
+#include <windows.h> // for winnls.h
+
+#ifdef VMIME_HAVE_MLANG_H
+# include <mlang.h>
+#endif
+
namespace vmime {
namespace platforms {
@@ -62,7 +68,7 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
const time_t t(::time(NULL));
// Get the local time
-#ifdef _REENTRANT
+#if defined(_REENTRANT) && defined(localtime_r)
tm local;
::localtime_r(&t, &local);
#else
@@ -70,7 +76,7 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
#endif
// Get the UTC time
-#ifdef _REENTRANT
+#if defined(_REENTRANT) && defined(gmtime_r)
tm gmt;
::gmtime_r(&t, &gmt);
#else
@@ -94,8 +100,9 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
const vmime::charset windowsHandler::getLocaleCharset() const
{
+#ifdef VMIME_HAVE_MLANG_H
char szCharset[256];
-
+
CoInitialize(NULL);
{
IMultiLanguage* pMultiLanguage;
@@ -111,15 +118,66 @@ const vmime::charset windowsHandler::getLocaleCharset() const
pMultiLanguage->GetCodePageInfo(codePage, &cpInfo);
int nLengthW = lstrlenW(cpInfo.wszBodyCharset) + 1;
-
+
WideCharToMultiByte(codePage, 0, cpInfo.wszBodyCharset, nLengthW, szCharset, sizeof(szCharset), NULL, NULL );
-
+
pMultiLanguage->Release();
- }
+ }
CoUninitialize();
return vmime::charset(szCharset);
+#else // VMIME_HAVE_MLANG_H
+ vmime::string ch = vmime::charsets::ISO8859_1; // default
+
+ switch (GetACP())
+ {
+ case 437: ch = vmime::charsets::CP_437; break;
+ case 737: ch = vmime::charsets::CP_737; break;
+ case 775: ch = vmime::charsets::CP_775; break;
+ case 850: ch = vmime::charsets::CP_850; break;
+ case 852: ch = vmime::charsets::CP_852; break;
+ case 853: ch = vmime::charsets::CP_853; break;
+ case 855: ch = vmime::charsets::CP_855; break;
+ case 857: ch = vmime::charsets::CP_857; break;
+ case 858: ch = vmime::charsets::CP_858; break;
+ case 860: ch = vmime::charsets::CP_860; break;
+ case 861: ch = vmime::charsets::CP_861; break;
+ case 862: ch = vmime::charsets::CP_862; break;
+ case 863: ch = vmime::charsets::CP_863; break;
+ case 864: ch = vmime::charsets::CP_864; break;
+ case 865: ch = vmime::charsets::CP_865; break;
+ case 866: ch = vmime::charsets::CP_866; break;
+ case 869: ch = vmime::charsets::CP_869; break;
+ case 874: ch = vmime::charsets::CP_874; break;
+
+ case 1125: ch = vmime::charsets::CP_1125; break;
+ case 1250: ch = vmime::charsets::CP_1250; break;
+ case 1251: ch = vmime::charsets::CP_1251; break;
+ case 1252: ch = vmime::charsets::CP_1252; break;
+ case 1253: ch = vmime::charsets::CP_1253; break;
+ case 1254: ch = vmime::charsets::CP_1254; break;
+ case 1255: ch = vmime::charsets::CP_1255; break;
+ case 1256: ch = vmime::charsets::CP_1256; break;
+ case 1257: ch = vmime::charsets::CP_1257; break;
+
+ case 28591: ch = vmime::charsets::ISO8859_1; break;
+ case 28592: ch = vmime::charsets::ISO8859_2; break;
+ case 28593: ch = vmime::charsets::ISO8859_3; break;
+ case 28594: ch = vmime::charsets::ISO8859_4; break;
+ case 28595: ch = vmime::charsets::ISO8859_5; break;
+ case 28596: ch = vmime::charsets::ISO8859_6; break;
+ case 28597: ch = vmime::charsets::ISO8859_7; break;
+ case 28598: ch = vmime::charsets::ISO8859_8; break;
+ case 28599: ch = vmime::charsets::ISO8859_9; break;
+ case 28605: ch = vmime::charsets::ISO8859_15; break;
+
+ case 65000: ch = vmime::charsets::UTF_7; break;
+ case 65001: ch = vmime::charsets::UTF_8; break;
+ }
+
+ return (vmime::charset(ch));
+#endif
}
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index 0c0a5799..919a3610 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -181,12 +181,12 @@ void url::parse(const string& str)
if (colonPos == string::npos)
{
- host = hostPart;
+ host = utility::stringUtils::trim(hostPart);
}
else
{
- host = string(hostPart.begin(), hostPart.begin() + colonPos);
- port = string(hostPart.begin() + colonPos + 1, hostPart.end());
+ host = utility::stringUtils::trim(string(hostPart.begin(), hostPart.begin() + colonPos));
+ port = utility::stringUtils::trim(string(hostPart.begin() + colonPos + 1, hostPart.end()));
}
// Path
@@ -198,8 +198,12 @@ void url::parse(const string& str)
// Some sanity check
if (proto.empty())
throw exceptions::malformed_url("No protocol specified");
- else if (host.empty() && path.empty()) // Accept empty host (eg. "file:///home/vincent/mydoc")
- throw exceptions::malformed_url("No host specified");
+ else if (host.empty())
+ {
+ // Accept empty host (eg. "file:///home/vincent/mydoc")
+ if (proto != PROTOCOL_FILE)
+ throw exceptions::malformed_url("No host specified");
+ }
bool onlyDigit = true;
@@ -217,6 +221,9 @@ void url::parse(const string& str)
iss >> portNum;
+ if (portNum == 0)
+ portNum = UNSPECIFIED_PORT;
+
// Now, save URL parts
m_protocol = proto;
diff --git a/src/utility/urlUtils.cpp b/src/utility/urlUtils.cpp
index 6099c19b..70a988cf 100644
--- a/src/utility/urlUtils.cpp
+++ b/src/utility/urlUtils.cpp
@@ -34,17 +34,18 @@ const string urlUtils::encode(const string& s)
{
const char_t c = *it;
- if (parserHelpers::isPrint(c) && c != '%')
+ if (parserHelpers::isPrint(c) && !parserHelpers::isSpace(c) && c != '%')
{
result += c;
}
else
{
char hex[4];
+ const unsigned char k = static_cast <unsigned char>(c);
hex[0] = '%';
- hex[1] = c / 16;
- hex[2] = c % 16;
+ hex[1] = "0123456789ABCDEF"[k / 16];
+ hex[2] = "0123456789ABCDEF"[k % 16];
hex[3] = 0;
result += hex;
@@ -71,7 +72,35 @@ const string urlUtils::decode(const string& s)
const char_t p = (++it != s.end() ? *it : 0);
const char_t q = (++it != s.end() ? *it : 0);
- result += static_cast <string::value_type>(p * 16 + q);
+ unsigned char r = 0;
+
+ switch (p)
+ {
+ case 0: r = '?'; break;
+ case 'a': case 'A': r = 10; break;
+ case 'b': case 'B': r = 11; break;
+ case 'c': case 'C': r = 12; break;
+ case 'd': case 'D': r = 13; break;
+ case 'e': case 'E': r = 14; break;
+ case 'f': case 'F': r = 15; break;
+ default: r = p - '0'; break;
+ }
+
+ r *= 16;
+
+ switch (q)
+ {
+ case 0: r = '?'; break;
+ case 'a': case 'A': r += 10; break;
+ case 'b': case 'B': r += 11; break;
+ case 'c': case 'C': r += 12; break;
+ case 'd': case 'D': r += 13; break;
+ case 'e': case 'E': r += 14; break;
+ case 'f': case 'F': r += 15; break;
+ default: r += q - '0'; break;
+ }
+
+ result += static_cast <string::value_type>(r);
if (it != s.end())
++it;