1 // 2 // VMime library (http://www.vmime.org) 3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org> 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License as 7 // published by the Free Software Foundation; either version 3 of 8 // the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License along 16 // with this program; if not, write to the Free Software Foundation, Inc., 17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 // 19 // Linking this library statically or dynamically with other modules is making 20 // a combined work based on this library. Thus, the terms and conditions of 21 // the GNU General Public License cover the whole combination. 22 // 23 24 #ifndef VMIME_STRINGCONTENTHANDLER_HPP_INCLUDED 25 #define VMIME_STRINGCONTENTHANDLER_HPP_INCLUDED 26 27 28 #include "vmime/contentHandler.hpp" 29 30 31 namespace vmime 32 { 33 34 35 class VMIME_EXPORT stringContentHandler : public contentHandler 36 { 37 public: 38 39 stringContentHandler(); 40 stringContentHandler(const string& buffer, const vmime::encoding& enc = NO_ENCODING); 41 stringContentHandler(const utility::stringProxy& str, const vmime::encoding& enc = NO_ENCODING); 42 stringContentHandler(const string& buffer, const size_t start, const size_t end, const vmime::encoding& enc = NO_ENCODING); 43 44 ~stringContentHandler(); 45 46 stringContentHandler(const stringContentHandler& cts); 47 stringContentHandler& operator=(const stringContentHandler& cts); 48 49 shared_ptr <contentHandler> clone() const; 50 51 // Set the data contained in the body. 52 // 53 // The two first functions take advantage of the COW (copy-on-write) system that 54 // might be implemented into std::string. This is done using "stringProxy" object. 55 // 56 // Set "enc" parameter to anything other than NO_ENCODING if the data managed by 57 // this content handler is already encoded with the specified encoding (so, no 58 // encoding/decoding will be performed on generate()/extract()). Note that the 59 // data may be re-encoded (that is, decoded and encoded) if the encoding passed 60 // to generate() is different from this one... 61 void setData(const utility::stringProxy& str, const vmime::encoding& enc = NO_ENCODING); 62 void setData(const string& buffer, const vmime::encoding& enc = NO_ENCODING); 63 void setData(const string& buffer, const size_t start, const size_t end, const vmime::encoding& enc = NO_ENCODING); 64 65 stringContentHandler& operator=(const string& buffer); 66 67 void generate(utility::outputStream& os, const vmime::encoding& enc, const size_t maxLineLength = lineLengthLimits::infinite) const; 68 69 void extract(utility::outputStream& os, utility::progressListener* progress = NULL) const; 70 void extractRaw(utility::outputStream& os, utility::progressListener* progress = NULL) const; 71 72 size_t getLength() const; 73 74 bool isEncoded() const; 75 76 const vmime::encoding& getEncoding() const; 77 78 bool isEmpty() const; 79 80 bool isBuffered() const; 81 82 void setContentTypeHint(const mediaType& type); 83 const mediaType getContentTypeHint() const; 84 85 private: 86 87 mediaType m_contentType; 88 89 // Equals to NO_ENCODING if data is not encoded, otherwise this 90 // specifies the encoding that have been used to encode the data. 91 vmime::encoding m_encoding; 92 93 // The actual data 94 utility::stringProxy m_string; 95 }; 96 97 98 } // vmime 99 100 101 #endif // VMIME_STRINGCONTENTHANDLER_HPP_INCLUDED 102