diff options
Diffstat (limited to '')
-rw-r--r-- | src/charsetConverter.cpp | 56 | ||||
-rw-r--r-- | src/net/smtp/SMTPTransport.cpp | 2 | ||||
-rw-r--r-- | src/platforms/posix/posixChildProcess.cpp | 5 | ||||
-rw-r--r-- | src/platforms/posix/posixFile.cpp | 6 | ||||
-rw-r--r-- | src/platforms/windows/windowsFile.cpp | 7 | ||||
-rw-r--r-- | src/utility/filteredStream.cpp | 19 | ||||
-rw-r--r-- | src/utility/stream.cpp | 26 |
7 files changed, 117 insertions, 4 deletions
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp index c6a77349..04d01db0 100644 --- a/src/charsetConverter.cpp +++ b/src/charsetConverter.cpp @@ -162,6 +162,8 @@ void charsetConverter::convert(const string& in, string& out) utility::outputStreamStringAdapter os(out); convert(is, os); + + os.flush(); } @@ -327,6 +329,60 @@ void charsetFilteredOutputStream::write } +void charsetFilteredOutputStream::flush() +{ + if (m_desc == NULL) + throw exceptions::charset_conv_error("Cannot initialize converter."); + + const iconv_t cd = *static_cast <iconv_t*>(m_desc); + + size_t offset = 0; + + // Process unconverted bytes + while (m_unconvCount != 0) + { + // Try a conversion + const char* inPtr = m_unconvBuffer + offset; + size_t inLength = m_unconvCount; + char* outPtr = m_outputBuffer; + size_t outLength = sizeof(m_outputBuffer); + + const size_t inLength0 = inLength; + + if (iconv(cd, ICONV_HACK(&inPtr), &inLength, &outPtr, &outLength) == static_cast <size_t>(-1)) + { + const size_t inputConverted = inLength0 - inLength; + + // Skip a "blocking" character + if (inputConverted == 0) + { + m_stream.write("?", 1); + + offset++; + m_unconvCount--; + } + else + { + // Write successfully converted bytes + m_stream.write(m_outputBuffer, sizeof(m_outputBuffer) - outLength); + + offset += inputConverted; + m_unconvCount -= inputConverted; + } + } + else + { + // Write successfully converted bytes + m_stream.write(m_outputBuffer, sizeof(m_outputBuffer) - outLength); + + m_unconvCount = 0; + } + } + + m_stream.flush(); +} + + } // utility diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp index c50d3c69..bb586d78 100644 --- a/src/net/smtp/SMTPTransport.cpp +++ b/src/net/smtp/SMTPTransport.cpp @@ -542,6 +542,8 @@ void SMTPTransport::send(const mailbox& expeditor, const mailboxList& recipients utility::bufferedStreamCopy(is, fos, size, progress); + fos.flush(); + // Send end-of-data delimiter m_socket->sendRaw("\r\n.\r\n", 5); diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp index 514f5b65..05681bb5 100644 --- a/src/platforms/posix/posixChildProcess.cpp +++ b/src/platforms/posix/posixChildProcess.cpp @@ -119,6 +119,11 @@ public: } } + void flush() + { + ::fsync(m_desc); + } + private: const int m_desc; diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp index e914520d..eca90d20 100644 --- a/src/platforms/posix/posixFile.cpp +++ b/src/platforms/posix/posixFile.cpp @@ -119,6 +119,12 @@ void posixFileWriterOutputStream::write(const value_type* const data, const size } +void posixFileWriterOutputStream::flush() +{ + ::fsync(m_fd); +} + + // // posixFileReaderInputStream diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp index 9ecfd1d4..d00be306 100644 --- a/src/platforms/windows/windowsFile.cpp +++ b/src/platforms/windows/windowsFile.cpp @@ -516,6 +516,13 @@ void windowsFileWriterOutputStream::write(const value_type* const data, const si windowsFileSystemFactory::reportError(m_path, GetLastError()); } + +void windowsFileWriterOutputStream::flush() +{ + // TODO +} + + } // windows } // platforms } // vmime diff --git a/src/utility/filteredStream.cpp b/src/utility/filteredStream.cpp index 57846f96..6c6a8c1a 100644 --- a/src/utility/filteredStream.cpp +++ b/src/utility/filteredStream.cpp @@ -160,6 +160,13 @@ void dotFilteredOutputStream::write } +void dotFilteredOutputStream::flush() +{ + // Do nothing + m_stream.flush(); +} + + // CRLFToLFFilteredOutputStream CRLFToLFFilteredOutputStream::CRLFToLFFilteredOutputStream(outputStream& os) @@ -185,8 +192,8 @@ void CRLFToLFFilteredOutputStream::write const value_type* start = data; // Warning: if the whole buffer finishes with '\r', this - // last character will not be written back... - // TODO: add a finalize() method? + // last character will not be written back if flush() is + // not called if (m_previousChar == '\r') { if (*pos != '\n') @@ -228,6 +235,14 @@ void CRLFToLFFilteredOutputStream::write } +void CRLFToLFFilteredOutputStream::flush() +{ + m_stream.flush(); + + // TODO +} + + // stopSequenceFilteredInputStream <1> template <> diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp index c9f901ec..82748928 100644 --- a/src/utility/stream.cpp +++ b/src/utility/stream.cpp @@ -100,6 +100,12 @@ void outputStreamAdapter::write } +void outputStreamAdapter::flush() +{ + m_stream.flush(); +} + + // outputStreamStringAdapter @@ -116,6 +122,12 @@ void outputStreamStringAdapter::write(const value_type* const data, const size_t } +void outputStreamStringAdapter::flush() +{ + // Do nothing +} + + // outputStreamByteArrayAdapter @@ -132,6 +144,12 @@ void outputStreamByteArrayAdapter::write(const value_type* const data, const siz } +void outputStreamByteArrayAdapter::flush() +{ + // Do nothing +} + + // inputStreamAdapter @@ -421,6 +439,12 @@ void outputStreamSocketAdapter::write } +void outputStreamSocketAdapter::flush() +{ + // Do nothing +} + + // inputStreamSocketAdapter inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok) @@ -460,7 +484,5 @@ const stream::size_type inputStreamSocketAdapter::skip #endif // VMIME_HAVE_MESSAGING_FEATURES - - } // utility } // vmime |