Reference counting and smart pointers.

This commit is contained in:
Vincent Richard 2005-07-12 22:28:02 +00:00
parent 53f96cdb75
commit 681297e10b
187 changed files with 3003 additions and 2153 deletions

View File

@ -2,6 +2,11 @@
VERSION 0.7.2cvs
================
2005-07-13 Vincent Richard <vincent@vincent-richard.net>
* All files: added reference counting and smart pointers to simplify the
use of VMime objects. Please see README.refcounting for more information.
2005-07-06 Vincent Richard <vincent@vincent-richard.net>
* *contentHandler.{hpp|cpp}: added extractRaw() method to allow extracting

105
README.refcounting Normal file
View File

@ -0,0 +1,105 @@
==============================================
Reference counting and smart pointers in VMime
==============================================
I. Introduction
===============
Since version 0.7.2cvs, VMime has been modified to use smart pointers and
reference counting instead of raw pointers.
This simplifies a lot using VMime objects as you don't have to worry about
freeing memory occupied by objects, or even wondering which of your program
or VMime is responsible for deleting the object.
This is also convenient when a function returns a list of objects. Before,
you wrote:
std::vector <vmime::messaging::folder*> subFolders = folder->getFolders();
...do something with result...
for (std::vector <vmime::messaging::folder*>::iterator
it = subFolders.begin() ; it != subFolders.end() ; ++it)
{
delete *it;
}
Now, you can simply write:
std::vector <vmime::messaging::folder*> subFolders = folder->getFolders();
...do something with result...
and nothing more!
Two new template classes were introduced:
- vmime::ref <> holds a strong reference to an object. When there is no
more strong reference pointing to an object, the object is deleted.
- vmime::weak_ref <> holds a weak reference to an object. A weak reference
automatically points to NULL when the last strong reference is released.
It can be used to bypass the problems with circular references: A holds
a strong reference to B, which holds a strong reference back to A.
II. Creating objects
====================
You should not use 'new' to allocate VMime objects anymore. Instead, you
should use the vmime::create() helper function:
vmime::ref <vmime::mailbox> mbox =
vmime::create <vmime::mailbox>("me@somewhere.com");
III. Casting
============
Like raw C++ pointers, you can cast VMime references. Implicit downcast is
also supported.
To do a dynamic cast, write:
vmime::ref <vmime::component> foo = ...
vmime::ref <vmime::mailbox> mbox = foo.dynamicCast <vmime::mailbox>()
then 'mbox' will be set to null ref if the dynamic cast failed (ie. if dynamic
type of 'foo' is not/is not derived from 'vmime::mailbox').
The same thing is possible with static cast:
vmime::ref <vmime::component> foo = ...
vmime::ref <vmime::mailbox> mbox = foo.staticCast <vmime::mailbox>()
Like in standard C++, if 'foo' is not really a 'vmime::mailbox', the 'mbox'
reference can point to anything (ie. "invalid"), so be careful...
Finally, const cast is also supported:
vmime::ref <const vmime::component> foo_const = ...
vmime::ref <vmime::component> foo = foo_const.constCast();
IV. Upgrading your code from version <= 0.7.1
=============================================
1. vmime::text
--------------
In v0.7.1 and below:
vmime::text t1;
vmime::newFromString("blah blah", vmime::charset(...), &t1);
vmime::text* t2 = vmime::newFromString("foo", vmime::charset(...));
In v0.7.2:
vmime::text t1;
t1.createFromString("blah blah", vmime::charset(...));
vmime::ref <vmime::text> t2 = vmime::newFromString("foo", vmime::charset(...));

View File

