aboutsummaryrefslogtreecommitdiffstats
path: root/src/text.cpp
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2008-04-28 19:49:48 +0000
committerVincent Richard <[email protected]>2008-04-28 19:49:48 +0000
commit439b2b3e90cb78a81e8d42ffdcd8543c64b1d1de (patch)
treea51cb6e1f77bb6f2f6a7c1d4c14df290bf7370b7 /src/text.cpp
parentRemoved old GNU TLS error. (diff)
downloadvmime-439b2b3e90cb78a81e8d42ffdcd8543c64b1d1de.tar.gz
vmime-439b2b3e90cb78a81e8d42ffdcd8543c64b1d1de.zip
Fixed extra space in subject (see https://sourceforge.net/forum/message.php?msg_id=4894970).
Diffstat (limited to 'src/text.cpp')
-rw-r--r--src/text.cpp103
1 files changed, 59 insertions, 44 deletions
diff --git a/src/text.cpp b/src/text.cpp
index 67aed20f..13a682ef 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -269,63 +269,78 @@ void text::createFromString(const string& in, const charset& ch)
removeAllWords();
- for (string::size_type end = in.size(), pos = 0, start = 0 ; ; )
+ const string::size_type asciiCount =
+ utility::stringUtils::countASCIIchars(in.begin(), in.end());
+
+ const string::size_type asciiPercent =
+ (in.length() == 0 ? 100 : (100 * asciiCount) / in.length());
+
+ // If there are "too much" non-ASCII chars, encode everything
+ if (asciiPercent < 60) // less than 60% ASCII chars
+ {
+ appendWord(vmime::create <word>(in, ch));
+ }
+ // Else, only encode words which need it
+ else
{
- if (pos == end || parserHelpers::isSpace(in[pos]))
+ for (string::size_type end = in.size(), pos = 0, start = 0 ; ; )
{
- if (pos != end)
- ++pos;
+ if (pos == end || parserHelpers::isSpace(in[pos]))
+ {
+ const string chunk(in.begin() + start, in.begin() + pos);
- const string chunk(in.begin() + start, in.begin() + pos);
+ if (pos != end)
+ ++pos;
- if (is8bit)
- {
- if (count && prevIs8bit)
+ if (is8bit)
{
- // No need to create a new encoded word, just append
- // the current word to the previous one.
- ref <word> w = getWordAt(getWordCount() - 1);
- w->getBuffer() += chunk;
+ if (count && prevIs8bit)
+ {
+ // No need to create a new encoded word, just append
+ // the current word to the previous one.
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += " " + chunk;
+ }
+ else
+ {
+ appendWord(vmime::create <word>(chunk, ch));
+
+ prevIs8bit = true;
+ ++count;
+ }
}
else
{
- appendWord(vmime::create <word>(chunk, ch));
-
- prevIs8bit = true;
- ++count;
+ if (count && !prevIs8bit)
+ {
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += " " + chunk;
+ }
+ else
+ {
+ appendWord(vmime::create <word>
+ (chunk, charset(charsets::US_ASCII)));
+
+ prevIs8bit = false;
+ ++count;
+ }
}
+
+ if (pos == end)
+ break;
+
+ is8bit = false;
+ start = pos;
+ }
+ else if (!parserHelpers::isAscii(in[pos]))
+ {
+ is8bit = true;
+ ++pos;
}
else
{
- if (count && !prevIs8bit)
- {
- ref <word> w = getWordAt(getWordCount() - 1);
- w->getBuffer() += chunk;
- }
- else
- {
- appendWord(vmime::create <word>
- (chunk, charset(charsets::US_ASCII)));
-
- prevIs8bit = false;
- ++count;
- }
+ ++pos;
}
-
- if (pos == end)
- break;
-
- is8bit = false;
- start = pos;
- }
- else if (!parserHelpers::isAscii(in[pos]))
- {
- is8bit = true;
- ++pos;
- }
- else
- {
- ++pos;
}
}
}