diff options
author | Vincent Richard <[email protected]> | 2005-03-25 20:49:54 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2005-03-25 20:49:54 +0000 |
commit | 433f21263f7f34456be4aeba27f467ca1ad06d1a (patch) | |
tree | a3b8fb270fcd608acf36a20481a1ecaee7dbac80 /src/path.cpp | |
parent | Added a section about warnings at compilation. (diff) | |
download | vmime-433f21263f7f34456be4aeba27f467ca1ad06d1a.tar.gz vmime-433f21263f7f34456be4aeba27f467ca1ad06d1a.zip |
Basic support for MDN (RFC-3798).
Diffstat (limited to 'src/path.cpp')
-rw-r--r-- | src/path.cpp | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/path.cpp b/src/path.cpp new file mode 100644 index 00000000..153facd3 --- /dev/null +++ b/src/path.cpp @@ -0,0 +1,184 @@ +// +// 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/path.hpp" +#include "vmime/parserHelpers.hpp" + + +namespace vmime +{ + + +path::path() +{ +} + + +path::path(const string& localPart, const string& domain) + : m_localPart(localPart), m_domain(domain) +{ +} + + +path::path(const path& p) + : component(), m_localPart(p.m_localPart), m_domain(p.m_domain) +{ +} + + +const string& path::getLocalPart() const +{ + return (m_localPart); +} + + +void path::setLocalPart(const string& localPart) +{ + m_localPart = localPart; +} + + +const string& path::getDomain() const +{ + return (m_domain); +} + + +void path::setDomain(const string& domain) +{ + m_domain = domain; +} + + +const bool path::operator==(const path& p) const +{ + return (m_localPart == p.m_localPart && + m_domain == p.m_domain); +} + + +const bool path::operator!=(const path& p) const +{ + return (m_localPart != p.m_localPart || + m_domain != p.m_domain); +} + + +void path::copyFrom(const component& other) +{ + const path& p = dynamic_cast <const path&>(other); + + m_localPart = p.m_localPart; + m_domain = p.m_domain; +} + + +path* path::clone() const +{ + return new path(*this); +} + + +path& path::operator=(const path& other) +{ + copyFrom(other); + return (*this); +} + + +const std::vector <const component*> path::getChildComponents() const +{ + return std::vector <const component*>(); +} + + +void path::parse(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; + + string addrSpec; + + if (pos < end && buffer[pos] == '<') + { + // Skip '<' + ++pos; + + while (pos < end && parserHelpers::isSpace(buffer[pos])) + ++pos; + + const string::size_type addrStart = pos; + + while (pos < end && buffer[pos] != '>') + ++pos; + + string::size_type addrEnd = pos; + + while (addrEnd > addrStart && parserHelpers::isSpace(buffer[addrEnd - 1])) + addrEnd--; + + addrSpec = string(buffer.begin() + addrStart, buffer.begin() + addrEnd); + } + else + { + addrSpec = string(buffer.begin() + position, buffer.begin() + end); + } + + const string::size_type at = addrSpec.find_first_of('@'); + + if (at != string::npos) + { + m_localPart = string(addrSpec.begin(), addrSpec.begin() + at); + m_domain = string(addrSpec.begin() + at + 1, addrSpec.end()); + } + else + { + m_localPart.clear(); + m_domain = addrSpec; + } + + if (newPosition != NULL) + *newPosition = end; +} + + +void path::generate(utility::outputStream& os, const string::size_type /* maxLineLength */, + const string::size_type curLinePos, string::size_type* newLinePos) const +{ + if (m_localPart.empty() && m_domain.empty()) + { + os << "<>"; + + if (newLinePos) + *newLinePos = curLinePos + 2; + } + else + { + os << "<" << m_localPart << "@" << m_domain << ">"; + + if (newLinePos) + *newLinePos = curLinePos + m_localPart.length() + m_domain.length() + 3; + } +} + + +} // vmime |