@ -125,6 +125,7 @@ libvmime_sources = [
'messageId.cpp', 'messageId.hpp',
'messageIdSequence.cpp', 'messageIdSequence.hpp',
'messageParser.cpp', 'messageParser.hpp',
'object.cpp', 'object.hpp',
'options.cpp', 'options.hpp',
'path.cpp', 'path.hpp',
'parameter.cpp', 'parameter.hpp',
@ -2092,3 +2093,23 @@ doxygenDocPath = '(doxygen-generated-files)'
env.DoxygenDoc(doxygenDocPath, 'vmime.doxygen')
env.Alias('doc', doxygenDocPath)
################
# Unit tests #
################
def runTests(target, source, env):
for t in libvmimetest_sources:
print ""
print t[0] + ':' # test name
os.system(t[0])
return None
runTestsBuilder = Builder(action = runTests)
env.Append(BUILDERS = { 'RunTests' : runTestsBuilder })
env.Alias('run-tests', env.RunTests('foo', 'SConstruct'))

View File

@ -48,24 +48,24 @@ int main()
mb.setExpeditor(vmime::mailbox("me@somewhere.com"));
vmime::addressList to;
to.appendAddress(new vmime::mailbox("you@elsewhere.com"));
to.appendAddress(vmime::create <vmime::mailbox>("you@elsewhere.com"));
mb.setRecipients(to);
vmime::addressList bcc;
bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com"));
bcc.appendAddress(vmime::create <vmime::mailbox>("you-bcc@nowhere.com"));
mb.setBlindCopyRecipients(bcc);
mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
mb.getTextPart()->setText(vmime::stringContentHandler(
mb.getTextPart()->setText(vmime::create <vmime::stringContentHandler>(
"I'm writing this short text to test message construction " \
"using the vmime::messageBuilder component."));
// Construction
vmime::message* msg = mb.construct();
vmime::ref <vmime::message> msg = mb.construct();
// Raw text generation
std::cout << "Generated message:" << std::endl;
@ -73,9 +73,6 @@ int main()
vmime::utility::outputStreamAdapter out(std::cout);
msg->generate(out);
// Destruction
delete (msg);
}
// VMime exception
catch (vmime::exception& e)

View File

@ -48,24 +48,24 @@ int main()
mb.setExpeditor(vmime::mailbox("me@somewhere.com"));
vmime::addressList to;
to.appendAddress(new vmime::mailbox("you@elsewhere.com"));
to.appendAddress(vmime::create <vmime::mailbox>("you@elsewhere.com"));
mb.setRecipients(to);
vmime::addressList bcc;
bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com"));
bcc.appendAddress(vmime::create <vmime::mailbox>("you-bcc@nowhere.com"));
mb.setBlindCopyRecipients(bcc);
mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder"));
// Message body
mb.getTextPart()->setText(vmime::stringContentHandler(
mb.getTextPart()->setText(vmime::create <vmime::stringContentHandler>(
"I'm writing this short text to test message construction " \
"with attachment, using the vmime::messageBuilder component."));
// Adding an attachment
vmime::fileAttachment* a = new vmime::fileAttachment
vmime::ref <vmime::fileAttachment> a = vmime::create <vmime::fileAttachment>
(
"./example2.cpp", // full path to file
vmime::mediaType("application/octet-stream"), // content type
@ -78,7 +78,7 @@ int main()
mb.attach(a);
// Construction
vmime::message* msg = mb.construct();
vmime::ref <vmime::message> msg = mb.construct();
// Raw text generation
vmime::string dataToSend = msg->generate();
@ -87,9 +87,6 @@ int main()
std::cout << "==================" << std::endl;
std::cout << std::endl;
std::cout << dataToSend << std::endl;
// Destruction
delete (msg);
}
// VMime exception
catch (vmime::exception& e)

View File

@ -48,12 +48,12 @@ int main()
mb.setExpeditor(vmime::mailbox("me@somewhere.com"));
vmime::addressList to;
to.appendAddress(new vmime::mailbox("you@elsewhere.com"));
to.appendAddress(vmime::create <vmime::mailbox>("you@elsewhere.com"));
mb.setRecipients(to);
vmime::addressList bcc;
bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com"));
bcc.appendAddress(vmime::create <vmime::mailbox>("you-bcc@nowhere.com"));
mb.setBlindCopyRecipients(bcc);
@ -65,7 +65,7 @@ int main()
// Fill in the text part: the message is available in two formats: HTML and plain text.
// HTML text part also includes an inline image (embedded into the message).
vmime::htmlTextPart& textPart = dynamic_cast<vmime::htmlTextPart&>(*mb.getTextPart());
vmime::htmlTextPart& textPart = *mb.getTextPart().dynamicCast <vmime::htmlTextPart>();
// -- embed an image (the returned "CID" (content identifier) is used to reference
// -- the image into HTML content).
@ -73,11 +73,13 @@ int main()
vmime::mediaType(vmime::mediaTypes::IMAGE, vmime::mediaTypes::IMAGE_JPEG));
// -- message text
textPart.setText(vmime::stringContentHandler(vmime::string("This is the <b>HTML text</b>.<br/><img src=\"") + cid + vmime::string("\"/>")));
textPart.setPlainText(vmime::stringContentHandler("This is the plain text (without HTML formatting)."));
textPart.setText(vmime::create <vmime::stringContentHandler>
(vmime::string("This is the <b>HTML text</b>.<br/><img src=\"") + cid + vmime::string("\"/>")));
textPart.setPlainText(vmime::create <vmime::stringContentHandler>
("This is the plain text (without HTML formatting)."));
// Construction
vmime::message* msg = mb.construct();
vmime::ref <vmime::message> msg = mb.construct();
// Raw text generation
vmime::string dataToSend = msg->generate();
@ -86,9 +88,6 @@ int main()
std::cout << "==================" << std::endl;
std::cout << std::endl;
std::cout << dataToSend << std::endl;
// Destruction
delete (msg);
}
// VMime exception
catch (vmime::exception& e)

View File

@ -26,8 +26,8 @@
// Global session object
static vmime::utility::auto_ptr <vmime::messaging::session> g_session
= new vmime::messaging::session();
static vmime::ref <vmime::messaging::session> g_session
= vmime::create <vmime::messaging::session>();
// Authentification handler
@ -127,7 +127,7 @@ static void printStructure(const vmime::messaging::structure& s, const int level
}
static const vmime::string getFolderPathString(vmime::messaging::folder* f)
static const vmime::string getFolderPathString(vmime::ref <vmime::messaging::folder> f)
{
const vmime::string n = f->getName().getBuffer();
@ -137,7 +137,7 @@ static const vmime::string getFolderPathString(vmime::messaging::folder* f)
}
else
{
vmime::utility::auto_ptr <vmime::messaging::folder> p = f->getParent();
vmime::ref <vmime::messaging::folder> p = f->getParent();
return getFolderPathString(p) + n + "/";
}
}
@ -147,20 +147,17 @@ static const vmime::string getFolderPathString(vmime::messaging::folder* f)
*
* @param folder current folder
*/
static void printFolders(vmime::messaging::folder* folder, const int level = 0)
static void printFolders(vmime::ref <vmime::messaging::folder> folder, const int level = 0)
{
for (int j = 0 ; j < level * 2 ; ++j)
std::cout << " ";
std::cout << getFolderPathString(folder) << std::endl;
std::vector <vmime::messaging::folder*> subFolders = folder->getFolders(false);
std::vector <vmime::ref <vmime::messaging::folder> > subFolders = folder->getFolders(false);
for (unsigned int i = 0 ; i < subFolders.size() ; ++i)
{
printFolders(subFolders[i], level + 1);
delete subFolders[i];
}
}
@ -213,10 +210,8 @@ static void sendMessage()
vmime::utility::url url(urlString);
interactiveAuthenticator auth;
vmime::utility::auto_ptr <vmime::messaging::transport> tr =
g_session->getTransport(url, &auth);
vmime::ref <vmime::messaging::transport> tr =
g_session->getTransport(url, vmime::create <interactiveAuthenticator>());
// You can also set some properties (see example7 to know the properties
// available for each service). For example, for SMTP:
@ -243,7 +238,7 @@ static void sendMessage()
cont = (toString.size() != 0);
if (cont)
to.appendMailbox(new vmime::mailbox(toString));
to.appendMailbox(vmime::create <vmime::mailbox>(toString));
}
std::cout << "Enter message data (end with '.' on a single line):" << std::endl;
@ -312,19 +307,19 @@ static void connectStore()
// If no authenticator is given in argument to getStore(), a default one
// is used. Its behaviour is to get the user credentials from the
// session properties "auth.username" and "auth.password".
interactiveAuthenticator auth;
vmime::ref <vmime::messaging::store> st;
vmime::utility::auto_ptr <vmime::messaging::store> st =
g_session->getStore(url,
(url.getUsername().empty() || url.getPassword().empty())
? &auth : NULL);
if (url.getUsername().empty() || url.getPassword().empty())
st = g_session->getStore(url, vmime::create <interactiveAuthenticator>());
else
st = g_session->getStore(url);
// Connect to the mail store
st->connect();
// Open the default folder in this store
vmime::utility::auto_ptr <vmime::messaging::folder> f = st->getDefaultFolder();
// vmime::utility::auto_ptr <vmime::messaging::folder> f = st->getFolder(vmime::utility::path("a"));
vmime::ref <vmime::messaging::folder> f = st->getDefaultFolder();
// vmime::ref <vmime::messaging::folder> f = st->getFolder(vmime::utility::path("a"));
f->open(vmime::messaging::folder::MODE_READ_WRITE);
@ -335,7 +330,7 @@ static void connectStore()
for (bool cont = true ; cont ; )
{
typedef std::map <int, vmime::utility::smart_ptr <vmime::messaging::message> > MessageList;
typedef std::map <int, vmime::ref <vmime::messaging::message> > MessageList;
MessageList msgList;
try
@ -353,7 +348,7 @@ static void connectStore()
const int choice = printMenu(choices);
// Request message number
vmime::utility::smart_ptr <vmime::messaging::message> msg;
vmime::ref <vmime::messaging::message> msg;
if (choice != 6 && choice != 7)
{
@ -431,7 +426,7 @@ static void connectStore()
f->fetchMessage(msg, vmime::messaging::folder::FETCH_ENVELOPE);
#define ENV_HELPER(x) \
try { std::cout << msg->getHeader().x().generate() << std::endl; } \
try { std::cout << msg->getHeader().x()->generate() << std::endl; } \
catch (vmime::exception) { /* In case the header field does not exist. */ }
ENV_HELPER(From)
@ -454,7 +449,7 @@ static void connectStore()
// List folders
case 6:
{
vmime::utility::auto_ptr <vmime::messaging::folder>
vmime::ref <vmime::messaging::folder>
root = st->getRootFolder();
printFolders(root);
@ -482,25 +477,21 @@ static void connectStore()
// Folder renaming
{
vmime::messaging::folder* f = st->getFolder(vmime::messaging::folder::path("c"));
vmime::ref <vmime::messaging::folder> f = st->getFolder(vmime::messaging::folder::path("c"));
f->rename(vmime::messaging::folder::path("c2"));
delete (f);
vmime::messaging::folder* g = st->getFolder(vmime::messaging::folder::path("c2"));
vmime::ref <vmime::messaging::folder> g = st->getFolder(vmime::messaging::folder::path("c2"));
g->rename(vmime::messaging::folder::path("c"));
delete (g);
}
// Message copy: copy all messages from 'f' to 'g'
{
vmime::messaging::folder* g = st->getFolder(vmime::messaging::folder::path("TEMP"));
vmime::ref <vmime::messaging::folder> g = st->getFolder(vmime::messaging::folder::path("TEMP"));
if (!g->exists())
g->create(vmime::messaging::folder::TYPE_CONTAINS_MESSAGES);
f->copyMessages(g->getFullPath());
delete (g);
}
*/
}

View File

@ -49,14 +49,12 @@ int main()
std::cout << " * " << enc.getName() << std::endl;
vmime::encoder* e = enc.create();
vmime::ref <vmime::encoder> e = enc.create();
std::vector <vmime::string> props = e->getAvailableProperties();
for (std::vector <vmime::string>::const_iterator it = props.begin() ; it != props.end() ; ++it)
std::cout << " - " << *it << std::endl;
delete (e);
}
std::cout << std::endl;

View File

@ -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);

