aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/address.cpp22
-rw-r--r--src/addressList.cpp56
-rw-r--r--src/base.cpp5
-rw-r--r--src/body.cpp155
-rw-r--r--src/bodyPart.cpp53
-rw-r--r--src/charset.cpp8
-rw-r--r--src/component.cpp12
-rw-r--r--src/contentDisposition.cpp8
-rw-r--r--src/dateTime.cpp8
-rw-r--r--src/defaultAttachment.cpp32
-rw-r--r--src/defaultParameter.cpp34
-rw-r--r--src/disposition.cpp8
-rw-r--r--src/emptyContentHandler.cpp4
-rw-r--r--src/encoderFactory.cpp19
-rw-r--r--src/encoding.cpp12
-rw-r--r--src/fileAttachment.cpp18
-rw-r--r--src/header.cpp133
-rw-r--r--src/headerField.cpp14
-rw-r--r--src/headerFieldFactory.cpp4
-rw-r--r--src/htmlTextPart.cpp179
-rw-r--r--src/mailbox.cpp8
-rw-r--r--src/mailboxField.cpp8
-rw-r--r--src/mailboxGroup.cpp62
-rw-r--r--src/mailboxList.cpp46
-rw-r--r--src/mdn/MDNHelper.cpp132
-rw-r--r--src/mdn/receivedMDNInfos.cpp16
-rw-r--r--src/mdn/sendableMDNInfos.cpp4
-rw-r--r--src/mediaType.cpp8
-rw-r--r--src/messageBuilder.cpp61
-rw-r--r--src/messageId.cpp12
-rw-r--r--src/messageIdSequence.cpp52
-rw-r--r--src/messageParser.cpp69
-rw-r--r--src/messaging/authenticationInfos.cpp2
-rw-r--r--src/messaging/defaultAuthenticator.cpp8
-rw-r--r--src/messaging/events.cpp13
-rw-r--r--src/messaging/imap/IMAPConnection.cpp27
-rw-r--r--src/messaging/imap/IMAPFolder.cpp196
-rw-r--r--src/messaging/imap/IMAPMessage.cpp83
-rw-r--r--src/messaging/imap/IMAPStore.cpp35
-rw-r--r--src/messaging/imap/IMAPTag.cpp2
-rw-r--r--src/messaging/maildir/maildirFolder.cpp223
-rw-r--r--src/messaging/maildir/maildirMessage.cpp72
-rw-r--r--src/messaging/maildir/maildirStore.cpp19
-rw-r--r--src/messaging/maildir/maildirUtils.cpp2
-rw-r--r--src/messaging/pop3/POP3Folder.cpp99
-rw-r--r--src/messaging/pop3/POP3Store.cpp17
-rw-r--r--src/messaging/sendmail/sendmailTransport.cpp4
-rw-r--r--src/messaging/service.cpp20
-rw-r--r--src/messaging/serviceFactory.cpp27
-rw-r--r--src/messaging/serviceInfos.cpp2
-rw-r--r--src/messaging/session.cpp50
-rw-r--r--src/messaging/smtp/SMTPTransport.cpp5
-rw-r--r--src/messaging/transport.cpp6
-rw-r--r--src/misc/importanceHelper.cpp24
-rw-r--r--src/object.cpp130
-rw-r--r--src/parameter.cpp10
-rw-r--r--src/parameterFactory.cpp8
-rw-r--r--src/parameterizedHeaderField.cpp78
-rw-r--r--src/path.cpp8
-rw-r--r--src/plainTextPart.cpp25
-rw-r--r--src/platforms/posix/posixChildProcess.cpp15
-rw-r--r--src/platforms/posix/posixFile.cpp33
-rw-r--r--src/platforms/posix/posixSocket.cpp4
-rw-r--r--src/platforms/windows/windowsFile.cpp37
-rw-r--r--src/platforms/windows/windowsSocket.cpp6
-rw-r--r--src/propertySet.cpp38
-rw-r--r--src/relay.cpp8
-rw-r--r--src/streamContentHandler.cpp88
-rw-r--r--src/stringContentHandler.cpp12
-rw-r--r--src/text.cpp94
-rw-r--r--src/textPartFactory.cpp16
-rw-r--r--src/utility/path.cpp1
-rw-r--r--src/utility/stream.cpp7
-rw-r--r--src/utility/url.cpp4
-rw-r--r--src/word.cpp24
75 files changed, 1443 insertions, 1401 deletions
diff --git a/src/address.cpp b/src/address.cpp
index b0e11521..13a0ad59 100644
--- a/src/address.cpp
+++ b/src/address.cpp
@@ -62,7 +62,7 @@ address-list = (address *("," address)) / obs-addr-list
*/
-address* address::parseNext(const string& buffer, const string::size_type position,
+ref <address> address::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
bool escaped = false;
@@ -171,22 +171,14 @@ address* address::parseNext(const string& buffer, const string::size_type positi
// Parse extracted address (mailbox or group)
if (pos != start)
{
- address* parsedAddress = isGroup
- ? static_cast<address*>(new mailboxGroup)
- : static_cast<address*>(new mailbox);
+ ref <address> parsedAddress = isGroup
+ ? create <mailboxGroup>().dynamicCast <address>()
+ : create <mailbox>().dynamicCast <address>();
- try
- {
- parsedAddress->parse(buffer, start, pos, NULL);
- parsedAddress->setParsedBounds(start, pos);
+ parsedAddress->parse(buffer, start, pos, NULL);
+ parsedAddress->setParsedBounds(start, pos);
- return (parsedAddress);
- }
- catch (std::exception&)
- {
- delete (parsedAddress);
- throw;
- }
+ return (parsedAddress);
}
return (NULL);
diff --git a/src/addressList.cpp b/src/addressList.cpp
index 9693a663..e4f9ab04 100644
--- a/src/addressList.cpp
+++ b/src/addressList.cpp
@@ -54,7 +54,7 @@ void addressList::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- address* parsedAddress = address::parseNext(buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(buffer, pos, end, &pos);
if (parsedAddress != NULL)
m_list.push_back(parsedAddress);
@@ -74,7 +74,7 @@ void addressList::generate(utility::outputStream& os, const string::size_type ma
if (!m_list.empty())
{
- for (std::vector <address*>::const_iterator i = m_list.begin() ; ; )
+ for (std::vector <ref <address> >::const_iterator i = m_list.begin() ; ; )
{
(*i)->generate(os, maxLineLength - 2, pos, &pos);
@@ -97,10 +97,10 @@ void addressList::copyFrom(const component& other)
removeAllAddresses();
- for (std::vector <address*>::const_iterator it = addrList.m_list.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = addrList.m_list.begin() ;
it != addrList.m_list.end() ; ++it)
{
- m_list.push_back(static_cast <address*>((*it)->clone()));
+ m_list.push_back((*it)->clone().dynamicCast <address>());
}
}
@@ -117,27 +117,27 @@ addressList& addressList::operator=(const mailboxList& other)
removeAllAddresses();
for (int i = 0 ; i < other.getMailboxCount() ; ++i)
- m_list.push_back(other.getMailboxAt(i)->clone());
+ m_list.push_back(other.getMailboxAt(i)->clone().dynamicCast <address>());
return (*this);
}
-addressList* addressList::clone() const
+ref <component> addressList::clone() const
{
- return new addressList(*this);
+ return vmime::create <addressList>(*this);
}
-void addressList::appendAddress(address* addr)
+void addressList::appendAddress(ref <address> addr)
{
m_list.push_back(addr);
}
-void addressList::insertAddressBefore(address* beforeAddress, address* addr)
+void addressList::insertAddressBefore(ref <address> beforeAddress, ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeAddress);
if (it == m_list.end())
@@ -147,15 +147,15 @@ void addressList::insertAddressBefore(address* beforeAddress, address* addr)
}
-void addressList::insertAddressBefore(const int pos, address* addr)
+void addressList::insertAddressBefore(const int pos, ref <address> addr)
{
m_list.insert(m_list.begin() + pos, addr);
}
-void addressList::insertAddressAfter(address* afterAddress, address* addr)
+void addressList::insertAddressAfter(ref <address> afterAddress, ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterAddress);
if (it == m_list.end())
@@ -165,31 +165,27 @@ void addressList::insertAddressAfter(address* afterAddress, address* addr)
}
-void addressList::insertAddressAfter(const int pos, address* addr)
+void addressList::insertAddressAfter(const int pos, ref <address> addr)
{
m_list.insert(m_list.begin() + pos + 1, addr);
}
-void addressList::removeAddress(address* addr)
+void addressList::removeAddress(ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <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);
}
void addressList::removeAddress(const int pos)
{
- const std::vector <address*>::iterator it = m_list.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <address> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -197,7 +193,7 @@ void addressList::removeAddress(const int pos)
void addressList::removeAllAddresses()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -213,25 +209,25 @@ const bool addressList::isEmpty() const
}
-address* addressList::getAddressAt(const int pos)
+ref <address> addressList::getAddressAt(const int pos)
{
return (m_list[pos]);
}
-const address* addressList::getAddressAt(const int pos) const
+const ref <const address> addressList::getAddressAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const address*> addressList::getAddressList() const
+const std::vector <ref <const address> > addressList::getAddressList() const
{
- std::vector <const address*> list;
+ std::vector <ref <const address> > list;
list.reserve(m_list.size());
- for (std::vector <address*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -241,15 +237,15 @@ const std::vector <const address*> addressList::getAddressList() const
}
-const std::vector <address*> addressList::getAddressList()
+const std::vector <ref <address> > addressList::getAddressList()
{
return (m_list);
}
-const std::vector <const component*> addressList::getChildComponents() const
+const std::vector <ref <const component> > addressList::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_list, list);
diff --git a/src/base.cpp b/src/base.cpp
index 235bedbf..79ad0655 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -96,6 +96,11 @@ const string CRLF = "\r\n";
const string SUPPORTED_MIME_VERSION = "1.0";
+/** Null reference.
+ */
+const null_ref null = null_ref();
+
+
// Line length limits
namespace lineLengthLimits
{
diff --git a/src/body.cpp b/src/body.cpp
index 5438d2e0..135b1e14 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -37,23 +37,13 @@ namespace vmime
body::body()
- : m_contents(new emptyContentHandler()), m_part(NULL), m_header(NULL)
-{
-}
-
-
-body::body(bodyPart* parentPart)
- : m_contents(new emptyContentHandler()),
- m_part(parentPart), m_header(parentPart != NULL ? parentPart->getHeader() : NULL)
+ : m_contents(create <emptyContentHandler>()), m_part(NULL), m_header(NULL)
{
}
body::~body()
{
- delete (m_contents);
-
- removeAllParts();
}
@@ -68,16 +58,16 @@ void body::parse(const string& buffer, const string::size_type position,
try
{
- const contentTypeField& ctf = dynamic_cast <contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::MULTIPART)
+ if (ctf->getValue().getType() == mediaTypes::MULTIPART)
{
isMultipart = true;
try
{
- boundary = ctf.getBoundary();
+ boundary = ctf->getBoundary();
}
catch (exceptions::no_such_parameter&)
{
@@ -175,18 +165,9 @@ void body::parse(const string& buffer, const string::size_type position,
if (index > 0)
{
- bodyPart* part = new bodyPart;
-
- try
- {
- part->parse(buffer, partStart, partEnd, NULL);
- }
- catch (std::exception&)
- {
- delete (part);
- throw;
- }
+ ref <bodyPart> part = vmime::create <bodyPart>();
+ part->parse(buffer, partStart, partEnd, NULL);
part->m_parent = m_part;
m_parts.push_back(part);
@@ -196,7 +177,7 @@ void body::parse(const string& buffer, const string::size_type position,
pos = buffer.find(boundarySep, partStart);
}
- setContentsImpl(emptyContentHandler());
+ m_contents = vmime::create <emptyContentHandler>();
if (partStart < end)
m_epilogText = string(buffer.begin() + partStart, buffer.begin() + end);
@@ -205,7 +186,7 @@ void body::parse(const string& buffer, const string::size_type position,
else
{
// Extract the (encoded) contents
- setContentsImpl(stringContentHandler(buffer, position, end, getEncoding()));
+ m_contents = vmime::create <stringContentHandler>(buffer, position, end, getEncoding());
}
setParsedBounds(position, end);
@@ -231,10 +212,10 @@ void body::generate(utility::outputStream& os, const string::size_type maxLineLe
{
try
{
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();
- boundary = ctf.getBoundary();
+ boundary = ctf->getBoundary();
}
catch (exceptions::no_such_field&)
{
@@ -400,10 +381,10 @@ const mediaType body::getContentType() const
{
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();
- return (ctf.getValue());
+ return (ctf->getValue());
}
catch (exceptions::no_such_field&)
{
@@ -417,12 +398,10 @@ const charset body::getCharset() const
{
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- const class charset& cs = ctf.getCharset();
-
- return (cs);
+ return (ctf->getCharset());
}
catch (exceptions::no_such_parameter&)
{
@@ -441,10 +420,10 @@ const encoding body::getEncoding() const
{
try
{
- const contentEncodingField& cef = dynamic_cast<contentEncodingField&>
- (*m_header->findField(fields::CONTENT_TRANSFER_ENCODING));
+ const ref <const contentEncodingField> cef =
+ m_header->findField(fields::CONTENT_TRANSFER_ENCODING).dynamicCast <contentEncodingField>();
- return (cef.getValue());
+ return (cef->getValue());
}
catch (exceptions::no_such_field&)
{
@@ -454,15 +433,22 @@ const encoding body::getEncoding() const
}
+void body::setParentPart(weak_ref <bodyPart> parent)
+{
+ m_part = parent;
+ m_header = (parent != NULL ? parent->getHeader() : NULL);
+}
+
+
const bool body::isRootPart() const
{
return (m_part == NULL || m_part->getParentPart() == NULL);
}
-body* body::clone() const
+ref <component> body::clone() const
{
- body* bdy = new body(NULL);
+ ref <body> bdy = vmime::create <body>();
bdy->copyFrom(*this);
@@ -477,13 +463,13 @@ void body::copyFrom(const component& other)
m_prologText = bdy.m_prologText;
m_epilogText = bdy.m_epilogText;
- setContentsImpl(*bdy.m_contents);
+ m_contents = bdy.m_contents;
removeAllParts();
for (int p = 0 ; p < bdy.getPartCount() ; ++p)
{
- bodyPart* part = bdy.getPartAt(p)->clone();
+ ref <bodyPart> part = bdy.getPartAt(p)->clone().dynamicCast <bodyPart>();
part->m_parent = m_part;
@@ -523,19 +509,19 @@ void body::setEpilogText(const string& epilogText)
}
-const contentHandler& body::getContents() const
+const ref <const contentHandler> body::getContents() const
{
- return (*m_contents);
+ return (m_contents);
}
-void body::setContents(const contentHandler& contents)
+void body::setContents(ref <contentHandler> contents)
{
- setContentsImpl(contents);
+ m_contents = contents;
}
-void body::initNewPart(bodyPart* part)
+void body::initNewPart(ref <bodyPart> part)
{
part->m_parent = m_part;
@@ -544,23 +530,23 @@ void body::initNewPart(bodyPart* part)
// Check whether we have a boundary string
try
{
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
try
{
- const string boundary = ctf.getBoundary();
+ const string boundary = ctf->getBoundary();
if (boundary.empty() || !isValidBoundary(boundary))
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setBoundary(generateRandomBoundaryString());
}
catch (exceptions::no_such_parameter&)
{
// No "boundary" parameter: generate a random one.
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setBoundary(generateRandomBoundaryString());
}
- if (ctf.getValue().getType() != mediaTypes::MULTIPART)
+ if (ctf->getValue().getType() != mediaTypes::MULTIPART)
{
// Warning: multi-part body but the Content-Type is
// not specified as "multipart/..."
@@ -570,17 +556,17 @@ void body::initNewPart(bodyPart* part)
{
// No "Content-Type" field: create a new one and generate
// a random boundary string.
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->getField(fields::CONTENT_TYPE));
+ ref <contentTypeField> ctf =
+ m_header->getField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- ctf.setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
+ ctf->setBoundary(generateRandomBoundaryString());
}
}
}
-void body::appendPart(bodyPart* part)
+void body::appendPart(ref <bodyPart> part)
{
initNewPart(part);
@@ -588,11 +574,11 @@ void body::appendPart(bodyPart* part)
}
-void body::insertPartBefore(bodyPart* beforePart, bodyPart* part)
+void body::insertPartBefore(ref <bodyPart> beforePart, ref <bodyPart> part)
{
initNewPart(part);
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), beforePart);
if (it == m_parts.end())
@@ -602,7 +588,7 @@ void body::insertPartBefore(bodyPart* beforePart, bodyPart* part)
}
-void body::insertPartBefore(const int pos, bodyPart* part)
+void body::insertPartBefore(const int pos, ref <bodyPart> part)
{
initNewPart(part);
@@ -610,11 +596,11 @@ void body::insertPartBefore(const int pos, bodyPart* part)
}
-void body::insertPartAfter(bodyPart* afterPart, bodyPart* part)
+void body::insertPartAfter(ref <bodyPart> afterPart, ref <bodyPart> part)
{
initNewPart(part);
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), afterPart);
if (it == m_parts.end())
@@ -624,7 +610,7 @@ void body::insertPartAfter(bodyPart* afterPart, bodyPart* part)
}
-void body::insertPartAfter(const int pos, bodyPart* part)
+void body::insertPartAfter(const int pos, ref <bodyPart> part)
{
initNewPart(part);
@@ -632,31 +618,27 @@ void body::insertPartAfter(const int pos, bodyPart* part)
}
-void body::removePart(bodyPart* part)
+void body::removePart(ref <bodyPart> part)
{
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), part);
if (it == m_parts.end())
throw exceptions::no_such_part();
- delete (*it);
-
m_parts.erase(it);
}
void body::removePart(const int pos)
{
- delete (m_parts[pos]);
-
m_parts.erase(m_parts.begin() + pos);
}
void body::removeAllParts()
{
- free_container(m_parts);
+ m_parts.clear();
}
@@ -672,25 +654,25 @@ const bool body::isEmpty() const
}
-bodyPart* body::getPartAt(const int pos)
+ref <bodyPart> body::getPartAt(const int pos)
{
return (m_parts[pos]);
}
-const bodyPart* body::getPartAt(const int pos) const
+const ref <const bodyPart> body::getPartAt(const int pos) const
{
return (m_parts[pos]);
}
-const std::vector <const bodyPart*> body::getPartList() const
+const std::vector <ref <const bodyPart> > body::getPartList() const
{
- std::vector <const bodyPart*> list;
+ std::vector <ref <const bodyPart> > list;
list.reserve(m_parts.size());
- for (std::vector <bodyPart*>::const_iterator it = m_parts.begin() ;
+ for (std::vector <ref <bodyPart> >::const_iterator it = m_parts.begin() ;
it != m_parts.end() ; ++it)
{
list.push_back(*it);
@@ -700,15 +682,15 @@ const std::vector <const bodyPart*> body::getPartList() const
}
-const std::vector <bodyPart*> body::getPartList()
+const std::vector <ref <bodyPart> > body::getPartList()
{
return (m_parts);
}
-const std::vector <const component*> body::getChildComponents() const
+const std::vector <ref <const component> > body::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_parts, list);
@@ -716,11 +698,4 @@ const std::vector <const component*> body::getChildComponents() const
}
-void body::setContentsImpl(const contentHandler& cts)
-{
- delete (m_contents);
- m_contents = cts.clone();
-}
-
-
} // vmime
diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp
index 6995ccac..898fab23 100644
--- a/src/bodyPart.cpp
+++ b/src/bodyPart.cpp
@@ -25,8 +25,11 @@ namespace vmime
bodyPart::bodyPart()
- : m_body(this), m_parent(NULL)
+ : m_header(vmime::create <header>()),
+ m_body(vmime::create <body>()),
+ m_parent(NULL)
{
+ m_body->setParentPart(this);
}
@@ -35,10 +38,10 @@ void bodyPart::parse(const string& buffer, const string::size_type position,
{
// Parse the headers
string::size_type pos = position;
- m_header.parse(buffer, pos, end, &pos);
+ m_header->parse(buffer, pos, end, &pos);
// Parse the body contents
- m_body.parse(buffer, pos, end, NULL);
+ m_body->parse(buffer, pos, end, NULL);
setParsedBounds(position, end);
@@ -50,25 +53,25 @@ void bodyPart::parse(const string& buffer, const string::size_type position,
void bodyPart::generate(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
- m_header.generate(os, maxLineLength);
+ m_header->generate(os, maxLineLength);
os << CRLF;
- m_body.generate(os, maxLineLength);
+ m_body->generate(os, maxLineLength);
if (newLinePos)
*newLinePos = 0;
}
-bodyPart* bodyPart::clone() const
+ref <component> bodyPart::clone() const
{
- bodyPart* p = new bodyPart;
+ ref <bodyPart> p = vmime::create <bodyPart>();
- p->m_parent = NULL;
+ p->m_parent = null;
- p->m_header.copyFrom(m_header);
- p->m_body.copyFrom(m_body);
+ p->m_header->copyFrom(*m_header);
+ p->m_body->copyFrom(*m_body);
return (p);
}
@@ -78,8 +81,8 @@ void bodyPart::copyFrom(const component& other)
{
const bodyPart& bp = dynamic_cast <const bodyPart&>(other);
- m_header = bp.m_header;
- m_body = bp.m_body;
+ m_header->copyFrom(*(bp.m_header));
+ m_body->copyFrom(*(bp.m_body));
}
@@ -90,42 +93,42 @@ bodyPart& bodyPart::operator=(const bodyPart& other)
}
-const header* bodyPart::getHeader() const
+const ref <const header> bodyPart::getHeader() const
{
- return (&m_header);
+ return (m_header);
}
-header* bodyPart::getHeader()
+ref <header> bodyPart::getHeader()
{
- return (&m_header);
+ return (m_header);
}
-const body* bodyPart::getBody() const
+const ref <const body> bodyPart::getBody() const
{
- return (&m_body);
+ return (m_body);
}
-body* bodyPart::getBody()
+ref <body> bodyPart::getBody()
{
- return (&m_body);
+ return (m_body);
}
-bodyPart* bodyPart::getParentPart() const
+weak_ref <bodyPart> bodyPart::getParentPart() const
{
return (m_parent);
}
-const std::vector <const component*> bodyPart::getChildComponents() const
+const std::vector <ref <const component> > bodyPart::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&m_header);
- list.push_back(&m_body);
+ list.push_back(m_header);
+ list.push_back(m_body);
return (list);
}
diff --git a/src/charset.cpp b/src/charset.cpp
index cc2ba9ba..2a39b03f 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -280,9 +280,9 @@ const bool charset::operator!=(const charset& value) const
}
-charset* charset::clone() const
+ref <component> charset::clone() const
{
- return new charset(m_name);
+ return vmime::create <charset>(m_name);
}
@@ -298,9 +298,9 @@ void charset::copyFrom(const component& other)
}
-const std::vector <const component*> charset::getChildComponents() const
+const std::vector <ref <const component> > charset::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/component.cpp b/src/component.cpp
index c0301f7c..c237bd74 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -75,19 +75,19 @@ void component::setParsedBounds(const string::size_type start, const string::siz
}
-const std::vector <component*> component::getChildComponents()
+const std::vector <ref <component> > component::getChildComponents()
{
- const std::vector <const component*> constList =
+ const std::vector <ref <const component> > constList =
const_cast <const component*>(this)->getChildComponents();
- std::vector <component*> list;
+ std::vector <ref <component> > list;
- const std::vector <const component*>::size_type count = constList.size();
+ const std::vector <ref <const component> >::size_type count = constList.size();
list.resize(count);
- for (std::vector <const component*>::size_type i = 0 ; i < count ; ++i)
- list[i] = const_cast <component*>(constList[i]);
+ for (std::vector <ref <const component> >::size_type i = 0 ; i < count ; ++i)
+ list[i] = constList[i].constCast <component>();
return (list);
}
diff --git a/src/contentDisposition.cpp b/src/contentDisposition.cpp
index a2c53843..0b93cdda 100644
--- a/src/contentDisposition.cpp
+++ b/src/contentDisposition.cpp
@@ -85,9 +85,9 @@ const bool contentDisposition::operator!=(const contentDisposition& value) const
}
-contentDisposition* contentDisposition::clone() const
+ref <component> contentDisposition::clone() const
{
- return new contentDisposition(*this);
+ return vmime::create <contentDisposition>(*this);
}
@@ -118,9 +118,9 @@ void contentDisposition::setName(const string& name)
}
-const std::vector <const component*> contentDisposition::getChildComponents() const
+const std::vector <ref <const component> > contentDisposition::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index d2807a2a..a98fcc8b 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -730,15 +730,15 @@ const datetime datetime::now()
}
-datetime* datetime::clone() const
+ref <component> datetime::clone() const
{
- return new datetime(*this);
+ return vmime::create <datetime>(*this);
}
-const std::vector <const component*> datetime::getChildComponents() const
+const std::vector <ref <const component> > datetime::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/defaultAttachment.cpp b/src/defaultAttachment.cpp
index fe0e6d2f..dc8f8ccc 100644
--- a/src/defaultAttachment.cpp
+++ b/src/defaultAttachment.cpp
@@ -30,16 +30,16 @@ defaultAttachment::defaultAttachment()
}
-defaultAttachment::defaultAttachment(const contentHandler& data,
+defaultAttachment::defaultAttachment(ref <contentHandler> data,
const encoding& enc, const mediaType& type, const text& desc)
- : m_type(type), m_desc(desc), m_data(data.clone()), m_encoding(enc)
+ : m_type(type), m_desc(desc), m_data(data), m_encoding(enc)
{
}
-defaultAttachment::defaultAttachment(const contentHandler& data,
+defaultAttachment::defaultAttachment(ref <contentHandler> data,
const mediaType& type, const text& desc)
- : m_type(type), m_desc(desc), m_data(data.clone()),
+ : m_type(type), m_desc(desc), m_data(data),
m_encoding(encoding::decide(data))
{
}
@@ -47,25 +47,21 @@ defaultAttachment::defaultAttachment(const contentHandler& data,
defaultAttachment::defaultAttachment(const defaultAttachment& attach)
: attachment(), m_type(attach.m_type), m_desc(attach.m_desc),
- m_data(attach.m_data->clone()), m_encoding(attach.m_encoding)
+ m_data(attach.m_data->clone().dynamicCast <contentHandler>()), m_encoding(attach.m_encoding)
{
}
defaultAttachment::~defaultAttachment()
{
- delete (m_data);
}
defaultAttachment& defaultAttachment::operator=(const defaultAttachment& attach)
{
- if (m_data)
- delete (m_data);
-
m_type = attach.m_type;
m_desc = attach.m_desc;
- m_data = attach.m_data->clone();
+ m_data = attach.m_data->clone().dynamicCast <contentHandler>();
m_encoding = attach.m_encoding;
return (*this);
@@ -75,7 +71,7 @@ defaultAttachment& defaultAttachment::operator=(const defaultAttachment& attach)
void defaultAttachment::generateIn(bodyPart& parent) const
{
// Create and append a new part for this attachment
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
generatePart(*part);
@@ -85,13 +81,13 @@ void defaultAttachment::generateIn(bodyPart& parent) const
void defaultAttachment::generatePart(bodyPart& part) const
{
// Set header fields
- part.getHeader()->ContentType().setValue(m_type);
- if (!m_desc.isEmpty()) part.getHeader()->ContentDescription().setValue(m_desc);
- part.getHeader()->ContentTransferEncoding().setValue(m_encoding);
- part.getHeader()->ContentDisposition().setValue(contentDisposition(contentDispositionTypes::ATTACHMENT));
+ part.getHeader()->ContentType()->setValue(m_type);
+ if (!m_desc.isEmpty()) part.getHeader()->ContentDescription()->setValue(m_desc);
+ part.getHeader()->ContentTransferEncoding()->setValue(m_encoding);
+ part.getHeader()->ContentDisposition()->setValue(contentDisposition(contentDispositionTypes::ATTACHMENT));
// Set contents
- part.getBody()->setContents(*m_data);
+ part.getBody()->setContents(m_data);
}
@@ -107,9 +103,9 @@ const text& defaultAttachment::getDescription() const
}
-const contentHandler& defaultAttachment::getData() const
+const ref <const contentHandler> defaultAttachment::getData() const
{
- return (*m_data);
+ return (m_data);
}
diff --git a/src/defaultParameter.cpp b/src/defaultParameter.cpp
index 3a70eb72..5a0d2132 100644
--- a/src/defaultParameter.cpp
+++ b/src/defaultParameter.cpp
@@ -26,6 +26,7 @@ namespace vmime
defaultParameter::defaultParameter()
+ : m_value(vmime::create <word>())
{
}
@@ -37,36 +38,49 @@ defaultParameter& defaultParameter::operator=(const defaultParameter& other)
}
-const word& defaultParameter::getValue() const
+const ref <const component> defaultParameter::getValueImp() const
{
return (m_value);
}
-word& defaultParameter::getValue()
+const ref <component> defaultParameter::getValueImp()
{
return (m_value);
}
+const word& defaultParameter::getValue() const
+{
+ return (*m_value);
+}
+
+
+word& defaultParameter::getValue()
+{
+ return (*m_value);
+}
+
+
void defaultParameter::setValue(const word& value)
{
- m_value = value;
+ *m_value = value;
}
void defaultParameter::setValue(const component& value)
{
const word& v = dynamic_cast <const word&>(value);
- m_value = v;
+ *m_value = v;
}
void defaultParameter::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
- m_value = word(string(buffer.begin() + position, buffer.begin() + end),
- charset(charsets::US_ASCII));
+ m_value = vmime::create <word>
+ (string(buffer.begin() + position, buffer.begin() + end),
+ charset(charsets::US_ASCII));
if (newPosition)
*newPosition = end;
@@ -177,7 +191,7 @@ void defaultParameter::parse(const std::vector <valueChunk>& chunks)
}
}
- m_value = word(value.str(), ch);
+ m_value = vmime::create <word>(value.str(), ch);
}
@@ -185,7 +199,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
const string::size_type curLinePos, string::size_type* newLinePos) const
{
const string& name = getName();
- const string& value = m_value.getBuffer();
+ const string& value = m_value->getBuffer();
// For compatibility with implementations that do not understand RFC-2231,
// also generate a normal "7bit/us-ascii" parameter
@@ -298,7 +312,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
// + at least 5 characters for the value
const string::size_type firstSectionLength =
name.length() + 4 /* *0*= */ + 2 /* '' */
- + m_value.getCharset().getName().length();
+ + m_value->getCharset().getName().length();
if (pos + firstSectionLength + 5 >= maxLineLength)
{
@@ -395,7 +409,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
if (sectionNumber == 0)
{
- os << m_value.getCharset().getName();
+ os << m_value->getCharset().getName();
os << '\'' << /* No language */ '\'';
}
diff --git a/src/disposition.cpp b/src/disposition.cpp
index b894f85e..0ed98f9e 100644
--- a/src/disposition.cpp
+++ b/src/disposition.cpp
@@ -40,9 +40,9 @@ disposition::disposition(const string& actionMode, const string& sendingMode,
}
-disposition* disposition::clone() const
+ref <component> disposition::clone() const
{
- disposition* disp = new disposition;
+ ref <disposition> disp = vmime::create <disposition>();
disp->m_actionMode = m_actionMode;
disp->m_sendingMode = m_sendingMode;
@@ -75,9 +75,9 @@ disposition& disposition::operator=(const disposition& other)
}
-const std::vector <const component*> disposition::getChildComponents() const
+const std::vector <ref <const component> > disposition::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/emptyContentHandler.cpp b/src/emptyContentHandler.cpp
index 4dea2763..57153fa9 100644
--- a/src/emptyContentHandler.cpp
+++ b/src/emptyContentHandler.cpp
@@ -29,9 +29,9 @@ emptyContentHandler::emptyContentHandler()
}
-contentHandler* emptyContentHandler::clone() const
+ref <contentHandler> emptyContentHandler::clone() const
{
- return new emptyContentHandler();
+ return vmime::create <emptyContentHandler>();
}
diff --git a/src/encoderFactory.cpp b/src/encoderFactory.cpp
index 055dcecf..bd4227bf 100644
--- a/src/encoderFactory.cpp
+++ b/src/encoderFactory.cpp
@@ -46,11 +46,6 @@ encoderFactory::encoderFactory()
encoderFactory::~encoderFactory()
{
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
- it != m_encoders.end() ; ++it)
- {
- delete (*it);
- }
}
@@ -61,17 +56,17 @@ encoderFactory* encoderFactory::getInstance()
}
-encoder* encoderFactory::create(const string& name)
+ref <encoder> encoderFactory::create(const string& name)
{
return (getEncoderByName(name)->create());
}
-const encoderFactory::registeredEncoder* encoderFactory::getEncoderByName(const string& name) const
+const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderByName(const string& name) const
{
const string lcName(utility::stringUtils::toLower(name));
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
+ for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
if ((*it)->getName() == lcName)
@@ -88,17 +83,17 @@ const int encoderFactory::getEncoderCount() const
}
-const encoderFactory::registeredEncoder* encoderFactory::getEncoderAt(const int pos) const
+const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderAt(const int pos) const
{
return (m_encoders[pos]);
}
-const std::vector <const encoderFactory::registeredEncoder*> encoderFactory::getEncoderList() const
+const std::vector <ref <const encoderFactory::registeredEncoder> > encoderFactory::getEncoderList() const
{
- std::vector <const registeredEncoder*> res;
+ std::vector <ref <const registeredEncoder> > res;
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
+ for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
res.push_back(*it);
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 632333fb..94168645 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -69,7 +69,7 @@ void encoding::generate(utility::outputStream& os, const string::size_type /* ma
}
-encoder* encoding::getEncoder() const
+ref <encoder> encoding::getEncoder() const
{
return (encoderFactory::getInstance()->create(generate()));
}
@@ -155,16 +155,16 @@ const encoding encoding::decide
}
-const encoding encoding::decide(const contentHandler& /* data */)
+const encoding encoding::decide(ref <const contentHandler> /* data */)
{
// TODO: a better solution to do that?
return (encoding(encodingTypes::BASE64));
}
-encoding* encoding::clone() const
+ref <component> encoding::clone() const
{
- return new encoding(*this);
+ return vmime::create <encoding>(*this);
}
@@ -188,9 +188,9 @@ void encoding::setName(const string& name)
}
-const std::vector <const component*> encoding::getChildComponents() const
+const std::vector <ref <const component> > encoding::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index 423020b2..de1a3ba3 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -37,7 +37,7 @@ fileAttachment::fileAttachment(const string& filename, const mediaType& type, co
setData(filename);
- m_encoding = encoding::decide(*m_data);
+ m_encoding = encoding::decide(m_data);
}
@@ -64,7 +64,9 @@ void fileAttachment::setData(const string& filename)
throw exceptions::open_file_error();
}
- m_data = new streamContentHandler(new utility::inputStreamPointerAdapter(file, true), 0, true);
+ ref <utility::inputStream> is = vmime::create <utility::inputStreamPointerAdapter>(file, true);
+
+ m_data = vmime::create <streamContentHandler>(is, 0);
}
@@ -72,13 +74,13 @@ void fileAttachment::generatePart(bodyPart& part) const
{
defaultAttachment::generatePart(part);
- contentDispositionField& cdf = part.getHeader()->ContentDisposition();
+ ref <contentDispositionField> cdf = part.getHeader()->ContentDisposition();
- if (m_fileInfo.hasSize()) cdf.setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
- if (m_fileInfo.hasFilename()) cdf.setFilename(m_fileInfo.getFilename());
- if (m_fileInfo.hasCreationDate()) cdf.setCreationDate(m_fileInfo.getCreationDate());
- if (m_fileInfo.hasModificationDate()) cdf.setModificationDate(m_fileInfo.getModificationDate());
- if (m_fileInfo.hasReadDate()) cdf.setReadDate(m_fileInfo.getReadDate());
+ if (m_fileInfo.hasSize()) cdf->setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
+ if (m_fileInfo.hasFilename()) cdf->setFilename(m_fileInfo.getFilename());
+ if (m_fileInfo.hasCreationDate()) cdf->setCreationDate(m_fileInfo.getCreationDate());
+ if (m_fileInfo.hasModificationDate()) cdf->setModificationDate(m_fileInfo.getModificationDate());
+ if (m_fileInfo.hasReadDate()) cdf->setReadDate(m_fileInfo.getReadDate());
}
diff --git a/src/header.cpp b/src/header.cpp
index a89f750d..41718e47 100644
--- a/src/header.cpp
+++ b/src/header.cpp
@@ -64,7 +64,7 @@ void header::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- headerField* field = headerField::parseNext(buffer, pos, end, &pos);
+ ref <headerField> field = headerField::parseNext(buffer, pos, end, &pos);
if (field == NULL) break;
m_fields.push_back(field);
@@ -81,7 +81,7 @@ void header::generate(utility::outputStream& os, const string::size_type maxLine
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
// Generate the fields
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
it != m_fields.end() ; ++it)
{
(*it)->generate(os, maxLineLength);
@@ -93,26 +93,16 @@ void header::generate(utility::outputStream& os, const string::size_type maxLine
}
-header* header::clone() const
+ref <component> header::clone() const
{
- header* hdr = new header();
+ ref <header> hdr = vmime::create <header>();
- try
- {
- hdr->m_fields.reserve(m_fields.size());
+ hdr->m_fields.reserve(m_fields.size());
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
- it != m_fields.end() ; ++it)
- {
- hdr->m_fields.push_back((*it)->clone());
- }
- }
- catch (std::exception&)
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
+ it != m_fields.end() ; ++it)
{
- free_container(hdr->m_fields);
-
- delete (hdr);
- throw;
+ hdr->m_fields.push_back((*it)->clone().dynamicCast <headerField>());
}
return (hdr);
@@ -123,29 +113,20 @@ void header::copyFrom(const component& other)
{
const header& h = dynamic_cast <const header&>(other);
- std::vector <headerField*> fields;
-
- try
- {
- fields.reserve(h.m_fields.size());
-
- for (std::vector <headerField*>::const_iterator it = h.m_fields.begin() ;
- it != h.m_fields.end() ; ++it)
- {
- fields.push_back((*it)->clone());
- }
+ std::vector <ref <headerField> > fields;
- free_container(m_fields);
+ fields.reserve(h.m_fields.size());
- m_fields.resize(fields.size());
-
- std::copy(fields.begin(), fields.end(), m_fields.begin());
- }
- catch (std::exception&)
+ for (std::vector <ref <headerField> >::const_iterator it = h.m_fields.begin() ;
+ it != h.m_fields.end() ; ++it)
{
- free_container(fields);
- throw;
+ fields.push_back((*it)->clone().dynamicCast <headerField>());
}
+
+ m_fields.clear();
+ m_fields.resize(fields.size());
+
+ std::copy(fields.begin(), fields.end(), m_fields.begin());
}
@@ -160,8 +141,8 @@ const bool header::hasField(const string& fieldName) const
{
const string name = utility::stringUtils::toLower(fieldName);
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -169,13 +150,13 @@ const bool header::hasField(const string& fieldName) const
}
-headerField* header::findField(const string& fieldName) const
+ref <headerField> header::findField(const string& fieldName) const
{
const string name = utility::stringUtils::toLower(fieldName);
// Find the first field that matches the specified name
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -192,14 +173,14 @@ headerField* header::findField(const string& fieldName) const
}
-std::vector <headerField*> header::findAllFields(const string& fieldName)
+std::vector <ref <headerField> > header::findAllFields(const string& fieldName)
{
const string name = utility::stringUtils::toLower(fieldName);
- std::vector <headerField*> result;
+ std::vector <ref <headerField> > result;
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end ; ++pos)
{
@@ -214,30 +195,22 @@ std::vector <headerField*> header::findAllFields(const string& fieldName)
}
-headerField* header::getField(const string& fieldName)
+ref <headerField> header::getField(const string& fieldName)
{
const string name = utility::stringUtils::toLower(fieldName);
// Find the first field that matches the specified name
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
// If no field with this name can be found, create a new one
if (pos == end)
{
- headerField* field = headerFieldFactory::getInstance()->create(fieldName);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(fieldName);
- try
- {
- appendField(field);
- }
- catch (std::exception&)
- {
- delete (field);
- throw;
- }
+ appendField(field);
// Return a reference to the new field
return (field);
@@ -250,15 +223,15 @@ headerField* header::getField(const string& fieldName)
}
-void header::appendField(headerField* field)
+void header::appendField(ref <headerField> field)
{
m_fields.push_back(field);
}
-void header::insertFieldBefore(headerField* beforeField, headerField* field)
+void header::insertFieldBefore(ref <headerField> beforeField, ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), beforeField);
if (it == m_fields.end())
@@ -268,15 +241,15 @@ void header::insertFieldBefore(headerField* beforeField, headerField* field)
}
-void header::insertFieldBefore(const int pos, headerField* field)
+void header::insertFieldBefore(const int pos, ref <headerField> field)
{
m_fields.insert(m_fields.begin() + pos, field);
}
-void header::insertFieldAfter(headerField* afterField, headerField* field)
+void header::insertFieldAfter(ref <headerField> afterField, ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), afterField);
if (it == m_fields.end())
@@ -286,31 +259,27 @@ void header::insertFieldAfter(headerField* afterField, headerField* field)
}
-void header::insertFieldAfter(const int pos, headerField* field)
+void header::insertFieldAfter(const int pos, ref <headerField> field)
{
m_fields.insert(m_fields.begin() + pos + 1, field);
}
-void header::removeField(headerField* field)
+void header::removeField(ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), field);
if (it == m_fields.end())
throw exceptions::no_such_field();
- delete (*it);
-
m_fields.erase(it);
}
void header::removeField(const int pos)
{
- const std::vector <headerField*>::iterator it = m_fields.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <headerField> >::iterator it = m_fields.begin() + pos;
m_fields.erase(it);
}
@@ -318,7 +287,7 @@ void header::removeField(const int pos)
void header::removeAllFields()
{
- free_container(m_fields);
+ m_fields.clear();
}
@@ -334,25 +303,25 @@ const bool header::isEmpty() const
}
-headerField* header::getFieldAt(const int pos)
+ref <headerField> header::getFieldAt(const int pos)
{
return (m_fields[pos]);
}
-const headerField* header::getFieldAt(const int pos) const
+const ref <const headerField> header::getFieldAt(const int pos) const
{
return (m_fields[pos]);
}
-const std::vector <const headerField*> header::getFieldList() const
+const std::vector <ref <const headerField> > header::getFieldList() const
{
- std::vector <const headerField*> list;
+ std::vector <ref <const headerField> > list;
list.reserve(m_fields.size());
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
it != m_fields.end() ; ++it)
{
list.push_back(*it);
@@ -362,15 +331,15 @@ const std::vector <const headerField*> header::getFieldList() const
}
-const std::vector <headerField*> header::getFieldList()
+const std::vector <ref <headerField> > header::getFieldList()
{
return (m_fields);
}
-const std::vector <const component*> header::getChildComponents() const
+const std::vector <ref <const component> > header::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_fields, list);
diff --git a/src/headerField.cpp b/src/headerField.cpp
index 72a3927e..7f2c8ca4 100644
--- a/src/headerField.cpp
+++ b/src/headerField.cpp
@@ -44,9 +44,9 @@ headerField::~headerField()
}
-headerField* headerField::clone() const
+ref <component> headerField::clone() const
{
- headerField* field = headerFieldFactory::getInstance()->create(m_name);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(m_name);
field->copyFrom(*this);
@@ -69,7 +69,7 @@ headerField& headerField::operator=(const headerField& other)
}
-headerField* headerField::parseNext(const string& buffer, const string::size_type position,
+ref <headerField> headerField::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
string::size_type pos = position;
@@ -191,7 +191,7 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
}
// Return a new field
- headerField* field = headerFieldFactory::getInstance()->create(name);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(name);
field->parse(buffer, contentsStart, contentsEnd, NULL);
field->setParsedBounds(nameStart, pos);
@@ -248,11 +248,11 @@ const bool headerField::isCustom() const
}
-const std::vector <const component*> headerField::getChildComponents() const
+const std::vector <ref <const component> > headerField::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&getValue());
+ list.push_back(getValueImp());
return (list);
}
diff --git a/src/headerFieldFactory.cpp b/src/headerFieldFactory.cpp
index fa990c6f..bdc58bce 100644
--- a/src/headerFieldFactory.cpp
+++ b/src/headerFieldFactory.cpp
@@ -76,11 +76,11 @@ headerFieldFactory* headerFieldFactory::getInstance()
}
-headerField* headerFieldFactory::create
+ref <headerField> headerFieldFactory::create
(const string& name, const string& body)
{
NameMap::const_iterator pos = m_nameMap.find(utility::stringUtils::toLower(name));
- headerField* field = NULL;
+ ref <headerField> field = NULL;
if (pos != m_nameMap.end())
{
diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp
index 36a82217..aa477dc6 100644
--- a/src/htmlTextPart.cpp
+++ b/src/htmlTextPart.cpp
@@ -29,18 +29,14 @@ namespace vmime
htmlTextPart::htmlTextPart()
- : m_plainText(new emptyContentHandler),
- m_text(new emptyContentHandler)
+ : m_plainText(vmime::create <emptyContentHandler>()),
+ m_text(vmime::create <emptyContentHandler>())
{
}
htmlTextPart::~htmlTextPart()
{
- free_container(m_objects);
-
- delete (m_plainText);
- delete (m_text);
}
@@ -62,48 +58,48 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
if (!m_plainText->isEmpty())
{
// -- Create a new part
- bodyPart* part = new bodyPart();
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
// -- Set header fields
- part->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
- part->getHeader()->ContentType().setCharset(m_charset);
- part->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
+ part->getHeader()->ContentType()->setCharset(m_charset);
+ part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents
- part->getBody()->setContents(*m_plainText);
+ part->getBody()->setContents(m_plainText);
}
// HTML text
// -- Create a new part
- bodyPart* htmlPart = new bodyPart();
+ ref <bodyPart> htmlPart = vmime::create <bodyPart>();
// -- Set header fields
- htmlPart->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
- htmlPart->getHeader()->ContentType().setCharset(m_charset);
- htmlPart->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ htmlPart->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
+ htmlPart->getHeader()->ContentType()->setCharset(m_charset);
+ htmlPart->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents
- htmlPart->getBody()->setContents(*m_text);
+ htmlPart->getBody()->setContents(m_text);
// Handle the case we have embedded objects
if (!m_objects.empty())
{
// Create a "multipart/related" body part
- bodyPart* relPart = new bodyPart();
+ ref <bodyPart> relPart = vmime::create <bodyPart>();
parent.getBody()->appendPart(relPart);
- relPart->getHeader()->ContentType().
+ relPart->getHeader()->ContentType()->
setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_RELATED));
// Add the HTML part into this part
relPart->getBody()->appendPart(htmlPart);
// Also add objects into this part
- for (std::vector <embeddedObject*>::const_iterator it = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator it = m_objects.begin() ;
it != m_objects.end() ; ++it)
{
- bodyPart* objPart = new bodyPart();
+ ref <bodyPart> objPart = vmime::create <bodyPart>();
relPart->getBody()->appendPart(objPart);
string id = (*it)->getId();
@@ -111,13 +107,13 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
if (id.substr(0, 4) == "CID:")
id = id.substr(4);
- objPart->getHeader()->ContentType().setValue((*it)->getType());
- objPart->getHeader()->ContentId().setValue(messageId("<" + id + ">"));
- objPart->getHeader()->ContentDisposition().setValue(contentDisposition(contentDispositionTypes::INLINE));
- objPart->getHeader()->ContentTransferEncoding().setValue((*it)->getEncoding());
+ objPart->getHeader()->ContentType()->setValue((*it)->getType());
+ objPart->getHeader()->ContentId()->setValue(messageId("<" + id + ">"));
+ objPart->getHeader()->ContentDisposition()->setValue(contentDisposition(contentDispositionTypes::INLINE));
+ objPart->getHeader()->ContentTransferEncoding()->setValue((*it)->getEncoding());
//encoding(encodingTypes::BASE64);
- objPart->getBody()->setContents((*it)->getData());
+ objPart->getBody()->setContents((*it)->getData()->clone());
}
}
else
@@ -129,16 +125,16 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
void htmlTextPart::findEmbeddedParts(const bodyPart& part,
- std::vector <const bodyPart*>& cidParts, std::vector <const bodyPart*>& locParts)
+ std::vector <ref <const bodyPart> >& cidParts, std::vector <ref <const bodyPart> >& locParts)
{
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- dynamic_cast<messageIdField&>(*p.getHeader()->findField(fields::CONTENT_ID));
- cidParts.push_back(&p);
+ p->getHeader()->findField(fields::CONTENT_ID);
+ cidParts.push_back(p);
}
catch (exceptions::no_such_field)
{
@@ -146,8 +142,8 @@ void htmlTextPart::findEmbeddedParts(const bodyPart& part,
// Maybe there is a "Content-Location" field...
try
{
- dynamic_cast<messageIdField&>(*p.getHeader()->findField(fields::CONTENT_ID));
- locParts.push_back(&p);
+ p->getHeader()->findField(fields::CONTENT_ID);
+ locParts.push_back(p);
}
catch (exceptions::no_such_field)
{
@@ -156,7 +152,7 @@ void htmlTextPart::findEmbeddedParts(const bodyPart& part,
}
}
- findEmbeddedParts(p, cidParts, locParts);
+ findEmbeddedParts(*p, cidParts, locParts);
}
}
@@ -167,26 +163,25 @@ void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id)
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*part.getHeader()->findField(fields::CONTENT_TYPE));
-
- type = ctf.getValue();
+ const ref <const contentTypeField> ctf = part.getHeader()->ContentType();
+ type = ctf->getValue();
}
catch (exceptions::no_such_field)
{
// No "Content-type" field: assume "application/octet-stream".
}
- m_objects.push_back(new embeddedObject
- (part.getBody()->getContents(), part.getBody()->getEncoding(), id, type));
+ m_objects.push_back(vmime::create <embeddedObject>
+ (part.getBody()->getContents()->clone().dynamicCast <contentHandler>(),
+ part.getBody()->getEncoding(), id, type));
}
void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const bodyPart& textPart)
{
// Search for possible embedded objects in the _whole_ message.
- std::vector <const bodyPart*> cidParts;
- std::vector <const bodyPart*> locParts;
+ std::vector <ref <const bodyPart> > cidParts;
+ std::vector <ref <const bodyPart> > locParts;
findEmbeddedParts(message, cidParts, locParts);
@@ -194,19 +189,18 @@ void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const
std::ostringstream oss;
utility::outputStreamAdapter adapter(oss);
- textPart.getBody()->getContents().extract(adapter);
+ textPart.getBody()->getContents()->extract(adapter);
const string data = oss.str();
- delete (m_text);
- m_text = textPart.getBody()->getContents().clone();
+ m_text = textPart.getBody()->getContents()->clone();
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*textPart.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ textPart.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- m_charset = ctf.getCharset();
+ m_charset = ctf->getCharset();
}
catch (exceptions::no_such_field)
{
@@ -219,39 +213,38 @@ void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const
// Extract embedded objects. The algorithm is quite simple: for each previously
// found inline part, we check if its CID/Location is contained in the HTML text.
- for (std::vector <const bodyPart*>::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p)
+ for (std::vector <ref <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p)
{
- const messageIdField& midField = dynamic_cast<messageIdField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_ID));
+ const ref <const messageIdField> midField =
+ (*p)->getHeader()->findField(fields::CONTENT_ID).dynamicCast <messageIdField>();
- const string searchFor("CID:" + midField.getValue().getId());
+ const string searchFor("CID:" + midField->getValue().getId());
if (data.find(searchFor) != string::npos)
{
// This part is referenced in the HTML text.
// Add it to the embedded object list.
- addEmbeddedObject(**p, "CID:" + midField.getValue().getId());
+ addEmbeddedObject(**p, "CID:" + midField->getValue().getId());
}
}
- for (std::vector <const bodyPart*>::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p)
+ for (std::vector <ref <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p)
{
- const defaultField& locField = dynamic_cast<defaultField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_LOCATION));
+ const ref <const defaultField> locField =
+ (*p)->getHeader()->findField(fields::CONTENT_LOCATION).dynamicCast <defaultField>();
- if (data.find(locField.getValue()) != string::npos)
+ if (data.find(locField->getValue()) != string::npos)
{
// This part is referenced in the HTML text.
// Add it to the embedded object list.
- addEmbeddedObject(**p, locField.getValue());
+ addEmbeddedObject(**p, locField->getValue());
}
}
// Extract plain text, if any.
if (!findPlainTextPart(message, parent, textPart))
{
- delete (m_plainText);
- m_plainText = new emptyContentHandler();
+ m_plainText = vmime::create <emptyContentHandler>();
}
}
@@ -261,22 +254,22 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
// We search for the nearest "multipart/alternative" part.
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*part.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ part.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::MULTIPART &&
- ctf.getValue().getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
+ if (ctf->getValue().getType() == mediaTypes::MULTIPART &&
+ ctf->getValue().getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
{
- bodyPart const* foundPart = NULL;
+ ref <const bodyPart> foundPart = NULL;
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart* p = part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
if (p == &parent || // if "text/html" is in "multipart/related"
p == &textPart) // if not...
{
- foundPart = &(*p);
+ foundPart = p;
}
}
@@ -287,18 +280,17 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
// Now, search for the alternative plain text part
for (int i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*p.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ p->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::TEXT &&
- ctf.getValue().getSubType() == mediaTypes::TEXT_PLAIN)
+ if (ctf->getValue().getType() == mediaTypes::TEXT &&
+ ctf->getValue().getSubType() == mediaTypes::TEXT_PLAIN)
{
- delete (m_plainText);
- m_plainText = p.getBody()->getContents().clone();
+ m_plainText = p->getBody()->getContents()->clone();
found = true;
}
}
@@ -343,29 +335,27 @@ void htmlTextPart::setCharset(const charset& ch)
}
-const contentHandler& htmlTextPart::getPlainText() const
+const ref <const contentHandler> htmlTextPart::getPlainText() const
{
- return (*m_plainText);
+ return (m_plainText);
}
-void htmlTextPart::setPlainText(const contentHandler& plainText)
+void htmlTextPart::setPlainText(ref <contentHandler> plainText)
{
- delete (m_plainText);
- m_plainText = plainText.clone();
+ m_plainText = plainText->clone();
}
-const contentHandler& htmlTextPart::getText() const
+const ref <const contentHandler> htmlTextPart::getText() const
{
- return (*m_text);
+ return (m_text);
}
-void htmlTextPart::setText(const contentHandler& text)
+void htmlTextPart::setText(ref <contentHandler> text)
{
- delete (m_text);
- m_text = text.clone();
+ m_text = text->clone();
}
@@ -375,15 +365,15 @@ const int htmlTextPart::getObjectCount() const
}
-const htmlTextPart::embeddedObject* htmlTextPart::getObjectAt(const int pos) const
+const ref <const htmlTextPart::embeddedObject> htmlTextPart::getObjectAt(const int pos) const
{
return (m_objects[pos]);
}
-const htmlTextPart::embeddedObject* htmlTextPart::findObject(const string& id) const
+const ref <const htmlTextPart::embeddedObject> htmlTextPart::findObject(const string& id) const
{
- for (std::vector <embeddedObject*>::const_iterator o = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator o = m_objects.begin() ;
o != m_objects.end() ; ++o)
{
if ((*o)->getId() == id)
@@ -396,7 +386,7 @@ const htmlTextPart::embeddedObject* htmlTextPart::findObject(const string& id) c
const bool htmlTextPart::hasObject(const string& id) const
{
- for (std::vector <embeddedObject*>::const_iterator o = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator o = m_objects.begin() ;
o != m_objects.end() ; ++o)
{
if ((*o)->getId() == id)
@@ -407,19 +397,19 @@ const bool htmlTextPart::hasObject(const string& id) const
}
-const string htmlTextPart::addObject(const contentHandler& data,
+const string htmlTextPart::addObject(ref <contentHandler> data,
const vmime::encoding& enc, const mediaType& type)
{
const messageId mid(messageId::generateId());
const string id = "CID:" + mid.getId();
- m_objects.push_back(new embeddedObject(data, enc, id, type));
+ m_objects.push_back(vmime::create <embeddedObject>(data, enc, id, type));
return (id);
}
-const string htmlTextPart::addObject(const contentHandler& data, const mediaType& type)
+const string htmlTextPart::addObject(ref <contentHandler> data, const mediaType& type)
{
return (addObject(data, encoding::decide(data), type));
}
@@ -427,7 +417,7 @@ const string htmlTextPart::addObject(const contentHandler& data, const mediaType
const string htmlTextPart::addObject(const string& data, const mediaType& type)
{
- stringContentHandler cts(data);
+ ref <stringContentHandler> cts = vmime::create <stringContentHandler>(data);
return (addObject(cts, encoding::decide(cts), type));
}
@@ -438,16 +428,17 @@ const string htmlTextPart::addObject(const string& data, const mediaType& type)
//
htmlTextPart::embeddedObject::embeddedObject
- (const contentHandler& data, const encoding& enc,
+ (ref <contentHandler> data, const encoding& enc,
const string& id, const mediaType& type)
- : m_data(data.clone()), m_encoding(enc), m_id(id), m_type(type)
+ : m_data(data->clone().dynamicCast <contentHandler>()),
+ m_encoding(enc), m_id(id), m_type(type)
{
}
-const contentHandler& htmlTextPart::embeddedObject::getData() const
+const ref <const contentHandler> htmlTextPart::embeddedObject::getData() const
{
- return (*m_data);
+ return (m_data);
}
diff --git a/src/mailbox.cpp b/src/mailbox.cpp
index 9580d8e4..3fb1a10e 100644
--- a/src/mailbox.cpp
+++ b/src/mailbox.cpp
@@ -455,9 +455,9 @@ mailbox& mailbox::operator=(const mailbox& other)
}
-mailbox* mailbox::clone() const
+ref <component>mailbox::clone() const
{
- return new mailbox(*this);
+ return vmime::create <mailbox>(*this);
}
@@ -504,9 +504,9 @@ void mailbox::setEmail(const string& email)
}
-const std::vector <const component*> mailbox::getChildComponents() const
+const std::vector <ref <const component> > mailbox::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp
index 3580b011..db62b36c 100644
--- a/src/mailboxField.cpp
+++ b/src/mailboxField.cpp
@@ -44,7 +44,7 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
// Here, we cannot simply call "m_mailbox.parse()" because it
// may have more than one address specified (even if this field
// should contain only one). We are never too much careful...
- address* parsedAddress = address::parseNext(buffer, position, end, newPosition);
+ ref <address> parsedAddress = address::parseNext(buffer, position, end, newPosition);
if (parsedAddress)
{
@@ -52,7 +52,7 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
{
// If it is a group of mailboxes, take the first
// mailbox of the group
- mailboxGroup* group = static_cast <mailboxGroup*>(parsedAddress);
+ ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>();
if (!group->isEmpty())
getValue() = *(group->getMailboxAt(0));
@@ -60,12 +60,10 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
else
{
// Parse only if it is a mailbox
- getValue() = *static_cast <mailbox*>(parsedAddress);
+ getValue() = *parsedAddress.staticCast <mailbox>();
}
}
- delete (parsedAddress);
-
getValue().setParsedBounds(position, end);
setParsedBounds(position, end);
diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp
index c018c3ce..1a5d3729 100644
--- a/src/mailboxGroup.cpp
+++ b/src/mailboxGroup.cpp
@@ -76,26 +76,24 @@ void mailboxGroup::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- address* parsedAddress = address::parseNext(buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(buffer, pos, end, &pos);
if (parsedAddress)
{
if (parsedAddress->isGroup())
{
- mailboxGroup* group = static_cast <mailboxGroup*>(parsedAddress);
+ ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>();
// Sub-groups are not allowed in mailbox groups: so, we add all
// the contents of the sub-group into this group...
for (int i = 0 ; i < group->getMailboxCount() ; ++i)
{
- m_list.push_back(group->getMailboxAt(i)->clone());
+ m_list.push_back(group->getMailboxAt(i)->clone().staticCast <mailbox>());
}
-
- delete (parsedAddress);
}
else
{
- m_list.push_back(static_cast <mailbox*>(parsedAddress));
+ m_list.push_back(parsedAddress.staticCast <mailbox>());
}
}
}
@@ -160,7 +158,7 @@ void mailboxGroup::generate(utility::outputStream& os, const string::size_type m
os << ":";
++pos;
- for (std::vector <mailbox*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
if (it != m_list.begin())
@@ -193,17 +191,17 @@ void mailboxGroup::copyFrom(const component& other)
removeAllMailboxes();
- for (std::vector <mailbox*>::const_iterator it = source.m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = source.m_list.begin() ;
it != source.m_list.end() ; ++it)
{
- m_list.push_back((*it)->clone());
+ m_list.push_back((*it)->clone().staticCast <mailbox>());
}
}
-mailboxGroup* mailboxGroup::clone() const
+ref <component> mailboxGroup::clone() const
{
- return new mailboxGroup(*this);
+ return vmime::create <mailboxGroup>(*this);
}
@@ -238,15 +236,15 @@ const bool mailboxGroup::isEmpty() const
}
-void mailboxGroup::appendMailbox(mailbox* mbox)
+void mailboxGroup::appendMailbox(ref <mailbox> mbox)
{
m_list.push_back(mbox);
}
-void mailboxGroup::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
+void mailboxGroup::insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeMailbox);
if (it == m_list.end())
@@ -256,15 +254,15 @@ void mailboxGroup::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
}
-void mailboxGroup::insertMailboxBefore(const int pos, mailbox* mbox)
+void mailboxGroup::insertMailboxBefore(const int pos, ref <mailbox> mbox)
{
m_list.insert(m_list.begin() + pos, mbox);
}
-void mailboxGroup::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
+void mailboxGroup::insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterMailbox);
if (it == m_list.end())
@@ -274,31 +272,27 @@ void mailboxGroup::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
}
-void mailboxGroup::insertMailboxAfter(const int pos, mailbox* mbox)
+void mailboxGroup::insertMailboxAfter(const int pos, ref <mailbox> mbox)
{
m_list.insert(m_list.begin() + pos + 1, mbox);
}
-void mailboxGroup::removeMailbox(mailbox* mbox)
+void mailboxGroup::removeMailbox(ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), mbox);
if (it == m_list.end())
throw exceptions::no_such_mailbox();
- delete (*it);
-
m_list.erase(it);
}
void mailboxGroup::removeMailbox(const int pos)
{
- const std::vector <mailbox*>::iterator it = m_list.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <mailbox> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -306,7 +300,7 @@ void mailboxGroup::removeMailbox(const int pos)
void mailboxGroup::removeAllMailboxes()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -316,25 +310,25 @@ const int mailboxGroup::getMailboxCount() const
}
-mailbox* mailboxGroup::getMailboxAt(const int pos)
+ref <mailbox> mailboxGroup::getMailboxAt(const int pos)
{
return (m_list[pos]);
}
-const mailbox* mailboxGroup::getMailboxAt(const int pos) const
+const ref <const mailbox> mailboxGroup::getMailboxAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const mailbox*> mailboxGroup::getMailboxList() const
+const std::vector <ref <const mailbox> > mailboxGroup::getMailboxList() const
{
- std::vector <const mailbox*> list;
+ std::vector <ref <const mailbox> > list;
list.reserve(m_list.size());
- for (std::vector <mailbox*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -344,15 +338,15 @@ const std::vector <const mailbox*> mailboxGroup::getMailboxList() const
}
-const std::vector <mailbox*> mailboxGroup::getMailboxList()
+const std::vector <ref <mailbox> > mailboxGroup::getMailboxList()
{
return (m_list);
}
-const std::vector <const component*> mailboxGroup::getChildComponents() const
+const std::vector <ref <const component> > mailboxGroup::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_list, list);
diff --git a/src/mailboxList.cpp b/src/mailboxList.cpp
index fe636e1d..e6a64669 100644
--- a/src/mailboxList.cpp
+++ b/src/mailboxList.cpp
@@ -36,13 +36,13 @@ mailboxList::mailboxList(const mailboxList& mboxList)
}
-void mailboxList::appendMailbox(mailbox* mbox)
+void mailboxList::appendMailbox(ref <mailbox> mbox)
{
m_list.appendAddress(mbox);
}
-void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
+void mailboxList::insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox)
{
try
{
@@ -55,13 +55,13 @@ void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
}
-void mailboxList::insertMailboxBefore(const int pos, mailbox* mbox)
+void mailboxList::insertMailboxBefore(const int pos, ref <mailbox> mbox)
{
m_list.insertAddressBefore(pos, mbox);
}
-void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
+void mailboxList::insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox)
{
try
{
@@ -74,13 +74,13 @@ void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
}
-void mailboxList::insertMailboxAfter(const int pos, mailbox* mbox)
+void mailboxList::insertMailboxAfter(const int pos, ref <mailbox> mbox)
{
m_list.insertAddressAfter(pos, mbox);
}
-void mailboxList::removeMailbox(mailbox* mbox)
+void mailboxList::removeMailbox(ref <mailbox> mbox)
{
try
{
@@ -117,27 +117,27 @@ const bool mailboxList::isEmpty() const
}
-mailbox* mailboxList::getMailboxAt(const int pos)
+ref <mailbox> mailboxList::getMailboxAt(const int pos)
{
- return static_cast <mailbox*>(m_list.getAddressAt(pos));
+ return m_list.getAddressAt(pos).staticCast <mailbox>();
}
-const mailbox* mailboxList::getMailboxAt(const int pos) const
+const ref <const mailbox> mailboxList::getMailboxAt(const int pos) const
{
- return static_cast <const mailbox*>(m_list.getAddressAt(pos));
+ return m_list.getAddressAt(pos).staticCast <const mailbox>();
}
-const std::vector <const mailbox*> mailboxList::getMailboxList() const
+const std::vector <ref <const mailbox> > mailboxList::getMailboxList() const
{
- const std::vector <const address*> addrList = m_list.getAddressList();
- std::vector <const mailbox*> res;
+ const std::vector <ref <const address> > addrList = m_list.getAddressList();
+ std::vector <ref <const mailbox> > res;
- for (std::vector <const address*>::const_iterator it = addrList.begin() ;
+ for (std::vector <ref <const address> >::const_iterator it = addrList.begin() ;
it != addrList.end() ; ++it)
{
- const mailbox* mbox = dynamic_cast <const mailbox*>(*it);
+ const ref <const mailbox> mbox = (*it).dynamicCast <const mailbox>();
if (mbox != NULL)
res.push_back(mbox);
@@ -147,15 +147,15 @@ const std::vector <const mailbox*> mailboxList::getMailboxList() const
}
-const std::vector <mailbox*> mailboxList::getMailboxList()
+const std::vector <ref <mailbox> > mailboxList::getMailboxList()
{
- const std::vector <address*> addrList = m_list.getAddressList();
- std::vector <mailbox*> res;
+ const std::vector <ref <address> > addrList = m_list.getAddressList();
+ std::vector <ref <mailbox> > res;
- for (std::vector <address*>::const_iterator it = addrList.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = addrList.begin() ;
it != addrList.end() ; ++it)
{
- mailbox* mbox = dynamic_cast <mailbox*>(*it);
+ const ref <mailbox> mbox = (*it).dynamicCast <mailbox>();
if (mbox != NULL)
res.push_back(mbox);
@@ -165,9 +165,9 @@ const std::vector <mailbox*> mailboxList::getMailboxList()
}
-mailboxList* mailboxList::clone() const
+ref <component> mailboxList::clone() const
{
- return new mailboxList(*this);
+ return vmime::create <mailboxList>(*this);
}
@@ -186,7 +186,7 @@ mailboxList& mailboxList::operator=(const mailboxList& other)
}
-const std::vector <const component*> mailboxList::getChildComponents() const
+const std::vector <ref <const component> > mailboxList::getChildComponents() const
{
return (m_list.getChildComponents());
}
diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp
index 324807e0..62028a12 100644
--- a/src/mdn/MDNHelper.cpp
+++ b/src/mdn/MDNHelper.cpp
@@ -27,32 +27,32 @@ namespace vmime {
namespace mdn {
-void MDNHelper::attachMDNRequest(message* msg, const mailboxList& mailboxes)
+void MDNHelper::attachMDNRequest(ref <message> msg, const mailboxList& mailboxes)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
- hdr->DispositionNotificationTo().setValue(mailboxes);
+ hdr->DispositionNotificationTo()->setValue(mailboxes);
}
-void MDNHelper::attachMDNRequest(message* msg, const mailbox& mbox)
+void MDNHelper::attachMDNRequest(ref <message> msg, const mailbox& mbox)
{
mailboxList mboxList;
- mboxList.appendMailbox(mbox.clone());
+ mboxList.appendMailbox(mbox.clone().dynamicCast <mailbox>());
attachMDNRequest(msg, mboxList);
}
-const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const message* msg)
+const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const ref <const message> msg)
{
std::vector <sendableMDNInfos> result;
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{
- const mailboxList& dnto = hdr->DispositionNotificationTo().getValue();
+ const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue();
for (int i = 0 ; i < dnto.getMailboxCount() ; ++i)
result.push_back(sendableMDNInfos(msg, *dnto.getMailboxAt(i)));
@@ -62,9 +62,9 @@ const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const message* m
}
-const bool MDNHelper::isMDN(const message* msg)
+const bool MDNHelper::isMDN(const ref <const message> msg)
{
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
// A MDN message implies the following:
// - a Content-Type field is present and its value is "multipart/report"
@@ -72,7 +72,7 @@ const bool MDNHelper::isMDN(const message* msg)
// and its value is "disposition-notification"
if (hdr->hasField(fields::CONTENT_TYPE))
{
- const contentTypeField& ctf = hdr->ContentType();
+ const contentTypeField& ctf = *(hdr->ContentType());
if (ctf.getValue().getType() == vmime::mediaTypes::MULTIPART &&
ctf.getValue().getSubType() == vmime::mediaTypes::MULTIPART_REPORT)
@@ -89,7 +89,7 @@ const bool MDNHelper::isMDN(const message* msg)
}
-receivedMDNInfos MDNHelper::getReceivedMDN(const message* msg)
+receivedMDNInfos MDNHelper::getReceivedMDN(const ref <const message> msg)
{
if (!isMDN(msg))
throw exceptions::invalid_argument();
@@ -98,7 +98,7 @@ receivedMDNInfos MDNHelper::getReceivedMDN(const message* msg)
}
-bool MDNHelper::needConfirmation(const message* msg)
+const bool MDNHelper::needConfirmation(const ref <const message> msg)
{
const header* hdr = msg->getHeader();
@@ -109,14 +109,14 @@ bool MDNHelper::needConfirmation(const message* msg)
// More than one address in Disposition-Notification-To
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{
- const mailboxList& dnto = hdr->DispositionNotificationTo().getValue();
+ const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue();
if (dnto.getMailboxCount() > 1)
return (true);
// Return-Path != Disposition-Notification-To
const mailbox& mbox = *dnto.getMailboxAt(0);
- const path& rp = hdr->ReturnPath().getValue();
+ const path& rp = hdr->ReturnPath()->getValue();
if (mbox.getEmail() != rp.getLocalPart() + "@" + rp.getDomain())
return (true);
@@ -127,32 +127,32 @@ bool MDNHelper::needConfirmation(const message* msg)
}
-message* MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
- const string& text,
- const charset& ch,
- const mailbox& expeditor,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts)
+ref <message> MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
+ const string& text,
+ const charset& ch,
+ const mailbox& expeditor,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts)
{
// Create a new message
- message* msg = new message;
+ ref <message> msg = vmime::create <message>();
// Fill-in header fields
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::MULTIPART,
- vmime::mediaTypes::MULTIPART_REPORT));
- hdr->ContentType().setReportType("disosition-notification");
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MULTIPART,
+ vmime::mediaTypes::MULTIPART_REPORT));
+ hdr->ContentType()->setReportType("disosition-notification");
- hdr->Disposition().setValue(dispo);
+ hdr->Disposition()->setValue(dispo);
- hdr->To().getValue().appendAddress(new mailbox(mdnInfos.getRecipient()));
- hdr->From().getValue() = expeditor;
- hdr->Subject().getValue().appendWord(new word("Disposition notification"));
+ hdr->To()->getValue().appendAddress(vmime::create <mailbox>(mdnInfos.getRecipient()));
+ hdr->From()->getValue() = expeditor;
+ hdr->Subject()->getValue().appendWord(vmime::create <word>("Disposition notification"));
- hdr->Date().setValue(datetime::now());
- hdr->MimeVersion().setValue(string(SUPPORTED_MIME_VERSION));
+ hdr->Date()->setValue(datetime::now());
+ hdr->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));
msg->getBody()->appendPart(createFirstMDNPart(mdnInfos, text, ch));
msg->getBody()->appendPart(createSecondMDNPart(mdnInfos,
@@ -163,39 +163,39 @@ message* MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
}
-bodyPart* MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
- const string& text, const charset& ch)
+ref <bodyPart> MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
+ const string& text, const charset& ch)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::TEXT,
- vmime::mediaTypes::TEXT_PLAIN));
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
+ vmime::mediaTypes::TEXT_PLAIN));
- hdr->ContentType().setCharset(ch);
+ hdr->ContentType()->setCharset(ch);
// Body
- part->getBody()->setContents(stringContentHandler(text));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(text));
return (part);
}
-bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts)
+ref <bodyPart> MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentDisposition().setValue(vmime::contentDispositionTypes::INLINE);
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::MESSAGE,
- vmime::mediaTypes::MESSAGE_DISPOSITION_NOTIFICATION));
+ hdr->ContentDisposition()->setValue(vmime::contentDispositionTypes::INLINE);
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MESSAGE,
+ vmime::mediaTypes::MESSAGE_DISPOSITION_NOTIFICATION));
// Body
//
@@ -233,8 +233,9 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
ruaText += reportingUAProducts[i];
}
- defaultField* rua = dynamic_cast <defaultField*>
- (headerFieldFactory::getInstance()->create(vmime::fields::REPORTING_UA));
+ ref <defaultField> rua =
+ (headerFieldFactory::getInstance()->create
+ (vmime::fields::REPORTING_UA)).dynamicCast <defaultField>();
rua->setValue(ruaText);
@@ -242,20 +243,21 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
}
// -- Final-Recipient
- defaultField* fr = dynamic_cast <defaultField*>
- (headerFieldFactory::getInstance()->create(vmime::fields::FINAL_RECIPIENT));
+ ref <defaultField> fr =
+ (headerFieldFactory::getInstance()->
+ create(vmime::fields::FINAL_RECIPIENT)).dynamicCast <defaultField>();
fr->setValue("rfc822; " + mdnInfos.getRecipient().getEmail());
// -- Original-Message-ID
if (mdnInfos.getMessage()->getHeader()->hasField(vmime::fields::MESSAGE_ID))
{
- fields.OriginalMessageId().setValue
- (mdnInfos.getMessage()->getHeader()->MessageId().getValue());
+ fields.OriginalMessageId()->setValue
+ (mdnInfos.getMessage()->getHeader()->MessageId()->getValue());
}
// -- Disposition
- fields.Disposition().setValue(dispo);
+ fields.Disposition()->setValue(dispo);
std::ostringstream oss;
@@ -263,22 +265,22 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
fields.generate(vos);
- part->getBody()->setContents(stringContentHandler(oss.str()));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(oss.str()));
return (part);
}
-bodyPart* MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
+ref <bodyPart> MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentDisposition().setValue(vmime::contentDispositionTypes::INLINE);
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::TEXT,
- vmime::mediaTypes::TEXT_RFC822_HEADERS));
+ hdr->ContentDisposition()->setValue(vmime::contentDispositionTypes::INLINE);
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
+ vmime::mediaTypes::TEXT_RFC822_HEADERS));
// Body: original message headers
std::ostringstream oss;
@@ -286,7 +288,7 @@ bodyPart* MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
mdnInfos.getMessage()->getHeader()->generate(vos);
- part->getBody()->setContents(stringContentHandler(oss.str()));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(oss.str()));
return (part);
}
diff --git a/src/mdn/receivedMDNInfos.cpp b/src/mdn/receivedMDNInfos.cpp
index e9a82198..7c6f2893 100644
--- a/src/mdn/receivedMDNInfos.cpp
+++ b/src/mdn/receivedMDNInfos.cpp
@@ -24,7 +24,7 @@ namespace vmime {
namespace mdn {
-receivedMDNInfos::receivedMDNInfos(const message* msg)
+receivedMDNInfos::receivedMDNInfos(const ref <const message> msg)
: m_msg(msg)
{
extract();
@@ -45,7 +45,7 @@ receivedMDNInfos& receivedMDNInfos::operator=(const receivedMDNInfos& other)
}
-const message* receivedMDNInfos::getMessage() const
+const ref <const message> receivedMDNInfos::getMessage() const
{
return (m_msg);
}
@@ -73,16 +73,16 @@ void receivedMDNInfos::copyFrom(const receivedMDNInfos& other)
void receivedMDNInfos::extract()
{
- const body* bdy = m_msg->getBody();
+ const ref <const body> bdy = m_msg->getBody();
for (int i = 0 ; i < bdy->getPartCount() ; ++i)
{
- const bodyPart* part = bdy->getPartAt(i);
+ const ref <const bodyPart> part = bdy->getPartAt(i);
if (!part->getHeader()->hasField(fields::CONTENT_TYPE))
continue;
- const mediaType& type = part->getHeader()->ContentType().getValue();
+ const mediaType& type = part->getHeader()->ContentType()->getValue();
// Extract from second part (message/disposition-notification)
if (type.getType() == vmime::mediaTypes::MESSAGE &&
@@ -91,16 +91,16 @@ void receivedMDNInfos::extract()
std::ostringstream oss;
utility::outputStreamAdapter vos(oss);
- part->getBody()->getContents().extract(vos);
+ part->getBody()->getContents()->extract(vos);
// Body actually contains fields
header fields;
fields.parse(oss.str());
- try { m_omid = fields.OriginalMessageId().getValue(); }
+ try { m_omid = fields.OriginalMessageId()->getValue(); }
catch (exceptions::no_such_field&) { /* Ignore */ }
- try { m_disp = fields.Disposition().getValue(); }
+ try { m_disp = fields.Disposition()->getValue(); }
catch (exceptions::no_such_field&) { /* Ignore */ }
}
}
diff --git a/src/mdn/sendableMDNInfos.cpp b/src/mdn/sendableMDNInfos.cpp
index e8ae8b62..40a0fe96 100644
--- a/src/mdn/sendableMDNInfos.cpp
+++ b/src/mdn/sendableMDNInfos.cpp
@@ -24,7 +24,7 @@ namespace vmime {
namespace mdn {
-sendableMDNInfos::sendableMDNInfos(const message* msg, const mailbox& mbox)
+sendableMDNInfos::sendableMDNInfos(const ref <const message> msg, const mailbox& mbox)
: m_msg(msg), m_mailbox(mbox)
{
}
@@ -44,7 +44,7 @@ sendableMDNInfos& sendableMDNInfos::operator=(const sendableMDNInfos& other)
}
-const message* sendableMDNInfos::getMessage() const
+const ref <const message> sendableMDNInfos::getMessage() const
{
return (m_msg);
}
diff --git a/src/mediaType.cpp b/src/mediaType.cpp
index deb0c129..807131fb 100644
--- a/src/mediaType.cpp
+++ b/src/mediaType.cpp
@@ -120,9 +120,9 @@ mediaType& mediaType::operator=(const string& type)
}
-mediaType* mediaType::clone() const
+ref <component> mediaType::clone() const
{
- return new mediaType(m_type, m_subType);
+ return vmime::create <mediaType>(m_type, m_subType);
}
@@ -172,9 +172,9 @@ void mediaType::setFromString(const string& type)
}
-const std::vector <const component*> mediaType::getChildComponents() const
+const std::vector <ref <const component> > mediaType::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/messageBuilder.cpp b/src/messageBuilder.cpp
index 7081332f..beb252d5 100644
--- a/src/messageBuilder.cpp
+++ b/src/messageBuilder.cpp
@@ -27,7 +27,6 @@ namespace vmime
messageBuilder::messageBuilder()
- : m_textPart(NULL)
{
// By default there is one text part of type "text/plain"
constructTextPart(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
@@ -36,19 +35,16 @@ messageBuilder::messageBuilder()
messageBuilder::~messageBuilder()
{
- delete (m_textPart);
-
- free_container(m_attach);
}
-message* messageBuilder::construct() const
+ref <message> messageBuilder::construct() const
{
// Create a new message
- message* msg = new message;
+ ref <message> msg = vmime::create <message>();
// Generate the header fields
- msg->getHeader()->Subject().setValue(m_subject);
+ msg->getHeader()->Subject()->setValue(m_subject);
if (m_from.isEmpty())
throw exceptions::no_expeditor();
@@ -56,20 +52,20 @@ message* messageBuilder::construct() const
if (m_to.isEmpty() || m_to.getAddressAt(0)->isEmpty())
throw exceptions::no_recipient();
- msg->getHeader()->From().setValue(m_from);
- msg->getHeader()->To().setValue(m_to);
+ msg->getHeader()->From()->setValue(m_from);
+ msg->getHeader()->To()->setValue(m_to);
if (!m_cc.isEmpty())
- msg->getHeader()->Cc().setValue(m_cc);
+ msg->getHeader()->Cc()->setValue(m_cc);
if (!m_bcc.isEmpty())
- msg->getHeader()->Bcc().setValue(m_bcc);
+ msg->getHeader()->Bcc()->setValue(m_bcc);
// Add a "Date" field
- msg->getHeader()->Date().setValue(datetime::now());
+ msg->getHeader()->Date()->setValue(datetime::now());
// Add a "Mime-Version" header field
- msg->getHeader()->MimeVersion().setValue(string(SUPPORTED_MIME_VERSION));
+ msg->getHeader()->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));
// If there is one or more attachments (or other parts that are
// not "text/...") and if there is more than one parts for the
@@ -92,14 +88,14 @@ message* messageBuilder::construct() const
if (!m_attach.empty() && m_textPart->getPartCount() > 1)
{
// Set parent part (message) to "multipart/mixed"
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
// Create a sub-part "multipart/alternative" for text parts
- bodyPart* subPart = new bodyPart;
+ ref <bodyPart> subPart = vmime::create <bodyPart>();
msg->getBody()->appendPart(subPart);
- subPart->getHeader()->ContentType().setValue
+ subPart->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_ALTERNATIVE));
// Generate the text parts into this sub-part (normally, this
@@ -114,13 +110,13 @@ message* messageBuilder::construct() const
// If any attachment, set message content-type to "multipart/mixed"
if (!m_attach.empty())
{
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
}
// Else, set it to "multipart/alternative" if there are more than one text part.
else if (m_textPart->getPartCount() > 1)
{
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_ALTERNATIVE));
}
}
@@ -128,7 +124,7 @@ message* messageBuilder::construct() const
// Generate the attachments
if (!m_attach.empty())
{
- for (std::vector <attachment*>::const_iterator a = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator a = m_attach.begin() ;
a != m_attach.end() ; ++a)
{
(*a)->generateIn(*msg);
@@ -142,9 +138,9 @@ message* messageBuilder::construct() const
const bodyPart& part = *msg->getBody()->getPartAt(0);
// First, copy (and replace) the header fields
- const std::vector <const headerField*> fields = part.getHeader()->getFieldList();
+ const std::vector <ref <const headerField> > fields = part.getHeader()->getFieldList();
- for (std::vector <const headerField*>::const_iterator it = fields.begin() ;
+ for (std::vector <ref <const headerField> >::const_iterator it = fields.begin() ;
it != fields.end() ; ++it)
{
*(msg->getHeader()->getField((*it)->getName())) = **it;
@@ -159,13 +155,13 @@ message* messageBuilder::construct() const
}
-void messageBuilder::attach(attachment* attach)
+void messageBuilder::attach(ref <attachment> attach)
{
appendAttachment(attach);
}
-void messageBuilder::appendAttachment(attachment* attach)
+void messageBuilder::appendAttachment(ref <attachment> attach)
{
m_attach.push_back(attach);
}
@@ -173,7 +169,7 @@ void messageBuilder::appendAttachment(attachment* attach)
void messageBuilder::constructTextPart(const mediaType& type)
{
- textPart* part = NULL;
+ ref <textPart> part = NULL;
try
{
@@ -184,12 +180,11 @@ void messageBuilder::constructTextPart(const mediaType& type)
throw;
}
- delete (m_textPart);
m_textPart = part;
}
-textPart* messageBuilder::getTextPart()
+ref <textPart> messageBuilder::getTextPart()
{
return (m_textPart);
}
@@ -275,19 +270,17 @@ void messageBuilder::setSubject(const text& subject)
void messageBuilder::removeAttachment(const int pos)
{
- delete (m_attach[pos]);
-
m_attach.erase(m_attach.begin() + pos);
}
-const attachment* messageBuilder::getAttachmentAt(const int pos) const
+const ref <const attachment> messageBuilder::getAttachmentAt(const int pos) const
{
return (m_attach[pos]);
}
-attachment* messageBuilder::getAttachmentAt(const int pos)
+ref <attachment> messageBuilder::getAttachmentAt(const int pos)
{
return (m_attach[pos]);
}
@@ -299,13 +292,13 @@ const int messageBuilder::getAttachmentCount() const
}
-const std::vector <const attachment*> messageBuilder::getAttachmentList() const
+const std::vector <ref <const attachment> > messageBuilder::getAttachmentList() const
{
- std::vector <const attachment*> res;
+ std::vector <ref <const attachment> > res;
res.reserve(m_attach.size());
- for (std::vector <attachment*>::const_iterator it = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator it = m_attach.begin() ;
it != m_attach.end() ; ++it)
{
res.push_back(*it);
@@ -315,7 +308,7 @@ const std::vector <const attachment*> messageBuilder::getAttachmentList() const
}
-const std::vector <attachment*> messageBuilder::getAttachmentList()
+const std::vector <ref <attachment> > messageBuilder::getAttachmentList()
{
return (m_attach);
}
diff --git a/src/messageId.cpp b/src/messageId.cpp
index 9e878c2f..b8490792 100644
--- a/src/messageId.cpp
+++ b/src/messageId.cpp
@@ -129,7 +129,7 @@ void messageId::parse(const string& buffer, const string::size_type position,
}
-messageId* messageId::parseNext(const string& buffer, const string::size_type position,
+ref <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;
@@ -144,7 +144,7 @@ messageId* messageId::parseNext(const string& buffer, const string::size_type po
while (pos < end && !parserHelpers::isSpace(buffer[pos]))
++pos;
- messageId* mid = new messageId();
+ ref <messageId> mid = vmime::create <messageId>();
mid->parse(buffer, begin, pos, NULL);
if (newPosition != NULL)
@@ -220,9 +220,9 @@ const bool messageId::operator!=(const messageId& mid) const
}
-messageId* messageId::clone() const
+ref <component> messageId::clone() const
{
- return new messageId(*this);
+ return vmime::create <messageId>(*this);
}
@@ -266,9 +266,9 @@ void messageId::setRight(const string& right)
}
-const std::vector <const component*> messageId::getChildComponents() const
+const std::vector <ref <const component> > messageId::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/messageIdSequence.cpp b/src/messageIdSequence.cpp
index a682a29f..8683c65d 100644
--- a/src/messageIdSequence.cpp
+++ b/src/messageIdSequence.cpp
@@ -46,9 +46,9 @@ messageIdSequence::messageIdSequence(const messageIdSequence& midSeq)
}
-messageIdSequence* messageIdSequence::clone() const
+ref <component> messageIdSequence::clone() const
{
- return new messageIdSequence(*this);
+ return vmime::create <messageIdSequence>(*this);
}
@@ -59,7 +59,7 @@ void messageIdSequence::copyFrom(const component& other)
removeAllMessageIds();
for (unsigned int i = 0 ; i < midSeq.m_list.size() ; ++i)
- m_list.push_back(midSeq.m_list[i]->clone());
+ m_list.push_back(midSeq.m_list[i]->clone().dynamicCast <messageId>());
}
@@ -70,9 +70,9 @@ messageIdSequence& messageIdSequence::operator=(const messageIdSequence& other)
}
-const std::vector <const component*> messageIdSequence::getChildComponents() const
+const std::vector <ref <const component> > messageIdSequence::getChildComponents() const
{
- std::vector <const component*> res;
+ std::vector <ref <const component> > res;
copy_vector(m_list, res);
@@ -89,7 +89,7 @@ void messageIdSequence::parse(const string& buffer, const string::size_type posi
while (pos < end)
{
- messageId* parsedMid = messageId::parseNext(buffer, pos, end, &pos);
+ ref <messageId> parsedMid = messageId::parseNext(buffer, pos, end, &pos);
if (parsedMid != NULL)
m_list.push_back(parsedMid);
@@ -109,7 +109,7 @@ void messageIdSequence::generate(utility::outputStream& os, const string::size_t
if (!m_list.empty())
{
- for (std::vector <messageId*>::const_iterator it = m_list.begin() ; ; )
+ for (std::vector <ref <messageId> >::const_iterator it = m_list.begin() ; ; )
{
(*it)->generate(os, maxLineLength - 2, pos, &pos);
@@ -126,15 +126,15 @@ void messageIdSequence::generate(utility::outputStream& os, const string::size_t
}
-void messageIdSequence::appendMessageId(messageId* mid)
+void messageIdSequence::appendMessageId(ref <messageId> mid)
{
m_list.push_back(mid);
}
-void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* mid)
+void messageIdSequence::insertMessageIdBefore(ref <messageId> beforeMid, ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <messageId> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeMid);
if (it == m_list.end())
@@ -144,15 +144,15 @@ void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* m
}
-void messageIdSequence::insertMessageIdBefore(const int pos, messageId* mid)
+void messageIdSequence::insertMessageIdBefore(const int pos, ref <messageId> mid)
{
m_list.insert(m_list.begin() + pos, mid);
}
-void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid)
+void messageIdSequence::insertMessageIdAfter(ref <messageId> afterMid, ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <messageId> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterMid);
if (it == m_list.end())
@@ -162,31 +162,27 @@ void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid
}
-void messageIdSequence::insertMessageIdAfter(const int pos, messageId* mid)
+void messageIdSequence::insertMessageIdAfter(const int pos, ref <messageId> mid)
{
m_list.insert(m_list.begin() + pos + 1, mid);
}
-void messageIdSequence::removeMessageId(messageId* mid)
+void messageIdSequence::removeMessageId(ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <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);
+ const std::vector <ref <messageId> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -194,7 +190,7 @@ void messageIdSequence::removeMessageId(const int pos)
void messageIdSequence::removeAllMessageIds()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -210,25 +206,25 @@ const bool messageIdSequence::isEmpty() const
}
-messageId* messageIdSequence::getMessageIdAt(const int pos)
+const ref <messageId> messageIdSequence::getMessageIdAt(const int pos)
{
return (m_list[pos]);
}
-const messageId* messageIdSequence::getMessageIdAt(const int pos) const
+const ref <const messageId> messageIdSequence::getMessageIdAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const messageId*> messageIdSequence::getMessageIdList() const
+const std::vector <ref <const messageId> > messageIdSequence::getMessageIdList() const
{
- std::vector <const messageId*> list;
+ std::vector <ref <const messageId> > list;
list.reserve(m_list.size());
- for (std::vector <messageId*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <messageId> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -238,7 +234,7 @@ const std::vector <const messageId*> messageIdSequence::getMessageIdList() const
}
-const std::vector <messageId*> messageIdSequence::getMessageIdList()
+const std::vector <ref <messageId> > messageIdSequence::getMessageIdList()
{
return (m_list);
}
diff --git a/src/messageParser.cpp b/src/messageParser.cpp
index 6ef9652a..94fec668 100644
--- a/src/messageParser.cpp
+++ b/src/messageParser.cpp
@@ -44,14 +44,6 @@ messageParser::messageParser(const message& msg)
messageParser::~messageParser()
{
- free_container(m_attach);
- free_container(m_textParts);
-
- for (std::map <attachment*, contentDispositionField*>::iterator
- it = m_attachInfo.begin() ; it != m_attachInfo.end() ; ++it)
- {
- delete ((*it).second);
- }
}
@@ -193,14 +185,15 @@ void messageParser::findAttachments(const bodyPart& part)
}
// Construct the attachment object
- attachment* attach = new defaultAttachment
- (bdy.getContents(), bdy.getEncoding(), type, description);
+ ref <attachment> attach = vmime::create <defaultAttachment>
+ (bdy.getContents()->clone().dynamicCast <contentHandler>(),
+ bdy.getEncoding(), type, description);
if (contentDispField != NULL)
{
- m_attachInfo.insert(std::map <attachment*, contentDispositionField*>::
- value_type(attach, dynamic_cast <contentDispositionField*>
- (contentDispField->clone())));
+ m_attachInfo.insert(std::map <attachment*, ref <contentDispositionField> >::
+ value_type(attach.get(), contentDispField->clone().
+ dynamicCast <contentDispositionField>()));
}
// Add the attachment to the list
@@ -242,10 +235,10 @@ void messageParser::findTextParts(const bodyPart& msg, const bodyPart& part)
if (accept)
{
- textPart* textPart = textPartFactory::getInstance()->create(type);
- textPart->parse(msg, msg, msg);
+ ref <textPart> txtPart = textPartFactory::getInstance()->create(type);
+ txtPart->parse(msg, msg, msg);
- m_textParts.push_back(textPart);
+ m_textParts.push_back(txtPart);
}
}
// Multipart message
@@ -263,20 +256,20 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
// So, wherever the text parts are, all we have to do is to find the first
// MIME part which is a text part.
- std::vector <const bodyPart*> textParts;
+ std::vector <ref <const bodyPart> > textParts;
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*p.getHeader()->findField(fields::CONTENT_TYPE));
+ const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
+ (*(p->getHeader()->findField(fields::CONTENT_TYPE)));
if (ctf.getValue().getType() == mediaTypes::TEXT)
{
- textParts.push_back(&p);
+ textParts.push_back(p);
}
}
catch (exceptions::no_such_field)
@@ -288,18 +281,18 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
if (textParts.size())
{
// Okay. So we have found at least one text part
- for (std::vector <const bodyPart*>::const_iterator p = textParts.begin() ;
+ for (std::vector <ref <const bodyPart> >::const_iterator p = textParts.begin() ;
p != textParts.end() ; ++p)
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_TYPE));
+ const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
+ (*((*p)->getHeader()->findField(fields::CONTENT_TYPE)));
try
{
- textPart* textPart = textPartFactory::getInstance()->create(ctf.getValue());
- textPart->parse(msg, part, **p);
+ ref <textPart> txtPart = textPartFactory::getInstance()->create(ctf.getValue());
+ txtPart->parse(msg, part, **p);
- m_textParts.push_back(textPart);
+ m_textParts.push_back(txtPart);
}
catch (exceptions::no_factory_available& e)
{
@@ -324,10 +317,10 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
}
-const contentDispositionField* messageParser::getAttachmentInfo(const attachment* a) const
+const ref <const contentDispositionField> messageParser::getAttachmentInfo(const ref <const attachment> a) const
{
- std::map <attachment*, contentDispositionField*>::const_iterator
- it = m_attachInfo.find(const_cast <attachment*>(a));
+ std::map <attachment*, ref <contentDispositionField> >::const_iterator
+ it = m_attachInfo.find(ref <attachment>(a.constCast <attachment>()).get());
return (it != m_attachInfo.end() ? (*it).second : NULL);
}
@@ -369,13 +362,13 @@ const datetime& messageParser::getDate() const
}
-const std::vector <const attachment*> messageParser::getAttachmentList() const
+const std::vector <ref <const attachment> > messageParser::getAttachmentList() const
{
- std::vector <const attachment*> res;
+ std::vector <ref <const attachment> > res;
res.reserve(m_attach.size());
- for (std::vector <attachment*>::const_iterator it = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator it = m_attach.begin() ;
it != m_attach.end() ; ++it)
{
res.push_back(*it);
@@ -391,19 +384,19 @@ const int messageParser::getAttachmentCount() const
}
-const attachment* messageParser::getAttachmentAt(const int pos) const
+const ref <const attachment> messageParser::getAttachmentAt(const int pos) const
{
return (m_attach[pos]);
}
-const std::vector <const textPart*> messageParser::getTextPartList() const
+const std::vector <ref <const textPart> > messageParser::getTextPartList() const
{
- std::vector <const textPart*> res;
+ std::vector <ref <const textPart> > res;
res.reserve(m_textParts.size());
- for (std::vector <textPart*>::const_iterator it = m_textParts.begin() ;
+ for (std::vector <ref <textPart> >::const_iterator it = m_textParts.begin() ;
it != m_textParts.end() ; ++it)
{
res.push_back(*it);
@@ -419,7 +412,7 @@ const int messageParser::getTextPartCount() const
}
-const textPart* messageParser::getTextPartAt(const int pos) const
+const ref <const textPart> messageParser::getTextPartAt(const int pos) const
{
return (m_textParts[pos]);
}
diff --git a/src/messaging/authenticationInfos.cpp b/src/messaging/authenticationInfos.cpp
index 99044f2f..0a7c3433 100644
--- a/src/messaging/authenticationInfos.cpp
+++ b/src/messaging/authenticationInfos.cpp
@@ -31,7 +31,7 @@ authenticationInfos::authenticationInfos(const string& username, const string& p
authenticationInfos::authenticationInfos(const authenticationInfos& infos)
- : m_username(infos.m_username), m_password(infos.m_password)
+ : object(), m_username(infos.m_username), m_password(infos.m_password)
{
}
diff --git a/src/messaging/defaultAuthenticator.cpp b/src/messaging/defaultAuthenticator.cpp
index db027339..373d3c1d 100644
--- a/src/messaging/defaultAuthenticator.cpp
+++ b/src/messaging/defaultAuthenticator.cpp
@@ -18,14 +18,15 @@
//
#include "vmime/messaging/defaultAuthenticator.hpp"
+#include "vmime/messaging/session.hpp"
namespace vmime {
namespace messaging {
-defaultAuthenticator::defaultAuthenticator(const propertySet& props, const string& prefix)
- : m_props(props), m_prefix(prefix)
+defaultAuthenticator::defaultAuthenticator(weak_ref <session> sess, const string& prefix)
+ : m_session(sess), m_prefix(prefix)
{
}
@@ -33,7 +34,8 @@ defaultAuthenticator::defaultAuthenticator(const propertySet& props, const strin
const authenticationInfos defaultAuthenticator::requestAuthInfos() const
{
return (authenticationInfos
- (m_props[m_prefix + "auth.username"], m_props[m_prefix + "auth.password"]));
+ (m_session->getProperties()[m_prefix + "auth.username"],
+ m_session->getProperties()[m_prefix + "auth.password"]));
}
diff --git a/src/messaging/events.cpp b/src/messaging/events.cpp
index edc736c1..13171832 100644
--- a/src/messaging/events.cpp
+++ b/src/messaging/events.cpp
@@ -18,6 +18,7 @@
//
#include "vmime/messaging/events.hpp"
+#include "vmime/messaging/folder.hpp"
#include <algorithm>
@@ -32,7 +33,7 @@ namespace events {
//
messageCountEvent::messageCountEvent
- (folder* folder, const Types type, const std::vector <int>& nums)
+ (ref <folder> folder, const Types type, const std::vector <int>& nums)
: m_folder(folder), m_type(type)
{
m_nums.resize(nums.size());
@@ -40,7 +41,7 @@ messageCountEvent::messageCountEvent
}
-const folder* messageCountEvent::getFolder() const { return (const_cast <folder*>(m_folder)); }
+ref <const folder> messageCountEvent::getFolder() const { return (m_folder); }
const messageCountEvent::Types messageCountEvent::getType() const { return (m_type); }
const std::vector <int>& messageCountEvent::getNumbers() const { return (m_nums); }
@@ -59,7 +60,7 @@ void messageCountEvent::dispatch(messageCountListener* listener) const
//
messageChangedEvent::messageChangedEvent
- (folder* folder, const Types type, const std::vector <int>& nums)
+ (ref <folder> folder, const Types type, const std::vector <int>& nums)
: m_folder(folder), m_type(type)
{
m_nums.resize(nums.size());
@@ -67,7 +68,7 @@ messageChangedEvent::messageChangedEvent
}
-const folder* messageChangedEvent::getFolder() const { return (const_cast <folder*>(m_folder)); }
+ref <const folder> messageChangedEvent::getFolder() const { return (m_folder); }
const messageChangedEvent::Types messageChangedEvent::getType() const { return (m_type); }
const std::vector <int>& messageChangedEvent::getNumbers() const { return (m_nums); }
@@ -83,14 +84,14 @@ void messageChangedEvent::dispatch(messageChangedListener* listener) const
//
folderEvent::folderEvent
- (folder* folder, const Types type,
+ (ref <folder> folder, const Types type,
const utility::path& oldPath, const utility::path& newPath)
: m_folder(folder), m_type(type), m_oldPath(oldPath), m_newPath(newPath)
{
}
-const folder* folderEvent::getFolder() const { return (m_folder); }
+ref <const folder> folderEvent::getFolder() const { return (m_folder); }
const folderEvent::Types folderEvent::getType() const { return (m_type); }
diff --git a/src/messaging/imap/IMAPConnection.cpp b/src/messaging/imap/IMAPConnection.cpp
index 37a132de..586a1716 100644
--- a/src/messaging/imap/IMAPConnection.cpp
+++ b/src/messaging/imap/IMAPConnection.cpp
@@ -42,7 +42,7 @@ namespace messaging {
namespace imap {
-IMAPConnection::IMAPConnection(IMAPStore* store, authenticator* auth)
+IMAPConnection::IMAPConnection(weak_ref <IMAPStore> store, ref <authenticator> auth)
: m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL),
m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL)
{
@@ -55,9 +55,6 @@ IMAPConnection::~IMAPConnection()
disconnect();
else if (m_socket)
internalDisconnect();
-
- delete (m_tag);
- delete (m_parser);
}
@@ -89,11 +86,8 @@ void IMAPConnection::connect()
m_socket->connect(address, port);
- delete (m_tag);
- m_tag = new IMAPTag();
-
- delete (m_parser);
- m_parser = new IMAPParser(m_tag, m_socket, m_timeoutHandler);
+ m_tag = vmime::create <IMAPTag>();
+ m_parser = vmime::create <IMAPParser>(m_tag, m_socket, m_timeoutHandler);
setState(STATE_NON_AUTHENTICATED);
@@ -164,11 +158,8 @@ void IMAPConnection::internalDisconnect()
send(true, "LOGOUT", true);
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_state = STATE_LOGOUT;
@@ -179,7 +170,7 @@ void IMAPConnection::initHierarchySeparator()
{
send(true, "LIST \"\" \"\"", true);
- utility::auto_ptr <IMAPParser::response> resp(m_parser->readResponse());
+ vmime::utility::auto_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@@ -284,31 +275,31 @@ const char IMAPConnection::hierarchySeparator() const
}
-const IMAPTag* IMAPConnection::getTag() const
+ref <const IMAPTag> IMAPConnection::getTag() const
{
return (m_tag);
}
-const IMAPParser* IMAPConnection::getParser() const
+ref <const IMAPParser> IMAPConnection::getParser() const
{
return (m_parser);
}
-const IMAPStore* IMAPConnection::getStore() const
+weak_ref <const IMAPStore> IMAPConnection::getStore() const
{
return (m_store);
}
-IMAPStore* IMAPConnection::getStore()
+weak_ref <IMAPStore> IMAPConnection::getStore()
{
return (m_store);
}
-session* IMAPConnection::getSession()
+ref <session> IMAPConnection::getSession()
{
return (m_store->getSession());
}
diff --git a/src/messaging/imap/IMAPFolder.cpp b/src/messaging/imap/IMAPFolder.cpp
index 35f3509b..c567c590 100644
--- a/src/messaging/imap/IMAPFolder.cpp
+++ b/src/messaging/imap/IMAPFolder.cpp
@@ -59,7 +59,7 @@ IMAPFolder::~IMAPFolder()
}
else if (m_open)
{
- delete (m_connection);
+ m_connection = NULL;
onClose();
}
}
@@ -132,8 +132,8 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
throw exceptions::illegal_state("Store disconnected");
// Open a connection for this folder
- IMAPConnection* connection =
- new IMAPConnection(m_store, m_store->oneTimeAuthenticator());
+ ref <IMAPConnection> connection =
+ vmime::create <IMAPConnection>(m_store, m_store->oneTimeAuthenticator());
try
{
@@ -263,7 +263,6 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
}
catch (std::exception&)
{
- delete (connection);
throw;
}
}
@@ -277,7 +276,7 @@ void IMAPFolder::close(const bool expunge)
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- IMAPConnection* oldConnection = m_connection;
+ ref <IMAPConnection> oldConnection = m_connection;
// Emit the "CLOSE" command to expunge messages marked
// as deleted (this is fastest than "EXPUNGE")
@@ -301,8 +300,6 @@ void IMAPFolder::close(const bool expunge)
m_uidValidity = 0;
onClose();
-
- delete (oldConnection);
}
@@ -358,7 +355,10 @@ void IMAPFolder::create(const int type)
}
// Notify folder created
- events::folderEvent event(this, events::folderEvent::TYPE_CREATED, m_path, m_path);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_CREATED, m_path, m_path);
+
notifyFolder(event);
}
@@ -450,7 +450,7 @@ const bool IMAPFolder::isOpen() const
}
-message* IMAPFolder::getMessage(const int num)
+ref <message> IMAPFolder::getMessage(const int num)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -458,33 +458,33 @@ message* IMAPFolder::getMessage(const int num)
if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new IMAPMessage(this, num);
+ return vmime::create <IMAPMessage>(this, num);
}
-std::vector <message*> IMAPFolder::getMessages(const int from, const int to)
+std::vector <ref <message> > IMAPFolder::getMessages(const int from, const int to)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new IMAPMessage(this, i));
+ v.push_back(vmime::create <IMAPMessage>(this, i));
return (v);
}
-std::vector <message*> IMAPFolder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > IMAPFolder::getMessages(const std::vector <int>& nums)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- v.push_back(new IMAPMessage(this, *it));
+ v.push_back(vmime::create <IMAPMessage>(this, *it));
return (v);
}
@@ -499,16 +499,16 @@ const int IMAPFolder::getMessageCount()
}
-folder* IMAPFolder::getFolder(const folder::path::component& name)
+ref <folder> IMAPFolder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new IMAPFolder(m_path / name, m_store);
+ return vmime::create <IMAPFolder>(m_path / name, m_store);
}
-std::vector <folder*> IMAPFolder::getFolders(const bool recursive)
+std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
{
if (!isOpen() && !m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -556,57 +556,47 @@ std::vector <folder*> IMAPFolder::getFolders(const bool recursive)
resp->continue_req_or_response_data();
- std::vector <folder*> v;
+ std::vector <ref <folder> > v;
- try
+ for (std::vector <IMAPParser::continue_req_or_response_data*>::const_iterator
+ it = respDataList.begin() ; it != respDataList.end() ; ++it)
{
- for (std::vector <IMAPParser::continue_req_or_response_data*>::const_iterator
- it = respDataList.begin() ; it != respDataList.end() ; ++it)
+ if ((*it)->response_data() == NULL)
{
- if ((*it)->response_data() == NULL)
- {
- throw exceptions::command_error("LIST",
- m_connection->getParser()->lastLine(), "invalid response");
- }
+ throw exceptions::command_error("LIST",
+ m_connection->getParser()->lastLine(), "invalid response");
+ }
- const IMAPParser::mailbox_data* mailboxData =
- (*it)->response_data()->mailbox_data();
+ const IMAPParser::mailbox_data* mailboxData =
+ (*it)->response_data()->mailbox_data();
- if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
- continue;
+ if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
+ continue;
- // Get folder path
- const class IMAPParser::mailbox* mailbox =
- mailboxData->mailbox_list()->mailbox();
+ // Get folder path
+ const class IMAPParser::mailbox* mailbox =
+ mailboxData->mailbox_list()->mailbox();
- folder::path path = IMAPUtils::stringToPath
- (mailboxData->mailbox_list()->quoted_char(), mailbox->name());
+ folder::path path = IMAPUtils::stringToPath
+ (mailboxData->mailbox_list()->quoted_char(), mailbox->name());
- if (recursive || m_path.isDirectParentOf(path))
- {
- // Append folder to list
- const class IMAPParser::mailbox_flag_list* mailbox_flag_list =
- mailboxData->mailbox_list()->mailbox_flag_list();
+ if (recursive || m_path.isDirectParentOf(path))
+ {
+ // Append folder to list
+ const class IMAPParser::mailbox_flag_list* mailbox_flag_list =
+ mailboxData->mailbox_list()->mailbox_flag_list();
- v.push_back(new IMAPFolder(path, m_store,
- IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
- IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
- }
+ v.push_back(vmime::create <IMAPFolder>(path, m_store,
+ IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
+ IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
}
}
- catch (std::exception&)
- {
- for (std::vector <folder*>::iterator it = v.begin() ; it != v.end() ; ++it)
- delete (*it);
-
- throw;
- }
return (v);
}
-void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
+void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int options,
utility::progressionListener* progress)
{
if (!m_store)
@@ -620,10 +610,10 @@ void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <IMAPMessage*>(*it)->fetch(this, options);
+ (*it).dynamicCast <IMAPMessage>()->fetch(this, options);
if (progress)
progress->progress(++current, total);
@@ -634,14 +624,14 @@ void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
}
-void IMAPFolder::fetchMessage(message* msg, const int options)
+void IMAPFolder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <IMAPMessage*>(msg)->fetch(this, options);
+ msg.dynamicCast <IMAPMessage>()->fetch(this, options);
}
@@ -652,19 +642,22 @@ const int IMAPFolder::getFetchCapabilities() const
}
-folder* IMAPFolder::getParent()
+ref <folder> IMAPFolder::getParent()
{
- return (m_path.isEmpty() ? NULL : new IMAPFolder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <IMAPFolder>(m_path.getParent(), m_store);
}
-const store* IMAPFolder::getStore() const
+weak_ref <const store> IMAPFolder::getStore() const
{
return (m_store);
}
-store* IMAPFolder::getStore()
+weak_ref <store> IMAPFolder::getStore()
{
return (m_store);
}
@@ -733,7 +726,9 @@ void IMAPFolder::deleteMessage(const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -794,7 +789,9 @@ void IMAPFolder::deleteMessages(const int from, const int to)
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -851,7 +848,9 @@ void IMAPFolder::deleteMessages(const std::vector <int>& nums)
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, list);
notifyMessageChanged(event);
}
@@ -937,7 +936,9 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags,
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -1013,7 +1014,9 @@ void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags,
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -1055,7 +1058,7 @@ void IMAPFolder::setMessageFlags(const string& set, const int flags, const int m
}
-void IMAPFolder::addMessage(vmime::message* msg, const int flags,
+void IMAPFolder::addMessage(ref <vmime::message> msg, const int flags,
vmime::datetime* date, utility::progressionListener* progress)
{
std::ostringstream oss;
@@ -1166,7 +1169,9 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
std::vector <int> nums;
nums.push_back(m_messageCount + 1);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
m_messageCount++;
notifyMessageCount(event);
@@ -1177,7 +1182,9 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
{
if ((*it) != this && (*it)->getFullPath() == m_path)
{
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->m_messageCount++;
(*it)->notifyMessageCount(event);
@@ -1250,7 +1257,9 @@ void IMAPFolder::expunge()
m_messageCount -= nums.size();
// Notify message expunged
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
notifyMessageCount(event);
@@ -1262,7 +1271,9 @@ void IMAPFolder::expunge()
{
(*it)->m_messageCount = m_messageCount;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1308,7 +1319,10 @@ void IMAPFolder::rename(const folder::path& newPath)
m_path = newPath;
m_name = newPath.getLastComponent();
- events::folderEvent event(this, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
notifyFolder(event);
// Notify folders with the same path and sub-folders
@@ -1320,7 +1334,10 @@ void IMAPFolder::rename(const folder::path& newPath)
(*it)->m_path = newPath;
(*it)->m_name = newPath.getLastComponent();
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
(*it)->notifyFolder(event);
}
else if ((*it) != this && oldPath.isParentOf((*it)->getFullPath()))
@@ -1329,7 +1346,10 @@ void IMAPFolder::rename(const folder::path& newPath)
(*it)->m_path.renameParent(oldPath, newPath);
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+
(*it)->notifyFolder(event);
}
}
@@ -1354,13 +1374,15 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount++;
(*it)->notifyMessageCount(event);
}
@@ -1398,13 +1420,15 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount += count;
(*it)->notifyMessageCount(event);
}
@@ -1425,13 +1449,15 @@ void IMAPFolder::copyMessages(const folder::path& dest, const std::vector <int>&
// Notify message count changed
const int count = nums.size();
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount += count;
(*it)->notifyMessageCount(event);
}
@@ -1545,7 +1571,9 @@ void IMAPFolder::status(int& count, int& unseen)
for (int i = oldCount + 1, j = 0 ; i <= count ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -1557,7 +1585,9 @@ void IMAPFolder::status(int& count, int& unseen)
{
(*it)->m_messageCount = count;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
diff --git a/src/messaging/imap/IMAPMessage.cpp b/src/messaging/imap/IMAPMessage.cpp
index 03af67c6..97aa2d28 100644
--- a/src/messaging/imap/IMAPMessage.cpp
+++ b/src/messaging/imap/IMAPMessage.cpp
@@ -43,17 +43,17 @@ class IMAPpart : public part
{
private:
- IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_mpart* mpart);
- IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_1part* part);
+ friend class vmime::creator;
-public:
+ IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_mpart* mpart);
+ IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_1part* part);
- ~IMAPpart();
+public:
const structure& getStructure() const;
structure& getStructure();
- const IMAPpart* getParent() const { return (m_parent); }
+ weak_ref <const IMAPpart> getParent() const { return (m_parent); }
const mediaType& getType() const { return (m_mediaType); }
const int getSize() const { return (m_size); }
@@ -68,12 +68,13 @@ public:
}
- static IMAPpart* create(IMAPpart* parent, const int number, const IMAPParser::body* body)
+ static ref <IMAPpart> create
+ (weak_ref <IMAPpart> parent, const int number, const IMAPParser::body* body)
{
if (body->body_type_mpart())
- return new IMAPpart(parent, number, body->body_type_mpart());
+ return vmime::create <IMAPpart>(parent, number, body->body_type_mpart());
else
- return new IMAPpart(parent, number, body->body_type_1part());
+ return vmime::create <IMAPpart>(parent, number, body->body_type_1part());
}
@@ -82,14 +83,14 @@ public:
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
private:
- IMAPstructure* m_structure;
- IMAPpart* m_parent;
- header* m_header;
+ ref <IMAPstructure> m_structure;
+ weak_ref <IMAPpart> m_parent;
+ ref <header> m_header;
int m_number;
int m_size;
@@ -117,7 +118,7 @@ public:
m_parts.push_back(IMAPpart::create(NULL, 1, body));
}
- IMAPstructure(IMAPpart* parent, const std::vector <IMAPParser::body*>& list)
+ IMAPstructure(weak_ref <IMAPpart> parent, const std::vector <IMAPParser::body*>& list)
{
int number = 1;
@@ -128,11 +129,6 @@ public:
}
}
- ~IMAPstructure()
- {
- free_container(m_parts);
- }
-
const part& operator[](const int x) const
{
@@ -159,7 +155,7 @@ private:
static IMAPstructure m_emptyStructure;
- std::vector <IMAPpart*> m_parts;
+ std::vector <ref <IMAPpart> > m_parts;
};
@@ -167,17 +163,18 @@ IMAPstructure IMAPstructure::m_emptyStructure;
-IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_mpart* mpart)
+IMAPpart::IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_mpart* mpart)
: m_parent(parent), m_header(NULL), m_number(number), m_size(0)
{
m_mediaType = vmime::mediaType
("multipart", mpart->media_subtype()->value());
- m_structure = new IMAPstructure(this, mpart->list());
+ m_structure = vmime::create <IMAPstructure>
+ (thisWeakRef().dynamicCast <IMAPpart>(), mpart->list());
}
-IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_1part* part)
+IMAPpart::IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_1part* part)
: m_parent(parent), m_header(NULL), m_number(number), m_size(0)
{
if (part->body_type_text())
@@ -207,13 +204,6 @@ IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_ty
}
-IMAPpart::~IMAPpart()
-{
- delete (m_structure);
- delete (m_header);
-}
-
-
const class structure& IMAPpart::getStructure() const
{
if (m_structure != NULL)
@@ -292,8 +282,6 @@ IMAPMessage::~IMAPMessage()
{
if (m_folder)
m_folder->unregisterMessage(this);
-
- delete dynamic_cast <header*>(m_header);
}
@@ -597,62 +585,61 @@ void IMAPMessage::processFetchResponse
vmime::header& hdr = getOrCreateHeader();
// Date
- hdr.Date().setValue(env->env_date()->value());
+ hdr.Date()->setValue(env->env_date()->value());
// Subject
text subject;
text::decodeAndUnfold(env->env_subject()->value(), &subject);
- hdr.Subject().setValue(subject);
+ hdr.Subject()->setValue(subject);
// From
mailboxList from;
convertAddressList(*(env->env_from()), from);
if (!from.isEmpty())
- hdr.From().setValue(*(from.getMailboxAt(0)));
+ hdr.From()->setValue(*(from.getMailboxAt(0)));
// To
mailboxList to;
convertAddressList(*(env->env_to()), to);
- hdr.To().setValue(to);
+ hdr.To()->setValue(to);
// Sender
mailboxList sender;
convertAddressList(*(env->env_sender()), sender);
if (!sender.isEmpty())
- hdr.Sender().setValue(*(sender.getMailboxAt(0)));
+ hdr.Sender()->setValue(*(sender.getMailboxAt(0)));
// Reply-to
mailboxList replyTo;
convertAddressList(*(env->env_reply_to()), replyTo);
if (!replyTo.isEmpty())
- hdr.ReplyTo().setValue(*(replyTo.getMailboxAt(0)));
+ hdr.ReplyTo()->setValue(*(replyTo.getMailboxAt(0)));
// Cc
mailboxList cc;
convertAddressList(*(env->env_cc()), cc);
if (!cc.isEmpty())
- hdr.Cc().setValue(cc);
+ hdr.Cc()->setValue(cc);
// Bcc
mailboxList bcc;
convertAddressList(*(env->env_bcc()), bcc);
if (!bcc.isEmpty())
- hdr.Bcc().setValue(bcc);
+ hdr.Bcc()->setValue(bcc);
}
break;
}
case IMAPParser::msg_att_item::BODY_STRUCTURE:
{
- delete (m_structure);
- m_structure = new IMAPstructure((*it)->body());
+ m_structure = vmime::create <IMAPstructure>((*it)->body());
break;
}
case IMAPParser::msg_att_item::RFC822_HEADER:
@@ -677,12 +664,12 @@ void IMAPMessage::processFetchResponse
tempHeader.parse((*it)->nstring()->value());
vmime::header& hdr = getOrCreateHeader();
- std::vector <headerField*> fields = tempHeader.getFieldList();
+ std::vector <ref <headerField> > fields = tempHeader.getFieldList();
- for (std::vector <headerField*>::const_iterator jt = fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator jt = fields.begin() ;
jt != fields.end() ; ++jt)
{
- hdr.appendField((*jt)->clone());
+ hdr.appendField((*jt)->clone().dynamicCast <headerField>());
}
}
}
@@ -710,7 +697,7 @@ header& IMAPMessage::getOrCreateHeader()
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
@@ -728,7 +715,7 @@ void IMAPMessage::convertAddressList
string email = addr.addr_mailbox()->value()
+ "@" + addr.addr_host()->value();
- dest.appendMailbox(new mailbox(name, email));
+ dest.appendMailbox(vmime::create <mailbox>(name, email));
}
}
@@ -829,7 +816,9 @@ void IMAPMessage::setFlags(const int flags, const int mode)
std::vector <int> nums;
nums.push_back(m_num);
- events::messageChangedEvent event(m_folder, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (m_folder->thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
for (std::list <IMAPFolder*>::iterator it = m_folder->m_store->m_folders.begin() ;
it != m_folder->m_store->m_folders.end() ; ++it)
diff --git a/src/messaging/imap/IMAPStore.cpp b/src/messaging/imap/IMAPStore.cpp
index 07b22351..00ef98f2 100644
--- a/src/messaging/imap/IMAPStore.cpp
+++ b/src/messaging/imap/IMAPStore.cpp
@@ -45,28 +45,27 @@ class IMAPauthenticator : public authenticator
{
public:
- IMAPauthenticator(authenticator* auth)
+ IMAPauthenticator(ref <authenticator> auth)
: m_auth(auth), m_infos(NULL)
{
}
~IMAPauthenticator()
{
- delete (m_infos);
}
const authenticationInfos requestAuthInfos() const
{
if (m_infos == NULL)
- m_infos = new authenticationInfos(m_auth->requestAuthInfos());
+ m_infos = vmime::create <authenticationInfos>(m_auth->requestAuthInfos());
return (*m_infos);
}
private:
- authenticator* m_auth;
- mutable authenticationInfos* m_infos;
+ ref <authenticator> m_auth;
+ mutable ref <authenticationInfos> m_infos;
};
#endif // VMIME_BUILDING_DOC
@@ -77,7 +76,7 @@ private:
// IMAPStore
//
-IMAPStore::IMAPStore(session* sess, authenticator* auth)
+IMAPStore::IMAPStore(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth),
m_connection(NULL), m_oneTimeAuth(NULL)
{
@@ -91,7 +90,7 @@ IMAPStore::~IMAPStore()
}
-authenticator* IMAPStore::oneTimeAuthenticator()
+ref <authenticator> IMAPStore::oneTimeAuthenticator()
{
return (m_oneTimeAuth);
}
@@ -103,30 +102,30 @@ const string IMAPStore::getProtocolName() const
}
-folder* IMAPStore::getRootFolder()
+ref <folder> IMAPStore::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(folder::path(), this);
+ return vmime::create <IMAPFolder>(folder::path(), this);
}
-folder* IMAPStore::getDefaultFolder()
+ref <folder> IMAPStore::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(folder::path::component("INBOX"), this);
+ return vmime::create <IMAPFolder>(folder::path::component("INBOX"), this);
}
-folder* IMAPStore::getFolder(const folder::path& path)
+ref <folder> IMAPStore::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(path, this);
+ return vmime::create <IMAPFolder>(path, this);
}
@@ -141,9 +140,10 @@ void IMAPStore::connect()
if (isConnected())
throw exceptions::already_connected();
- m_oneTimeAuth = new IMAPauthenticator(getAuthenticator());
+ m_oneTimeAuth = vmime::create <IMAPauthenticator>(getAuthenticator());
- m_connection = new IMAPConnection(this, m_oneTimeAuth);
+ m_connection = vmime::create <IMAPConnection>
+ (thisWeakRef().dynamicCast <IMAPStore>(), m_oneTimeAuth);
try
{
@@ -151,7 +151,6 @@ void IMAPStore::connect()
}
catch (std::exception&)
{
- delete (m_connection);
m_connection = NULL;
throw;
}
@@ -180,10 +179,8 @@ void IMAPStore::disconnect()
m_connection->disconnect();
- delete (m_oneTimeAuth);
m_oneTimeAuth = NULL;
- delete (m_connection);
m_connection = NULL;
}
@@ -205,7 +202,7 @@ void IMAPStore::noop()
}
-IMAPConnection* IMAPStore::connection()
+ref <IMAPConnection> IMAPStore::connection()
{
return (m_connection);
}
diff --git a/src/messaging/imap/IMAPTag.cpp b/src/messaging/imap/IMAPTag.cpp
index bc6b656d..c1cf659d 100644
--- a/src/messaging/imap/IMAPTag.cpp
+++ b/src/messaging/imap/IMAPTag.cpp
@@ -36,7 +36,7 @@ IMAPTag::IMAPTag(const int number)
IMAPTag::IMAPTag(const IMAPTag& tag)
- : m_number(tag.m_number)
+ : object(), m_number(tag.m_number)
{
m_tag.resize(4);
}
diff --git a/src/messaging/maildir/maildirFolder.cpp b/src/messaging/maildir/maildirFolder.cpp
index fa337d09..d24ab5e5 100644
--- a/src/messaging/maildir/maildirFolder.cpp
+++ b/src/messaging/maildir/maildirFolder.cpp
@@ -36,7 +36,7 @@ namespace messaging {
namespace maildir {
-maildirFolder::maildirFolder(const folder::path& path, maildirStore* store)
+maildirFolder::maildirFolder(const folder::path& path, weak_ref <maildirStore> store)
: m_store(store), m_path(path),
m_name(path.isEmpty() ? folder::path::component("") : path.getLastComponent()),
m_mode(-1), m_open(false), m_unreadMessageCount(0), m_messageCount(0)
@@ -91,14 +91,14 @@ const int maildirFolder::getFlags()
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
- utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
+ ref <utility::fileIterator> it = rootDir->getFiles();
while (it->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = it->nextElement();
+ ref <utility::file> file = it->nextElement();
if (maildirUtils::isSubfolderDirectory(*file))
{
@@ -204,14 +204,14 @@ void maildirFolder::create(const int /* type */)
if (!fsf->isValidPath(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT)))
throw exceptions::invalid_folder_name();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> newDir = fsf->create
+ ref <utility::file> newDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW));
- utility::auto_ptr <utility::file> tmpDir = fsf->create
+ ref <utility::file> tmpDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP));
- utility::auto_ptr <utility::file> curDir = fsf->create
+ ref <utility::file> curDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CUR));
rootDir->createDirectory(true);
@@ -226,7 +226,10 @@ void maildirFolder::create(const int /* type */)
}
// Notify folder created
- events::folderEvent event(this, events::folderEvent::TYPE_CREATED, m_path, m_path);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_CREATED, m_path, m_path);
+
notifyFolder(event);
}
@@ -235,14 +238,14 @@ const bool maildirFolder::exists()
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> newDir = fsf->create
+ ref <utility::file> newDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW));
- utility::auto_ptr <utility::file> tmpDir = fsf->create
+ ref <utility::file> tmpDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP));
- utility::auto_ptr <utility::file> curDir = fsf->create
+ ref <utility::file> curDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CUR));
return (rootDir->exists() && rootDir->isDirectory() &&
@@ -269,40 +272,36 @@ void maildirFolder::scanFolder()
utility::file::path newDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_NEW);
- utility::auto_ptr <utility::file> newDir = fsf->create(newDirPath);
+ ref <utility::file> newDir = fsf->create(newDirPath);
utility::file::path curDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_CUR);
- utility::auto_ptr <utility::file> curDir = fsf->create(curDirPath);
+ ref <utility::file> curDir = fsf->create(curDirPath);
// New received messages (new/)
- utility::fileIterator* nit = newDir->getFiles();
+ ref <utility::fileIterator> nit = newDir->getFiles();
std::vector <utility::file::path::component> newMessageFilenames;
while (nit->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = nit->nextElement();
+ ref <utility::file> file = nit->nextElement();
if (maildirUtils::isMessageFile(*file))
newMessageFilenames.push_back(file->getFullPath().getLastComponent());
}
- delete (nit); // Free directory
-
// Current messages (cur/)
- utility::fileIterator* cit = curDir->getFiles();
+ ref <utility::fileIterator> cit = curDir->getFiles();
std::vector <utility::file::path::component> curMessageFilenames;
while (cit->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = cit->nextElement();
+ ref <utility::file> file = cit->nextElement();
if (maildirUtils::isMessageFile(*file))
curMessageFilenames.push_back(file->getFullPath().getLastComponent());
}
- delete (cit); // Free directory
-
// Update/delete existing messages (found in previous scan)
for (unsigned int i = 0 ; i < m_messageInfos.size() ; ++i)
{
@@ -347,7 +346,7 @@ void maildirFolder::scanFolder()
maildirUtils::buildFilename(maildirUtils::extractId(*it), 0);
// Move messages from 'new' to 'cur'
- utility::auto_ptr <utility::file> file = fsf->create(newDirPath / *it);
+ ref <utility::file> file = fsf->create(newDirPath / *it);
file->rename(curDirPath / newFilename);
// Append to message list
@@ -391,7 +390,7 @@ void maildirFolder::scanFolder()
}
-message* maildirFolder::getMessage(const int num)
+ref <message> maildirFolder::getMessage(const int num)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -399,33 +398,40 @@ message* maildirFolder::getMessage(const int num)
if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new maildirMessage(this, num);
+ return vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), num);
}
-std::vector <message*> maildirFolder::getMessages(const int from, const int to)
+std::vector <ref <message> > maildirFolder::getMessages(const int from, const int to)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new maildirMessage(this, i));
+ {
+ v.push_back(vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), i));
+ }
return (v);
}
-std::vector <message*> maildirFolder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > maildirFolder::getMessages(const std::vector <int>& nums)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- v.push_back(new maildirMessage(this, *it));
+ {
+ v.push_back(vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), *it));
+ }
return (v);
}
@@ -437,68 +443,54 @@ const int maildirFolder::getMessageCount()
}
-folder* maildirFolder::getFolder(const folder::path::component& name)
+ref <folder> maildirFolder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new maildirFolder(m_path / name, m_store);
+ return vmime::create <maildirFolder>(m_path / name, m_store);
}
-std::vector <folder*> maildirFolder::getFolders(const bool recursive)
+std::vector <ref <folder> > maildirFolder::getFolders(const bool recursive)
{
if (!isOpen() && !m_store)
throw exceptions::illegal_state("Store disconnected");
- std::vector <folder*> list;
+ std::vector <ref <folder> > list;
- try
- {
- listFolders(list, recursive);
- }
- catch (std::exception&)
- {
- for (std::vector <folder*>::iterator it = list.begin() ; it != list.end() ; ++it)
- delete (*it);
-
- throw;
- }
- catch (vmime::exception&)
- {
- for (std::vector <folder*>::iterator it = list.begin() ; it != list.end() ; ++it)
- delete (*it);
-
- throw;
- }
+ listFolders(list, recursive);
return (list);
}
-void maildirFolder::listFolders(std::vector <folder*>& list, const bool recursive)
+void maildirFolder::listFolders(std::vector <ref <folder> >& list, const bool recursive)
{
try
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path,
m_path.isEmpty() ? maildirUtils::FOLDER_PATH_ROOT
: maildirUtils::FOLDER_PATH_CONTAINER));
if (rootDir->exists())
{
- utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
+ ref <utility::fileIterator> it = rootDir->getFiles();
while (it->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = it->nextElement();
+ ref <utility::file> file = it->nextElement();
if (maildirUtils::isSubfolderDirectory(*file))
{
- const utility::path subPath = m_path / file->getFullPath().getLastComponent();
- maildirFolder* subFolder = new maildirFolder(subPath, m_store);
+ const utility::path subPath =
+ m_path / file->getFullPath().getLastComponent();
+
+ ref <maildirFolder> subFolder =
+ vmime::create <maildirFolder>(subPath, m_store);
list.push_back(subFolder);
@@ -531,9 +523,9 @@ void maildirFolder::rename(const folder::path& newPath)
// Rename the directory on the file system
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> contDir = fsf->create
+ ref <utility::file> contDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
try
@@ -582,7 +574,10 @@ void maildirFolder::rename(const folder::path& newPath)
m_path = newPath;
m_name = newPath.getLastComponent();
- events::folderEvent event(this, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
notifyFolder(event);
// Notify folders with the same path
@@ -594,7 +589,10 @@ void maildirFolder::rename(const folder::path& newPath)
(*it)->m_path = newPath;
(*it)->m_name = newPath.getLastComponent();
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
(*it)->notifyFolder(event);
}
else if ((*it) != this && oldPath.isParentOf((*it)->getFullPath()))
@@ -603,7 +601,10 @@ void maildirFolder::rename(const folder::path& newPath)
(*it)->m_path.renameParent(oldPath, newPath);
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+
(*it)->notifyFolder(event);
}
}
@@ -707,9 +708,13 @@ void maildirFolder::setMessageFlags
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
+
+ // TODO: notify other folders with the same path
}
@@ -784,9 +789,13 @@ void maildirFolder::setMessageFlags
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
+
+ // TODO: notify other folders with the same path
}
@@ -806,7 +815,7 @@ void maildirFolder::setMessageFlagsImpl
try
{
const utility::file::path::component path = m_messageInfos[num].path;
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / path);
+ ref <utility::file> file = fsf->create(curDirPath / path);
int newFlags = maildirUtils::extractFlags(path);
@@ -838,7 +847,7 @@ void maildirFolder::setMessageFlagsImpl
}
-void maildirFolder::addMessage(vmime::message* msg, const int flags,
+void maildirFolder::addMessage(ref <vmime::message> msg, const int flags,
vmime::datetime* date, utility::progressionListener* progress)
{
std::ostringstream oss;
@@ -876,7 +885,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
try
{
- utility::auto_ptr <utility::file> tmpDir = fsf->create(tmpDirPath);
+ ref <utility::file> tmpDir = fsf->create(tmpDirPath);
tmpDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -886,7 +895,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
try
{
- utility::auto_ptr <utility::file> curDir = fsf->create(curDirPath);
+ ref <utility::file> curDir = fsf->create(curDirPath);
curDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -912,7 +921,9 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
std::vector <int> nums;
nums.push_back(m_messageCount);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -928,7 +939,9 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
@@ -943,7 +956,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
if (progress)
progress->start(size);
@@ -953,8 +966,8 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
{
file->createFile();
- utility::auto_ptr <utility::fileWriter> fw = file->getFileWriter();
- utility::auto_ptr <utility::outputStream> os = fw->getOutputStream();
+ ref <utility::fileWriter> fw = file->getFileWriter();
+ ref <utility::outputStream> os = fw->getOutputStream();
utility::stream::value_type buffer[65536];
utility::stream::size_type total = 0;
@@ -981,7 +994,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
// Delete temporary file
try
{
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
file->remove();
}
catch (exceptions::filesystem_exception&)
@@ -1005,7 +1018,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
// Delete temporary file
try
{
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
file->remove();
}
catch (exceptions::filesystem_exception&)
@@ -1083,7 +1096,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
// Create destination directories
try
{
- utility::auto_ptr <utility::file> destTmpDir = fsf->create(destTmpDirPath);
+ ref <utility::file> destTmpDir = fsf->create(destTmpDirPath);
destTmpDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -1093,7 +1106,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
try
{
- utility::auto_ptr <utility::file> destCurDir = fsf->create(destCurDirPath);
+ ref <utility::file> destCurDir = fsf->create(destCurDirPath);
destCurDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -1114,9 +1127,9 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
const utility::file::path::component filename =
maildirUtils::buildFilename(maildirUtils::generateId(), flags);
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / msg.path);
- utility::auto_ptr <utility::fileReader> fr = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = fr->getInputStream();
+ ref <utility::file> file = fsf->create(curDirPath / msg.path);
+ ref <utility::fileReader> fr = file->getFileReader();
+ ref <utility::inputStream> is = fr->getInputStream();
copyMessageImpl(destTmpDirPath, destCurDirPath,
filename, *is, file->getLength(), NULL);
@@ -1168,7 +1181,9 @@ void maildirFolder::status(int& count, int& unseen)
for (int i = oldCount + 1, j = 0 ; i <= count ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -1184,7 +1199,9 @@ void maildirFolder::status(int& count, int& unseen)
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1233,7 +1250,7 @@ void maildirFolder::expunge()
// Delete file from file system
try
{
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / infos.path);
+ ref <utility::file> file = fsf->create(curDirPath / infos.path);
file->remove();
}
catch (exceptions::filesystem_exception& e)
@@ -1253,7 +1270,9 @@ void maildirFolder::expunge()
m_unreadMessageCount -= unreadCount;
// Notify message expunged
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
notifyMessageCount(event);
@@ -1269,7 +1288,9 @@ void maildirFolder::expunge()
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1277,25 +1298,28 @@ void maildirFolder::expunge()
}
-folder* maildirFolder::getParent()
+ref <folder> maildirFolder::getParent()
{
- return (m_path.isEmpty() ? NULL : new maildirFolder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <maildirFolder>(m_path.getParent(), m_store);
}
-const store* maildirFolder::getStore() const
+weak_ref <const store> maildirFolder::getStore() const
{
return (m_store);
}
-store* maildirFolder::getStore()
+weak_ref <store> maildirFolder::getStore()
{
return (m_store);
}
-void maildirFolder::fetchMessages(std::vector <message*>& msg,
+void maildirFolder::fetchMessages(std::vector <ref <message> >& msg,
const int options, utility::progressionListener* progress)
{
if (!m_store)
@@ -1309,10 +1333,12 @@ void maildirFolder::fetchMessages(std::vector <message*>& msg,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ weak_ref <maildirFolder> _this = thisWeakRef().dynamicCast <maildirFolder>();
+
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <maildirMessage*>(*it)->fetch(this, options);
+ (*it).dynamicCast <maildirMessage>()->fetch(_this, options);
if (progress)
progress->progress(++current, total);
@@ -1323,14 +1349,15 @@ void maildirFolder::fetchMessages(std::vector <message*>& msg,
}
-void maildirFolder::fetchMessage(message* msg, const int options)
+void maildirFolder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <maildirMessage*>(msg)->fetch(this, options);
+ msg.dynamicCast <maildirMessage>()->fetch
+ (thisWeakRef().dynamicCast <maildirFolder>(), options);
}
@@ -1341,7 +1368,7 @@ const int maildirFolder::getFetchCapabilities() const
}
-const utility::file::path maildirFolder::getMessageFSPath(const int number)
+const utility::file::path maildirFolder::getMessageFSPath(const int number) const
{
utility::file::path curDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_CUR);
diff --git a/src/messaging/maildir/maildirMessage.cpp b/src/messaging/maildir/maildirMessage.cpp
index e9042979..408b27c8 100644
--- a/src/messaging/maildir/maildirMessage.cpp
+++ b/src/messaging/maildir/maildirMessage.cpp
@@ -20,6 +20,7 @@
#include "vmime/messaging/maildir/maildirMessage.hpp"
#include "vmime/messaging/maildir/maildirFolder.hpp"
#include "vmime/messaging/maildir/maildirUtils.hpp"
+#include "vmime/messaging/maildir/maildirStore.hpp"
#include "vmime/message.hpp"
@@ -42,14 +43,14 @@ class maildirPart : public part
{
public:
- maildirPart(maildirPart* parent, const int number, const bodyPart& part);
+ maildirPart(weak_ref <maildirPart> parent, const int number, const bodyPart& part);
~maildirPart();
const structure& getStructure() const;
structure& getStructure();
- const maildirPart* getParent() const { return (m_parent); }
+ weak_ref <const maildirPart> getParent() const { return (m_parent); }
const mediaType& getType() const { return (m_mediaType); }
const int getSize() const { return (m_size); }
@@ -68,7 +69,7 @@ public:
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
const int getHeaderParsedOffset() const { return (m_headerParsedOffset); }
@@ -79,9 +80,9 @@ public:
private:
- maildirStructure* m_structure;
- maildirPart* m_parent;
- header* m_header;
+ ref <maildirStructure> m_structure;
+ weak_ref <maildirPart> m_parent;
+ ref <header> m_header;
int m_number;
int m_size;
@@ -110,22 +111,17 @@ private:
public:
- maildirStructure(maildirPart* parent, const bodyPart& part)
+ maildirStructure(weak_ref <maildirPart> parent, const bodyPart& part)
{
- m_parts.push_back(new maildirPart(parent, 1, part));
+ m_parts.push_back(vmime::create <maildirPart>(parent, 1, part));
}
- maildirStructure(maildirPart* parent, const std::vector <const vmime::bodyPart*>& list)
+ maildirStructure(weak_ref <maildirPart> parent, const std::vector <ref <const vmime::bodyPart> >& list)
{
int number = 1;
for (unsigned int i = 0 ; i < list.size() ; ++i)
- m_parts.push_back(new maildirPart(parent, number, *list[i]));
- }
-
- ~maildirStructure()
- {
- free_container(m_parts);
+ m_parts.push_back(vmime::create <maildirPart>(parent, number, *list[i]));
}
@@ -154,7 +150,7 @@ private:
static maildirStructure m_emptyStructure;
- std::vector <maildirPart*> m_parts;
+ std::vector <ref <maildirPart> > m_parts;
};
@@ -162,13 +158,17 @@ maildirStructure maildirStructure::m_emptyStructure;
-maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart& part)
+maildirPart::maildirPart(weak_ref <maildirPart> parent, const int number, const bodyPart& part)
: m_parent(parent), m_header(NULL), m_number(number)
{
if (part.getBody()->getPartList().size() == 0)
m_structure = NULL;
else
- m_structure = new maildirStructure(this, part.getBody()->getPartList());
+ {
+ m_structure = vmime::create <maildirStructure>
+ (thisWeakRef().dynamicCast <maildirPart>(),
+ part.getBody()->getPartList());
+ }
m_headerParsedOffset = part.getHeader()->getParsedOffset();
m_headerParsedLength = part.getHeader()->getParsedLength();
@@ -176,7 +176,7 @@ maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart&
m_bodyParsedOffset = part.getBody()->getParsedOffset();
m_bodyParsedLength = part.getBody()->getParsedLength();
- m_size = part.getBody()->getContents().getLength();
+ m_size = part.getBody()->getContents()->getLength();
m_mediaType = part.getBody()->getContentType();
}
@@ -184,8 +184,6 @@ maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart&
maildirPart::~maildirPart()
{
- delete (m_structure);
- delete (m_header);
}
@@ -212,7 +210,7 @@ structure& maildirPart::getStructure()
// maildirMessage
//
-maildirMessage::maildirMessage(maildirFolder* folder, const int num)
+maildirMessage::maildirMessage(weak_ref <maildirFolder> folder, const int num)
: m_folder(folder), m_num(num), m_size(-1), m_flags(FLAG_UNDEFINED),
m_expunged(false), m_header(NULL), m_structure(NULL)
{
@@ -224,9 +222,6 @@ maildirMessage::~maildirMessage()
{
if (m_folder)
m_folder->unregisterMessage(this);
-
- delete (m_header);
- delete (m_structure);
}
@@ -334,10 +329,10 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progression
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = m_folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
is->skip(start + partialStart);
@@ -379,10 +374,10 @@ void maildirMessage::fetchPartHeader(part& p)
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = m_folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
is->skip(mp.getHeaderParsedOffset());
@@ -406,7 +401,7 @@ void maildirMessage::fetchPartHeader(part& p)
}
-void maildirMessage::fetch(maildirFolder* folder, const int options)
+void maildirMessage::fetch(weak_ref <maildirFolder> folder, const int options)
{
if (m_folder != folder)
throw exceptions::folder_not_found();
@@ -414,7 +409,7 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
if (options & folder::FETCH_FLAGS)
m_flags = maildirUtils::extractFlags(path.getLastComponent());
@@ -430,8 +425,8 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
{
string contents;
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
// Need whole message contents for structure
if (options & folder::FETCH_STRUCTURE)
@@ -480,10 +475,7 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
// Extract structure
if (options & folder::FETCH_STRUCTURE)
{
- if (m_structure)
- delete (m_structure);
-
- m_structure = new maildirStructure(NULL, msg);
+ m_structure = vmime::create <maildirStructure>(null, msg);
}
// Extract some header fields or whole header
@@ -502,7 +494,7 @@ header& maildirMessage::getOrCreateHeader()
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
diff --git a/src/messaging/maildir/maildirStore.cpp b/src/messaging/maildir/maildirStore.cpp
index 87204299..ccbd35a4 100644
--- a/src/messaging/maildir/maildirStore.cpp
+++ b/src/messaging/maildir/maildirStore.cpp
@@ -39,7 +39,7 @@ namespace messaging {
namespace maildir {
-maildirStore::maildirStore(session* sess, authenticator* auth)
+maildirStore::maildirStore(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth), m_connected(false)
{
}
@@ -58,30 +58,33 @@ const string maildirStore::getProtocolName() const
}
-folder* maildirStore::getRootFolder()
+ref <folder> maildirStore::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(folder::path(), this);
+ return vmime::create <maildirFolder>(folder::path(),
+ thisWeakRef().dynamicCast <maildirStore>());
}
-folder* maildirStore::getDefaultFolder()
+ref <folder> maildirStore::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(folder::path::component("inbox"), this);
+ return vmime::create <maildirFolder>(folder::path::component("inbox"),
+ thisWeakRef().dynamicCast <maildirStore>());
}
-folder* maildirStore::getFolder(const folder::path& path)
+ref <folder> maildirStore::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(path, this);
+ return vmime::create <maildirFolder>(path,
+ thisWeakRef().dynamicCast <maildirStore>());
}
@@ -117,7 +120,7 @@ void maildirStore::connect()
m_fsPath = fsf->stringToPath(GET_PROPERTY(string, PROPERTY_SERVER_ROOTPATH));
- utility::auto_ptr <utility::file> rootDir = fsf->create(m_fsPath);
+ ref <utility::file> rootDir = fsf->create(m_fsPath);
// Try to create the root directory if it does not exist
if (!(rootDir->exists() && rootDir->isDirectory()))
diff --git a/src/messaging/maildir/maildirUtils.cpp b/src/messaging/maildir/maildirUtils.cpp
index 091fd871..9e411cd6 100644
--- a/src/messaging/maildir/maildirUtils.cpp
+++ b/src/messaging/maildir/maildirUtils.cpp
@@ -34,7 +34,7 @@ const vmime::word maildirUtils::NEW_DIR("new", vmime::charset(vmime::charsets::U
const utility::file::path maildirUtils::getFolderFSPath
- (maildirStore* store, const utility::path& folderPath, const FolderFSPathMode mode)
+ (weak_ref <maildirStore> store, const utility::path& folderPath, const FolderFSPathMode mode)
{
// Root path
utility::file::path path(store->getFileSystemPath());
diff --git a/src/messaging/pop3/POP3Folder.cpp b/src/messaging/pop3/POP3Folder.cpp
index 6f4cb237..0f0a5369 100644
--- a/src/messaging/pop3/POP3Folder.cpp
+++ b/src/messaging/pop3/POP3Folder.cpp
@@ -191,7 +191,7 @@ const bool POP3Folder::isOpen() const
}
-message* POP3Folder::getMessage(const int num)
+ref <message> POP3Folder::getMessage(const int num)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -200,11 +200,11 @@ message* POP3Folder::getMessage(const int num)
else if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new POP3Message(this, num);
+ return vmime::create <POP3Message>(this, num);
}
-std::vector <message*> POP3Folder::getMessages(const int from, const int to)
+std::vector <ref <message> > POP3Folder::getMessages(const int from, const int to)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -213,40 +213,30 @@ std::vector <message*> POP3Folder::getMessages(const int from, const int to)
else if (to < from || from < 1 || to < 1 || from > m_messageCount || to > m_messageCount)
throw exceptions::message_not_found();
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new POP3Message(this, i));
+ v.push_back(vmime::create <POP3Message>(this, i));
return (v);
}
-std::vector <message*> POP3Folder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > POP3Folder::getMessages(const std::vector <int>& nums)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
- try
+ for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
{
- for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- {
- if (*it < 1|| *it > m_messageCount)
- throw exceptions::message_not_found();
+ if (*it < 1|| *it > m_messageCount)
+ throw exceptions::message_not_found();
- v.push_back(new POP3Message(this, *it));
- }
- }
- catch (std::exception& e)
- {
- for (std::vector <message*>::iterator it = v.begin() ; it != v.end() ; ++it)
- delete (*it);
-
- throw;
+ v.push_back(vmime::create <POP3Message>(this, *it));
}
return (v);
@@ -264,35 +254,35 @@ const int POP3Folder::getMessageCount()
}
-folder* POP3Folder::getFolder(const folder::path::component& name)
+ref <folder> POP3Folder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new POP3Folder(m_path / name, m_store);
+ return vmime::create <POP3Folder>(m_path / name, m_store);
}
-std::vector <folder*> POP3Folder::getFolders(const bool /* recursive */)
+std::vector <ref <folder> > POP3Folder::getFolders(const bool /* recursive */)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
if (m_path.isEmpty())
{
- std::vector <folder*> v;
- v.push_back(new POP3Folder(folder::path::component("INBOX"), m_store));
+ std::vector <ref <folder> > v;
+ v.push_back(vmime::create <POP3Folder>(folder::path::component("INBOX"), m_store));
return (v);
}
else
{
- std::vector <folder*> v;
+ std::vector <ref <folder> > v;
return (v);
}
}
-void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
+void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int options,
utility::progressionListener* progress)
{
if (!m_store)
@@ -306,10 +296,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <POP3Message*>(*it)->fetch(this, options);
+ (*it).dynamicCast <POP3Message>()->fetch(this, options);
if (progress)
progress->progress(++current, total);
@@ -339,10 +329,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
std::map <int, string> result;
parseMultiListOrUidlResponse(response, result);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- POP3Message* m = dynamic_cast <POP3Message*>(*it);
+ ref <POP3Message> m = (*it).dynamicCast <POP3Message>();
std::map <int, string>::const_iterator x = result.find(m->m_num);
@@ -384,10 +374,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
std::map <int, string> result;
parseMultiListOrUidlResponse(response, result);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- POP3Message* m = dynamic_cast <POP3Message*>(*it);
+ ref <POP3Message> m = (*it).dynamicCast <POP3Message>();
std::map <int, string>::const_iterator x = result.find(m->m_num);
@@ -402,14 +392,14 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
}
-void POP3Folder::fetchMessage(message* msg, const int options)
+void POP3Folder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <POP3Message*>(msg)->fetch(this, options);
+ msg.dynamicCast <POP3Message>()->fetch(this, options);
if (options & FETCH_SIZE)
{
@@ -442,7 +432,7 @@ void POP3Folder::fetchMessage(message* msg, const int options)
std::istringstream iss(string(it, response.end()));
iss >> size;
- dynamic_cast <POP3Message*>(msg)->m_size = size;
+ msg.dynamicCast <POP3Message>()->m_size = size;
}
}
}
@@ -473,7 +463,7 @@ void POP3Folder::fetchMessage(message* msg, const int options)
if (it != response.end())
{
- dynamic_cast <POP3Message*>(msg)->m_uid =
+ msg.dynamicCast <POP3Message>()->m_uid =
string(it, response.end());
}
}
@@ -488,19 +478,22 @@ const int POP3Folder::getFetchCapabilities() const
}
-folder* POP3Folder::getParent()
+ref <folder> POP3Folder::getParent()
{
- return (m_path.isEmpty() ? NULL : new POP3Folder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <POP3Folder>(m_path.getParent(), m_store);
}
-const store* POP3Folder::getStore() const
+weak_ref <const store> POP3Folder::getStore() const
{
return (m_store);
}
-store* POP3Folder::getStore()
+weak_ref <store> POP3Folder::getStore()
{
return (m_store);
}
@@ -556,7 +549,9 @@ void POP3Folder::deleteMessage(const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -604,7 +599,9 @@ void POP3Folder::deleteMessages(const int from, const int to)
for (int i = from ; i <= to2 ; ++i)
nums.push_back(i);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -654,7 +651,9 @@ void POP3Folder::deleteMessages(const std::vector <int>& nums)
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, list);
notifyMessageChanged(event);
}
@@ -680,7 +679,7 @@ void POP3Folder::rename(const folder::path& /* newPath */)
}
-void POP3Folder::addMessage(vmime::message* /* msg */, const int /* flags */,
+void POP3Folder::addMessage(ref <vmime::message> /* msg */, const int /* flags */,
vmime::datetime* /* date */, utility::progressionListener* /* progress */)
{
throw exceptions::operation_not_supported();
@@ -750,7 +749,9 @@ void POP3Folder::status(int& count, int& unseen)
nums[j] = i;
// Notify message count changed
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -762,7 +763,9 @@ void POP3Folder::status(int& count, int& unseen)
{
(*it)->m_messageCount = count;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
diff --git a/src/messaging/pop3/POP3Store.cpp b/src/messaging/pop3/POP3Store.cpp
index f1a4d45e..1407df35 100644
--- a/src/messaging/pop3/POP3Store.cpp
+++ b/src/messaging/pop3/POP3Store.cpp
@@ -41,7 +41,7 @@ namespace messaging {
namespace pop3 {
-POP3Store::POP3Store(session* sess, authenticator* auth)
+POP3Store::POP3Store(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth), m_socket(NULL),
m_authentified(false), m_timeoutHandler(NULL)
{
@@ -63,30 +63,30 @@ const string POP3Store::getProtocolName() const
}
-folder* POP3Store::getDefaultFolder()
+ref <folder> POP3Store::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(folder::path(folder::path::component("INBOX")), this);
+ return vmime::create <POP3Folder>(folder::path(folder::path::component("INBOX")), this);
}
-folder* POP3Store::getRootFolder()
+ref <folder> POP3Store::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(folder::path(), this);
+ return vmime::create <POP3Folder>(folder::path(), this);
}
-folder* POP3Store::getFolder(const folder::path& path)
+ref <folder> POP3Store::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(path, this);
+ return vmime::create <POP3Folder>(path, this);
}
@@ -244,11 +244,8 @@ void POP3Store::internalDisconnect()
sendRequest("QUIT");
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_authentified = false;
diff --git a/src/messaging/sendmail/sendmailTransport.cpp b/src/messaging/sendmail/sendmailTransport.cpp
index 969cb7ae..e9b8256b 100644
--- a/src/messaging/sendmail/sendmailTransport.cpp
+++ b/src/messaging/sendmail/sendmailTransport.cpp
@@ -46,7 +46,7 @@ namespace messaging {
namespace sendmail {
-sendmailTransport::sendmailTransport(session* sess, authenticator* auth)
+sendmailTransport::sendmailTransport(ref <session> sess, ref <authenticator> auth)
: transport(sess, getInfosInstance(), auth), m_connected(false)
{
}
@@ -145,7 +145,7 @@ void sendmailTransport::internalSend
const utility::file::path path = vmime::platformDependant::getHandler()->
getFileSystemFactory()->stringToPath(m_sendmailPath);
- utility::auto_ptr <utility::childProcess> proc =
+ ref <utility::childProcess> proc =
vmime::platformDependant::getHandler()->
getChildProcessFactory()->create(path);
diff --git a/src/messaging/service.cpp b/src/messaging/service.cpp
index c8872758..eab4db8a 100644
--- a/src/messaging/service.cpp
+++ b/src/messaging/service.cpp
@@ -26,39 +26,41 @@ namespace vmime {
namespace messaging {
-service::service(session* sess, const serviceInfos& infos, authenticator* auth)
- : m_deleteAuth(auth == NULL), m_session(sess), m_auth(auth ? auth :
- new defaultAuthenticator(sess->getProperties(), infos.getPropertyPrefix()))
+service::service(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
+ : m_session(sess), m_auth(auth)
{
+ if (!auth)
+ {
+ m_auth = vmime::create <defaultAuthenticator>
+ (sess, infos.getPropertyPrefix());
+ }
}
service::~service()
{
- if (m_deleteAuth)
- delete (m_auth);
}
-const session* service::getSession() const
+ref <const session> service::getSession() const
{
return (m_session);
}
-session* service::getSession()
+ref <session> service::getSession()
{
return (m_session);
}
-const authenticator* service::getAuthenticator() const
+ref <const authenticator> service::getAuthenticator() const
{
return (m_auth);
}
-authenticator* service::getAuthenticator()
+ref <authenticator> service::getAuthenticator()
{
return (m_auth);
}
diff --git a/src/messaging/serviceFactory.cpp b/src/messaging/serviceFactory.cpp
index ea1752dd..a706b0ba 100644
--- a/src/messaging/serviceFactory.cpp
+++ b/src/messaging/serviceFactory.cpp
@@ -37,11 +37,6 @@ serviceFactory::serviceFactory()
serviceFactory::~serviceFactory()
{
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
- it != m_services.end() ; ++it)
- {
- delete (*it);
- }
}
@@ -52,17 +47,17 @@ serviceFactory* serviceFactory::getInstance()
}
-service* serviceFactory::create
- (session* sess, const string& protocol, authenticator* auth)
+ref <service> serviceFactory::create
+ (ref <session> sess, const string& protocol, ref <authenticator> auth)
{
return (getServiceByProtocol(protocol)->create(sess, auth));
}
-service* serviceFactory::create
- (session* sess, const utility::url& u, authenticator* auth)
+ref <service> serviceFactory::create
+ (ref <session> sess, const utility::url& u, ref <authenticator> auth)
{
- service* serv = create(sess, u.getProtocol(), auth);
+ ref <service> serv = create(sess, u.getProtocol(), auth);
sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.address"] = u.getHost();
@@ -84,11 +79,11 @@ service* serviceFactory::create
}
-const serviceFactory::registeredService* serviceFactory::getServiceByProtocol(const string& protocol) const
+ref <const serviceFactory::registeredService> serviceFactory::getServiceByProtocol(const string& protocol) const
{
const string name(utility::stringUtils::toLower(protocol));
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
+ for (std::vector <ref <registeredService> >::const_iterator it = m_services.begin() ;
it != m_services.end() ; ++it)
{
if ((*it)->getName() == name)
@@ -105,17 +100,17 @@ const int serviceFactory::getServiceCount() const
}
-const serviceFactory::registeredService* serviceFactory::getServiceAt(const int pos) const
+ref <const serviceFactory::registeredService> serviceFactory::getServiceAt(const int pos) const
{
return (m_services[pos]);
}
-const std::vector <const serviceFactory::registeredService*> serviceFactory::getServiceList() const
+const std::vector <ref <const serviceFactory::registeredService> > serviceFactory::getServiceList() const
{
- std::vector <const registeredService*> res;
+ std::vector <ref <const registeredService> > res;
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
+ for (std::vector <ref <registeredService> >::const_iterator it = m_services.begin() ;
it != m_services.end() ; ++it)
{
res.push_back(*it);
diff --git a/src/messaging/serviceInfos.cpp b/src/messaging/serviceInfos.cpp
index 685ccf3e..a8359fd0 100644
--- a/src/messaging/serviceInfos.cpp
+++ b/src/messaging/serviceInfos.cpp
@@ -71,7 +71,7 @@ serviceInfos::~serviceInfos()
}
-const bool serviceInfos::hasProperty(session* s, const property& p) const
+const bool serviceInfos::hasProperty(ref <session> s, const property& p) const
{
return s->getProperties().hasProperty(getPropertyPrefix() + p.getName());
}
diff --git a/src/messaging/session.cpp b/src/messaging/session.cpp
index 35c188a2..12aca36d 100644
--- a/src/messaging/session.cpp
+++ b/src/messaging/session.cpp
@@ -33,6 +33,12 @@ session::session()
}
+session::session(const session& sess)
+ : object(), m_props(sess.m_props)
+{
+}
+
+
session::session(const propertySet& props)
: m_props(props)
{
@@ -44,71 +50,63 @@ session::~session()
}
-transport* session::getTransport(authenticator* auth)
+ref <transport> session::getTransport(ref <authenticator> auth)
{
return (getTransport(m_props["transport.protocol"], auth));
}
-transport* session::getTransport(const string& protocol, authenticator* auth)
+ref <transport> session::getTransport(const string& protocol, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, protocol, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, protocol, auth);
if (sv->getType() != service::TYPE_TRANSPORT)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<transport*>(sv);
+ return sv.staticCast <transport>();
}
-transport* session::getTransport(const utility::url& url, authenticator* auth)
+ref <transport> session::getTransport(const utility::url& url, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, url, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, url, auth);
if (sv->getType() != service::TYPE_TRANSPORT)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<transport*>(sv);
+ return sv.staticCast <transport>();
}
-store* session::getStore(authenticator* auth)
+ref <store> session::getStore(ref <authenticator> auth)
{
return (getStore(m_props["store.protocol"], auth));
}
-store* session::getStore(const string& protocol, authenticator* auth)
+ref <store> session::getStore(const string& protocol, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, protocol, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, protocol, auth);
if (sv->getType() != service::TYPE_STORE)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<store*>(sv);
+ return sv.staticCast <store>();
}
-store* session::getStore(const utility::url& url, authenticator* auth)
+ref <store> session::getStore(const utility::url& url, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, url, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, url, auth);
if (sv->getType() != service::TYPE_STORE)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<store*>(sv);
+ return sv.staticCast <store>();
}
diff --git a/src/messaging/smtp/SMTPTransport.cpp b/src/messaging/smtp/SMTPTransport.cpp
index a32b0c95..5613a47d 100644
--- a/src/messaging/smtp/SMTPTransport.cpp
+++ b/src/messaging/smtp/SMTPTransport.cpp
@@ -41,7 +41,7 @@ namespace messaging {
namespace smtp {
-SMTPTransport::SMTPTransport(session* sess, authenticator* auth)
+SMTPTransport::SMTPTransport(ref <session> sess, ref <authenticator> auth)
: transport(sess, getInfosInstance(), auth), m_socket(NULL),
m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL)
{
@@ -239,11 +239,8 @@ void SMTPTransport::internalDisconnect()
sendRequest("QUIT");
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_authentified = false;
diff --git a/src/messaging/transport.cpp b/src/messaging/transport.cpp
index 0b52aa39..59a2871c 100644
--- a/src/messaging/transport.cpp
+++ b/src/messaging/transport.cpp
@@ -28,7 +28,7 @@ namespace vmime {
namespace messaging {
-transport::transport(session* sess, const serviceInfos& infos, authenticator* auth)
+transport::transport(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
: service(sess, infos, auth)
{
}
@@ -39,7 +39,7 @@ static void extractMailboxes
{
for (int i = 0 ; i < list.getAddressCount() ; ++i)
{
- mailbox* mbox = dynamic_cast <mailbox*>(list.getAddressAt(i)->clone());
+ ref <mailbox> mbox = list.getAddressAt(i)->clone().dynamicCast <mailbox>();
if (mbox != NULL)
recipients.appendMailbox(mbox);
@@ -47,7 +47,7 @@ static void extractMailboxes
}
-void transport::send(vmime::message* msg, utility::progressionListener* progress)
+void transport::send(ref <vmime::message> msg, utility::progressionListener* progress)
{
// Extract expeditor
mailbox expeditor;
diff --git a/src/misc/importanceHelper.cpp b/src/misc/importanceHelper.cpp
index ac36538d..0fc9e16a 100644
--- a/src/misc/importanceHelper.cpp
+++ b/src/misc/importanceHelper.cpp
@@ -25,13 +25,13 @@ namespace vmime {
namespace misc {
-void importanceHelper::resetImportance(message* msg)
+void importanceHelper::resetImportance(ref <message> msg)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
try
{
- headerField* fld = hdr->findField("X-Priority");
+ ref <headerField> fld = hdr->findField("X-Priority");
hdr->removeField(fld);
}
catch (exceptions::no_such_field)
@@ -41,7 +41,7 @@ void importanceHelper::resetImportance(message* msg)
try
{
- headerField* fld = hdr->findField("Importance");
+ ref <headerField> fld = hdr->findField("Importance");
hdr->removeField(fld);
}
catch (exceptions::no_such_field)
@@ -51,13 +51,13 @@ void importanceHelper::resetImportance(message* msg)
}
-const importanceHelper::Importance importanceHelper::getImportance(const message* msg)
+const importanceHelper::Importance importanceHelper::getImportance(const ref <const message> msg)
{
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
try
{
- const defaultField* fld = dynamic_cast <const defaultField*>(hdr->findField("X-Priority"));
+ const ref <const defaultField> fld = hdr->findField("X-Priority").dynamicCast <const defaultField>();
const string value = fld->getValue();
int n = IMPORTANCE_NORMAL;
@@ -80,7 +80,7 @@ const importanceHelper::Importance importanceHelper::getImportance(const message
}
catch (exceptions::no_such_field)
{
- const defaultField* fld = dynamic_cast <const defaultField*>(hdr->findField("Importance"));
+ const ref <const defaultField> fld = hdr->findField("Importance").dynamicCast <const defaultField>();
const string value = utility::stringUtils::toLower(utility::stringUtils::trim(fld->getValue()));
if (value == "low")
@@ -96,12 +96,12 @@ const importanceHelper::Importance importanceHelper::getImportance(const message
}
-void importanceHelper::setImportance(message* msg, const Importance i)
+void importanceHelper::setImportance(ref <message> msg, const Importance i)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
// "X-Priority:" Field
- defaultField* fld = dynamic_cast <defaultField*>(hdr->getField("X-Priority"));
+ ref <defaultField> fld = hdr->getField("X-Priority").dynamicCast <defaultField>();
switch (i)
{
@@ -114,7 +114,7 @@ void importanceHelper::setImportance(message* msg, const Importance i)
}
// "Importance:" Field
- fld = dynamic_cast <defaultField*>(hdr->getField("Importance"));
+ fld = hdr->getField("Importance").dynamicCast <defaultField>();
switch (i)
{
diff --git a/src/object.cpp b/src/object.cpp
new file mode 100644
index 00000000..481a3564
--- /dev/null
+++ b/src/object.cpp
@@ -0,0 +1,130 @@
+//
+// 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/types.hpp"
+#include "vmime/object.hpp"
+
+#include <algorithm> // std::find
+#include <sstream> // std::ostringstream
+#include <stdexcept> // std::runtime_error
+
+
+namespace vmime
+{
+
+
+object::object()
+ : m_strongCount(0)
+{
+}
+
+
+object::object(const object&)
+ : m_strongCount(0)
+{
+ // Not used
+}
+
+
+object::~object()
+{
+ for (std::vector <utility::weak_ref_base*>::iterator
+ it = m_weakRefs.begin() ; it != m_weakRefs.end() ; ++it)
+ {
+ (*it)->notifyObjectDestroyed();
+ }
+
+#if VMIME_DEBUG
+ if (m_strongCount != 0)
+ {
+ std::ostringstream oss;
+ oss << "ERROR: Deleting object and strong count != 0."
+ << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
+
+ throw std::runtime_error(oss.str());
+ }
+#endif // VMIME_DEBUG
+}
+
+
+void object::addStrong() const
+{
+ ++m_strongCount;
+}
+
+
+void object::addWeak(utility::weak_ref_base* w) const
+{
+ m_weakRefs.push_back(w);
+}
+
+
+void object::releaseStrong() const
+{
+ if (--m_strongCount == 0)
+ delete this;
+}
+
+
+void object::releaseWeak(utility::weak_ref_base* w) const
+{
+ std::vector <utility::weak_ref_base*>::iterator
+ it = std::find(m_weakRefs.begin(), m_weakRefs.end(), w);
+
+ if (it != m_weakRefs.end())
+ m_weakRefs.erase(it);
+#if VMIME_DEBUG
+ else
+ {
+ std::ostringstream oss;
+ oss << "ERROR: weak ref does not exist anymore!"
+ << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
+
+ throw std::runtime_error(oss.str());
+ }
+#endif // VMIME_DEBUG
+}
+
+
+ref <object> object::thisRef()
+{
+ return ref <object>::fromPtr(this);
+}
+
+
+ref <const object> object::thisRef() const
+{
+ return ref <const object>::fromPtr(this);
+}
+
+
+weak_ref <object> object::thisWeakRef()
+{
+ return weak_ref <object>(thisRef());
+}
+
+
+weak_ref <const object> object::thisWeakRef() const
+{
+ return weak_ref <const object>(thisRef());
+}
+
+
+} // vmime
+
diff --git a/src/parameter.cpp b/src/parameter.cpp
index 988755be..e3c84b85 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -25,9 +25,9 @@ namespace vmime
{
-parameter* parameter::clone() const
+ref <component> parameter::clone() const
{
- parameter* p = parameterFactory::getInstance()->create(m_name);
+ ref <parameter> p = parameterFactory::getInstance()->create(m_name);
p->copyFrom(*this);
return (p);
@@ -169,11 +169,11 @@ void parameter::generateValue(utility::outputStream& os, const string::size_type
}
-const std::vector <const component*> parameter::getChildComponents() const
+const std::vector <ref <const component> > parameter::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&getValue());
+ list.push_back(getValueImp());
return (list);
}
diff --git a/src/parameterFactory.cpp b/src/parameterFactory.cpp
index a5a7a81c..35619eec 100644
--- a/src/parameterFactory.cpp
+++ b/src/parameterFactory.cpp
@@ -49,13 +49,13 @@ parameterFactory* parameterFactory::getInstance()
}
-parameter* parameterFactory::create
+ref <parameter> parameterFactory::create
(const string& name, const string& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
- parameter* param = NULL;
+ ref <parameter> param;
if (pos != m_nameMap.end())
{
@@ -73,12 +73,12 @@ parameter* parameterFactory::create
}
-parameter* parameterFactory::create(const string& name, const component& value)
+ref <parameter> parameterFactory::create(const string& name, const component& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
- parameter* param = NULL;
+ ref <parameter> param;
if (pos != m_nameMap.end())
{
diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp
index 6e5e47ad..ccc8b8e3 100644
--- a/src/parameterizedHeaderField.cpp
+++ b/src/parameterizedHeaderField.cpp
@@ -291,7 +291,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty
const paramInfo& info = (*it).second;
// Append this parameter to the list
- parameter* param = parameterFactory::getInstance()->create((*it).first);
+ ref <parameter> param = parameterFactory::getInstance()->create((*it).first);
param->parse(info.value);
param->setParsedBounds(info.start, info.end);
@@ -314,7 +314,7 @@ void parameterizedHeaderField::generate(utility::outputStream& os, const string:
headerField::generate(os, maxLineLength, pos, &pos);
// Parameters
- for (std::vector <parameter*>::const_iterator
+ for (std::vector <ref <parameter> >::const_iterator
it = m_params.begin() ; it != m_params.end() ; ++it)
{
os << "; ";
@@ -336,10 +336,10 @@ void parameterizedHeaderField::copyFrom(const component& other)
removeAllParameters();
- for (std::vector <parameter*>::const_iterator i = source.m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator i = source.m_params.begin() ;
i != source.m_params.end() ; ++i)
{
- appendParameter((*i)->clone());
+ appendParameter((*i)->clone().dynamicCast <parameter>());
}
}
@@ -355,8 +355,8 @@ const bool parameterizedHeaderField::hasParameter(const string& paramName) const
{
const string name = utility::stringUtils::toLower(paramName);
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -364,13 +364,13 @@ const bool parameterizedHeaderField::hasParameter(const string& paramName) const
}
-parameter* parameterizedHeaderField::findParameter(const string& paramName) const
+ref <parameter> parameterizedHeaderField::findParameter(const string& paramName) const
{
const string name = utility::stringUtils::toLower(paramName);
// Find the first parameter that matches the specified name
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -387,30 +387,22 @@ parameter* parameterizedHeaderField::findParameter(const string& paramName) cons
}
-parameter* parameterizedHeaderField::getParameter(const string& paramName)
+ref <parameter> parameterizedHeaderField::getParameter(const string& paramName)
{
const string name = utility::stringUtils::toLower(paramName);
// Find the first parameter that matches the specified name
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
// If no parameter with this name can be found, create a new one
if (pos == end)
{
- parameter* param = parameterFactory::getInstance()->create(paramName);
+ ref <parameter> param = parameterFactory::getInstance()->create(paramName);
- try
- {
- appendParameter(param);
- }
- catch (std::exception&)
- {
- delete (param);
- throw;
- }
+ appendParameter(param);
// Return a reference to the new parameter
return (param);
@@ -423,15 +415,15 @@ parameter* parameterizedHeaderField::getParameter(const string& paramName)
}
-void parameterizedHeaderField::appendParameter(parameter* param)
+void parameterizedHeaderField::appendParameter(ref <parameter> param)
{
m_params.push_back(param);
}
-void parameterizedHeaderField::insertParameterBefore(parameter* beforeParam, parameter* param)
+void parameterizedHeaderField::insertParameterBefore(ref <parameter> beforeParam, ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), beforeParam);
if (it == m_params.end())
@@ -441,15 +433,15 @@ void parameterizedHeaderField::insertParameterBefore(parameter* beforeParam, par
}
-void parameterizedHeaderField::insertParameterBefore(const int pos, parameter* param)
+void parameterizedHeaderField::insertParameterBefore(const int pos, ref <parameter> param)
{
m_params.insert(m_params.begin() + pos, param);
}
-void parameterizedHeaderField::insertParameterAfter(parameter* afterParam, parameter* param)
+void parameterizedHeaderField::insertParameterAfter(ref <parameter> afterParam, ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), afterParam);
if (it == m_params.end())
@@ -459,15 +451,15 @@ void parameterizedHeaderField::insertParameterAfter(parameter* afterParam, param
}
-void parameterizedHeaderField::insertParameterAfter(const int pos, parameter* param)
+void parameterizedHeaderField::insertParameterAfter(const int pos, ref <parameter> param)
{
m_params.insert(m_params.begin() + pos + 1, param);
}
-void parameterizedHeaderField::removeParameter(parameter* param)
+void parameterizedHeaderField::removeParameter(ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), param);
if (it == m_params.end())
@@ -479,9 +471,7 @@ void parameterizedHeaderField::removeParameter(parameter* param)
void parameterizedHeaderField::removeParameter(const int pos)
{
- const std::vector <parameter*>::iterator it = m_params.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <parameter> >::iterator it = m_params.begin() + pos;
m_params.erase(it);
}
@@ -489,7 +479,7 @@ void parameterizedHeaderField::removeParameter(const int pos)
void parameterizedHeaderField::removeAllParameters()
{
- free_container(m_params);
+ m_params.clear();
}
@@ -505,25 +495,25 @@ const bool parameterizedHeaderField::isEmpty() const
}
-parameter* parameterizedHeaderField::getParameterAt(const int pos)
+const ref <parameter> parameterizedHeaderField::getParameterAt(const int pos)
{
return (m_params[pos]);
}
-const parameter* parameterizedHeaderField::getParameterAt(const int pos) const
+const ref <parameter> parameterizedHeaderField::getParameterAt(const int pos) const
{
return (m_params[pos]);
}
-const std::vector <const parameter*> parameterizedHeaderField::getParameterList() const
+const std::vector <ref <const parameter> > parameterizedHeaderField::getParameterList() const
{
- std::vector <const parameter*> list;
+ std::vector <ref <const parameter> > list;
list.reserve(m_params.size());
- for (std::vector <parameter*>::const_iterator it = m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator it = m_params.begin() ;
it != m_params.end() ; ++it)
{
list.push_back(*it);
@@ -533,17 +523,17 @@ const std::vector <const parameter*> parameterizedHeaderField::getParameterList(
}
-const std::vector <parameter*> parameterizedHeaderField::getParameterList()
+const std::vector <ref <parameter> > parameterizedHeaderField::getParameterList()
{
return (m_params);
}
-const std::vector <const component*> parameterizedHeaderField::getChildComponents() const
+const std::vector <ref <const component> > parameterizedHeaderField::getChildComponents() const
{
- std::vector <const component*> list = headerField::getChildComponents();
+ std::vector <ref <const component> > list = headerField::getChildComponents();
- for (std::vector <parameter*>::const_iterator it = m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator it = m_params.begin() ;
it != m_params.end() ; ++it)
{
list.push_back(*it);
diff --git a/src/path.cpp b/src/path.cpp
index 153facd3..5cb6371c 100644
--- a/src/path.cpp
+++ b/src/path.cpp
@@ -89,9 +89,9 @@ void path::copyFrom(const component& other)
}
-path* path::clone() const
+ref <component> path::clone() const
{
- return new path(*this);
+ return vmime::create <path>(*this);
}
@@ -102,9 +102,9 @@ path& path::operator=(const path& other)
}
-const std::vector <const component*> path::getChildComponents() const
+const std::vector <ref <const component> > path::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/plainTextPart.cpp b/src/plainTextPart.cpp
index 8e065c76..86eb2f67 100644
--- a/src/plainTextPart.cpp
+++ b/src/plainTextPart.cpp
@@ -29,14 +29,13 @@ namespace vmime
plainTextPart::plainTextPart()
- : m_text(new emptyContentHandler)
+ : m_text(vmime::create <emptyContentHandler>())
{
}
plainTextPart::~plainTextPart()
{
- delete (m_text);
}
@@ -55,24 +54,23 @@ const int plainTextPart::getPartCount() const
void plainTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
{
// Create a new part
- bodyPart* part = new bodyPart();
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
// Set header fields
- part->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
- part->getHeader()->ContentType().setCharset(m_charset);
- part->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
+ part->getHeader()->ContentType()->setCharset(m_charset);
+ part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// Set contents
- part->getBody()->setContents(*m_text);
+ part->getBody()->setContents(m_text);
}
void plainTextPart::parse(const bodyPart& /* message */,
const bodyPart& /* parent */, const bodyPart& textPart)
{
- delete (m_text);
- m_text = textPart.getBody()->getContents().clone();
+ m_text = textPart.getBody()->getContents()->clone().dynamicCast <contentHandler>();
try
{
@@ -104,16 +102,15 @@ void plainTextPart::setCharset(const charset& ch)
}
-const contentHandler& plainTextPart::getText() const
+const ref <const contentHandler> plainTextPart::getText() const
{
- return (*m_text);
+ return (m_text);
}
-void plainTextPart::setText(const contentHandler& text)
+void plainTextPart::setText(ref <contentHandler> text)
{
- delete (m_text);
- m_text = text.clone();
+ m_text = text->clone().dynamicCast <contentHandler>();
}
diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp
index 54410bf6..cd3aafb3 100644
--- a/src/platforms/posix/posixChildProcess.cpp
+++ b/src/platforms/posix/posixChildProcess.cpp
@@ -39,9 +39,9 @@ namespace posix {
// posixChildProcessFactory
-utility::childProcess* posixChildProcessFactory::create(const utility::file::path& path) const
+ref <utility::childProcess> posixChildProcessFactory::create(const utility::file::path& path) const
{
- return new posixChildProcess(path);
+ return vmime::create <posixChildProcess>(path);
}
@@ -220,9 +220,6 @@ posixChildProcess::~posixChildProcess()
if (m_pipe[1] != 0)
close(m_pipe[1]);
- delete (m_stdIn);
- delete (m_stdOut);
-
delete [] (m_argArray);
}
@@ -307,7 +304,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
if (flags & FLAG_REDIRECT_STDIN)
{
- m_stdIn = new outputStreamPosixPipeAdapter(m_pipe[1]);
+ m_stdIn = vmime::create <outputStreamPosixPipeAdapter>(m_pipe[1]);
}
else
{
@@ -317,7 +314,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
if (flags & FLAG_REDIRECT_STDOUT)
{
- m_stdOut = new inputStreamPosixPipeAdapter(m_pipe[0]);
+ m_stdOut = vmime::create <inputStreamPosixPipeAdapter>(m_pipe[0]);
}
else
{
@@ -330,13 +327,13 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
}
-utility::outputStream* posixChildProcess::getStdIn()
+ref <utility::outputStream> posixChildProcess::getStdIn()
{
return (m_stdIn);
}
-utility::inputStream* posixChildProcess::getStdOut()
+ref <utility::inputStream> posixChildProcess::getStdOut()
{
return (m_stdOut);
}
diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp
index 83ea0f1b..2f2ef39f 100644
--- a/src/platforms/posix/posixFile.cpp
+++ b/src/platforms/posix/posixFile.cpp
@@ -68,9 +68,10 @@ const bool posixFileIterator::hasMoreElements() const
}
-vmime::utility::file* posixFileIterator::nextElement()
+ref <vmime::utility::file> posixFileIterator::nextElement()
{
- posixFile* file = new posixFile(m_path / vmime::utility::file::path::component(m_dirEntry->d_name));
+ ref <posixFile> file = vmime::create <posixFile>
+ (m_path / vmime::utility::file::path::component(m_dirEntry->d_name));
getNextElement();
@@ -182,14 +183,14 @@ posixFileWriter::posixFileWriter(const vmime::utility::file::path& path, const v
}
-vmime::utility::outputStream* posixFileWriter::getOutputStream()
+ref <vmime::utility::outputStream> posixFileWriter::getOutputStream()
{
int fd = 0;
if ((fd = ::open(m_nativePath.c_str(), O_WRONLY, 0660)) == -1)
posixFileSystemFactory::reportError(m_path, errno);
- return new posixFileWriterOutputStream(m_path, fd);
+ return vmime::create <posixFileWriterOutputStream>(m_path, fd);
}
@@ -204,14 +205,14 @@ posixFileReader::posixFileReader(const vmime::utility::file::path& path, const v
}
-vmime::utility::inputStream* posixFileReader::getInputStream()
+ref <vmime::utility::inputStream> posixFileReader::getInputStream()
{
int fd = 0;
if ((fd = ::open(m_nativePath.c_str(), O_RDONLY, 0640)) == -1)
posixFileSystemFactory::reportError(m_path, errno);
- return new posixFileReaderInputStream(m_path, fd);
+ return vmime::create <posixFileReaderInputStream>(m_path, fd);
}
@@ -299,12 +300,12 @@ const bool posixFile::exists() const
}
-const vmime::utility::file* posixFile::getParent() const
+ref <vmime::utility::file> posixFile::getParent() const
{
if (m_path.isEmpty())
return NULL;
else
- return new posixFile(m_path.getParent());
+ return vmime::create <posixFile>(m_path.getParent());
}
@@ -340,24 +341,24 @@ void posixFile::remove()
}
-vmime::utility::fileWriter* posixFile::getFileWriter()
+ref <vmime::utility::fileWriter> posixFile::getFileWriter()
{
- return new posixFileWriter(m_path, m_nativePath);
+ return vmime::create <posixFileWriter>(m_path, m_nativePath);
}
-vmime::utility::fileReader* posixFile::getFileReader()
+ref <vmime::utility::fileReader> posixFile::getFileReader()
{
- return new posixFileReader(m_path, m_nativePath);
+ return vmime::create <posixFileReader>(m_path, m_nativePath);
}
-vmime::utility::fileIterator* posixFile::getFiles() const
+ref <vmime::utility::fileIterator> posixFile::getFiles() const
{
if (!isDirectory())
throw vmime::exceptions::not_a_directory(m_path);
- return new posixFileIterator(m_path, m_nativePath);
+ return vmime::create <posixFileIterator>(m_path, m_nativePath);
}
@@ -383,9 +384,9 @@ void posixFile::createDirectoryImpl(const vmime::utility::file::path& fullPath,
// posixFileSystemFactory
//
-vmime::utility::file* posixFileSystemFactory::create(const vmime::utility::file::path& path) const
+ref <vmime::utility::file> posixFileSystemFactory::create(const vmime::utility::file::path& path) const
{
- return new posixFile(path);
+ return vmime::create <posixFile>(path);
}
diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp
index a958680f..be346b2a 100644
--- a/src/platforms/posix/posixSocket.cpp
+++ b/src/platforms/posix/posixSocket.cpp
@@ -172,9 +172,9 @@ void posixSocket::sendRaw(const char* buffer, const int count)
// posixSocketFactory
//
-vmime::messaging::socket* posixSocketFactory::create()
+ref <vmime::messaging::socket> posixSocketFactory::create()
{
- return new posixSocket();
+ return vmime::create <posixSocket>();
}
diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp
index 2cc7c289..4d2b708d 100644
--- a/src/platforms/windows/windowsFile.cpp
+++ b/src/platforms/windows/windowsFile.cpp
@@ -34,9 +34,9 @@ namespace platforms {
namespace windows {
-vmime::utility::file* windowsFileSystemFactory::create(const vmime::utility::file::path& path) const
+ref <vmime::utility::file> windowsFileSystemFactory::create(const vmime::utility::file::path& path) const
{
- return new windowsFile(path);
+ return vmime::create <windowsFile>(path);
}
@@ -105,7 +105,7 @@ const bool windowsFileSystemFactory::isValidPathComponent(
if (firstComponent && (buffer.length() == 2) && (buffer[1] == ':'))
{
char drive = tolower(buffer[0]);
- if ((drive >= 'a') && (drive <= 'z'))
+ if ((drive >= 'a') && (drive <= 'z'))
return true;
}
@@ -131,7 +131,7 @@ const bool windowsFileSystemFactory::isValidPathComponent(
}
string upperBuffer = vmime::utility::stringUtils::toUpper(buffer);
-
+
// Check for reserved names
if (upperBuffer.length() == 3)
{
@@ -300,12 +300,12 @@ const bool windowsFile::exists() const
return false;
}
-const vmime::utility::file* windowsFile::getParent() const
+ref <vmime::utility::file> windowsFile::getParent() const
{
if (m_path.isEmpty())
return NULL;
else
- return new windowsFile(m_path.getParent());
+ return vmime::create <windowsFile>(m_path.getParent());
}
void windowsFile::rename(const path& newName)
@@ -326,19 +326,19 @@ void windowsFile::remove()
windowsFileSystemFactory::reportError(m_path, GetLastError());
}
-vmime::utility::fileWriter* windowsFile::getFileWriter()
+ref <vmime::utility::fileWriter> windowsFile::getFileWriter()
{
- return new windowsFileWriter(m_path, m_nativePath);
+ return vmime::create <windowsFileWriter>(m_path, m_nativePath);
}
-vmime::utility::fileReader* windowsFile::getFileReader()
+ref <vmime::utility::fileReader> windowsFile::getFileReader()
{
- return new windowsFileReader(m_path, m_nativePath);
+ return vmime::create <windowsFileReader>(m_path, m_nativePath);
}
-vmime::utility::fileIterator* windowsFile::getFiles() const
+ref <vmime::utility::fileIterator> windowsFile::getFiles() const
{
- return new windowsFileIterator(m_path, m_nativePath);
+ return vmime::create <windowsFileIterator>(m_path, m_nativePath);
}
void windowsFile::createDirectoryImpl(const vmime::utility::file::path& fullPath, const vmime::utility::file::path& path, const bool recursive)
@@ -373,9 +373,10 @@ const bool windowsFileIterator::hasMoreElements() const
return m_moreElements;
}
-vmime::utility::file* windowsFileIterator::nextElement()
+ref <vmime::utility::file> windowsFileIterator::nextElement()
{
- vmime::utility::file* pFile = new windowsFile(m_path / vmime::utility::file::path::component(m_findData.cFileName));
+ ref <vmime::utility::file> pFile = vmime::create <windowsFile>
+ (m_path / vmime::utility::file::path::component(m_findData.cFileName));
findNext();
@@ -422,7 +423,7 @@ windowsFileReader::windowsFileReader(const vmime::utility::file::path& path, con
{
}
-vmime::utility::inputStream* windowsFileReader::getInputStream()
+ref <vmime::utility::inputStream> windowsFileReader::getInputStream()
{
HANDLE hFile = CreateFile(
m_nativePath.c_str(),
@@ -434,7 +435,7 @@ vmime::utility::inputStream* windowsFileReader::getInputStream()
NULL);
if (hFile == INVALID_HANDLE_VALUE)
windowsFileSystemFactory::reportError(m_path, GetLastError());
- return new windowsFileReaderInputStream(m_path, hFile);
+ return vmime::create <windowsFileReaderInputStream>(m_path, hFile);
}
windowsFileReaderInputStream::windowsFileReaderInputStream(const vmime::utility::file::path& path, HANDLE hFile)
@@ -479,7 +480,7 @@ windowsFileWriter::windowsFileWriter(const vmime::utility::file::path& path, con
{
}
-vmime::utility::outputStream* windowsFileWriter::getOutputStream()
+ref <vmime::utility::outputStream> windowsFileWriter::getOutputStream()
{
HANDLE hFile = CreateFile(
m_nativePath.c_str(),
@@ -491,7 +492,7 @@ vmime::utility::outputStream* windowsFileWriter::getOutputStream()
NULL);
if (hFile == INVALID_HANDLE_VALUE)
windowsFileSystemFactory::reportError(m_path, GetLastError());
- return new windowsFileWriterOutputStream(m_path, hFile);
+ return vmime::create <windowsFileWriterOutputStream>(m_path, hFile);
}
windowsFileWriterOutputStream::windowsFileWriterOutputStream(const vmime::utility::file::path& path, HANDLE hFile)
diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp
index a572a271..b325eedd 100644
--- a/src/platforms/windows/windowsSocket.cpp
+++ b/src/platforms/windows/windowsSocket.cpp
@@ -77,7 +77,7 @@ void windowsSocket::connect(const vmime::string& address, const vmime::port_t po
// Error: cannot resolve address
throw vmime::exceptions::connection_error("Cannot resolve address.");
}
-
+
memcpy(reinterpret_cast <char*>(&addr.sin_addr), hostInfo->h_addr, hostInfo->h_length);
}
@@ -167,9 +167,9 @@ void windowsSocket::sendRaw(const char* buffer, const int count)
// posixSocketFactory
//
-vmime::messaging::socket* windowsSocketFactory::create()
+ref <vmime::messaging::socket> windowsSocketFactory::create()
{
- return new windowsSocket();
+ return vmime::create <windowsSocket>();
}
diff --git a/src/propertySet.cpp b/src/propertySet.cpp
index 88ee4f57..f1d7478c 100644
--- a/src/propertySet.cpp
+++ b/src/propertySet.cpp
@@ -37,9 +37,10 @@ propertySet::propertySet(const string& props)
propertySet::propertySet(const propertySet& set)
+ : object()
{
- for (std::list <property*>::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
- m_props.push_back(new property(**it));
+ for (std::list <ref <property> >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
+ m_props.push_back(vmime::create <property>(**it));
}
@@ -53,8 +54,8 @@ propertySet& propertySet::operator=(const propertySet& set)
{
removeAllProperties();
- for (std::list <property*>::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
- m_props.push_back(new property(**it));
+ for (std::list <ref <property> >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
+ m_props.push_back(vmime::create <property>(**it));
return (*this);
}
@@ -68,20 +69,17 @@ void propertySet::setFromString(const string& props)
void propertySet::removeAllProperties()
{
- free_container(m_props);
+ m_props.clear();
}
void propertySet::removeProperty(const string& name)
{
- std::list <property*>::iterator it = std::find_if
+ std::list <ref <property> >::iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
if (it != m_props.end())
- {
- delete (*it);
m_props.erase(it);
- }
}
@@ -172,24 +170,24 @@ void propertySet::parse(const string& props)
}
}
- m_props.push_back(new property(option, value));
+ m_props.push_back(vmime::create <property>(option, value));
}
}
}
-propertySet::property* propertySet::find(const string& name) const
+ref <propertySet::property> propertySet::find(const string& name) const
{
- std::list <property*>::const_iterator it = std::find_if
+ std::list <ref <property> >::const_iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
return (it != m_props.end() ? *it : NULL);
}
-propertySet::property* propertySet::findOrCreate(const string& name)
+ref <propertySet::property> propertySet::findOrCreate(const string& name)
{
- std::list <property*>::const_iterator it = std::find_if
+ std::list <ref <property> >::const_iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
if (it != m_props.end())
@@ -198,7 +196,7 @@ propertySet::property* propertySet::findOrCreate(const string& name)
}
else
{
- property* prop = new property(name, "");
+ ref <property> prop = vmime::create <property>(name, "");
m_props.push_back(prop);
return (prop);
}
@@ -223,9 +221,9 @@ const bool propertySet::hasProperty(const string& name) const
}
-const std::vector <const propertySet::property*> propertySet::getPropertyList() const
+const std::vector <ref <const propertySet::property> > propertySet::getPropertyList() const
{
- std::vector <const property*> res;
+ std::vector <ref <const property> > res;
for (list_type::const_iterator it = m_props.begin() ; it != m_props.end() ; ++it)
res.push_back(*it);
@@ -234,9 +232,9 @@ const std::vector <const propertySet::property*> propertySet::getPropertyList()
}
-const std::vector <propertySet::property*> propertySet::getPropertyList()
+const std::vector <ref <propertySet::property> > propertySet::getPropertyList()
{
- std::vector <property*> res;
+ std::vector <ref <property> > res;
for (list_type::const_iterator it = m_props.begin() ; it != m_props.end() ; ++it)
res.push_back(*it);
@@ -262,7 +260,7 @@ propertySet::property::property(const string& name)
propertySet::property::property(const property& prop)
- : m_name(prop.m_name), m_value(prop.m_value)
+ : object(), m_name(prop.m_name), m_value(prop.m_value)
{
}
diff --git a/src/relay.cpp b/src/relay.cpp
index 3724bde2..bdb14a90 100644
--- a/src/relay.cpp
+++ b/src/relay.cpp
@@ -244,9 +244,9 @@ relay& relay::operator=(const relay& other)
}
-relay* relay::clone() const
+ref <component> relay::clone() const
{
- return new relay(*this);
+ return vmime::create <relay>(*this);
}
@@ -334,10 +334,10 @@ std::vector <string>& relay::getWithList()
}
-const std::vector <const component*> relay::getChildComponents() const
+const std::vector <ref <const component> > relay::getChildComponents() const
{
// TODO: should fields inherit from 'component'? (using typeAdapter)
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp
index c5f6145c..0b9d33e3 100644
--- a/src/streamContentHandler.cpp
+++ b/src/streamContentHandler.cpp
@@ -25,15 +25,15 @@ namespace vmime
streamContentHandler::streamContentHandler()
- : m_encoding(NO_ENCODING), m_ownedStream(NULL), m_stream(NULL)
+ : m_encoding(NO_ENCODING), m_stream(null)
{
}
-streamContentHandler::streamContentHandler(utility::inputStream* is,
- const utility::stream::size_type length, const bool own, const vmime::encoding& enc)
+streamContentHandler::streamContentHandler(ref <utility::inputStream> is,
+ const utility::stream::size_type length, const vmime::encoding& enc)
{
- setData(is, length, own, enc);
+ setData(is, length, enc);
}
@@ -44,15 +44,14 @@ streamContentHandler::~streamContentHandler()
streamContentHandler::streamContentHandler(const streamContentHandler& cts)
: contentHandler(), m_encoding(cts.m_encoding),
- m_ownedStream(const_cast <utility::smart_ptr <utility::inputStream>&>(cts.m_ownedStream)),
m_stream(cts.m_stream), m_length(cts.m_length)
{
}
-contentHandler* streamContentHandler::clone() const
+ref <contentHandler> streamContentHandler::clone() const
{
- return new streamContentHandler(*this);
+ return vmime::create <streamContentHandler>(*this);
}
@@ -60,7 +59,6 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler
{
m_encoding = cts.m_encoding;
- m_ownedStream = const_cast <utility::smart_ptr <utility::inputStream>&>(cts.m_ownedStream);
m_stream = cts.m_stream;
m_length = cts.m_length;
@@ -68,29 +66,19 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler
}
-void streamContentHandler::setData(utility::inputStream* is,
- const utility::stream::size_type length, const bool own, const vmime::encoding& enc)
+void streamContentHandler::setData(ref <utility::inputStream> is,
+ const utility::stream::size_type length, const vmime::encoding& enc)
{
m_encoding = enc;
m_length = length;
-
- if (own)
- {
- m_ownedStream = is;
- m_stream = NULL;
- }
- else
- {
- m_ownedStream = NULL;
- m_stream = is;
- }
+ m_stream = is;
}
void streamContentHandler::generate(utility::outputStream& os, const vmime::encoding& enc,
const string::size_type maxLineLength) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
// Managed data is already encoded
@@ -102,20 +90,17 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
// buffer, and then re-encode to output stream...
if (m_encoding != enc)
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
std::ostringstream oss;
utility::outputStreamAdapter tempOut(oss);
- theDecoder->decode(in, tempOut);
+ theDecoder->decode(*m_stream, tempOut);
string str = oss.str();
utility::inputStreamStringAdapter tempIn(str);
@@ -125,71 +110,56 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
// No encoding to perform
else
{
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
}
// Need to encode data before
else
{
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- theEncoder->encode(in, os);
+ theEncoder->encode(*m_stream, os);
}
}
void streamContentHandler::extract(utility::outputStream& os) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
// No decoding to perform
if (!isEncoded())
{
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
+ m_stream->reset(); // may not work...
- in.reset(); // may not work...
-
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
// Need to decode data
else
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
-
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
+ ref <encoder> theDecoder = m_encoding.getEncoder();
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- theDecoder->decode(in, os);
+ theDecoder->decode(*m_stream, os);
}
}
void streamContentHandler::extractRaw(utility::outputStream& os) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
@@ -201,7 +171,7 @@ const string::size_type streamContentHandler::getLength() const
const bool streamContentHandler::isEmpty() const
{
- return (m_length == 0 || (m_stream == NULL && m_ownedStream.ptr() == NULL));
+ return (m_length == 0 || !m_stream);
}
diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp
index 1d4ccc5c..9c1553f4 100644
--- a/src/stringContentHandler.cpp
+++ b/src/stringContentHandler.cpp
@@ -54,9 +54,9 @@ stringContentHandler::~stringContentHandler()
}
-contentHandler* stringContentHandler::clone() const
+ref <contentHandler> stringContentHandler::clone() const
{
- return new stringContentHandler(*this);
+ return vmime::create <stringContentHandler>(*this);
}
@@ -110,8 +110,8 @@ void stringContentHandler::generate(utility::outputStream& os,
// buffer, and then re-encode to output stream...
if (m_encoding != enc)
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
@@ -136,7 +136,7 @@ void stringContentHandler::generate(utility::outputStream& os,
// Need to encode data before
else
{
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
utility::inputStreamStringProxyAdapter in(m_string);
@@ -156,7 +156,7 @@ void stringContentHandler::extract(utility::outputStream& os) const
// Need to decode data
else
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
utility::inputStreamStringProxyAdapter in(m_string);
diff --git a/src/text.cpp b/src/text.cpp
index a24d6668..7183e53f 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -40,19 +40,19 @@ text::text(const text& t)
text::text(const string& t, const charset& ch)
{
- text::newFromString(t, ch, this);
+ createFromString(t, ch);
}
text::text(const string& t)
{
- text::newFromString(t, charset::getLocaleCharset(), this);
+ createFromString(t, charset::getLocaleCharset());
}
text::text(const word& w)
{
- appendWord(new word(w));
+ appendWord(vmime::create <word>(w));
}
@@ -69,7 +69,7 @@ void text::parse(const string& buffer, const string::size_type position,
string::size_type newPos;
- const std::vector <word*> words = word::parseMultiple(buffer, position, end, &newPos);
+ const std::vector <ref <word> > words = word::parseMultiple(buffer, position, end, &newPos);
copy_vector(words, m_words);
@@ -93,7 +93,7 @@ const wstring text::getDecodedText() const
{
wstring out;
- for (std::vector <word*>::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
+ for (std::vector <ref <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
out += (*i)->getDecodedText();
return (out);
@@ -108,8 +108,8 @@ void text::copyFrom(const component& other)
removeAllWords();
- for (std::vector <word*>::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i)
- m_words.push_back(new word(**i));
+ for (std::vector <ref <word> >::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i)
+ m_words.push_back(vmime::create <word>(**i));
}
@@ -133,8 +133,8 @@ const bool text::operator==(const text& t) const
{
bool equal = true;
- std::vector <word*>::const_iterator i = m_words.begin();
- std::vector <word*>::const_iterator j = t.m_words.begin();
+ std::vector <ref <word> >::const_iterator i = m_words.begin();
+ std::vector <ref <word> >::const_iterator j = t.m_words.begin();
for ( ; equal && i != m_words.end() ; ++i, ++j)
equal = (**i == **j);
@@ -156,26 +156,26 @@ const string text::getConvertedText(const charset& dest) const
{
string out;
- for (std::vector <word*>::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
+ for (std::vector <ref <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
out += (*i)->getConvertedText(dest);
return (out);
}
-void text::appendWord(word* w)
+void text::appendWord(ref <word> w)
{
m_words.push_back(w);
}
-void text::insertWordBefore(const int pos, word* w)
+void text::insertWordBefore(const int pos, ref <word> w)
{
m_words.insert(m_words.begin() + pos, w);
}
-void text::insertWordAfter(const int pos, word* w)
+void text::insertWordAfter(const int pos, ref <word> w)
{
m_words.insert(m_words.begin() + pos + 1, w);
}
@@ -183,9 +183,7 @@ void text::insertWordAfter(const int pos, word* w)
void text::removeWord(const int pos)
{
- const std::vector <word*>::iterator it = m_words.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <word> >::iterator it = m_words.begin() + pos;
m_words.erase(it);
}
@@ -193,7 +191,7 @@ void text::removeWord(const int pos)
void text::removeAllWords()
{
- free_container(m_words);
+ m_words.clear();
}
@@ -209,25 +207,25 @@ const bool text::isEmpty() const
}
-word* text::getWordAt(const int pos)
+const ref <word> text::getWordAt(const int pos)
{
return (m_words[pos]);
}
-const word* text::getWordAt(const int pos) const
+const ref <const word> text::getWordAt(const int pos) const
{
return (m_words[pos]);
}
-const std::vector <const word*> text::getWordList() const
+const std::vector <ref <const word> > text::getWordList() const
{
- std::vector <const word*> list;
+ std::vector <ref <const word> > list;
list.reserve(m_words.size());
- for (std::vector <word*>::const_iterator it = m_words.begin() ;
+ for (std::vector <ref <word> >::const_iterator it = m_words.begin() ;
it != m_words.end() ; ++it)
{
list.push_back(*it);
@@ -237,19 +235,29 @@ const std::vector <const word*> text::getWordList() const
}
-const std::vector <word*> text::getWordList()
+const std::vector <ref <word> > text::getWordList()
{
return (m_words);
}
-text* text::clone() const
+ref <component> text::clone() const
+{
+ return vmime::create <text>(*this);
+}
+
+
+ref <text> text::newFromString(const string& in, const charset& ch)
{
- return new text(*this);
+ ref <text> t = vmime::create <text>();
+
+ t->createFromString(in, ch);
+
+ return t;
}
-text* text::newFromString(const string& in, const charset& ch, text* generateInExisting)
+void text::createFromString(const string& in, const charset& ch)
{
const string::const_iterator end = in.end();
string::const_iterator p = in.begin();
@@ -259,9 +267,7 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
bool prevIs8bit = false; // is previous word 8-bit?
unsigned int count = 0; // total number of words
- text* out = (generateInExisting != NULL) ? generateInExisting : new text();
-
- out->removeAllWords();
+ removeAllWords();
for ( ; ; )
{
@@ -276,12 +282,12 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
{
// No need to create a new encoded word, just append
// the current word to the previous one.
- out->getWordAt(out->getWordCount() - 1)->
- getBuffer() += string(start, p);
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += string(start, p);
}
else
{
- out->appendWord(new word(string(start, p), ch));
+ appendWord(vmime::create <word>(string(start, p), ch));
prevIs8bit = true;
++count;
@@ -291,12 +297,12 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
{
if (count && !prevIs8bit)
{
- out->getWordAt(out->getWordCount() - 1)->
- getBuffer() += string(start, p);
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += string(start, p);
}
else
{
- out->appendWord(new word
+ appendWord(vmime::create <word>
(string(start, p), charset(charsets::US_ASCII)));
prevIs8bit = false;
@@ -320,8 +326,6 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
++p;
}
}
-
- return (out);
}
@@ -341,13 +345,23 @@ void text::encodeAndFold(utility::outputStream& os, const string::size_type maxL
}
+ref <text> text::decodeAndUnfold(const string& in)
+{
+ ref <text> t = vmime::create <text>();
+
+ decodeAndUnfold(in, t.get());
+
+ return t;
+}
+
+
text* text::decodeAndUnfold(const string& in, text* generateInExisting)
{
text* out = (generateInExisting != NULL) ? generateInExisting : new text();
out->removeAllWords();
- const std::vector <word*> words = word::parseMultiple(in, 0, in.length(), NULL);
+ const std::vector <ref <word> > words = word::parseMultiple(in, 0, in.length(), NULL);
copy_vector(words, out->m_words);
@@ -355,9 +369,9 @@ text* text::decodeAndUnfold(const string& in, text* generateInExisting)
}
-const std::vector <const component*> text::getChildComponents() const
+const std::vector <ref <const component> > text::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_words, list);
diff --git a/src/textPartFactory.cpp b/src/textPartFactory.cpp
index c76697b2..2c910be0 100644
--- a/src/textPartFactory.cpp
+++ b/src/textPartFactory.cpp
@@ -49,18 +49,16 @@ textPartFactory* textPartFactory::getInstance()
}
-textPart* textPartFactory::create(const mediaType& type)
+ref <textPart> textPartFactory::create(const mediaType& type)
{
- NameMap::const_iterator pos = m_nameMap.find(type.generate());
-
- if (pos != m_nameMap.end())
- {
- return ((*pos).second)();
- }
- else
+ for (MapType::const_iterator it = m_map.begin() ;
+ it != m_map.end() ; ++it)
{
- throw exceptions::no_factory_available();
+ if ((*it).first == type)
+ return ((*it).second)();
}
+
+ throw exceptions::no_factory_available();
}
diff --git a/src/utility/path.cpp b/src/utility/path.cpp
index 5e6162ab..5dadefe1 100644
--- a/src/utility/path.cpp
+++ b/src/utility/path.cpp
@@ -38,6 +38,7 @@ path::path(const component& c)
path::path(const path& p)
+ : object()
{
m_list.resize(p.m_list.size());
std::copy(p.m_list.begin(), p.m_list.end(), m_list.begin());
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index 94be1447..799c6c32 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -284,6 +284,13 @@ inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const boo
}
+inputStreamPointerAdapter::inputStreamPointerAdapter(const inputStreamPointerAdapter&)
+ : inputStream(), m_stream(NULL), m_own(false)
+{
+ // Not copiable
+}
+
+
inputStreamPointerAdapter::~inputStreamPointerAdapter()
{
if (m_own)
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index cf991b86..a2d4e32b 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -122,7 +122,7 @@ const string url::build() const
oss << urlUtils::encode(m_path);
}
- const std::vector <const propertySet::property*> params
+ const std::vector <ref <const propertySet::property> > params
= m_params.getPropertyList();
if (!params.empty())
@@ -134,7 +134,7 @@ const string url::build() const
for (unsigned int i = 0 ; i < params.size() ; ++i)
{
- const propertySet::property* prop = params[i];
+ const ref <const propertySet::property> prop = params[i];
if (i != 0)
oss << "&";
diff --git a/src/word.cpp b/src/word.cpp
index f55a66f3..cff5afe3 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -57,7 +57,7 @@ word::word(const string& buffer, const charset& charset)
}
-word* word::parseNext(const string& buffer, const string::size_type position,
+ref <word> word::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition,
bool prevIsEncoded, bool* isEncoded, bool isFirst)
{
@@ -101,7 +101,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
if (!unencoded.empty())
{
- word* w = new word(unencoded, charset(charsets::US_ASCII));
+ ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, pos);
if (newPosition)
@@ -158,7 +158,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
pos += 2; // ?=
- word* w = new word();
+ ref <word> w = vmime::create <word>();
w->parse(buffer, wordStart, pos, NULL);
if (newPosition)
@@ -181,7 +181,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
unencoded += string(buffer.begin() + startPos, buffer.begin() + end);
- word* w = new word(unencoded, charset(charsets::US_ASCII));
+ ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, end);
if (newPosition)
@@ -193,15 +193,15 @@ word* word::parseNext(const string& buffer, const string::size_type position,
return (w);
}
- return (NULL);
+ return (null);
}
-const std::vector <word*> word::parseMultiple(const string& buffer, const string::size_type position,
+const std::vector <ref <word> > word::parseMultiple(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
- std::vector <word*> res;
- word* w = NULL;
+ std::vector <ref <word> > res;
+ ref <word> w;
string::size_type pos = position;
@@ -694,9 +694,9 @@ const string word::getConvertedText(const charset& dest) const
}
-word* word::clone() const
+ref <component> word::clone() const
{
- return new word(m_buffer, m_charset);
+ return vmime::create <word>(m_buffer, m_charset);
}
@@ -730,9 +730,9 @@ void word::setBuffer(const string& buffer)
}
-const std::vector <const component*> word::getChildComponents() const
+const std::vector <ref <const component> > word::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}