aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/charsetConverter.cpp2
-rw-r--r--src/component.cpp1
-rw-r--r--src/encoding.cpp1
-rw-r--r--src/fileAttachment.cpp1
-rw-r--r--src/generatedMessageAttachment.cpp2
-rw-r--r--src/htmlTextPart.cpp2
-rw-r--r--src/mdn/MDNHelper.cpp2
-rw-r--r--src/mdn/receivedMDNInfos.cpp2
-rw-r--r--src/message.cpp2
-rw-r--r--src/net/imap/IMAPFolder.cpp2
-rw-r--r--src/net/imap/IMAPMessage.cpp2
-rw-r--r--src/net/imap/IMAPMessagePartContentHandler.cpp3
-rw-r--r--src/net/maildir/maildirFolder.cpp3
-rw-r--r--src/net/maildir/maildirMessage.cpp2
-rw-r--r--src/net/pop3/POP3Message.cpp2
-rw-r--r--src/net/pop3/POP3Store.cpp1
-rw-r--r--src/net/sendmail/sendmailTransport.cpp2
-rw-r--r--src/net/smtp/SMTPTransport.cpp2
-rw-r--r--src/net/transport.cpp3
-rw-r--r--src/parameter.cpp3
-rw-r--r--src/parsedMessageAttachment.cpp2
-rw-r--r--src/security/cert/X509Certificate.cpp2
-rw-r--r--src/security/sasl/SASLContext.cpp3
-rw-r--r--src/streamContentHandler.cpp4
-rw-r--r--src/stringContentHandler.cpp4
-rw-r--r--src/utility/encoder/defaultEncoder.cpp2
-rw-r--r--src/utility/inputStream.cpp33
-rw-r--r--src/utility/inputStreamAdapter.cpp70
-rw-r--r--src/utility/inputStreamByteBufferAdapter.cpp90
-rw-r--r--src/utility/inputStreamPointerAdapter.cpp46
-rw-r--r--src/utility/inputStreamSocketAdapter.cpp82
-rw-r--r--src/utility/inputStreamStringAdapter.cpp94
-rw-r--r--src/utility/inputStreamStringProxyAdapter.cpp89
-rw-r--r--src/utility/outputStream.cpp33
-rw-r--r--src/utility/outputStreamAdapter.cpp54
-rw-r--r--src/utility/outputStreamByteArrayAdapter.cpp51
-rw-r--r--src/utility/outputStreamSocketAdapter.cpp68
-rw-r--r--src/utility/outputStreamStringAdapter.cpp51
-rw-r--r--src/utility/stream.cpp485
-rw-r--r--src/utility/streamUtils.cpp92
-rw-r--r--src/utility/stringProxy.cpp2
-rw-r--r--src/word.cpp3
-rw-r--r--src/wordEncoder.cpp3
43 files changed, 918 insertions, 485 deletions
diff --git a/src/charsetConverter.cpp b/src/charsetConverter.cpp
index 2135788c..cf75bdda 100644
--- a/src/charsetConverter.cpp
+++ b/src/charsetConverter.cpp
@@ -23,6 +23,8 @@
#include "vmime/charsetConverter.hpp"
#include "vmime/exception.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
extern "C"
diff --git a/src/component.cpp b/src/component.cpp
index fbf677b5..139cf664 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -23,6 +23,7 @@
#include "vmime/component.hpp"
#include "vmime/base.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
#include <sstream>
diff --git a/src/encoding.cpp b/src/encoding.cpp
index b4e79db7..5d99ab63 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -24,6 +24,7 @@
#include "vmime/encoding.hpp"
#include "vmime/contentHandler.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
#include "vmime/utility/encoder/encoderFactory.hpp"
#include <algorithm>
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index da7c4b7d..cb23cd04 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -28,6 +28,7 @@
#include "vmime/exception.hpp"
#include "vmime/streamContentHandler.hpp"
+#include "vmime/utility/inputStreamPointerAdapter.hpp"
#include "vmime/contentDispositionField.hpp"
diff --git a/src/generatedMessageAttachment.cpp b/src/generatedMessageAttachment.cpp
index e9bd1a6e..443a9d30 100644
--- a/src/generatedMessageAttachment.cpp
+++ b/src/generatedMessageAttachment.cpp
@@ -23,6 +23,8 @@
#include "vmime/generatedMessageAttachment.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp
index c845b576..98524afb 100644
--- a/src/htmlTextPart.cpp
+++ b/src/htmlTextPart.cpp
@@ -31,6 +31,8 @@
#include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp
index b419b854..1dd7ff34 100644
--- a/src/mdn/MDNHelper.cpp
+++ b/src/mdn/MDNHelper.cpp
@@ -31,6 +31,8 @@
#include "vmime/path.hpp"
#include "vmime/dateTime.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/mdn/receivedMDNInfos.cpp b/src/mdn/receivedMDNInfos.cpp
index cff211cf..f97a58d4 100644
--- a/src/mdn/receivedMDNInfos.cpp
+++ b/src/mdn/receivedMDNInfos.cpp
@@ -23,6 +23,8 @@
#include "vmime/mdn/receivedMDNInfos.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace mdn {
diff --git a/src/message.cpp b/src/message.cpp
index 6f4b046a..1b4f0867 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -24,6 +24,8 @@
#include "vmime/message.hpp"
#include "vmime/options.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <sstream>
diff --git a/src/net/imap/IMAPFolder.cpp b/src/net/imap/IMAPFolder.cpp
index 50a2f2ba..81bf3861 100644
--- a/src/net/imap/IMAPFolder.cpp
+++ b/src/net/imap/IMAPFolder.cpp
@@ -34,6 +34,8 @@
#include "vmime/exception.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <algorithm>
#include <sstream>
diff --git a/src/net/imap/IMAPMessage.cpp b/src/net/imap/IMAPMessage.cpp
index bc661edf..702d5f2b 100644
--- a/src/net/imap/IMAPMessage.cpp
+++ b/src/net/imap/IMAPMessage.cpp
@@ -31,6 +31,8 @@
#include "vmime/net/imap/IMAPPart.hpp"
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <sstream>
#include <iterator>
#include <typeinfo>
diff --git a/src/net/imap/IMAPMessagePartContentHandler.cpp b/src/net/imap/IMAPMessagePartContentHandler.cpp
index 4e6ba97a..85c6ec21 100644
--- a/src/net/imap/IMAPMessagePartContentHandler.cpp
+++ b/src/net/imap/IMAPMessagePartContentHandler.cpp
@@ -23,6 +23,9 @@
#include "vmime/net/imap/IMAPMessagePartContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/maildir/maildirFolder.cpp b/src/net/maildir/maildirFolder.cpp
index d11ae3b8..8c4b2758 100644
--- a/src/net/maildir/maildirFolder.cpp
+++ b/src/net/maildir/maildirFolder.cpp
@@ -35,6 +35,9 @@
#include "vmime/exception.hpp"
#include "vmime/platform.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/maildir/maildirMessage.cpp b/src/net/maildir/maildirMessage.cpp
index 51cd1bad..4ab75e75 100644
--- a/src/net/maildir/maildirMessage.cpp
+++ b/src/net/maildir/maildirMessage.cpp
@@ -31,6 +31,8 @@
#include "vmime/exception.hpp"
#include "vmime/platform.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/net/pop3/POP3Message.cpp b/src/net/pop3/POP3Message.cpp
index 50f4f874..69ef004c 100644
--- a/src/net/pop3/POP3Message.cpp
+++ b/src/net/pop3/POP3Message.cpp
@@ -25,6 +25,8 @@
#include "vmime/net/pop3/POP3Folder.hpp"
#include "vmime/net/pop3/POP3Store.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <sstream>
diff --git a/src/net/pop3/POP3Store.cpp b/src/net/pop3/POP3Store.cpp
index 9d554c6d..793112a7 100644
--- a/src/net/pop3/POP3Store.cpp
+++ b/src/net/pop3/POP3Store.cpp
@@ -30,6 +30,7 @@
#include "vmime/security/digest/messageDigestFactory.hpp"
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/inputStreamSocketAdapter.hpp"
#include "vmime/net/defaultConnectionInfos.hpp"
diff --git a/src/net/sendmail/sendmailTransport.cpp b/src/net/sendmail/sendmailTransport.cpp
index 53ff0d15..e7762ccc 100644
--- a/src/net/sendmail/sendmailTransport.cpp
+++ b/src/net/sendmail/sendmailTransport.cpp
@@ -32,6 +32,8 @@
#include "vmime/utility/childProcess.hpp"
#include "vmime/utility/smartPtr.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
#include "vmime/net/defaultConnectionInfos.hpp"
#include "vmime/config.hpp"
diff --git a/src/net/smtp/SMTPTransport.cpp b/src/net/smtp/SMTPTransport.cpp
index d9fb7b86..bbbea755 100644
--- a/src/net/smtp/SMTPTransport.cpp
+++ b/src/net/smtp/SMTPTransport.cpp
@@ -30,6 +30,8 @@
#include "vmime/utility/filteredStream.hpp"
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/outputStreamSocketAdapter.hpp"
+#include "vmime/utility/streamUtils.hpp"
#include "vmime/net/defaultConnectionInfos.hpp"
diff --git a/src/net/transport.cpp b/src/net/transport.cpp
index dd4663d8..f8ca7b7a 100644
--- a/src/net/transport.cpp
+++ b/src/net/transport.cpp
@@ -27,6 +27,9 @@
#include "vmime/mailboxList.hpp"
#include "vmime/message.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime {
namespace net {
diff --git a/src/parameter.cpp b/src/parameter.cpp
index d757e1be..ccbe1a5b 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -27,6 +27,9 @@
#include "vmime/text.hpp"
#include "vmime/encoding.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+
namespace vmime
{
diff --git a/src/parsedMessageAttachment.cpp b/src/parsedMessageAttachment.cpp
index bde56aaf..cb7d71de 100644
--- a/src/parsedMessageAttachment.cpp
+++ b/src/parsedMessageAttachment.cpp
@@ -26,6 +26,8 @@
#include "vmime/stringContentHandler.hpp"
#include "vmime/contentDisposition.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/security/cert/X509Certificate.cpp b/src/security/cert/X509Certificate.cpp
index 1cd079c3..8df4e5e8 100644
--- a/src/security/cert/X509Certificate.cpp
+++ b/src/security/cert/X509Certificate.cpp
@@ -28,6 +28,8 @@
#include "vmime/security/cert/X509Certificate.hpp"
+#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
+
namespace vmime {
namespace security {
diff --git a/src/security/sasl/SASLContext.cpp b/src/security/sasl/SASLContext.cpp
index 51c2bed0..4bb33c14 100644
--- a/src/security/sasl/SASLContext.cpp
+++ b/src/security/sasl/SASLContext.cpp
@@ -33,6 +33,9 @@
#include "vmime/utility/encoder/encoderFactory.hpp"
#include "vmime/utility/stream.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
namespace vmime {
diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp
index 2ebd073a..89a36b4f 100644
--- a/src/streamContentHandler.cpp
+++ b/src/streamContentHandler.cpp
@@ -23,6 +23,10 @@
#include "vmime/streamContentHandler.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
namespace vmime
{
diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp
index 4e85a6ce..5a1e72cd 100644
--- a/src/stringContentHandler.cpp
+++ b/src/stringContentHandler.cpp
@@ -23,6 +23,10 @@
#include "vmime/stringContentHandler.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
namespace vmime
{
diff --git a/src/utility/encoder/defaultEncoder.cpp b/src/utility/encoder/defaultEncoder.cpp
index 4d0ffb5d..e2d226e6 100644
--- a/src/utility/encoder/defaultEncoder.cpp
+++ b/src/utility/encoder/defaultEncoder.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/encoder/defaultEncoder.hpp"
+#include "vmime/utility/streamUtils.hpp"
+
namespace vmime {
namespace utility {
diff --git a/src/utility/inputStream.cpp b/src/utility/inputStream.cpp
new file mode 100644
index 00000000..dd0adf4d
--- /dev/null
+++ b/src/utility/inputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamAdapter.cpp b/src/utility/inputStreamAdapter.cpp
new file mode 100644
index 00000000..b44b0841
--- /dev/null
+++ b/src/utility/inputStreamAdapter.cpp
@@ -0,0 +1,70 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamAdapter::inputStreamAdapter(std::istream& is)
+ : m_stream(is)
+{
+}
+
+
+bool inputStreamAdapter::eof() const
+{
+ return (m_stream.eof());
+}
+
+
+void inputStreamAdapter::reset()
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.seekg(0, std::ios::beg);
+ m_stream.clear();
+}
+
+
+stream::size_type inputStreamAdapter::read
+ (value_type* const data, const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.read(data, count);
+ return (m_stream.gcount());
+}
+
+
+stream::size_type inputStreamAdapter::skip(const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.ignore(count);
+ return (m_stream.gcount());
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamByteBufferAdapter.cpp b/src/utility/inputStreamByteBufferAdapter.cpp
new file mode 100644
index 00000000..92e779fe
--- /dev/null
+++ b/src/utility/inputStreamByteBufferAdapter.cpp
@@ -0,0 +1,90 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamByteBufferAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
+ : m_buffer(buffer), m_length(length), m_pos(0)
+{
+}
+
+
+bool inputStreamByteBufferAdapter::eof() const
+{
+ return m_pos >= m_length;
+}
+
+
+void inputStreamByteBufferAdapter::reset()
+{
+ m_pos = 0;
+}
+
+
+stream::size_type inputStreamByteBufferAdapter::read
+ (value_type* const data, const size_type count)
+{
+ const size_type remaining = m_length - m_pos;
+
+ if (remaining < count)
+ {
+ std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
+ m_pos += remaining;
+
+ return remaining;
+ }
+ else
+ {
+ std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
+ m_pos += count;
+
+ return count;
+ }
+}
+
+
+stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
+{
+ const size_type remaining = m_length - m_pos;
+
+ if (remaining < count)
+ {
+ m_pos += remaining;
+ return remaining;
+ }
+ else
+ {
+ m_pos += count;
+ return count;
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamPointerAdapter.cpp b/src/utility/inputStreamPointerAdapter.cpp
new file mode 100644
index 00000000..4d03e306
--- /dev/null
+++ b/src/utility/inputStreamPointerAdapter.cpp
@@ -0,0 +1,46 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamPointerAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
+ : inputStreamAdapter(*is), m_stream(is), m_own(own)
+{
+}
+
+
+inputStreamPointerAdapter::~inputStreamPointerAdapter()
+{
+ if (m_own)
+ delete (m_stream);
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamSocketAdapter.cpp b/src/utility/inputStreamSocketAdapter.cpp
new file mode 100644
index 00000000..b93cc3cd
--- /dev/null
+++ b/src/utility/inputStreamSocketAdapter.cpp
@@ -0,0 +1,82 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamSocketAdapter.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include "vmime/net/socket.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
+ : m_socket(sok)
+{
+}
+
+
+bool inputStreamSocketAdapter::eof() const
+{
+ // Can't know...
+ return false;
+}
+
+
+void inputStreamSocketAdapter::reset()
+{
+ // Not supported
+}
+
+
+stream::size_type inputStreamSocketAdapter::read
+ (value_type* const data, const size_type count)
+{
+ return m_socket.receiveRaw(data, count);
+}
+
+
+stream::size_type inputStreamSocketAdapter::skip
+ (const size_type /* count */)
+{
+ // Not supported
+ return 0;
+}
+
+
+stream::size_type inputStreamSocketAdapter::getBlockSize()
+{
+ return m_socket.getBlockSize();
+}
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
diff --git a/src/utility/inputStreamStringAdapter.cpp b/src/utility/inputStreamStringAdapter.cpp
new file mode 100644
index 00000000..31c9fdaf
--- /dev/null
+++ b/src/utility/inputStreamStringAdapter.cpp
@@ -0,0 +1,94 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
+ : m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
+{
+}
+
+
+inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
+ const string::size_type begin, const string::size_type end)
+ : m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
+{
+}
+
+
+bool inputStreamStringAdapter::eof() const
+{
+ return (m_pos >= m_end);
+}
+
+
+void inputStreamStringAdapter::reset()
+{
+ m_pos = m_begin;
+}
+
+
+stream::size_type inputStreamStringAdapter::read
+ (value_type* const data, const size_type count)
+{
+ if (m_pos + count >= m_end)
+ {
+ const size_type remaining = m_end - m_pos;
+
+ std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
+ m_pos = m_end;
+ return (remaining);
+ }
+ else
+ {
+ std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+stream::size_type inputStreamStringAdapter::skip(const size_type count)
+{
+ if (m_pos + count >= m_end)
+ {
+ const size_type remaining = m_end - m_pos;
+ m_pos = m_end;
+ return (remaining);
+ }
+ else
+ {
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/inputStreamStringProxyAdapter.cpp b/src/utility/inputStreamStringProxyAdapter.cpp
new file mode 100644
index 00000000..5e4b60b9
--- /dev/null
+++ b/src/utility/inputStreamStringProxyAdapter.cpp
@@ -0,0 +1,89 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/inputStreamStringProxyAdapter.hpp"
+#include "vmime/utility/stringProxy.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
+ : m_buffer(buffer), m_pos(0)
+{
+}
+
+
+bool inputStreamStringProxyAdapter::eof() const
+{
+ return (m_pos >= m_buffer.length());
+}
+
+
+void inputStreamStringProxyAdapter::reset()
+{
+ m_pos = 0;
+}
+
+
+stream::size_type inputStreamStringProxyAdapter::read
+ (value_type* const data, const size_type count)
+{
+ const size_type remaining = m_buffer.length() - m_pos;
+
+ if (count > remaining)
+ {
+ std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
+ m_pos = m_buffer.length();
+ return (remaining);
+ }
+ else
+ {
+ std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
+{
+ const size_type remaining = m_buffer.length() - m_pos;
+
+ if (count > remaining)
+ {
+ m_pos = m_buffer.length();
+ return (remaining);
+ }
+ else
+ {
+ m_pos += count;
+ return (count);
+ }
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStream.cpp b/src/utility/outputStream.cpp
new file mode 100644
index 00000000..8a65db53
--- /dev/null
+++ b/src/utility/outputStream.cpp
@@ -0,0 +1,33 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/outputStream.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamAdapter.cpp b/src/utility/outputStreamAdapter.cpp
new file mode 100644
index 00000000..2da94f16
--- /dev/null
+++ b/src/utility/outputStreamAdapter.cpp
@@ -0,0 +1,54 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/outputStreamAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamAdapter::outputStreamAdapter(std::ostream& os)
+ : m_stream(os)
+{
+}
+
+
+void outputStreamAdapter::write
+ (const value_type* const data, const size_type count)
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.write(data, count);
+}
+
+
+void outputStreamAdapter::flush()
+{
+ m_stream.exceptions(std::ios_base::badbit);
+ m_stream.flush();
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamByteArrayAdapter.cpp b/src/utility/outputStreamByteArrayAdapter.cpp
new file mode 100644
index 00000000..97b27d2b
--- /dev/null
+++ b/src/utility/outputStreamByteArrayAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/outputStreamByteArrayAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
+ : m_array(array)
+{
+}
+
+
+void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
+{
+ m_array.insert(m_array.end(), data, data + count);
+}
+
+
+void outputStreamByteArrayAdapter::flush()
+{
+ // Do nothing
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/outputStreamSocketAdapter.cpp b/src/utility/outputStreamSocketAdapter.cpp
new file mode 100644
index 00000000..d933e73d
--- /dev/null
+++ b/src/utility/outputStreamSocketAdapter.cpp
@@ -0,0 +1,68 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/outputStreamSocketAdapter.hpp"
+
+
+#if VMIME_HAVE_MESSAGING_FEATURES
+
+
+#include "vmime/net/socket.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
+ : m_socket(sok)
+{
+}
+
+
+void outputStreamSocketAdapter::write
+ (const value_type* const data, const size_type count)
+{
+ m_socket.sendRaw(data, count);
+}
+
+
+void outputStreamSocketAdapter::flush()
+{
+ // Do nothing
+}
+
+
+stream::size_type outputStreamSocketAdapter::getBlockSize()
+{
+ return m_socket.getBlockSize();
+}
+
+
+
+} // utility
+} // vmime
+
+
+#endif // VMIME_HAVE_MESSAGING_FEATURES
+
diff --git a/src/utility/outputStreamStringAdapter.cpp b/src/utility/outputStreamStringAdapter.cpp
new file mode 100644
index 00000000..62b2a72c
--- /dev/null
+++ b/src/utility/outputStreamStringAdapter.cpp
@@ -0,0 +1,51 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
+ : m_buffer(buffer)
+{
+}
+
+
+void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
+{
+ m_buffer.append(data, count);
+}
+
+
+void outputStreamStringAdapter::flush()
+{
+ // Do nothing
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index ec30b7d3..1c940c2a 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -22,503 +22,18 @@
//
#include "vmime/utility/stream.hpp"
-#include "vmime/utility/stringProxy.hpp"
-#include <algorithm> // for std::copy
-#include <iterator> // for std::back_inserter
-
-#if VMIME_HAVE_MESSAGING_FEATURES
- #include "vmime/net/socket.hpp"
-#endif
namespace vmime {
namespace utility {
-// stream
-
stream::size_type stream::getBlockSize()
{
return 32768; // 32 KB
}
-// Helpers
-
-outputStream& operator<<(outputStream& os, const stream::value_type c)
-{
- os.write(&c, 1);
- return (os);
-}
-
-
-outputStream& operator<<(outputStream& os, const string& str)
-{
- os.write(str.data(), str.length());
- return (os);
-}
-
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
-{
- return bufferedStreamCopy(is, os, 0, NULL);
-}
-
-
-stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
- const stream::size_type length, progressListener* progress)
-{
- const stream::size_type blockSize =
- std::min(is.getBlockSize(), os.getBlockSize());
-
- std::vector <stream::value_type> vbuffer(blockSize);
-
- stream::value_type* buffer = &vbuffer.front();
- stream::size_type total = 0;
-
- if (progress != NULL)
- progress->start(length);
-
- while (!is.eof())
- {
- const stream::size_type read = is.read(buffer, blockSize);
-
- if (read != 0)
- {
- os.write(buffer, read);
- total += read;
-
- if (progress != NULL)
- progress->progress(total, std::max(total, length));
- }
- }
-
- if (progress != NULL)
- progress->stop(total);
-
- return (total);
-}
-
-
-
-// outputStreamAdapter
-
-outputStreamAdapter::outputStreamAdapter(std::ostream& os)
- : m_stream(os)
-{
-}
-
-
-void outputStreamAdapter::write
- (const value_type* const data, const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.write(data, count);
-}
-
-
-void outputStreamAdapter::flush()
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.flush();
-}
-
-
-
-// outputStreamStringAdapter
-
-outputStreamStringAdapter::outputStreamStringAdapter(string& buffer)
- : m_buffer(buffer)
-{
-}
-
-
-void outputStreamStringAdapter::write(const value_type* const data, const size_type count)
-{
- m_buffer.append(data, count);
-}
-
-
-void outputStreamStringAdapter::flush()
-{
- // Do nothing
-}
-
-
-
-// outputStreamByteArrayAdapter
-
-outputStreamByteArrayAdapter::outputStreamByteArrayAdapter(byteArray& array)
- : m_array(array)
-{
-}
-
-
-void outputStreamByteArrayAdapter::write(const value_type* const data, const size_type count)
-{
- m_array.insert(m_array.end(), data, data + count);
-}
-
-
-void outputStreamByteArrayAdapter::flush()
-{
- // Do nothing
-}
-
-
-
-// inputStreamAdapter
-
-inputStreamAdapter::inputStreamAdapter(std::istream& is)
- : m_stream(is)
-{
-}
-
-
-bool inputStreamAdapter::eof() const
-{
- return (m_stream.eof());
-}
-
-
-void inputStreamAdapter::reset()
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.seekg(0, std::ios::beg);
- m_stream.clear();
-}
-
-
-stream::size_type inputStreamAdapter::read
- (value_type* const data, const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.read(data, count);
- return (m_stream.gcount());
-}
-
-
-stream::size_type inputStreamAdapter::skip(const size_type count)
-{
- m_stream.exceptions(std::ios_base::badbit);
- m_stream.ignore(count);
- return (m_stream.gcount());
-}
-
-
-
-// inputStreamStringAdapter
-
-inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer)
- : m_buffer(buffer), m_begin(0), m_end(buffer.length()), m_pos(0)
-{
-}
-
-
-inputStreamStringAdapter::inputStreamStringAdapter(const string& buffer,
- const string::size_type begin, const string::size_type end)
- : m_buffer(buffer), m_begin(begin), m_end(end), m_pos(begin)
-{
-}
-
-
-bool inputStreamStringAdapter::eof() const
-{
- return (m_pos >= m_end);
-}
-
-
-void inputStreamStringAdapter::reset()
-{
- m_pos = m_begin;
-}
-
-
-stream::size_type inputStreamStringAdapter::read
- (value_type* const data, const size_type count)
-{
- if (m_pos + count >= m_end)
- {
- const size_type remaining = m_end - m_pos;
-
- std::copy(m_buffer.begin() + m_pos, m_buffer.end(), data);
- m_pos = m_end;
- return (remaining);
- }
- else
- {
- std::copy(m_buffer.begin() + m_pos, m_buffer.begin() + m_pos + count, data);
- m_pos += count;
- return (count);
- }
-}
-
-
-stream::size_type inputStreamStringAdapter::skip(const size_type count)
-{
- if (m_pos + count >= m_end)
- {
- const size_type remaining = m_end - m_pos;
- m_pos = m_end;
- return (remaining);
- }
- else
- {
- m_pos += count;
- return (count);
- }
-}
-
-
-
-// inputStreamStringProxyAdapter
-
-inputStreamStringProxyAdapter::inputStreamStringProxyAdapter(const stringProxy& buffer)
- : m_buffer(buffer), m_pos(0)
-{
-}
-
-
-bool inputStreamStringProxyAdapter::eof() const
-{
- return (m_pos >= m_buffer.length());
-}
-
-
-void inputStreamStringProxyAdapter::reset()
-{
- m_pos = 0;
-}
-
-
-stream::size_type inputStreamStringProxyAdapter::read
- (value_type* const data, const size_type count)
-{
- const size_type remaining = m_buffer.length() - m_pos;
-
- if (count > remaining)
- {
- std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_end(), data);
- m_pos = m_buffer.length();
- return (remaining);
- }
- else
- {
- std::copy(m_buffer.it_begin() + m_pos, m_buffer.it_begin() + m_pos + count, data);
- m_pos += count;
- return (count);
- }
-}
-
-
-stream::size_type inputStreamStringProxyAdapter::skip(const size_type count)
-{
- const size_type remaining = m_buffer.length() - m_pos;
-
- if (count > remaining)
- {
- m_pos = m_buffer.length();
- return (remaining);
- }
- else
- {
- m_pos += count;
- return (count);
- }
-}
-
-
-
-// inputStreamPointerAdapter
-
-inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const bool own)
- : m_stream(is), m_own(own)
-{
-}
-
-
-inputStreamPointerAdapter::inputStreamPointerAdapter(const inputStreamPointerAdapter&)
- : inputStream(), m_stream(NULL), m_own(false)
-{
- // Not copiable
-}
-
-
-inputStreamPointerAdapter::~inputStreamPointerAdapter()
-{
- if (m_own)
- delete (m_stream);
-}
-
-
-bool inputStreamPointerAdapter::eof() const
-{
- return (m_stream->eof());
-}
-
-
-void inputStreamPointerAdapter::reset()
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->seekg(0, std::ios::beg);
- m_stream->clear();
-}
-
-
-stream::size_type inputStreamPointerAdapter::read
- (value_type* const data, const size_type count)
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->read(data, count);
- return (m_stream->gcount());
-}
-
-
-stream::size_type inputStreamPointerAdapter::skip(const size_type count)
-{
- m_stream->exceptions(std::ios_base::badbit);
- m_stream->ignore(count);
- return (m_stream->gcount());
-}
-
-
-
-// inputStreamByteBufferAdapter
-
-inputStreamByteBufferAdapter::inputStreamByteBufferAdapter(const byte_t* buffer, const size_type length)
- : m_buffer(buffer), m_length(length), m_pos(0)
-{
-}
-
-
-bool inputStreamByteBufferAdapter::eof() const
-{
- return m_pos >= m_length;
-}
-
-
-void inputStreamByteBufferAdapter::reset()
-{
- m_pos = 0;
-}
-
-
-stream::size_type inputStreamByteBufferAdapter::read
- (value_type* const data, const size_type count)
-{
- const size_type remaining = m_length - m_pos;
-
- if (remaining < count)
- {
- std::copy(m_buffer + m_pos, m_buffer + m_pos + remaining, data);
- m_pos += remaining;
-
- return remaining;
- }
- else
- {
- std::copy(m_buffer + m_pos, m_buffer + m_pos + count, data);
- m_pos += count;
-
- return count;
- }
-}
-
-
-stream::size_type inputStreamByteBufferAdapter::skip(const size_type count)
-{
- const size_type remaining = m_length - m_pos;
-
- if (remaining < count)
- {
- m_pos += remaining;
- return remaining;
- }
- else
- {
- m_pos += count;
- return count;
- }
-}
-
-
-
-#ifdef VMIME_HAVE_MESSAGING_FEATURES
-
-
-// outputStreamSocketAdapter
-
-outputStreamSocketAdapter::outputStreamSocketAdapter(net::socket& sok)
- : m_socket(sok)
-{
-}
-
-
-void outputStreamSocketAdapter::write
- (const value_type* const data, const size_type count)
-{
- m_socket.sendRaw(data, count);
-}
-
-
-void outputStreamSocketAdapter::flush()
-{
- // Do nothing
-}
-
-
-stream::size_type outputStreamSocketAdapter::getBlockSize()
-{
- return m_socket.getBlockSize();
-}
-
-
-
-// inputStreamSocketAdapter
-
-inputStreamSocketAdapter::inputStreamSocketAdapter(net::socket& sok)
- : m_socket(sok)
-{
-}
-
-
-bool inputStreamSocketAdapter::eof() const
-{
- // Can't know...
- return false;
-}
-
-
-void inputStreamSocketAdapter::reset()
-{
- // Not supported
-}
-
-
-stream::size_type inputStreamSocketAdapter::read
- (value_type* const data, const size_type count)
-{
- return m_socket.receiveRaw(data, count);
-}
-
-
-stream::size_type inputStreamSocketAdapter::skip
- (const size_type /* count */)
-{
- // Not supported
- return 0;
-}
-
-
-stream::size_type inputStreamSocketAdapter::getBlockSize()
-{
- return m_socket.getBlockSize();
-}
-
-
-#endif // VMIME_HAVE_MESSAGING_FEATURES
-
-
} // utility
} // vmime
diff --git a/src/utility/streamUtils.cpp b/src/utility/streamUtils.cpp
new file mode 100644
index 00000000..f1d3b9de
--- /dev/null
+++ b/src/utility/streamUtils.cpp
@@ -0,0 +1,92 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2012 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/utility/streamUtils.hpp"
+
+#include <algorithm> // for std::copy
+#include <iterator> // for std::back_inserter
+
+
+
+namespace vmime {
+namespace utility {
+
+
+outputStream& operator<<(outputStream& os, const stream::value_type c)
+{
+ os.write(&c, 1);
+ return (os);
+}
+
+
+outputStream& operator<<(outputStream& os, const string& str)
+{
+ os.write(str.data(), str.length());
+ return (os);
+}
+
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os)
+{
+ return bufferedStreamCopy(is, os, 0, NULL);
+}
+
+
+stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os,
+ const stream::size_type length, progressListener* progress)
+{
+ const stream::size_type blockSize =
+ std::min(is.getBlockSize(), os.getBlockSize());
+
+ std::vector <stream::value_type> vbuffer(blockSize);
+
+ stream::value_type* buffer = &vbuffer.front();
+ stream::size_type total = 0;
+
+ if (progress != NULL)
+ progress->start(length);
+
+ while (!is.eof())
+ {
+ const stream::size_type read = is.read(buffer, blockSize);
+
+ if (read != 0)
+ {
+ os.write(buffer, read);
+ total += read;
+
+ if (progress != NULL)
+ progress->progress(total, std::max(total, length));
+ }
+ }
+
+ if (progress != NULL)
+ progress->stop(total);
+
+ return (total);
+}
+
+
+} // utility
+} // vmime
+
diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp
index a4ba6d22..74344b57 100644
--- a/src/utility/stringProxy.cpp
+++ b/src/utility/stringProxy.cpp
@@ -23,6 +23,8 @@
#include "vmime/utility/stringProxy.hpp"
+#include "vmime/utility/outputStreamAdapter.hpp"
+
#include <iterator>
#include <algorithm>
diff --git a/src/word.cpp b/src/word.cpp
index aeaa7371..79060a18 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -28,6 +28,9 @@
#include "vmime/utility/smartPtr.hpp"
#include "vmime/parserHelpers.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
#include "vmime/utility/encoder/encoder.hpp"
#include "vmime/utility/encoder/b64Encoder.hpp"
#include "vmime/utility/encoder/qpEncoder.hpp"
diff --git a/src/wordEncoder.cpp b/src/wordEncoder.cpp
index 67bd7a1d..194a1890 100644
--- a/src/wordEncoder.cpp
+++ b/src/wordEncoder.cpp
@@ -33,6 +33,9 @@
#include "vmime/utility/stringUtils.hpp"
+#include "vmime/utility/outputStreamStringAdapter.hpp"
+#include "vmime/utility/inputStreamStringAdapter.hpp"
+
namespace vmime
{