View File

@ -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);

View File

@ -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
{

View File

@ -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

View File

@ -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);
}

View File

@ -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> >();
}

View File

@ -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);
}

View File

@ -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> >();
}

View File

@ -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> >();
}

View File

@ -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);
}

View File

@ -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);
}
const ref <component> defaultParameter::getValueImp()
{
return (m_value);
}
const word& defaultParameter::getValue() const
{
return (*m_value);
}
word& defaultParameter::getValue()
{
return (m_value);
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 */ '\'';
}

View File

@ -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> >();
}

View File

@ -29,9 +29,9 @@ emptyContentHandler::emptyContentHandler()
}
contentHandler* emptyContentHandler::clone() const
ref <contentHandler> emptyContentHandler::clone() const
{
return new emptyContentHandler();
return vmime::create <emptyContentHandler>();
}

View File

@ -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);

View File

@ -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> >();
}

View File

@ -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());
}

View File

@ -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());
for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
it != m_fields.end() ; ++it)
{
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&)
{
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;
std::vector <ref <headerField> > fields;
try
fields.reserve(h.m_fields.size());
for (std::vector <ref <headerField> >::const_iterator it = h.m_fields.begin() ;
it != h.m_fields.end() ; ++it)
{
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());
}
free_container(m_fields);
m_fields.resize(fields.size());
std::copy(fields.begin(), fields.end(), m_fields.begin());
}
catch (std::exception&)
{
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);

