diff options
Diffstat (limited to 'vmime')
-rw-r--r-- | vmime/body.hpp | 53 | ||||
-rw-r--r-- | vmime/charset.hpp | 13 | ||||
-rw-r--r-- | vmime/contentHandler.hpp | 7 | ||||
-rw-r--r-- | vmime/emptyContentHandler.hpp | 2 | ||||
-rw-r--r-- | vmime/encoding.hpp | 35 | ||||
-rw-r--r-- | vmime/net/imap/IMAPMessagePartContentHandler.hpp | 2 | ||||
-rw-r--r-- | vmime/streamContentHandler.hpp | 2 | ||||
-rw-r--r-- | vmime/stringContentHandler.hpp | 2 |
8 files changed, 108 insertions, 8 deletions
diff --git a/vmime/body.hpp b/vmime/body.hpp index 80c1bb5d..9e83d6b5 100644 --- a/vmime/body.hpp +++ b/vmime/body.hpp @@ -184,6 +184,45 @@ public: */ void setContents(ref <const contentHandler> contents); + /** Set the body contents and type. + * + * @param contents new body contents + * @param type type of contents + */ + void setContents(ref <const contentHandler> contents, const mediaType& type); + + /** Set the body contents, type and charset. + * + * @param contents new body contents + * @param type type of contents + * @param charset charset of contents + */ + void setContents(ref <const contentHandler> contents, const mediaType& type, const charset& chset); + + /** Set the body contents, type, charset and encoding. + * + * @param contents new body contents + * @param type type of contents + * @param charset charset of contents + * @param encoding contents encoding + */ + void setContents(ref <const contentHandler> contents, const mediaType& type, + const charset& chset, const encoding& enc); + + /** Set the MIME type and charset of contents. + * If a charset is defined, it will not be modified. + * + * @param type MIME media type of contents + * @param chset charset of contents + */ + void setContentType(const mediaType& type, const charset& chset); + + /** Set the MIME type of contents. + * + * @param type MIME media type of contents + */ + void setContentType(const mediaType& type); + /** Return the media type of the data contained in the body contents. * This is a shortcut for getHeader()->ContentType()->getValue() * on the parent part. @@ -192,6 +231,13 @@ public: */ const mediaType getContentType() const; + /** Set the charset of contents. + * If the type is not set, it will be set to default "text/plain" type. + * + * @param chset charset of contents + */ + void setCharset(const charset& chset); + /** Return the charset of the data contained in the body contents. * This is a shortcut for getHeader()->ContentType()->getCharset() * on the parent part. @@ -200,6 +246,13 @@ public: */ const charset getCharset() const; + /** Set the output encoding of contents. + * Contents will be encoded (or re-encoded) when this node is being generated. + * + * @param enc encoding of contents + */ + void setEncoding(const encoding& enc); + /** Return the encoding used to encode the body contents. * This is a shortcut for getHeader()->ContentTransferEncoding()->getValue() * on the parent part. diff --git a/vmime/charset.hpp b/vmime/charset.hpp index 1d25b748..b2e241cc 100644 --- a/vmime/charset.hpp +++ b/vmime/charset.hpp @@ -33,6 +33,9 @@ namespace vmime { +class encoding; // forward reference + + /** Charset description (basic type). */ @@ -59,6 +62,16 @@ public: const std::vector <ref <const component> > getChildComponents() const; + /** Gets the recommended encoding for this charset. + * Note: there may be no recommended encoding. + * + * @param enc output parameter that will hold recommended encoding + * @return true if an encoding is recommended (the encoding is stored + * in the enc parameter), false otherwise (in this case, the enc + * parameter is not modified) + */ + bool getRecommendedEncoding(encoding& enc) const; + /** Returns the default charset used on the system. * * This function simply calls <code>platformHandler::getLocaleCharset()</code> diff --git a/vmime/contentHandler.hpp b/vmime/contentHandler.hpp index 38e4e245..0374cbea 100644 --- a/vmime/contentHandler.hpp +++ b/vmime/contentHandler.hpp @@ -111,6 +111,13 @@ public: * @return true if no data is managed by this object, false otherwise */ virtual bool isEmpty() const = 0; + + /** Indicates whether the extract() method can be called multiple times. + * + * @return true if the data can be extracted multiple times, or false + * if not (ie. streamed data from socket) + */ + virtual bool isBuffered() const = 0; }; diff --git a/vmime/emptyContentHandler.hpp b/vmime/emptyContentHandler.hpp index 727c065c..7b1e7eb9 100644 --- a/vmime/emptyContentHandler.hpp +++ b/vmime/emptyContentHandler.hpp @@ -52,6 +52,8 @@ public: const vmime::encoding& getEncoding() const; bool isEmpty() const; + + bool isBuffered() const; }; diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp index fa72dfb1..ba78081a 100644 --- a/vmime/encoding.hpp +++ b/vmime/encoding.hpp @@ -45,6 +45,13 @@ class encoding : public headerFieldValue { public: + enum EncodingUsage + { + USAGE_TEXT, /**< Use for body text. */ + USAGE_BINARY_DATA /**< Use for attachment, image... */ + }; + + encoding(); explicit encoding(const string& name); encoding(const encoding& enc); @@ -75,20 +82,21 @@ public: /** Decide which encoding to use based on the specified data. * - * \deprecated Use the new decide() method which takes a contentHandler parameter. - * - * @param begin start iterator in buffer - * @param end end iterator in buffer + * @param data data used to determine encoding + * @param usage context of use of data * @return suitable encoding for specified data */ - static const encoding decide(const string::const_iterator begin, const string::const_iterator end); + static const encoding decide(ref <const contentHandler> data, const EncodingUsage usage = USAGE_BINARY_DATA); - /** Decide which encoding to use based on the specified data. + /** Decide which encoding to use based on the specified data and charset. * * @param data data used to determine encoding - * @return suitable encoding for specified data + * @param charset charset of data + * @param usage context of use of data + * @return suitable encoding for specified data and charset */ - static const encoding decide(ref <const contentHandler> data); + static const encoding decide(ref <const contentHandler> data, const charset& chset, const EncodingUsage usage = USAGE_BINARY_DATA); + ref <component> clone() const; void copyFrom(const component& other); @@ -106,6 +114,17 @@ private: string m_name; + /** Decide which encoding to use based on the specified data. + * + * Please note: this will read the whole buffer, so it should be used only + * for small amount of data (eg. text), and not large binary attachments. + * + * @param begin start iterator in buffer + * @param end end iterator in buffer + * @return suitable encoding for specified data + */ + static const encoding decideImpl(const string::const_iterator begin, const string::const_iterator end); + public: using component::parse; diff --git a/vmime/net/imap/IMAPMessagePartContentHandler.hpp b/vmime/net/imap/IMAPMessagePartContentHandler.hpp index 0c4641e9..75a03afd 100644 --- a/vmime/net/imap/IMAPMessagePartContentHandler.hpp +++ b/vmime/net/imap/IMAPMessagePartContentHandler.hpp @@ -55,6 +55,8 @@ public: bool isEmpty() const; + bool isBuffered() const; + private: weak_ref <IMAPMessage> m_message; diff --git a/vmime/streamContentHandler.hpp b/vmime/streamContentHandler.hpp index aa62b2fc..703fb72c 100644 --- a/vmime/streamContentHandler.hpp +++ b/vmime/streamContentHandler.hpp @@ -62,6 +62,8 @@ public: bool isEmpty() const; + bool isBuffered() const; + private: // Equals to NO_ENCODING if data is not encoded, otherwise this diff --git a/vmime/stringContentHandler.hpp b/vmime/stringContentHandler.hpp index 8d368890..a73ae67d 100644 --- a/vmime/stringContentHandler.hpp +++ b/vmime/stringContentHandler.hpp @@ -80,6 +80,8 @@ public: bool isEmpty() const; + bool isBuffered() const; + private: // Equals to NO_ENCODING if data is not encoded, otherwise this |