diff options
author | Vincent Richard <[email protected]> | 2010-05-23 16:18:00 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2010-05-23 16:18:00 +0000 |
commit | 2f8026dc5bb17e7fecf126070481e34a20485b67 (patch) | |
tree | 74625e9c08910c4db6ed19c341246aa1a922a494 /src/charset.cpp | |
parent | FileSystemFactory is now a ref. (diff) | |
download | vmime-2f8026dc5bb17e7fecf126070481e34a20485b67.tar.gz vmime-2f8026dc5bb17e7fecf126070481e34a20485b67.zip |
Improved automatic encoding selection. Added helper functions on body for setting contents, type, charset and encoding.
Diffstat (limited to 'src/charset.cpp')
-rw-r--r-- | src/charset.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/charset.cpp b/src/charset.cpp index e3c11daa..e0431860 100644 --- a/src/charset.cpp +++ b/src/charset.cpp @@ -24,6 +24,7 @@ #include "vmime/charset.hpp" #include "vmime/exception.hpp" #include "vmime/platform.hpp" +#include "vmime/encoding.hpp" #include "vmime/utility/stringUtils.hpp" @@ -140,4 +141,53 @@ const std::vector <ref <const component> > charset::getChildComponents() const } + +// Explicitly force encoding for some charsets +struct CharsetEncodingEntry +{ + CharsetEncodingEntry(const string& charset_, const string& encoding_) + : charset(charset_), encoding(encoding_) + { + } + + const string charset; + const string encoding; +}; + +CharsetEncodingEntry g_charsetEncodingMap[] = +{ + // Use QP encoding for ISO-8859-x charsets + CharsetEncodingEntry("iso-8859", encodingTypes::QUOTED_PRINTABLE), + CharsetEncodingEntry("iso8859", encodingTypes::QUOTED_PRINTABLE), + + // RFC-1468 states: + // " ISO-2022-JP may also be used in MIME Part 2 headers. The "B" + // encoding should be used with ISO-2022-JP text. " + // Use Base64 encoding for all ISO-2022 charsets. + CharsetEncodingEntry("iso-2022", encodingTypes::BASE64), + CharsetEncodingEntry("iso2022", encodingTypes::BASE64), + + // Last entry is not used + CharsetEncodingEntry("", "") +}; + + +bool charset::getRecommendedEncoding(encoding& enc) const +{ + // Special treatment for some charsets + const string cset = utility::stringUtils::toLower(getName()); + + for (unsigned int i = 0 ; i < (sizeof(g_charsetEncodingMap) / sizeof(g_charsetEncodingMap[0])) - 1 ; ++i) + { + if (cset.find(g_charsetEncodingMap[i].charset) != string::npos) + { + enc = g_charsetEncodingMap[i].encoding; + return true; + } + } + + return false; +} + + } // vmime |