View File

@ -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);
}

View File

@ -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())
{

View File

@ -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);
}

View File

@ -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> >();
}

View File

@ -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);

View File

@ -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);

View File

@ -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());
}

View File

@ -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);
}

View File

@ -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 */ }
}
}

View File

@ -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);
}

View File

@ -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> >();
}

View File

@ -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);
}

View File

@ -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> >();
}

View File

@ -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);
}

View File

@ -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]);
}

View File

@ -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)
{
}

View File

@ -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"]));
}

View File

@ -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); }

View File

@ -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());
}

View File

@ -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");
}
const IMAPParser::mailbox_data* mailboxData =
(*it)->response_data()->mailbox_data();
if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
continue;
// Get folder path
const class IMAPParser::mailbox* mailbox =
mailboxData->mailbox_list()->mailbox();
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();
v.push_back(new IMAPFolder(path, m_store,
IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
}
throw exceptions::command_error("LIST",
m_connection->getParser()->lastLine(), "invalid response");
}
}
catch (std::exception&)
{
for (std::vector <folder*>::iterator it = v.begin() ; it != v.end() ; ++it)
delete (*it);
throw;
const IMAPParser::mailbox_data* mailboxData =
(*it)->response_data()->mailbox_data();
if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
continue;
// Get folder path
const class IMAPParser::mailbox* mailbox =
mailboxData->mailbox_list()->mailbox();
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();
v.push_back(vmime::create <IMAPFolder>(path, m_store,
IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
}
}
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);
}

View File

@ -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;
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);
public:
~IMAPpart();
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)

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);

View File

@ -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>()));
}

View File

@ -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()))

View File

@ -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());

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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());
}

View File

@ -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>();
}

View File

@ -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;

View File

@ -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;

View File

@ -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)
{

130
src/object.cpp Normal file
View File

@ -0,0 +1,130 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "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

View File

@ -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);
}

View File

@ -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())
{

View File

@ -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);

View File

@ -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> >();
}

View File

@ -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>();
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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>();
}

View File

@ -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)

View File

@ -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>();
}

View File

@ -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)
{
}

View File

@ -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> >();
}

View File

@ -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()));
m_stream->reset(); // may not work...
in.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()));
m_stream->reset(); // may not work...
in.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());
ref <encoder> theDecoder = m_encoding.getEncoder();
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...
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()));
m_stream->reset(); // may not work...
in.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);
}

View File

@ -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);

View File

@ -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 new text(*this);
return vmime::create <text>(*this);
}
text* text::newFromString(const string& in, const charset& ch, text* generateInExisting)
ref <text> text::newFromString(const string& in, const charset& ch)
{
ref <text> t = vmime::create <text>();
t->createFromString(in, ch);
return t;
}
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);

View File

@ -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());
for (MapType::const_iterator it = m_map.begin() ;
it != m_map.end() ; ++it)
{
if ((*it).first == type)
return ((*it).second)();
}
if (pos != m_nameMap.end())
{
return ((*pos).second)();
}
else
{
throw exceptions::no_factory_available();
}
throw exceptions::no_factory_available();
}

View File

@ -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());

View File

@ -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)

View File

@ -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 << "&";

View File

@ -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> >();
}

View File

@ -68,7 +68,7 @@ namespace
{
vmime::bodyPart p1;
p1.getHeader()->getField("Foo")->setValue(vmime::string("bar"));
p1.getBody()->setContents(vmime::stringContentHandler("Baz"));
p1.getBody()->setContents(vmime::create <vmime::stringContentHandler>("Baz"));
assert_eq("1", "Foo: bar\r\n\r\nBaz", p1.generate());
}

View File

