aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-04-16 12:03:13 +0200
committerVincent Richard <[email protected]>2013-04-16 12:03:13 +0200
commit462311e382834bc893df9433b916f28ae9830090 (patch)
treebd06919a108eeff55ef8e0a7031885fcb573b60c /src/utility
parentIssue #4: set envelope sender. (diff)
downloadvmime-462311e382834bc893df9433b916f28ae9830090.tar.gz
vmime-462311e382834bc893df9433b916f28ae9830090.zip
Added filtered output stream to transform LFs to CRLFs.
Diffstat (limited to 'src/utility')
-rw-r--r--src/utility/filteredStream.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/utility/filteredStream.cpp b/src/utility/filteredStream.cpp
index 9af7b32a..294a7a94 100644
--- a/src/utility/filteredStream.cpp
+++ b/src/utility/filteredStream.cpp
@@ -286,6 +286,77 @@ void CRLFToLFFilteredOutputStream::flush()
}
+// LFToCRLFFilteredOutputStream
+
+LFToCRLFFilteredOutputStream::LFToCRLFFilteredOutputStream(outputStream& os)
+ : m_stream(os), m_previousChar('\0')
+{
+}
+
+
+outputStream& LFToCRLFFilteredOutputStream::getNextOutputStream()
+{
+ return (m_stream);
+}
+
+
+void LFToCRLFFilteredOutputStream::write
+ (const value_type* const data, const size_type count)
+{
+ if (count == 0)
+ return;
+
+ std::string buffer;
+ buffer.reserve(count);
+
+ const value_type* pos = data;
+ const value_type* end = data + count;
+
+ value_type previousChar = m_previousChar;
+
+ while (pos < end)
+ {
+ switch (*pos)
+ {
+ case '\r':
+
+ buffer.append(1, '\r');
+ buffer.append(1, '\n');
+
+ break;
+
+ case '\n':
+
+ if (previousChar != '\r')
+ {
+ buffer.append(1, '\r');
+ buffer.append(1, '\n');
+ }
+
+ break;
+
+ default:
+
+ buffer.append(1, *pos);
+ break;
+ }
+
+ previousChar = *pos;
+ ++pos;
+ }
+
+ m_stream.write(&buffer[0], buffer.length());
+
+ m_previousChar = previousChar;
+}
+
+
+void LFToCRLFFilteredOutputStream::flush()
+{
+ m_stream.flush();
+}
+
+
// stopSequenceFilteredInputStream <1>
template <>