diff options
Diffstat (limited to 'vmime')
35 files changed, 313 insertions, 409 deletions
diff --git a/vmime/address.hpp b/vmime/address.hpp index 6e73e3a1..5fb3c99d 100644 --- a/vmime/address.hpp +++ b/vmime/address.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -39,7 +39,7 @@ namespace vmime * and mailboxGroup classes. */ -class address : public component +class address : public headerFieldValue { friend class addressList; diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp index a48aabbe..4b4e43d0 100644 --- a/vmime/addressList.hpp +++ b/vmime/addressList.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include "vmime/address.hpp" @@ -41,7 +41,7 @@ class mailboxList; /** A list of addresses. */ -class addressList : public component +class addressList : public headerFieldValue { public: diff --git a/vmime/bodyPartAttachment.hpp b/vmime/bodyPartAttachment.hpp index c079b0d6..7ac1914e 100644 --- a/vmime/bodyPartAttachment.hpp +++ b/vmime/bodyPartAttachment.hpp @@ -27,6 +27,9 @@ #include "vmime/attachment.hpp" +#include "vmime/contentDispositionField.hpp" +#include "vmime/contentTypeField.hpp" + namespace vmime { diff --git a/vmime/contentDisposition.hpp b/vmime/contentDisposition.hpp index 6c4a9cd0..fa3cf7f9 100644 --- a/vmime/contentDisposition.hpp +++ b/vmime/contentDisposition.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -36,7 +36,7 @@ namespace vmime /** Content disposition (basic type). */ -class contentDisposition : public component +class contentDisposition : public headerFieldValue { public: diff --git a/vmime/contentDispositionField.hpp b/vmime/contentDispositionField.hpp index e7f79296..e02f64fa 100644 --- a/vmime/contentDispositionField.hpp +++ b/vmime/contentDispositionField.hpp @@ -26,7 +26,6 @@ #include "vmime/parameterizedHeaderField.hpp" -#include "vmime/genericField.hpp" #include "vmime/contentDisposition.hpp" #include "vmime/dateTime.hpp" @@ -37,7 +36,7 @@ namespace vmime { -class contentDispositionField : public parameterizedHeaderField, public genericField <contentDisposition> +class contentDispositionField : public parameterizedHeaderField { friend class vmime::creator; // create ref @@ -48,19 +47,69 @@ protected: public: - const datetime& getCreationDate() const; + /** Return the value of the "creation-date" parameter. + * + * @return value of the "creation-date" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist + */ + const datetime getCreationDate() const; + + /** Set the value of the "creation-date" parameter. + * + * @param creationDate new value for the "creation-date" parameter + */ void setCreationDate(const datetime& creationDate); - const datetime& getModificationDate() const; + /** Return the value of the "modification-date" parameter. + * + * @return value of the "modification-date" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist + */ + const datetime getModificationDate() const; + + /** Set the value of the "modification-date" parameter. + * + * @param modificationDate new value for the "modification-date" parameter + */ void setModificationDate(const datetime& modificationDate); - const datetime& getReadDate() const; + /** Return the value of the "read-date" parameter. + * + * @return value of the "read-date" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist + */ + const datetime getReadDate() const; + + /** Set the value of the "read-date" parameter. + * + * @param readDate new value for the "read-date" parameter + */ void setReadDate(const datetime& readDate); + /** Return the value of the "filename" parameter. + * + * @return value of the "filename" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist + */ const word getFilename() const; + + /** Set the value of the "filename" parameter. + * + * @param filename new value for the "filename" parameter + */ void setFilename(const word& filename); + /** Return the value of the "size" parameter. + * + * @return value of the "size" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist + */ const string getSize() const; + + /** Set the value of the "size" parameter. + * + * @param size new value for the "size" parameter + */ void setSize(const string& size); }; diff --git a/vmime/contentTypeField.hpp b/vmime/contentTypeField.hpp index b66f20d0..c78642f1 100644 --- a/vmime/contentTypeField.hpp +++ b/vmime/contentTypeField.hpp @@ -26,7 +26,6 @@ #include "vmime/parameterizedHeaderField.hpp" -#include "vmime/genericField.hpp" #include "vmime/mediaType.hpp" #include "vmime/charset.hpp" @@ -36,7 +35,7 @@ namespace vmime { -class contentTypeField : public parameterizedHeaderField, public genericField <mediaType> +class contentTypeField : public parameterizedHeaderField { friend class vmime::creator; // create ref @@ -47,25 +46,33 @@ protected: public: - /** Return the value of the "boundary" parameter. + /** Return the value of the "boundary" parameter. Boundary is a + * random string used to separate body parts. * * @return value of the "boundary" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist */ const string getBoundary() const; - /** Set the value of the "boundary" parameter. + /** Set the value of the "boundary" parameter. Boundary is a + * random string used to separate body parts. Normally, the + * boundary is generated automatically by VMime, you should + * not need to call this. * * @param boundary new value for the "boundary" parameter */ void setBoundary(const string& boundary); - /** Return the value of the "charset" parameter. + /** Return the value of the "charset" parameter. It specifies the + * charset used in the body part contents. * * @return value of the "charset" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist */ - const charset& getCharset() const; + const charset getCharset() const; - /** Set the value of the "charset" parameter. + /** Set the value of the "charset" parameter. It specifies the + * charset used in the body part contents. * * @param ch new value for the "charset" parameter */ @@ -74,6 +81,7 @@ public: /** Return the value of the "report-type" parameter (RFC-1892). * * @return value of the "report-type" parameter + * @throw exceptions::no_such_parameter if the parameter does not exist */ const string getReportType() const; diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp index 5f2499ce..ffc17bde 100644 --- a/vmime/dateTime.hpp +++ b/vmime/dateTime.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include <ctime> @@ -38,7 +38,7 @@ namespace vmime /** Date and time (basic type). */ -class datetime : public component +class datetime : public headerFieldValue { public: diff --git a/vmime/disposition.hpp b/vmime/disposition.hpp index 03d476db..b98b558c 100644 --- a/vmime/disposition.hpp +++ b/vmime/disposition.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include <vector> @@ -38,7 +38,7 @@ namespace vmime /** Disposition - from RFC-3798 (basic type). */ -class disposition : public component +class disposition : public headerFieldValue { public: diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp index 692585b0..4308de05 100644 --- a/vmime/encoding.hpp +++ b/vmime/encoding.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include "vmime/encoder.hpp" @@ -40,7 +40,7 @@ class contentHandler; /** Content encoding (basic type). */ -class encoding : public component +class encoding : public headerFieldValue { public: diff --git a/vmime/fileAttachment.hpp b/vmime/fileAttachment.hpp index 3fb24ebf..785690db 100644 --- a/vmime/fileAttachment.hpp +++ b/vmime/fileAttachment.hpp @@ -27,6 +27,8 @@ #include "vmime/defaultAttachment.hpp" +#include "vmime/dateTime.hpp" + namespace vmime { diff --git a/vmime/header.hpp b/vmime/header.hpp index e7a834df..bb806fc7 100644 --- a/vmime/header.hpp +++ b/vmime/header.hpp @@ -32,13 +32,6 @@ #include "vmime/headerField.hpp" #include "vmime/headerFieldFactory.hpp" -#include "vmime/mailboxField.hpp" -#include "vmime/contentTypeField.hpp" -#include "vmime/contentDispositionField.hpp" - -#include "vmime/standardFields.hpp" -#include "vmime/standardParams.hpp" - namespace vmime { @@ -61,38 +54,38 @@ public: header(); ~header(); -#define FIELD_ACCESS(methodName, fieldName, type) \ - ref <type> methodName() { return getField(fields::fieldName).dynamicCast <type>(); } \ - ref <const type> methodName() const { return findField(fields::fieldName).dynamicCast <const type>(); } - - FIELD_ACCESS(From, FROM, mailboxField) - FIELD_ACCESS(Sender, SENDER, mailboxField) - FIELD_ACCESS(ReplyTo, REPLY_TO, mailboxField) - FIELD_ACCESS(DeliveredTo, DELIVERED_TO, mailboxField) - FIELD_ACCESS(InReplyTo, IN_REPLY_TO, messageIdSequenceField) - FIELD_ACCESS(ReturnPath, RETURN_PATH, pathField) - FIELD_ACCESS(References, REFERENCES, messageIdSequenceField) - - FIELD_ACCESS(To, TO, addressListField) - FIELD_ACCESS(Cc, CC, addressListField) - FIELD_ACCESS(Bcc, BCC, addressListField) - FIELD_ACCESS(Date, DATE, dateField) - FIELD_ACCESS(Subject, SUBJECT, textField) - FIELD_ACCESS(Organization, ORGANIZATION, textField) - FIELD_ACCESS(UserAgent, USER_AGENT, textField) - - FIELD_ACCESS(ContentType, CONTENT_TYPE, contentTypeField) - FIELD_ACCESS(ContentDescription, CONTENT_DESCRIPTION, textField) - FIELD_ACCESS(ContentTransferEncoding, CONTENT_TRANSFER_ENCODING, contentEncodingField) - FIELD_ACCESS(MimeVersion, MIME_VERSION, defaultField) - FIELD_ACCESS(ContentDisposition, CONTENT_DISPOSITION, contentDispositionField) - FIELD_ACCESS(ContentId, CONTENT_ID, messageIdField) - FIELD_ACCESS(MessageId, MESSAGE_ID, messageIdField) - FIELD_ACCESS(ContentLocation, CONTENT_LOCATION, defaultField) - - FIELD_ACCESS(OriginalMessageId, ORIGINAL_MESSAGE_ID, messageIdField) - FIELD_ACCESS(Disposition, DISPOSITION, dispositionField) - FIELD_ACCESS(DispositionNotificationTo, DISPOSITION_NOTIFICATION_TO, mailboxListField) +#define FIELD_ACCESS(methodName, fieldName) \ + ref <headerField> methodName() { return getField(fields::fieldName); } \ + ref <const headerField> methodName() const { return findField(fields::fieldName); } + + FIELD_ACCESS(From, FROM) + FIELD_ACCESS(Sender, SENDER) + FIELD_ACCESS(ReplyTo, REPLY_TO) + FIELD_ACCESS(DeliveredTo, DELIVERED_TO) + FIELD_ACCESS(InReplyTo, IN_REPLY_TO) + FIELD_ACCESS(ReturnPath, RETURN_PATH) + FIELD_ACCESS(References, REFERENCES) + + FIELD_ACCESS(To, TO) + FIELD_ACCESS(Cc, CC) + FIELD_ACCESS(Bcc, BCC) + FIELD_ACCESS(Date, DATE) + FIELD_ACCESS(Subject, SUBJECT) + FIELD_ACCESS(Organization, ORGANIZATION) + FIELD_ACCESS(UserAgent, USER_AGENT) + + FIELD_ACCESS(ContentType, CONTENT_TYPE) + FIELD_ACCESS(ContentDescription, CONTENT_DESCRIPTION) + FIELD_ACCESS(ContentTransferEncoding, CONTENT_TRANSFER_ENCODING) + FIELD_ACCESS(MimeVersion, MIME_VERSION) + FIELD_ACCESS(ContentDisposition, CONTENT_DISPOSITION) + FIELD_ACCESS(ContentId, CONTENT_ID) + FIELD_ACCESS(MessageId, MESSAGE_ID) + FIELD_ACCESS(ContentLocation, CONTENT_LOCATION) + + FIELD_ACCESS(OriginalMessageId, ORIGINAL_MESSAGE_ID) + FIELD_ACCESS(Disposition, DISPOSITION) + FIELD_ACCESS(DispositionNotificationTo, DISPOSITION_NOTIFICATION_TO) #undef FIELD_ACCESS diff --git a/vmime/headerField.hpp b/vmime/headerField.hpp index 9047a2ac..27d53f0c 100644 --- a/vmime/headerField.hpp +++ b/vmime/headerField.hpp @@ -27,6 +27,7 @@ #include "vmime/base.hpp" #include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -41,8 +42,12 @@ class headerField : public component friend class headerFieldFactory; friend class header; + friend class vmime::creator; // create ref + protected: + // Protected constructor to prevent the user from creating + // new objects without using 'headerFieldFactory' headerField(); headerField(const string& fieldName); @@ -56,6 +61,12 @@ public: const std::vector <ref <const component> > getChildComponents() const; + /** Sets the name of this field. + * + * @param name field name (eg: "From" or "X-MyField"). + */ + void setName(const string& name); + /** Return the name of this field. * * @return field name @@ -73,21 +84,32 @@ public: * * @return read-only value object */ - virtual const component& getValue() const = 0; + virtual ref <const headerFieldValue> getValue() const; /** Return the value object attached to this field. * * @return value object */ - virtual component& getValue() = 0; + virtual ref <headerFieldValue> getValue(); /** Set the value of this field. * - * @throw std::bad_cast_exception if the value type is - * incompatible with the header field type - * @param value value object + * @param value new value + */ + virtual void setValue(ref <headerFieldValue> value); + + /** Set the value of this field by cloning the specified value. + * + * @param value new value + */ + virtual void setValueConst(ref <const headerFieldValue> value); + + /** Set the value of this field (reference version). + * The value will be cloned. + * + * @param value new value */ - virtual void setValue(const component& value) = 0; + virtual void setValue(const headerFieldValue& value); /** Set the value of this field given a character string. * @@ -104,15 +126,11 @@ public: protected: - virtual const ref <const component> getValueImp() const = 0; - virtual ref <component> getValueImp() = 0; - -private: - static ref <headerField> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL); string m_name; + ref <headerFieldValue> m_value; }; diff --git a/vmime/headerFieldFactory.hpp b/vmime/headerFieldFactory.hpp index 2099e341..04867547 100644 --- a/vmime/headerFieldFactory.hpp +++ b/vmime/headerFieldFactory.hpp @@ -33,6 +33,9 @@ namespace vmime { +/** Creates header field and header field value objects. + */ + class headerFieldFactory { protected: @@ -45,17 +48,23 @@ protected: NameMap m_nameMap; + typedef ref <headerFieldValue> (*ValueAllocFunc)(void); + typedef std::map <string, ValueAllocFunc> ValueMap; + + ValueMap m_valueMap; + public: static headerFieldFactory* getInstance(); #ifndef VMIME_BUILDING_DOC - template <class TYPE> + // TYPE must inherit from BASE_TYPE + template <class BASE_TYPE, class TYPE> class registerer { public: - static ref <headerField> creator() + static ref <BASE_TYPE> creator() { // Allocate a new object return vmime::create <TYPE>(); @@ -64,14 +73,49 @@ public: #endif // VMIME_BUILDING_DOC + /** Register a field type. + * + * @param T field class (must inherit from 'headerField') + * @param name field name (eg. "X-MyField") + */ template <class T> - void registerName(const string& name) + void registerField(const string& name) { m_nameMap.insert(NameMap::value_type - (utility::stringUtils::toLower(name), ®isterer<T>::creator)); + (utility::stringUtils::toLower(name), + ®isterer <headerField, T>::creator)); + } + + /** Register a field value type. + * + * @param T value class (must inherit from 'headerFieldValue') + * @param name field name + */ + template <class T> + void registerFieldValue(const string& name) + { + m_valueMap.insert(ValueMap::value_type + (utility::stringUtils::toLower(name), + ®isterer <headerFieldValue, T>::creator)); } + /** Create a new field object for the specified field name. + * If the field name has not been registered, a default type + * is used. + * + * @param name field name + * @param body string that will be parsed to initialize + * the value of the field + * @return a new field object + */ ref <headerField> create(const string& name, const string& body = NULL_STRING); + + /** Create a new field value for the specified field. + * + * @param fieldName name of the field for which to create value + * @return a new value object for the field + */ + ref <headerFieldValue> createValue(const string& fieldName); }; diff --git a/vmime/defaultParameter.hpp b/vmime/headerFieldValue.hpp index a6546a4b..ed26bb51 100644 --- a/vmime/defaultParameter.hpp +++ b/vmime/headerFieldValue.hpp @@ -21,57 +21,31 @@ // the GNU General Public License cover the whole combination. // -#ifndef VMIME_DEFAULTPARAMETER_HPP_INCLUDED -#define VMIME_DEFAULTPARAMETER_HPP_INCLUDED +#ifndef VMIME_HEADERFIELDVALUE_HPP_INCLUDED +#define VMIME_HEADERFIELDVALUE_HPP_INCLUDED -#include "vmime/parameter.hpp" -#include "vmime/parameterFactory.hpp" - -#include "vmime/word.hpp" +#include "vmime/base.hpp" +#include "vmime/component.hpp" namespace vmime { -/** Default parameter implementation (with support for RFC-2231). +/** Base class for all classes that can be used as a value + * for a header field. */ -class defaultParameter : public parameter +class headerFieldValue : public component { - friend class vmime::creator; // create ref - -protected: - - defaultParameter(); - public: - defaultParameter& operator=(const defaultParameter& other); - - const word& getValue() const; - word& getValue(); - - void setValue(const word& value); - void setValue(const component& value); - - void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL); - void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const; - -private: - - void parse(const std::vector <valueChunk>& chunks); - - const ref <const component> getValueImp() const; - const ref <component> getValueImp(); - - - ref <word> m_value; }; } // vmime -#endif // VMIME_DEFAULTPARAMETER_HPP_INCLUDED +#endif // VMIME_HEADERFIELDVALUE_HPP_INCLUDED + diff --git a/vmime/mailboxField.hpp b/vmime/mailboxField.hpp index afd61ac7..18a016de 100644 --- a/vmime/mailboxField.hpp +++ b/vmime/mailboxField.hpp @@ -25,15 +25,23 @@ #define VMIME_MAILBOXFIELD_HPP_INCLUDED -#include "vmime/genericField.hpp" +#include "vmime/headerField.hpp" #include "vmime/mailbox.hpp" +// Hide implementation details from user +#ifndef VMIME_BUILDING_DOC + + namespace vmime { -class mailboxField : public genericField <mailbox> +/** Work-around for malformed header fields that are of type 'mailbox' + * and contains multiple addresses. + */ + +class mailboxField : public headerField { friend class vmime::creator; // create ref @@ -48,7 +56,11 @@ public: }; +#endif // VMIME_BUILDING_DOC + + } // vmime #endif // VMIME_MAILBOXFIELD_HPP_INCLUDED + diff --git a/vmime/mailboxList.hpp b/vmime/mailboxList.hpp index fe417c42..126d1ae6 100644 --- a/vmime/mailboxList.hpp +++ b/vmime/mailboxList.hpp @@ -39,7 +39,7 @@ namespace vmime * from inserting mailbox groups where it is not allowed by the RFC. */ -class mailboxList : public component +class mailboxList : public headerFieldValue { public: diff --git a/vmime/mdn/MDNHelper.hpp b/vmime/mdn/MDNHelper.hpp index 322c61ab..ad6b9409 100644 --- a/vmime/mdn/MDNHelper.hpp +++ b/vmime/mdn/MDNHelper.hpp @@ -28,6 +28,8 @@ #include "vmime/mdn/receivedMDNInfos.hpp" #include "vmime/mdn/sendableMDNInfos.hpp" +#include "vmime/mailboxList.hpp" + namespace vmime { namespace mdn { diff --git a/vmime/mdn/receivedMDNInfos.hpp b/vmime/mdn/receivedMDNInfos.hpp index 0ba88fc6..b8041d16 100644 --- a/vmime/mdn/receivedMDNInfos.hpp +++ b/vmime/mdn/receivedMDNInfos.hpp @@ -26,7 +26,10 @@ #include "vmime/mdn/MDNInfos.hpp" + #include "vmime/disposition.hpp" +#include "vmime/messageId.hpp" +#include "vmime/mailbox.hpp" namespace vmime { diff --git a/vmime/mdn/sendableMDNInfos.hpp b/vmime/mdn/sendableMDNInfos.hpp index ae3c8ea0..ea01edd0 100644 --- a/vmime/mdn/sendableMDNInfos.hpp +++ b/vmime/mdn/sendableMDNInfos.hpp @@ -27,6 +27,8 @@ #include "vmime/mdn/MDNInfos.hpp" +#include "vmime/mailbox.hpp" + namespace vmime { namespace mdn { diff --git a/vmime/mediaType.hpp b/vmime/mediaType.hpp index 3e5c86ce..1bdda268 100644 --- a/vmime/mediaType.hpp +++ b/vmime/mediaType.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -36,7 +36,7 @@ namespace vmime /** Content media type (basic type). */ -class mediaType : public component +class mediaType : public headerFieldValue { public: diff --git a/vmime/messageId.hpp b/vmime/messageId.hpp index 1853d24d..d83bf242 100644 --- a/vmime/messageId.hpp +++ b/vmime/messageId.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -36,7 +36,7 @@ namespace vmime /** Message identifier (basic type). */ -class messageId : public component +class messageId : public headerFieldValue { friend class messageIdSequence; diff --git a/vmime/messageIdSequence.hpp b/vmime/messageIdSequence.hpp index a33d8a57..f7c96151 100644 --- a/vmime/messageIdSequence.hpp +++ b/vmime/messageIdSequence.hpp @@ -35,7 +35,7 @@ namespace vmime /** A list of message identifiers (basic type). */ -class messageIdSequence : public component +class messageIdSequence : public headerFieldValue { public: diff --git a/vmime/messageParser.hpp b/vmime/messageParser.hpp index 73bd4769..8c539c4f 100644 --- a/vmime/messageParser.hpp +++ b/vmime/messageParser.hpp @@ -30,6 +30,10 @@ #include "vmime/message.hpp" #include "vmime/attachment.hpp" +#include "vmime/mailbox.hpp" +#include "vmime/addressList.hpp" +#include "vmime/dateTime.hpp" + #include "vmime/textPart.hpp" diff --git a/vmime/net/message.hpp b/vmime/net/message.hpp index 7f77747e..63656608 100644 --- a/vmime/net/message.hpp +++ b/vmime/net/message.hpp @@ -26,6 +26,7 @@ #include "vmime/header.hpp" +#include "vmime/mediaType.hpp" #include "vmime/utility/progressListener.hpp" #include "vmime/utility/stream.hpp" diff --git a/vmime/net/pop3/POP3Store.hpp b/vmime/net/pop3/POP3Store.hpp index ad58f043..2839d198 100644 --- a/vmime/net/pop3/POP3Store.hpp +++ b/vmime/net/pop3/POP3Store.hpp @@ -26,6 +26,7 @@ #include "vmime/config.hpp" +#include "vmime/messageId.hpp" #include "vmime/net/store.hpp" #include "vmime/net/socket.hpp" diff --git a/vmime/net/transport.hpp b/vmime/net/transport.hpp index 8d297166..b43c05f0 100644 --- a/vmime/net/transport.hpp +++ b/vmime/net/transport.hpp @@ -28,6 +28,8 @@ #include "vmime/net/service.hpp" #include "vmime/utility/stream.hpp" +#include "vmime/mailboxList.hpp" + namespace vmime { diff --git a/vmime/parameter.hpp b/vmime/parameter.hpp index cf676084..8ac7e82c 100644 --- a/vmime/parameter.hpp +++ b/vmime/parameter.hpp @@ -27,6 +27,7 @@ #include "vmime/base.hpp" #include "vmime/component.hpp" +#include "vmime/word.hpp" namespace vmime @@ -35,11 +36,19 @@ namespace vmime class parameter : public component { - friend class parameterFactory; friend class parameterizedHeaderField; +private: + + parameter(const parameter&); + public: + parameter(const string& name); + parameter(const string& name, const word& value); + parameter(const string& name, const string& value); + + #ifndef VMIME_BUILDING_DOC /** A single section of a multi-section parameter, @@ -60,31 +69,58 @@ public: const std::vector <ref <const component> > getChildComponents() const; - /** Return the name of the parameter. + /** Return the name of this parameter. * - * @return name of the parameter + * @return name of this parameter */ const string& getName() const; - /** Return the read-only value object attached to this field. + /** Return the raw value of this parameter. * - * @return read-only value object + * @return read-only value */ - virtual const component& getValue() const = 0; + const word& getValue() const; - /** Return the value object attached to this field. + /** Return the value of this object in the specified type. + * For example, the following code: * - * @return value object + * <pre> + * getParameter("creation-date")->getValueAs <vmime::dateTime>()</pre> + * </pre> + * + * is equivalent to: + * + * <pre> + * ref <vmime::word> rawValue = getParameter("creation-date"); + * + * vmime::dateTime theDate; + * theDate.parse(rawValue->getBuffer()); + * </pre> + * + * @param T type to which convert the value + * @return value */ - virtual component& getValue() = 0; + template <typename T> + const T getValueAs() const + { + T ret; + ret.parse(m_value.getBuffer()); - /** Set the value of the parameter. + return ret; + } + + /** Set the value of this parameter. * - * @throw std::bad_cast_exception if the value type is - * incompatible with the parameter type - * @param value value object + * @param value new value */ - virtual void setValue(const component& value) = 0; + void setValue(const component& value); + + /** Set the raw value of this parameter. + * + * @param value new value + */ + void setValue(const word& value); + using component::parse; using component::generate; @@ -92,18 +128,13 @@ public: void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL); void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const; -protected: - - virtual const ref <const component> getValueImp() const = 0; - virtual const ref <component> getValueImp() = 0; - private: - string m_name; + void parse(const std::vector <valueChunk>& chunks); - void generateValue(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos) const; - virtual void parse(const std::vector <valueChunk>& chunks); + string m_name; + word m_value; }; diff --git a/vmime/parameterFactory.hpp b/vmime/parameterFactory.hpp deleted file mode 100644 index 358f2172..00000000 --- a/vmime/parameterFactory.hpp +++ /dev/null @@ -1,97 +0,0 @@ -// -// VMime library (http://www.vmime.org) -// Copyright (C) 2002-2005 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 2 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. -// - -#ifndef VMIME_PARAMETERFACTORY_HPP_INCLUDED -#define VMIME_PARAMETERFACTORY_HPP_INCLUDED - - -#include "vmime/parameter.hpp" -#include "vmime/utility/stringUtils.hpp" - - -namespace vmime -{ - - -class parameterFactory -{ -protected: - - parameterFactory(); - ~parameterFactory(); - - typedef ref <parameter> (*AllocFunc)(void); - typedef std::map <string, AllocFunc> NameMap; - - NameMap m_nameMap; - -public: - - static parameterFactory* getInstance(); - -#ifndef VMIME_BUILDING_DOC - template <class TYPE> - class registerer - { - public: - - static ref <parameter> creator() - { - // Allocate a new object - return vmime::create <TYPE>(); - } - }; -#endif // VMIME_BUILDING_DOC - - - template <class T> - void registerName(const string& name) - { - m_nameMap.insert(NameMap::value_type - (utility::stringUtils::toLower(name), ®isterer<T>::creator)); - } - - /** Create a new parameter and parse its value. The returned parameter - * can then be added in a vmime::parameterizedHeaderField object. - * - * @param name parameter name (ASCII characters only) - * @param value value to be parsed - * @return created parameter - */ - ref <parameter> create(const string& name, const string& value = NULL_STRING); - - /** Create a new parameter and set its value. The returned parameter - * can then be added in a vmime::parameterizedHeaderField object. - * - * @param name parameter name (ASCII characters only) - * @param value value to be set - * @return created parameter - */ - ref <parameter> create(const string& name, const component& value); -}; - - -} // vmime - - -#endif // VMIME_PARAMETERFACTORY_HPP_INCLUDED diff --git a/vmime/parameterizedHeaderField.hpp b/vmime/parameterizedHeaderField.hpp index 79ab49b5..bc1dc5be 100644 --- a/vmime/parameterizedHeaderField.hpp +++ b/vmime/parameterizedHeaderField.hpp @@ -29,7 +29,6 @@ #include "vmime/headerFieldFactory.hpp" #include "vmime/parameter.hpp" #include "vmime/exception.hpp" -#include "vmime/parameterFactory.hpp" namespace vmime @@ -42,10 +41,12 @@ namespace vmime class parameterizedHeaderField : virtual public headerField { - friend class headerFieldFactory::registerer <parameterizedHeaderField>; + friend class vmime::creator; // create ref protected: + // Protected constructor to prevent the user from creating + // new objects without using 'headerFieldFactory' parameterizedHeaderField(); public: diff --git a/vmime/path.hpp b/vmime/path.hpp index 5e45aa2c..0e8f6d3b 100644 --- a/vmime/path.hpp +++ b/vmime/path.hpp @@ -25,7 +25,7 @@ #define VMIME_PATH_HPP_INCLUDED -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" namespace vmime @@ -35,7 +35,7 @@ namespace vmime /** A path: a local part + '@' + a domain. */ -class path : public component +class path : public headerFieldValue { public: diff --git a/vmime/relay.hpp b/vmime/relay.hpp index 9f21da2b..f6391221 100644 --- a/vmime/relay.hpp +++ b/vmime/relay.hpp @@ -26,7 +26,7 @@ #include "vmime/base.hpp" -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include "vmime/dateTime.hpp" @@ -38,7 +38,7 @@ namespace vmime /** Trace information about a relay (basic type). */ -class relay : public component +class relay : public headerFieldValue { public: diff --git a/vmime/text.hpp b/vmime/text.hpp index a2914fa4..8da6d9e0 100644 --- a/vmime/text.hpp +++ b/vmime/text.hpp @@ -25,6 +25,7 @@ #define VMIME_TEXT_HPP_INCLUDED +#include "vmime/headerFieldValue.hpp" #include "vmime/base.hpp" #include "vmime/word.hpp" @@ -36,7 +37,7 @@ namespace vmime /** List of encoded-words, as defined in RFC-2047 (basic type). */ -class text : public component +class text : public headerFieldValue { public: @@ -142,6 +143,14 @@ public: */ const string getConvertedText(const charset& dest) const; + /** Return the unconverted (raw) data of all words. This is the + * concatenation of the results returned by getBuffer() on + * the contained words. + * + * @return raw data + */ + const string getWholeBuffer() const; + /** This function can be used to make several encoded words from a text. * All the characters in the text must be in the same specified charset. * diff --git a/vmime/typeAdapter.hpp b/vmime/typeAdapter.hpp deleted file mode 100644 index 2ad8e80a..00000000 --- a/vmime/typeAdapter.hpp +++ /dev/null @@ -1,159 +0,0 @@ -// -// VMime library (http://www.vmime.org) -// Copyright (C) 2002-2005 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 2 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. -// - -#ifndef VMIME_TYPEADAPTER_HPP_INCLUDED -#define VMIME_TYPEADAPTER_HPP_INCLUDED - - -#include <sstream> - -#include "vmime/component.hpp" - - -namespace vmime -{ - - -/** An adapter to allow any type to act as a 'component'. - */ - -template <class TYPE> -class typeAdapter : public component -{ -public: - - typeAdapter() - { - } - - typeAdapter(typeAdapter& a) - : component(), m_value(a.m_value) - { - } - - typeAdapter(const TYPE& v) - : m_value(v) - { - } - - - ref <component> clone() const - { - return create <typeAdapter>(*this); - } - - - void copyFrom(const component& other) - { - m_value = dynamic_cast <const typeAdapter <TYPE>&>(other).m_value; - } - - - typeAdapter& operator=(const TYPE& v) - { - m_value = v; - return (*this); - } - - - typeAdapter& operator=(const component& other) - { - copyFrom(other); - return (*this); - } - - - operator TYPE() const - { - return (m_value); - } - - - void parse(const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition = NULL) - { - std::istringstream iss(string(buffer.begin() + position, buffer.begin() + end)); - iss >> m_value; - - setParsedBounds(position, end); - - if (newPosition) - *newPosition = end; - } - - - void generate(utility::outputStream& os, - const string::size_type /* maxLineLength */ = lineLengthLimits::infinite, - const string::size_type curLinePos = 0, - string::size_type* newLinePos = NULL) const - { - std::ostringstream oss; - oss << m_value; - - os << oss.str(); - - if (newLinePos) - *newLinePos = curLinePos + oss.str().length(); - } - - const std::vector <ref <const component> > getChildComponents() const - { - return std::vector <ref <const component> >(); - } - -private: - - TYPE m_value; -}; - - -#if (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ <= 2)) || defined(_MSC_VER) - - // Because of a bug with g++ <= 3.2, we have to put the implementation - // of the function inline. - - template <> - inline void typeAdapter <string>::parse - (const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition) - { - m_value = string(buffer.begin() + position, buffer.begin() + end); - - if (newPosition) - *newPosition = end; - } - -#else - - template <> - void typeAdapter <string>::parse - (const string& buffer, const string::size_type position, - const string::size_type end, string::size_type* newPosition); - -#endif // (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ <= 2)) || defined(_MSC_VER) - - -} // vmime - - -#endif // VMIME_TYPEADAPTE_HPP_INCLUDED diff --git a/vmime/vmime.hpp b/vmime/vmime.hpp index 36b9e0e3..cbae859e 100644 --- a/vmime/vmime.hpp +++ b/vmime/vmime.hpp @@ -48,8 +48,10 @@ #include "vmime/addressList.hpp" #include "vmime/mediaType.hpp" #include "vmime/messageId.hpp" +#include "vmime/messageIdSequence.hpp" #include "vmime/relay.hpp" #include "vmime/disposition.hpp" +#include "vmime/path.hpp" #include "vmime/emptyContentHandler.hpp" #include "vmime/stringContentHandler.hpp" @@ -62,7 +64,6 @@ #include "vmime/headerFieldFactory.hpp" #include "vmime/mailboxField.hpp" #include "vmime/parameterizedHeaderField.hpp" -#include "vmime/standardFields.hpp" // Encoders #include "vmime/encoderFactory.hpp" diff --git a/vmime/word.hpp b/vmime/word.hpp index 79aef9c8..284b64d6 100644 --- a/vmime/word.hpp +++ b/vmime/word.hpp @@ -25,7 +25,7 @@ #define VMIME_WORD_HPP_INCLUDED -#include "vmime/component.hpp" +#include "vmime/headerFieldValue.hpp" #include "vmime/charset.hpp" @@ -37,7 +37,7 @@ namespace vmime * some text encoded into one specified charset. */ -class word : public component +class word : public headerFieldValue { friend class text; |