@ -35,7 +35,7 @@ namespace
// Encoding helper function
static const vmime::string encode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
{
vmime::encoder* enc = vmime::encoderFactory::getInstance()->create(name);
vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
if (maxLineLength != 0)
enc->getProperties()["maxlinelength"] = maxLineLength;
@ -53,7 +53,7 @@ namespace
// Decoding helper function
static const vmime::string decode(const vmime::string& name, const vmime::string& in, int maxLineLength = 0)
{
vmime::encoder* enc = vmime::encoderFactory::getInstance()->create(name);
vmime::ref <vmime::encoder> enc = vmime::encoderFactory::getInstance()->create(name);
if (maxLineLength != 0)
enc->getProperties()["maxlinelength"] = maxLineLength;

View File

@ -68,10 +68,10 @@ namespace
vmime::header hdr;
hdr.parse("");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("A", "a");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("A", "a");
hdr.appendField(hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(1), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -82,10 +82,10 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\n");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
hdr.appendField(hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(2), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -98,10 +98,10 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nC: c\r\n");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
hdr.insertFieldBefore(hdr.getField("C"), hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(3), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -114,10 +114,10 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nC: c\r\n");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
hdr.insertFieldBefore(1, hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(3), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -131,10 +131,10 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nC: c\r\n");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
hdr.insertFieldAfter(hdr.getField("A"), hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(3), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -147,10 +147,10 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nC: c\r\n");
vmime::headerField* hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("B", "b");
hdr.insertFieldAfter(0, hf);
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(3), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -168,13 +168,13 @@ namespace
hdr1.removeField(hdr1.getField("B"));
hdr2.removeField(1);
std::vector <vmime::headerField*> res1 = hdr1.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
assert_eq("Count", static_cast <unsigned int>(2), res1.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res1[0]));
assert_eq("Second value", "C: c", headerTest::getFieldValue(*res1[1]));
std::vector <vmime::headerField*> res2 = hdr2.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
assert_eq("Count", static_cast <unsigned int>(2), res2.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res2[0]));
@ -190,10 +190,10 @@ namespace
hdr1.removeField(hdr1.getField("A"));
hdr2.removeField(0);
std::vector <vmime::headerField*> res1 = hdr1.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
assert_eq("Count", static_cast <unsigned int>(0), res1.size());
std::vector <vmime::headerField*> res2 = hdr2.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
assert_eq("Count", static_cast <unsigned int>(0), res2.size());
}
@ -207,10 +207,10 @@ namespace
hdr1.removeAllFields();
hdr2.removeAllFields();
std::vector <vmime::headerField*> res1 = hdr1.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res1 = hdr1.getFieldList();
assert_eq("Count", static_cast <unsigned int>(0), res1.size());
std::vector <vmime::headerField*> res2 = hdr2.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res2 = hdr2.getFieldList();
assert_eq("Count", static_cast <unsigned int>(0), res2.size());
}
@ -246,7 +246,7 @@ namespace
vmime::header hdr;
hdr.parse("B: b\r\nA: a\r\nC: c\r\n");
vmime::headerField* res = hdr.getFieldAt(2);
vmime::ref <vmime::headerField> res = hdr.getFieldAt(2);
assert_eq("Value", "C: c", getFieldValue(*res));
}
@ -257,7 +257,7 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nB: b1\r\nC: c\r\nB: b2\r\n");
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(4), res.size());
assert_eq("First value", "A: a", headerTest::getFieldValue(*res[0]));
@ -271,7 +271,7 @@ namespace
vmime::header hdr;
hdr.parse("\r\n");
std::vector <vmime::headerField*> res = hdr.getFieldList();
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
assert_eq("Count", static_cast <unsigned int>(0), res.size());
}
@ -282,7 +282,7 @@ namespace
vmime::header hdr;
hdr.parse("A: a\r\nB: b\r\nC: c\r\nB: d\r\n");
vmime::headerField* res = hdr.findField("B");
vmime::ref <vmime::headerField> res = hdr.findField("B");
assert_eq("Value", "B: b", getFieldValue(*res));
}
@ -293,7 +293,7 @@ namespace
vmime::header hdr;
hdr.parse("A: a1\nC: c1\n");
std::vector <vmime::headerField*> res = hdr.findAllFields("B");
std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
assert_eq("Count", static_cast <unsigned int>(0), res.size());
}
@ -303,7 +303,7 @@ namespace
vmime::header hdr;
hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\n");
std::vector <vmime::headerField*> res = hdr.findAllFields("B");
std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("B");
assert_eq("Count", static_cast <unsigned int>(2), res.size());
assert_eq("First value", "B: b1", headerTest::getFieldValue(*res[0]));
@ -315,7 +315,7 @@ namespace
vmime::header hdr;
hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\nC: c3\nC: c2\n");
std::vector <vmime::headerField*> res = hdr.findAllFields("C");
std::vector <vmime::ref <vmime::headerField> > res = hdr.findAllFields("C");
assert_eq("Count", static_cast <unsigned int>(3), res.size());
assert_eq("First value", "C: c1", headerTest::getFieldValue(*res[0]));

View File

@ -58,10 +58,10 @@ namespace
assert_eq("eq2", "sub", t1.getSubType());
assert_true("operator==", t1 == t1);
assert_true("clone", *(t1.clone()) == t1);
assert_true("clone", t1 == *vmime::clone(t1));
assert_eq("eq3", "type", t1.clone()->getType());
assert_eq("eq4", "sub", t1.clone()->getSubType());
assert_eq("eq3", "type", vmime::clone(t1)->getType());
assert_eq("eq4", "sub", vmime::clone(t1)->getSubType());
vmime::mediaType t2;
t2.copyFrom(t1);

View File

@ -66,13 +66,13 @@ namespace
void testGenerate()
{
vmime::messageIdSequence s1;
s1.appendMessageId(new vmime::messageId("a", "b"));
s1.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
assert_eq("1", "<a@b>", s1.generate());
vmime::messageIdSequence s2;
s2.appendMessageId(new vmime::messageId("a", "b"));
s2.appendMessageId(new vmime::messageId("c", "d"));
s2.appendMessageId(vmime::create <vmime::messageId>("a", "b"));
s2.appendMessageId(vmime::create <vmime::messageId>("c", "d"));
assert_eq("2", "<a@b> <c@d>", s2.generate());
}

