2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
// VMime library (http://vmime.sourceforge.net)
|
|
|
|
// Copyright (C) 2002-2004 Vincent Richard <vincent@vincent-richard.net>
|
|
|
|
//
|
|
|
|
// 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 "addressList.hpp"
|
|
|
|
#include "parserHelpers.hpp"
|
2004-10-21 15:05:47 +00:00
|
|
|
#include "exception.hpp"
|
|
|
|
#include "mailboxList.hpp"
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace vmime
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
addressList::addressList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
addressList::addressList(const addressList& addrList)
|
2004-10-05 10:28:21 +00:00
|
|
|
: component()
|
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
copyFrom(addrList);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
addressList::~addressList()
|
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
removeAllAddresses();
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addressList::parse(const string& buffer, const string::size_type position,
|
|
|
|
const string::size_type end, string::size_type* newPosition)
|
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
removeAllAddresses();
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
string::size_type pos = position;
|
|
|
|
|
|
|
|
while (pos < end)
|
|
|
|
{
|
|
|
|
address* parsedAddress = address::parseNext(buffer, pos, end, &pos);
|
|
|
|
|
|
|
|
if (parsedAddress != NULL)
|
|
|
|
m_list.push_back(parsedAddress);
|
|
|
|
}
|
|
|
|
|
2004-12-15 20:28:09 +00:00
|
|
|
setParsedBounds(position, end);
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
if (newPosition)
|
|
|
|
*newPosition = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addressList::generate(utility::outputStream& os, const string::size_type maxLineLength,
|
|
|
|
const string::size_type curLinePos, string::size_type* newLinePos) const
|
|
|
|
{
|
|
|
|
if (!m_list.empty())
|
|
|
|
{
|
|
|
|
string::size_type pos = curLinePos;
|
2004-10-21 15:05:47 +00:00
|
|
|
std::vector <address*>::const_iterator i = m_list.begin();
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
for ( ; ; )
|
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
(*i)->generate(os, maxLineLength - 2, pos, &pos);
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
if (++i != m_list.end())
|
|
|
|
{
|
|
|
|
os << ", ";
|
|
|
|
pos += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newLinePos)
|
|
|
|
*newLinePos = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::copyFrom(const component& other)
|
|
|
|
{
|
|
|
|
const addressList& addrList = dynamic_cast <const addressList&>(other);
|
|
|
|
|
|
|
|
removeAllAddresses();
|
|
|
|
|
|
|
|
for (std::vector <address*>::const_iterator it = addrList.m_list.begin() ;
|
|
|
|
it != addrList.m_list.end() ; ++it)
|
|
|
|
{
|
|
|
|
m_list.push_back(static_cast <address*>((*it)->clone()));
|
|
|
|
}
|
|
|
|
}
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
|
|
|
|
addressList& addressList::operator=(const addressList& other)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
copyFrom(other);
|
|
|
|
return (*this);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
addressList& addressList::operator=(const mailboxList& other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
return (*this);
|
|
|
|
}
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
|
|
|
|
addressList* addressList::clone() const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
return new addressList(*this);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::appendAddress(address* addr)
|
|
|
|
{
|
|
|
|
m_list.push_back(addr);
|
|
|
|
}
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::insertAddressBefore(address* beforeAddress, address* addr)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
const std::vector <address*>::iterator it = std::find
|
|
|
|
(m_list.begin(), m_list.end(), beforeAddress);
|
|
|
|
|
|
|
|
if (it == m_list.end())
|
|
|
|
throw exceptions::no_such_address();
|
|
|
|
|
|
|
|
m_list.insert(it, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addressList::insertAddressBefore(const int pos, address* addr)
|
|
|
|
{
|
|
|
|
m_list.insert(m_list.begin() + pos, addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addressList::insertAddressAfter(address* afterAddress, address* addr)
|
|
|
|
{
|
|
|
|
const std::vector <address*>::iterator it = std::find
|
|
|
|
(m_list.begin(), m_list.end(), afterAddress);
|
|
|
|
|
|
|
|
if (it == m_list.end())
|
|
|
|
throw exceptions::no_such_address();
|
|
|
|
|
|
|
|
m_list.insert(it + 1, addr);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::insertAddressAfter(const int pos, address* addr)
|
|
|
|
{
|
|
|
|
m_list.insert(m_list.begin() + pos + 1, addr);
|
|
|
|
}
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::removeAddress(address* addr)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
const std::vector <address*>::iterator it = std::find
|
|
|
|
(m_list.begin(), m_list.end(), addr);
|
|
|
|
|
|
|
|
if (it == m_list.end())
|
|
|
|
throw exceptions::no_such_address();
|
|
|
|
|
|
|
|
delete (*it);
|
|
|
|
|
|
|
|
m_list.erase(it);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
void addressList::removeAddress(const int pos)
|
|
|
|
{
|
|
|
|
const std::vector <address*>::iterator it = m_list.begin() + pos;
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
delete (*it);
|
|
|
|
|
|
|
|
m_list.erase(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void addressList::removeAllAddresses()
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
free_container(m_list);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const int addressList::getAddressCount() const
|
|
|
|
{
|
|
|
|
return (m_list.size());
|
|
|
|
}
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const bool addressList::isEmpty() const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
return (m_list.empty());
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
address* addressList::getAddressAt(const int pos)
|
|
|
|
{
|
|
|
|
return (m_list[pos]);
|
|
|
|
}
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const address* const addressList::getAddressAt(const int pos) const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
return (m_list[pos]);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const std::vector <const address*> addressList::getAddressList() const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
std::vector <const address*> list;
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
list.reserve(m_list.size());
|
|
|
|
|
|
|
|
for (std::vector <address*>::const_iterator it = m_list.begin() ;
|
|
|
|
it != m_list.end() ; ++it)
|
|
|
|
{
|
|
|
|
list.push_back(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (list);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const std::vector <address*> addressList::getAddressList()
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
return (m_list);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-12-20 12:33:55 +00:00
|
|
|
const std::vector <const component*> addressList::getChildComponents() const
|
|
|
|
{
|
|
|
|
std::vector <const component*> list;
|
|
|
|
|
|
|
|
copy_vector(m_list, list);
|
|
|
|
|
|
|
|
return (list);
|
|
|
|
}
|
2004-10-21 15:05:47 +00:00
|
|
|
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
} // vmime
|