diff options
| author | Vincent Richard <[email protected]> | 2011-03-31 21:13:03 +0200 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2011-03-31 21:13:03 +0200 |
| commit | d7c2fb2e5832a509ce4fccfd4aaf6f42a1c94361 (patch) | |
| tree | 1c3a33e7356c6ce229c076a197ef0afc39198042 /src | |
| parent | Allow static linking in mingw-cross-env. Added 'iconv' and uses 'ws2_32' inst... (diff) | |
| download | vmime-d7c2fb2e5832a509ce4fccfd4aaf6f42a1c94361.tar.gz vmime-d7c2fb2e5832a509ce4fccfd4aaf6f42a1c94361.zip | |
Flush stateful data from iconv (thanks to John van der Kamp, Zarafa).
Diffstat (limited to 'src')
| -rw-r--r-- | src/charsetConverter.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp index 38b9e5ed..2135788c 100644 --- a/src/charsetConverter.cpp +++ b/src/charsetConverter.cpp @@ -119,6 +119,7 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream& size_t inPos = 0; bool prevIsInvalid = false; + bool breakAfterNext = false; while (true) { @@ -126,11 +127,12 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream& size_t inLength = static_cast <size_t>(in.read(inBuffer + inPos, sizeof(inBuffer) - inPos) + inPos); size_t outLength = sizeof(outBuffer); - const char* inPtr = inBuffer; + const char* inPtr = breakAfterNext ? NULL : inBuffer; + size_t *ptrLength = breakAfterNext ? NULL : &inLength; char* outPtr = outBuffer; // Convert input bytes - if (iconv(cd, ICONV_HACK(&inPtr), &inLength, + if (iconv(cd, ICONV_HACK(&inPtr), ptrLength, &outPtr, &outLength) == static_cast <size_t>(-1)) { // Illegal input sequence or input sequence has no equivalent @@ -170,9 +172,12 @@ void charsetConverter::convert(utility::inputStream& in, utility::outputStream& prevIsInvalid = false; } - // Check for end of data - if (in.eof() && inPos == 0) + if (breakAfterNext) break; + + // Check for end of data, loop again to flush stateful data from iconv + if (in.eof() && inPos == 0) + breakAfterNext = true; } } |