View File

@ -37,25 +37,32 @@ namespace
{
private:
vmime::typeAdapter <vmime::string> m_value;
vmime::ref <vmime::typeAdapter <vmime::string> > m_value;
public:
parameterizedHeaderField() : headerField("F"), m_value("X") { }
parameterizedHeaderField()
: headerField("F"),
m_value(vmime::create <vmime::typeAdapter <vmime::string> >("X"))
{
}
const vmime::component& getValue() const { return m_value; }
vmime::component& getValue() { return m_value; }
const vmime::component& getValue() const { return *m_value; }
vmime::component& getValue() { return *m_value; }
void setValue(const vmime::component&) { /* Do nothing */ }
const vmime::ref <const vmime::component> getValueImp() const { return m_value; }
vmime::ref <vmime::component> getValueImp() { return m_value; }
};
#define PARAM_VALUE(p, n) (p.getParameterAt(n)->getValue().generate())
#define PARAM_NAME(p, n) (p.getParameterAt(n)->getName())
#define PARAM_CHARSET(p, n) (static_cast <vmime::defaultParameter*> \
(p.getParameterAt(n))->getValue().getCharset().generate())
#define PARAM_BUFFER(p, n) (static_cast <vmime::defaultParameter*> \
(p.getParameterAt(n))->getValue().getBuffer())
#define PARAM_CHARSET(p, n) ( \
(p.getParameterAt(n).staticCast <vmime::defaultParameter>())->getValue().getCharset().generate())
#define PARAM_BUFFER(p, n) ( \
(p.getParameterAt(n).staticCast <vmime::defaultParameter>())->getValue().getBuffer())
class parameterTest : public suite

View File

@ -61,7 +61,7 @@ namespace
assert_eq("4.3", w1.getCharset(), t4.getWordAt(0)->getCharset());
vmime::word w2("Other", vmime::charset(vmime::charsets::US_ASCII));
t4.appendWord(new vmime::word(w2));
t4.appendWord(vmime::create <vmime::word>(w2));
vmime::text t5(t4);
@ -77,7 +77,7 @@ namespace
vmime::text t1("Test: \xa9\xc3");
assert_true("operator==", t1 == t1);
assert_true("clone", *(t1.clone()) == t1);
assert_true("clone", *vmime::clone(t1) == t1);
vmime::text t2;
t2.copyFrom(t1);
@ -91,7 +91,7 @@ namespace
vmime::charset c1("test");
vmime::text t1;
vmime::text::newFromString(s1, c1, &t1);
t1.createFromString(s1, c1);
assert_eq("1.1", 1, t1.getWordCount());
assert_eq("1.2", s1, t1.getWordAt(0)->getBuffer());
@ -104,7 +104,7 @@ namespace
vmime::charset c2("test");
vmime::text t2;
vmime::text::newFromString(s2, c2, &t2);
t2.createFromString(s2, c2);
assert_eq("2.1", 3, t2.getWordCount());
assert_eq("2.2", s2_1, t2.getWordAt(0)->getBuffer());

View File

@ -59,7 +59,7 @@ public:
*/
virtual const bool isGroup() const = 0;
virtual address* clone() const = 0;
virtual ref <component> clone() const = 0;
protected:
@ -71,7 +71,7 @@ protected:
* @param newPosition will receive the new position in the input buffer
* @return a new address object, or null if no more address is available in the input buffer
*/
static address* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
static ref <address> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
};

View File

@ -47,19 +47,19 @@ public:
~addressList();
addressList* clone() const;
ref <component> clone() const;
void copyFrom(const component& other);
addressList& operator=(const addressList& other);
addressList& operator=(const mailboxList& other);
const std::vector <const component*> getChildComponents() const;
const std::vector <ref <const component> > getChildComponents() const;
/** Add a address at the end of the list.
*
* @param addr address to append
*/
void appendAddress(address* addr);
void appendAddress(ref <address> addr);
/** Insert a new address before the specified address.
*
@ -67,7 +67,7 @@ public:
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
*/
void insertAddressBefore(address* beforeAddress, address* addr);
void insertAddressBefore(ref <address> beforeAddress, ref <address> addr);
/** Insert a new address before the specified position.
*
@ -75,7 +75,7 @@ public:
* the beginning of the list)
* @param addr address to insert
*/
void insertAddressBefore(const int pos, address* addr);
void insertAddressBefore(const int pos, ref <address> addr);
/** Insert a new address after the specified address.
*
@ -83,21 +83,21 @@ public:
* @param addr address to insert
* @throw exceptions::no_such_address if the address is not in the list
*/
void insertAddressAfter(address* afterAddress, address* addr);
void insertAddressAfter(ref <address> afterAddress, ref <address> addr);
/** Insert a new address after the specified position.
*
* @param pos position of the address before the new address
* @param addr address to insert
*/
void insertAddressAfter(const int pos, address* addr);
void insertAddressAfter(const int pos, ref <address> addr);
/** Remove the specified address from the list.
*
* @param addr address to remove
* @throw exceptions::no_such_address if the address is not in the list
*/
void removeAddress(address* addr);
void removeAddress(ref <address> addr);
/** Remove the address at the specified position.
*
@ -126,30 +126,30 @@ public:
* @param pos position
* @return address at position 'pos'
*/
address* getAddressAt(const int pos);
ref <address> getAddressAt(const int pos);
/** Return the address at the specified position.
*
* @param pos position
* @return address at position 'pos'
*/
const address* getAddressAt(const int pos) const;
const ref <const address> getAddressAt(const int pos) const;
/** Return the address list.
*
* @return list of addresses
*/
const std::vector <const address*> getAddressList() const;
const std::vector <ref <const address> > getAddressList() const;
/** Return the address list.
*
* @return list of addresses
*/
const std::vector <address*> getAddressList();
const std::vector <ref <address> > getAddressList();
private:
std::vector <address*> m_list;
std::vector <ref <address> > m_list;
public:

