diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/addressList.cpp | 25 | ||||
-rw-r--r-- | src/constants.cpp | 1 | ||||
-rw-r--r-- | src/exception.cpp | 12 | ||||
-rw-r--r-- | src/headerFieldFactory.cpp | 3 | ||||
-rw-r--r-- | src/messageId.cpp | 43 | ||||
-rw-r--r-- | src/messageIdSequence.cpp | 246 |
6 files changed, 312 insertions, 18 deletions
diff --git a/src/addressList.cpp b/src/addressList.cpp index c6d9c9ad..9693a663 100644 --- a/src/addressList.cpp +++ b/src/addressList.cpp @@ -70,29 +70,24 @@ void addressList::parse(const string& buffer, const string::size_type position, void addressList::generate(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos) const { + string::size_type pos = curLinePos; + if (!m_list.empty()) { - string::size_type pos = curLinePos; - std::vector <address*>::const_iterator i = m_list.begin(); - - for ( ; ; ) + for (std::vector <address*>::const_iterator i = m_list.begin() ; ; ) { (*i)->generate(os, maxLineLength - 2, pos, &pos); - if (++i != m_list.end()) - { - os << ", "; - pos += 2; - } - else - { + if (++i == m_list.end()) break; - } - } - if (newLinePos) - *newLinePos = pos; + os << ", "; + pos += 2; + } } + + if (newLinePos) + *newLinePos = pos; } diff --git a/src/constants.cpp b/src/constants.cpp index 5ca08960..494428a2 100644 --- a/src/constants.cpp +++ b/src/constants.cpp @@ -176,6 +176,7 @@ namespace fields const string::value_type* const CONTENT_ID = "Content-Id"; const string::value_type* const CONTENT_LOCATION = "Content-Location"; const string::value_type* const IN_REPLY_TO = "In-Reply-To"; + const string::value_type* const REFERENCES = "References"; const string::value_type* const X_MAILER = "X-Mailer"; const string::value_type* const X_PRIORITY = "X-Priority"; diff --git a/src/exception.cpp b/src/exception.cpp index 4bbdefd3..b7be006c 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -163,6 +163,18 @@ const string no_such_mailbox::name() const { return "no_such_mailbox"; } // +// no_such_message_id +// + +no_such_message_id::~no_such_message_id() throw() {} +no_such_message_id::no_such_message_id(const exception& other) + : exception("Message-Id not found.", other) {} + +exception* no_such_message_id::clone() const { return new no_such_message_id(*this); } +const string no_such_message_id::name() const { return "no_such_message_id"; } + + +// // no_such_address // diff --git a/src/headerFieldFactory.cpp b/src/headerFieldFactory.cpp index 62eff647..fa990c6f 100644 --- a/src/headerFieldFactory.cpp +++ b/src/headerFieldFactory.cpp @@ -55,7 +55,8 @@ headerFieldFactory::headerFieldFactory() registerName <messageIdField>(vmime::fields::CONTENT_ID); registerName <messageIdField>(vmime::fields::MESSAGE_ID); registerName <defaultField>(vmime::fields::CONTENT_LOCATION); - registerName <messageIdField>(vmime::fields::IN_REPLY_TO); + registerName <messageIdSequenceField>(vmime::fields::IN_REPLY_TO); + registerName <messageIdSequenceField>(vmime::fields::REFERENCES); registerName <messageIdField>(vmime::fields::ORIGINAL_MESSAGE_ID); registerName <dispositionField>(vmime::fields::DISPOSITION); diff --git a/src/messageId.cpp b/src/messageId.cpp index 815266d5..9e878c2f 100644 --- a/src/messageId.cpp +++ b/src/messageId.cpp @@ -129,19 +129,58 @@ void messageId::parse(const string& buffer, const string::size_type position, } +messageId* messageId::parseNext(const string& buffer, const string::size_type position, + const string::size_type end, string::size_type* newPosition) +{ + string::size_type pos = position; + + while (pos < end && parserHelpers::isSpace(buffer[pos])) + ++pos; + + if (pos != end) + { + const string::size_type begin = pos; + + while (pos < end && !parserHelpers::isSpace(buffer[pos])) + ++pos; + + messageId* mid = new messageId(); + mid->parse(buffer, begin, pos, NULL); + + if (newPosition != NULL) + *newPosition = pos; + + return (mid); + } + + if (newPosition != NULL) + *newPosition = end; + + return (NULL); +} + + const string messageId::getId() const { return (m_left + '@' + m_right); } -void messageId::generate(utility::outputStream& os, const string::size_type /* maxLineLength */, +void messageId::generate(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos) const { + string::size_type pos = curLinePos; + + if (curLinePos + m_left.length() + m_right.length() + 3 > maxLineLength) + { + os << NEW_LINE_SEQUENCE; + pos = NEW_LINE_SEQUENCE_LENGTH; + } + os << '<' << m_left << '@' << m_right << '>'; if (newLinePos) - *newLinePos = curLinePos + m_left.length() + m_right.length() + 3; + *newLinePos = pos + m_left.length() + m_right.length() + 3; } diff --git a/src/messageIdSequence.cpp b/src/messageIdSequence.cpp new file mode 100644 index 00000000..7b3eae0d --- /dev/null +++ b/src/messageIdSequence.cpp @@ -0,0 +1,246 @@ +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// + +#include "vmime/messageIdSequence.hpp" +#include "vmime/exception.hpp" + + +namespace vmime +{ + + + + +messageIdSequence::messageIdSequence() +{ +} + + +messageIdSequence::~messageIdSequence() +{ + removeAllMessageIds(); +} + + +messageIdSequence::messageIdSequence(const messageIdSequence& midSeq) + : component() +{ + copyFrom(midSeq); +} + + +messageIdSequence* messageIdSequence::clone() const +{ + return new messageIdSequence(*this); +} + + +void messageIdSequence::copyFrom(const component& other) +{ + const messageIdSequence& midSeq = dynamic_cast <const messageIdSequence&>(other); + + removeAllMessageIds(); + + for (unsigned int i = 0 ; i < midSeq.m_list.size() ; ++i) + m_list.push_back(midSeq.m_list[i]->clone()); +} + + +messageIdSequence& messageIdSequence::operator=(const messageIdSequence& other) +{ + copyFrom(other); + return (*this); +} + + +const std::vector <const component*> messageIdSequence::getChildComponents() const +{ + std::vector <const component*> res; + + copy_vector(m_list, res); + + return (res); +} + + +void messageIdSequence::parse(const string& buffer, const string::size_type position, + const string::size_type end, string::size_type* newPosition) +{ + removeAllMessageIds(); + + string::size_type pos = position; + + while (pos < end) + { + messageId* parsedMid = messageId::parseNext(buffer, pos, end, &pos); + + if (parsedMid != NULL) + m_list.push_back(parsedMid); + } + + setParsedBounds(position, end); + + if (newPosition) + *newPosition = end; +} + + +void messageIdSequence::generate(utility::outputStream& os, const string::size_type maxLineLength, + const string::size_type curLinePos, string::size_type* newLinePos) const +{ + string::size_type pos = curLinePos; + + if (!m_list.empty()) + { + for (std::vector <messageId*>::const_iterator it = m_list.begin() ; ; ) + { + (*it)->generate(os, maxLineLength - 2, pos, &pos); + + if (++it == m_list.end()) + break; + + os << " "; + pos++; + } + } + + if (newLinePos) + *newLinePos = pos; +} + + +void messageIdSequence::appendMessageId(messageId* mid) +{ + m_list.push_back(mid); +} + + +void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* mid) +{ + const std::vector <messageId*>::iterator it = std::find + (m_list.begin(), m_list.end(), beforeMid); + + if (it == m_list.end()) + throw exceptions::no_such_message_id(); + + m_list.insert(it, mid); +} + + +void messageIdSequence::insertMessageIdBefore(const int pos, messageId* mid) +{ + m_list.insert(m_list.begin() + pos, mid); +} + + +void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid) +{ + const std::vector <messageId*>::iterator it = std::find + (m_list.begin(), m_list.end(), afterMid); + + if (it == m_list.end()) + throw exceptions::no_such_message_id(); + + m_list.insert(it + 1, mid); +} + + +void messageIdSequence::insertMessageIdAfter(const int pos, messageId* mid) +{ + m_list.insert(m_list.begin() + pos + 1, mid); +} + + +void messageIdSequence::removeMessageId(messageId* mid) +{ + const std::vector <messageId*>::iterator it = std::find + (m_list.begin(), m_list.end(), mid); + + if (it == m_list.end()) + throw exceptions::no_such_message_id(); + + delete (*it); + + m_list.erase(it); +} + + +void messageIdSequence::removeMessageId(const int pos) +{ + const std::vector <messageId*>::iterator it = m_list.begin() + pos; + + delete (*it); + + m_list.erase(it); +} + + +void messageIdSequence::removeAllMessageIds() +{ + free_container(m_list); +} + + +const int messageIdSequence::getMessageIdCount() const +{ + return (m_list.size()); +} + + +const bool messageIdSequence::isEmpty() const +{ + return (m_list.empty()); +} + + +messageId* messageIdSequence::getMessageIdAt(const int pos) +{ + return (m_list[pos]); +} + + +const messageId* messageIdSequence::getMessageIdAt(const int pos) const +{ + return (m_list[pos]); +} + + +const std::vector <const messageId*> messageIdSequence::getMessageIdList() const +{ + std::vector <const messageId*> list; + + list.reserve(m_list.size()); + + for (std::vector <messageId*>::const_iterator it = m_list.begin() ; + it != m_list.end() ; ++it) + { + list.push_back(*it); + } + + return (list); +} + + +const std::vector <messageId*> messageIdSequence::getMessageIdList() +{ + return (m_list); +} + + +} // vmime |