From 50a6a9cdfacfa4e1aaa5a35fe8c3bc6ac114fa57 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Wed, 15 Dec 2004 20:28:09 +0000 Subject: [PATCH] Added parsing bounds on 'component'. --- src/addressList.cpp | 2 ++ src/body.cpp | 2 ++ src/bodyPart.cpp | 2 ++ src/bodyPart.hpp | 22 ++++++++++++++++++++++ src/charset.cpp | 2 ++ src/component.cpp | 25 +++++++++++++++++++++++++ src/component.hpp | 26 ++++++++++++++++++++++++++ src/dateTime.cpp | 2 ++ src/disposition.cpp | 2 ++ src/encoding.cpp | 2 ++ src/header.cpp | 2 ++ src/headerField.cpp | 2 ++ src/mailbox.cpp | 2 ++ src/mailboxField.cpp | 2 ++ src/mailboxGroup.cpp | 2 ++ src/mediaType.cpp | 2 ++ src/messageId.cpp | 2 ++ src/parameter.cpp | 2 ++ src/relay.cpp | 2 ++ src/text.cpp | 2 ++ 20 files changed, 107 insertions(+) diff --git a/src/addressList.cpp b/src/addressList.cpp index 93f0cc5b..b10bfe1a 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -60,6 +60,8 @@ void addressList::parse(const string& buffer, const string::size_type position, m_list.push_back(parsedAddress); } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/body.cpp b/src/body.cpp index da279b9b..5e369d4b 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -202,6 +202,8 @@ void body::parse(const string& buffer, const string::size_type position, m_contents.setData(buffer, position, end, getEncoding()); } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp index ec046ce2..90962c7c 100644 --- a/src/bodyPart.cpp +++ b/src/bodyPart.cpp @@ -40,6 +40,8 @@ void bodyPart::parse(const string& buffer, const string::size_type position, // Parse the body contents m_body.parse(buffer, pos, end, NULL); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/bodyPart.hpp b/src/bodyPart.hpp index e8127a0c..bf52b248 100644 --- a/src/bodyPart.hpp +++ b/src/bodyPart.hpp @@ -43,12 +43,34 @@ public: bodyPart(); + /** Return the header section of this part. + * + * @return header section + */ const header* getHeader() const; + + /** Return the header section of this part. + * + * @return header section + */ header* getHeader(); + /** Return the body section of this part. + * + * @return body section + */ const body* getBody() const; + + /** Return the body section of this part. + * + * @return body section + */ body* getBody(); + /** Return the parent part of this part. + * + * @return parent part or NULL if not known + */ bodyPart* getParentPart() const; bodyPart* clone() const; diff --git a/src/charset.cpp b/src/charset.cpp index ffa5aea0..5a06722c 100644 --- a/src/charset.cpp +++ b/src/charset.cpp @@ -59,6 +59,8 @@ void charset::parse(const string& buffer, const string::size_type position, { m_name = string(buffer.begin() + position, buffer.begin() + end); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/component.cpp b/src/component.cpp index b387b9c5..35ff3dc0 100644 --- a/src/component.cpp +++ b/src/component.cpp @@ -27,6 +27,12 @@ namespace vmime { +component::component() + : m_parsedOffset(0), m_parsedLength(0) +{ +} + + component::~component() { } @@ -50,4 +56,23 @@ const string component::generate(const string::size_type maxLineLength, } +const string::size_type component::getParsedOffset() const +{ + return (m_parsedOffset); +} + + +const string::size_type component::getParsedLength() const +{ + return (m_parsedLength); +} + + +void component::setParsedBounds(const string::size_type start, const string::size_type end) +{ + m_parsedOffset = start; + m_parsedLength = end - start; +} + + } diff --git a/src/component.hpp b/src/component.hpp index adb8825c..b09d78bf 100644 --- a/src/component.hpp +++ b/src/component.hpp @@ -36,6 +36,7 @@ class component { public: + component(); virtual ~component(); /** Parse RFC-822/MIME data for this component. @@ -86,6 +87,31 @@ public: * @param other other component to copy data from */ virtual void copyFrom(const component& other) = 0; + + /** Return the start position of this component in the + * parsed message contents. + * + * @return start position in parsed buffer + * or 0 if this component has not been parsed + */ + const string::size_type getParsedOffset() const; + + /** Return the length of this component in the + * parsed message contents. + * + * @return length of the component in parsed buffer + * or 0 if this component has not been parsed + */ + const string::size_type getParsedLength() const; + +protected: + + void setParsedBounds(const string::size_type start, const string::size_type end); + +private: + + string::size_type m_parsedOffset; + string::size_type m_parsedLength; }; diff --git a/src/dateTime.cpp b/src/dateTime.cpp index 002769f0..7760d651 100644 --- a/src/dateTime.cpp +++ b/src/dateTime.cpp @@ -524,6 +524,8 @@ void datetime::parse(const string& buffer, const string::size_type position, m_zone = 0; } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/disposition.cpp b/src/disposition.cpp index dd4a59b8..9ac862c1 100644 --- a/src/disposition.cpp +++ b/src/disposition.cpp @@ -48,6 +48,8 @@ void disposition::parse(const string& buffer, const string::size_type position, { m_name = stringUtils::toLower(string(buffer.begin() + position, buffer.begin() + end)); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/encoding.cpp b/src/encoding.cpp index 3211f2a7..de7e3287 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -51,6 +51,8 @@ void encoding::parse(const string& buffer, const string::size_type position, { m_name = stringUtils::toLower(string(buffer.begin() + position, buffer.begin() + end)); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/header.cpp b/src/header.cpp index 317189b8..fbe6921f 100644 --- a/src/header.cpp +++ b/src/header.cpp @@ -212,6 +212,8 @@ void header::parse(const string& buffer, const string::size_type position, } } + setParsedBounds(position, pos); + if (newPosition) *newPosition = pos; } diff --git a/src/headerField.cpp b/src/headerField.cpp index db03c68e..791b6891 100644 --- a/src/headerField.cpp +++ b/src/headerField.cpp @@ -71,6 +71,8 @@ void headerField::parse(const string& buffer, const string::size_type position, string::size_type* newPosition) { getValue().parse(buffer, position, end, newPosition); + + setParsedBounds(position, end); } diff --git a/src/mailbox.cpp b/src/mailbox.cpp index a144de7b..89ede107 100644 --- a/src/mailbox.cpp +++ b/src/mailbox.cpp @@ -327,6 +327,8 @@ void mailbox::parse(const string& buffer, const string::size_type position, } } + setParsedBounds(position, position + (p - pstart)); + if (newPosition) *newPosition = position + (p - pstart); } diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp index 3cd7d910..f9ad2f8f 100644 --- a/src/mailboxField.cpp +++ b/src/mailboxField.cpp @@ -66,6 +66,8 @@ void mailboxField::parse(const string& buffer, const string::size_type position, delete (parsedAddress); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp index 505e8448..eac2a125 100644 --- a/src/mailboxGroup.cpp +++ b/src/mailboxGroup.cpp @@ -102,6 +102,8 @@ void mailboxGroup::parse(const string& buffer, const string::size_type position, text::decodeAndUnfold(name, &m_name); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/mediaType.cpp b/src/mediaType.cpp index 34e28cab..c16c316f 100644 --- a/src/mediaType.cpp +++ b/src/mediaType.cpp @@ -68,6 +68,8 @@ void mediaType::parse(const string& buffer, const string::size_type position, buffer.begin() + end)); } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/messageId.cpp b/src/messageId.cpp index 666136f5..42ac7cb6 100644 --- a/src/messageId.cpp +++ b/src/messageId.cpp @@ -122,6 +122,8 @@ void messageId::parse(const string& buffer, const string::size_type position, } } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/parameter.cpp b/src/parameter.cpp index 7c673703..9feff1cc 100644 --- a/src/parameter.cpp +++ b/src/parameter.cpp @@ -61,6 +61,8 @@ void parameter::parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition) { getValue().parse(buffer, position, end, newPosition); + + setParsedBounds(position, end); } diff --git a/src/relay.cpp b/src/relay.cpp index 2edc9a28..32cc99d8 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -187,6 +187,8 @@ void relay::parse(const string& buffer, const string::size_type position, } } + setParsedBounds(position, end); + if (newPosition) *newPosition = end; } diff --git a/src/text.cpp b/src/text.cpp index 5a5a1250..b2f29966 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -71,6 +71,8 @@ void text::parse(const string& buffer, const string::size_type position, { decodeAndUnfold(buffer.begin() + position, buffer.begin() + end, *this); + setParsedBounds(position, end); + if (newPosition) *newPosition = end; }