View File

@ -37,7 +37,7 @@ namespace vmime
/** Base class for all types of attachment.
*/
class attachment
class attachment : public object
{
friend class messageBuilder;
friend class messageParser;
@ -63,7 +63,7 @@ public:
/** Return the data contained in this attachment.
* @return attachment data
*/
virtual const contentHandler& getData() const = 0;
virtual const ref <const contentHandler> getData() const = 0;
/** Return the encoding used for this attachment.
* @return attachment data encoding

View File

@ -31,6 +31,7 @@
#include "vmime/types.hpp"
#include "vmime/constants.hpp"
#include "vmime/utility/stream.hpp"
#include "vmime/utility/smartPtr.hpp"
namespace vmime
@ -80,17 +81,6 @@ namespace vmime
}
// Free the pointer elements in a STL container and empty the container
template <class CONTAINER>
void free_container(CONTAINER& c)
{
for (typename CONTAINER::iterator it = c.begin() ; it != c.end() ; ++it)
delete (*it);
c.clear();
}
// Copy one vector to another, with type conversion
template <class T1, class T2>
@ -164,6 +154,90 @@ namespace vmime
/** Utility classes. */
namespace utility { }
#ifndef VMIME_BUILDING_DOC
/** Work-around for friend template functions.
*
* Make this class a friend if you want to be able to use
* vmime::create() with private/protected constructors.
*/
struct creator
{
template <class T>
static ref <T> create() { return ref <T>::fromPtr(new T); }
template <class T, class P0>
static ref <T> create(const P0& p0) { return ref <T>::fromPtr(new T(p0)); }
template <class T, class P0, class P1>
static ref <T> create(const P0& p0, const P1& p1) { return ref <T>::fromPtr(new T(p0, p1)); }
template <class T, class P0, class P1, class P2>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2) { return ref <T>::fromPtr(new T(p0, p1, p2)); }
template <class T, class P0, class P1, class P2, class P3>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return ref <T>::fromPtr(new T(p0, p1, p2, p3)); }
template <class T, class P0, class P1, class P2, class P3, class P4>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return ref <T>::fromPtr(new T(p0, p1, p2, p3, p4)); }
};
#endif // VMIME_BUILDING_DOC
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T>
static ref <T> create() { return creator::create <T>(); }
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T, class P0>
static ref <T> create(const P0& p0) { return creator::create <T, P0>(p0); }
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T, class P0, class P1>
static ref <T> create(const P0& p0, const P1& p1) { return creator::create <T, P0, P1>(p0, p1); }
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T, class P0, class P1, class P2>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2) { return creator::create <T, P0, P1, P2>(p0, p1, p2); }
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T, class P0, class P1, class P2, class P3>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return creator::create <T, P0, P1, P2, P3>(p0, p1, p2, p3); }
/** Create a new object and return a reference to it.
* @return reference to the new object
*/
template <class T, class P0, class P1, class P2, class P3, class P4>
static ref <T> create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return creator::create <T, P0, P1, P2, P3, P4>(p0, p1, p2, p3, p4); }
/** Clone helper.
* Use "vmime::clone(obj)" instead of "obj->clone().cast <objtype>()".
*/
template <class T>
ref <T> clone(ref <T> x)
{
return x->clone().template dynamicCast <T>();
}
/** Clone helper.
* Use "vmime::clone(obj)" instead of "obj.clone().cast <objtype>()".
*/
template <class T>
ref <T> clone(T& x)
{
return x.clone().template dynamicCast <T>();
}
} // vmime

View File

