From 53f96cdb7514cab91f3c9ca204ec83cf6fc41664 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 6 Jul 2005 20:28:43 +0000 Subject: [PATCH] Added contentHandler::extractRaw(). --- ChangeLog | 5 +++++ src/emptyContentHandler.cpp | 6 ++++++ src/streamContentHandler.cpp | 14 ++++++++++++++ src/stringContentHandler.cpp | 6 ++++++ vmime/contentHandler.hpp | 10 ++++++++++ vmime/emptyContentHandler.hpp | 1 + vmime/streamContentHandler.hpp | 1 + vmime/stringContentHandler.hpp | 1 + 8 files changed, 44 insertions(+) diff --git a/ChangeLog b/ChangeLog index b7b804e4..a0d4f8a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ VERSION 0.7.2cvs ================ +2005-07-06 Vincent Richard + + * *contentHandler.{hpp|cpp}: added extractRaw() method to allow extracting + data without performing any decoding. + 2005-06-22 Vincent Richard * Started version 0.7.2. diff --git a/src/emptyContentHandler.cpp b/src/emptyContentHandler.cpp index dceef55e..4dea2763 100644 --- a/src/emptyContentHandler.cpp +++ b/src/emptyContentHandler.cpp @@ -48,6 +48,12 @@ void emptyContentHandler::extract(utility::outputStream& /* os */) const } +void emptyContentHandler::extractRaw(utility::outputStream& /* os */) const +{ + // Nothing to do. +} + + const string::size_type emptyContentHandler::getLength() const { return (0); diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp index 5da7ffba..c5f6145c 100644 --- a/src/streamContentHandler.cpp +++ b/src/streamContentHandler.cpp @@ -179,6 +179,20 @@ void streamContentHandler::extract(utility::outputStream& os) const } +void streamContentHandler::extractRaw(utility::outputStream& os) const +{ + if (m_stream == NULL && m_ownedStream.ptr() == NULL) + return; + + utility::inputStream& in = const_cast + (*(m_stream ? m_stream : m_ownedStream.ptr())); + + in.reset(); // may not work... + + utility::bufferedStreamCopy(in, os); +} + + const string::size_type streamContentHandler::getLength() const { return (m_length); diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp index 812d8550..1d4ccc5c 100644 --- a/src/stringContentHandler.cpp +++ b/src/stringContentHandler.cpp @@ -165,6 +165,12 @@ void stringContentHandler::extract(utility::outputStream& os) const } +void stringContentHandler::extractRaw(utility::outputStream& os) const +{ + m_string.extract(os); +} + + const string::size_type stringContentHandler::getLength() const { return (m_string.length()); diff --git a/vmime/contentHandler.hpp b/vmime/contentHandler.hpp index 7f491f2e..45cbb48e 100644 --- a/vmime/contentHandler.hpp +++ b/vmime/contentHandler.hpp @@ -63,10 +63,20 @@ public: /** Extract the contents into the specified stream. If needed, data * will be decoded before being written into the stream. * + * @throw exceptions::no_encoder_available if the encoding is + * not supported * @param os output stream */ virtual void extract(utility::outputStream& os) const = 0; + /** Extract the contents into the specified stream, without + * decoding it. It may be useful in case the encoding is not + * supported and you want to extract raw data. + * + * @param os output stream + */ + virtual void extractRaw(utility::outputStream& os) const = 0; + /** Returns the actual length of data. WARNING: this can return 0 if no * length was specified when setting data of this object. * diff --git a/vmime/emptyContentHandler.hpp b/vmime/emptyContentHandler.hpp index ca44a12c..cee2fcbb 100644 --- a/vmime/emptyContentHandler.hpp +++ b/vmime/emptyContentHandler.hpp @@ -39,6 +39,7 @@ public: void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os) const; + void extractRaw(utility::outputStream& os) const; const string::size_type getLength() const; diff --git a/vmime/streamContentHandler.hpp b/vmime/streamContentHandler.hpp index 15ae280f..1dfa4071 100644 --- a/vmime/streamContentHandler.hpp +++ b/vmime/streamContentHandler.hpp @@ -48,6 +48,7 @@ public: void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os) const; + void extractRaw(utility::outputStream& os) const; const string::size_type getLength() const; diff --git a/vmime/stringContentHandler.hpp b/vmime/stringContentHandler.hpp index 1d75ceba..f3e905fa 100644 --- a/vmime/stringContentHandler.hpp +++ b/vmime/stringContentHandler.hpp @@ -66,6 +66,7 @@ public: void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const; void extract(utility::outputStream& os) const; + void extractRaw(utility::outputStream& os) const; const string::size_type getLength() const;