@ -47,10 +47,6 @@ class body : public component
{
friend class bodyPart;
private:
body(bodyPart* parentPart);
public:
body();
@ -60,7 +56,7 @@ public:
*
* @param part part to append
*/
void appendPart(bodyPart* part);
void appendPart(ref <bodyPart> part);
/** Insert a new part before the specified part.
*
@ -68,7 +64,7 @@ public:
* @param part part to insert
* @throw exceptions::no_such_part if the part is not in the list
*/
void insertPartBefore(bodyPart* beforePart, bodyPart* part);
void insertPartBefore(ref <bodyPart> beforePart, ref <bodyPart> part);
/** Insert a new part before the specified position.
*
@ -76,7 +72,7 @@ public:
* the beginning of the list)
* @param part part to insert
*/
void insertPartBefore(const int pos, bodyPart* part);
void insertPartBefore(const int pos, ref <bodyPart> part);
/** Insert a new part after the specified part.
*
@ -84,21 +80,21 @@ public:
* @param part part to insert
* @throw exceptions::no_such_part if the part is not in the list
*/
void insertPartAfter(bodyPart* afterPart, bodyPart* part);
void insertPartAfter(ref <bodyPart> afterPart, ref <bodyPart> part);
/** Insert a new part after the specified position.
*
* @param pos position of the part before the new part
* @param part part to insert
*/
void insertPartAfter(const int pos, bodyPart* part);
void insertPartAfter(const int pos, ref <bodyPart> part);
/** Remove the specified part from the list.
*
* @param part part to remove
* @throw exceptions::no_such_part if the part is not in the list
*/
void removePart(bodyPart* part);
void removePart(ref <bodyPart> part);
/** Remove the part at the specified position.
*
@ -127,26 +123,26 @@ public:
* @param pos position
* @return part at position 'pos'
*/
bodyPart* getPartAt(const int pos);
ref <bodyPart> getPartAt(const int pos);
/** Return the part at the specified position.
*
* @param pos position
* @return part at position 'pos'
*/
const bodyPart* getPartAt(const int pos) const;
const ref <const bodyPart> getPartAt(const int pos) const;
/** Return the part list.
*
* @return list of parts
*/
const std::vector <const bodyPart*> getPartList() const;
const std::vector <ref <const bodyPart> > getPartList() const;
/** Return the part list.
*
* @return list of parts
*/
const std::vector <bodyPart*> getPartList();
const std::vector <ref <bodyPart> > getPartList();
/** Return the prolog text.
*
@ -176,13 +172,13 @@ public:
*
* @return read-only body contents
*/
const contentHandler& getContents() const;
const ref <const contentHandler> getContents() const;
/** Set the body contents.
*
* @param contents new body contents
*/
void setContents(const contentHandler& contents);
void setContents(ref <contentHandler> contents);
/** Return the media type of the data contained in the body contents.
* This is a shortcut for getHeader()->ContentType()->getValue()
@ -221,29 +217,30 @@ public:
*/
static const bool isValidBoundary(const string& boundary);
body* clone() const;
ref <component> clone() const;
void copyFrom(const component& other);
body& operator=(const body& other);
const std::vector <const component*> getChildComponents() const;
const std::vector <ref <const component> > getChildComponents() const;
private:
void setParentPart(weak_ref <bodyPart> parent);
string m_prologText;
string m_epilogText;
contentHandler* m_contents;
ref <contentHandler> m_contents;
bodyPart* m_part;
header* m_header;
weak_ref <bodyPart> m_part;
weak_ref <header> m_header;
std::vector <bodyPart*> m_parts;
std::vector <ref <bodyPart> > m_parts;
const bool isRootPart() const;
void initNewPart(bodyPart* part);
void setContentsImpl(const contentHandler& cts);
void initNewPart(ref <bodyPart> part);
public:

View File

@ -47,44 +47,44 @@ public:
*
* @return header section
*/
const header* getHeader() const;
const ref <const header> getHeader() const;
/** Return the header section of this part.
*
* @return header section
*/
header* getHeader();
ref <header> getHeader();
/** Return the body section of this part.
*
* @return body section
*/
const body* getBody() const;
const ref <const body> getBody() const;
/** Return the body section of this part.
*
* @return body section
*/
body* getBody();
ref <body> getBody();
/** Return the parent part of this part.
*
* @return parent part or NULL if not known
*/
bodyPart* getParentPart() const;
weak_ref <bodyPart> getParentPart() const;
bodyPart* clone() const;
ref <component> clone() const;
void copyFrom(const component& other);
bodyPart& operator=(const bodyPart& other);
const std::vector <const component*> getChildComponents() const;
const std::vector <ref <const component> > getChildComponents() const;
private:
header m_header;
body m_body;
ref <header> m_header;
ref <body> m_body;
bodyPart* m_parent;
weak_ref <bodyPart> m_parent;
public:

View File

@ -53,7 +53,7 @@ public:
const bool operator==(const charset& value) const;
const bool operator!=(const charset& value) const;
const std::vector <const component*> getChildComponents() const;
const std::vector <ref <const component> > getChildComponents() const;
/** Returns the default charset used on the system.
*
@ -107,7 +107,7 @@ public:
*/
static void convert(utility::inputStream& in, utility::outputStream& out, const charset& source, const charset& dest);
charset* clone() const;
ref <component> clone() const;
void copyFrom(const component& other);
private:

View File

@ -32,7 +32,7 @@ namespace vmime
* It defines the methods for parsing and generating all the components.
*/
class component
class component : public object
{
public:
@ -77,7 +77,7 @@ public:
*
* @return a copy of this component
*/
virtual component* clone() const = 0;
virtual ref <component> clone() const = 0;
/** Replace data in this component by data in other component.
* Both components must be of the same type.
@ -108,13 +108,13 @@ public:
*
* @return list of child components
*/
const std::vector <component*> getChildComponents();
const std::vector <ref <component> > getChildComponents();
/** Return the list of children of this component (const version).
*
* @return list of child components
*/
virtual const std::vector <const component*> getChildComponents() const = 0;
virtual const std::vector <ref <const component> > getChildComponents() const = 0;
protected:

View File

@ -55,11 +55,11 @@ public:
*/
void setName(const string& name);
contentDisposition* clone() const;
ref <component> clone() const;
void copyFrom(const component& other);
contentDisposition& operator=(const contentDisposition& other);
const std::vector <const component*> getChildComponents() const;
const std::vector <ref <const component> > getChildComponents() const;
contentDisposition& operator=(const string& name);

View File

@ -35,7 +35,7 @@ namespace vmime
class contentDispositionField : public parameterizedHeaderField, public genericField <contentDisposition>
{
friend class headerFieldFactory::registerer <contentDispositionField>;
friend class vmime::creator; // create ref
protected:

Some files were not shown because too many files have changed in this diff Show More