aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2005-07-12 22:28:02 +0000
committerVincent Richard <[email protected]>2005-07-12 22:28:02 +0000
commit681297e10b666e13cc463f6fbb16236f36c3266c (patch)
tree5d2392e2283232ed3475cd9c69e22897b03e8a97
parentAdded contentHandler::extractRaw(). (diff)
downloadvmime-681297e10b666e13cc463f6fbb16236f36c3266c.tar.gz
vmime-681297e10b666e13cc463f6fbb16236f36c3266c.zip
Reference counting and smart pointers.
-rw-r--r--ChangeLog5
-rw-r--r--README.refcounting105
-rw-r--r--SConstruct21
-rw-r--r--examples/example1.cpp11
-rw-r--r--examples/example2.cpp13
-rw-r--r--examples/example3.cpp17
-rw-r--r--examples/example6.cpp55
-rw-r--r--examples/example7.cpp4
-rw-r--r--src/address.cpp22
-rw-r--r--src/addressList.cpp56
-rw-r--r--src/base.cpp5
-rw-r--r--src/body.cpp155
-rw-r--r--src/bodyPart.cpp53
-rw-r--r--src/charset.cpp8
-rw-r--r--src/component.cpp12
-rw-r--r--src/contentDisposition.cpp8
-rw-r--r--src/dateTime.cpp8
-rw-r--r--src/defaultAttachment.cpp32
-rw-r--r--src/defaultParameter.cpp34
-rw-r--r--src/disposition.cpp8
-rw-r--r--src/emptyContentHandler.cpp4
-rw-r--r--src/encoderFactory.cpp19
-rw-r--r--src/encoding.cpp12
-rw-r--r--src/fileAttachment.cpp18
-rw-r--r--src/header.cpp133
-rw-r--r--src/headerField.cpp14
-rw-r--r--src/headerFieldFactory.cpp4
-rw-r--r--src/htmlTextPart.cpp179
-rw-r--r--src/mailbox.cpp8
-rw-r--r--src/mailboxField.cpp8
-rw-r--r--src/mailboxGroup.cpp62
-rw-r--r--src/mailboxList.cpp46
-rw-r--r--src/mdn/MDNHelper.cpp132
-rw-r--r--src/mdn/receivedMDNInfos.cpp16
-rw-r--r--src/mdn/sendableMDNInfos.cpp4
-rw-r--r--src/mediaType.cpp8
-rw-r--r--src/messageBuilder.cpp61
-rw-r--r--src/messageId.cpp12
-rw-r--r--src/messageIdSequence.cpp52
-rw-r--r--src/messageParser.cpp69
-rw-r--r--src/messaging/authenticationInfos.cpp2
-rw-r--r--src/messaging/defaultAuthenticator.cpp8
-rw-r--r--src/messaging/events.cpp13
-rw-r--r--src/messaging/imap/IMAPConnection.cpp27
-rw-r--r--src/messaging/imap/IMAPFolder.cpp196
-rw-r--r--src/messaging/imap/IMAPMessage.cpp83
-rw-r--r--src/messaging/imap/IMAPStore.cpp35
-rw-r--r--src/messaging/imap/IMAPTag.cpp2
-rw-r--r--src/messaging/maildir/maildirFolder.cpp223
-rw-r--r--src/messaging/maildir/maildirMessage.cpp72
-rw-r--r--src/messaging/maildir/maildirStore.cpp19
-rw-r--r--src/messaging/maildir/maildirUtils.cpp2
-rw-r--r--src/messaging/pop3/POP3Folder.cpp99
-rw-r--r--src/messaging/pop3/POP3Store.cpp17
-rw-r--r--src/messaging/sendmail/sendmailTransport.cpp4
-rw-r--r--src/messaging/service.cpp20
-rw-r--r--src/messaging/serviceFactory.cpp27
-rw-r--r--src/messaging/serviceInfos.cpp2
-rw-r--r--src/messaging/session.cpp50
-rw-r--r--src/messaging/smtp/SMTPTransport.cpp5
-rw-r--r--src/messaging/transport.cpp6
-rw-r--r--src/misc/importanceHelper.cpp24
-rw-r--r--src/object.cpp130
-rw-r--r--src/parameter.cpp10
-rw-r--r--src/parameterFactory.cpp8
-rw-r--r--src/parameterizedHeaderField.cpp78
-rw-r--r--src/path.cpp8
-rw-r--r--src/plainTextPart.cpp25
-rw-r--r--src/platforms/posix/posixChildProcess.cpp15
-rw-r--r--src/platforms/posix/posixFile.cpp33
-rw-r--r--src/platforms/posix/posixSocket.cpp4
-rw-r--r--src/platforms/windows/windowsFile.cpp37
-rw-r--r--src/platforms/windows/windowsSocket.cpp6
-rw-r--r--src/propertySet.cpp38
-rw-r--r--src/relay.cpp8
-rw-r--r--src/streamContentHandler.cpp88
-rw-r--r--src/stringContentHandler.cpp12
-rw-r--r--src/text.cpp94
-rw-r--r--src/textPartFactory.cpp16
-rw-r--r--src/utility/path.cpp1
-rw-r--r--src/utility/stream.cpp7
-rw-r--r--src/utility/url.cpp4
-rw-r--r--src/word.cpp24
-rw-r--r--tests/parser/bodyPartTest.cpp2
-rw-r--r--tests/parser/encoderTest.cpp4
-rw-r--r--tests/parser/headerTest.cpp50
-rw-r--r--tests/parser/mediaTypeTest.cpp6
-rw-r--r--tests/parser/messageIdSequenceTest.cpp6
-rw-r--r--tests/parser/parameterTest.cpp23
-rw-r--r--tests/parser/textTest.cpp8
-rw-r--r--vmime/address.hpp4
-rw-r--r--vmime/addressList.hpp26
-rw-r--r--vmime/attachment.hpp4
-rw-r--r--vmime/base.hpp96
-rw-r--r--vmime/body.hpp47
-rw-r--r--vmime/bodyPart.hpp20
-rw-r--r--vmime/charset.hpp4
-rw-r--r--vmime/component.hpp8
-rw-r--r--vmime/contentDisposition.hpp4
-rw-r--r--vmime/contentDispositionField.hpp2
-rw-r--r--vmime/contentHandler.hpp4
-rw-r--r--vmime/contentTypeField.hpp2
-rw-r--r--vmime/dateTime.hpp4
-rw-r--r--vmime/defaultAttachment.hpp14
-rw-r--r--vmime/defaultParameter.hpp7
-rw-r--r--vmime/disposition.hpp4
-rw-r--r--vmime/emptyContentHandler.hpp2
-rw-r--r--vmime/encoder.hpp2
-rw-r--r--vmime/encoderFactory.hpp24
-rw-r--r--vmime/encoding.hpp8
-rw-r--r--vmime/genericField.hpp31
-rw-r--r--vmime/genericParameter.hpp25
-rw-r--r--vmime/header.hpp38
-rw-r--r--vmime/headerField.hpp13
-rw-r--r--vmime/headerFieldFactory.hpp8
-rw-r--r--vmime/htmlTextPart.hpp37
-rw-r--r--vmime/mailbox.hpp4
-rw-r--r--vmime/mailboxField.hpp2
-rw-r--r--vmime/mailboxGroup.hpp26
-rw-r--r--vmime/mailboxList.hpp24
-rw-r--r--vmime/mdn/MDNHelper.hpp40
-rw-r--r--vmime/mdn/MDNInfos.hpp5
-rw-r--r--vmime/mdn/receivedMDNInfos.hpp6
-rw-r--r--vmime/mdn/sendableMDNInfos.hpp6
-rw-r--r--vmime/mediaType.hpp4
-rw-r--r--vmime/messageBuilder.hpp22
-rw-r--r--vmime/messageId.hpp6
-rw-r--r--vmime/messageIdSequence.hpp28
-rw-r--r--vmime/messageParser.hpp16
-rw-r--r--vmime/messaging/authenticationInfos.hpp2
-rw-r--r--vmime/messaging/authenticator.hpp3
-rw-r--r--vmime/messaging/defaultAuthenticator.hpp7
-rw-r--r--vmime/messaging/events.hpp18
-rw-r--r--vmime/messaging/folder.hpp26
-rw-r--r--vmime/messaging/imap/IMAPConnection.hpp26
-rw-r--r--vmime/messaging/imap/IMAPFolder.hpp25
-rw-r--r--vmime/messaging/imap/IMAPMessage.hpp5
-rw-r--r--vmime/messaging/imap/IMAPParser.hpp12
-rw-r--r--vmime/messaging/imap/IMAPStore.hpp16
-rw-r--r--vmime/messaging/imap/IMAPTag.hpp2
-rw-r--r--vmime/messaging/maildir/maildirFolder.hpp31
-rw-r--r--vmime/messaging/maildir/maildirMessage.hpp11
-rw-r--r--vmime/messaging/maildir/maildirStore.hpp8
-rw-r--r--vmime/messaging/maildir/maildirUtils.hpp3
-rw-r--r--vmime/messaging/message.hpp12
-rw-r--r--vmime/messaging/pop3/POP3Folder.hpp23
-rw-r--r--vmime/messaging/pop3/POP3Message.hpp1
-rw-r--r--vmime/messaging/pop3/POP3Store.hpp14
-rw-r--r--vmime/messaging/sendmail/sendmailTransport.hpp2
-rw-r--r--vmime/messaging/service.hpp18
-rw-r--r--vmime/messaging/serviceFactory.hpp23
-rw-r--r--vmime/messaging/serviceInfos.hpp4
-rw-r--r--vmime/messaging/session.hpp15
-rw-r--r--vmime/messaging/smtp/SMTPTransport.hpp6
-rw-r--r--vmime/messaging/socket.hpp12
-rw-r--r--vmime/messaging/store.hpp8
-rw-r--r--vmime/messaging/timeoutHandler.hpp7
-rw-r--r--vmime/messaging/transport.hpp4
-rw-r--r--vmime/misc/importanceHelper.hpp6
-rw-r--r--vmime/object.hpp108
-rw-r--r--vmime/parameter.hpp9
-rw-r--r--vmime/parameterFactory.hpp10
-rw-r--r--vmime/parameterizedHeaderField.hpp28
-rw-r--r--vmime/path.hpp4
-rw-r--r--vmime/plainTextPart.hpp6
-rw-r--r--vmime/platforms/posix/posixChildProcess.hpp10
-rw-r--r--vmime/platforms/posix/posixFile.hpp16
-rw-r--r--vmime/platforms/posix/posixSocket.hpp2
-rw-r--r--vmime/platforms/windows/windowsFile.hpp38
-rw-r--r--vmime/platforms/windows/windowsSocket.hpp5
-rw-r--r--vmime/propertySet.hpp22
-rw-r--r--vmime/relay.hpp4
-rw-r--r--vmime/standardFields.hpp6
-rw-r--r--vmime/standardParams.hpp2
-rw-r--r--vmime/streamContentHandler.hpp9
-rw-r--r--vmime/stringContentHandler.hpp2
-rw-r--r--vmime/text.hpp61
-rw-r--r--vmime/textPart.hpp6
-rw-r--r--vmime/textPartFactory.hpp14
-rw-r--r--vmime/typeAdapter.hpp12
-rw-r--r--vmime/types.hpp14
-rw-r--r--vmime/utility/childProcess.hpp8
-rw-r--r--vmime/utility/file.hpp32
-rw-r--r--vmime/utility/path.hpp2
-rw-r--r--vmime/utility/smartPtr.hpp508
-rw-r--r--vmime/utility/stream.hpp12
-rw-r--r--vmime/word.hpp13
187 files changed, 2982 insertions, 2132 deletions
diff --git a/ChangeLog b/ChangeLog
index a0d4f8a6..f3696c06 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
VERSION 0.7.2cvs
================
+2005-07-13 Vincent Richard <[email protected]>
+
+ * 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 <[email protected]>
* *contentHandler.{hpp|cpp}: added extractRaw() method to allow extracting
diff --git a/README.refcounting b/README.refcounting
new file mode 100644
index 00000000..37501587
--- /dev/null
+++ b/README.refcounting
@@ -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>("[email protected]");
+
+
+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(...));
+
diff --git a/SConstruct b/SConstruct
index 214bee33..68aace55 100644
--- a/SConstruct
+++ b/SConstruct
@@ -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'))
+
diff --git a/examples/example1.cpp b/examples/example1.cpp
index 8cd271d3..f5c5aae3 100644
--- a/examples/example1.cpp
+++ b/examples/example1.cpp
@@ -48,24 +48,24 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(new vmime::mailbox("[email protected]"));
+ to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(new vmime::mailbox("[email protected]"));
+ bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
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)
diff --git a/examples/example2.cpp b/examples/example2.cpp
index 70389076..ef4759aa 100644
--- a/examples/example2.cpp
+++ b/examples/example2.cpp
@@ -48,24 +48,24 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(new vmime::mailbox("[email protected]"));
+ to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(new vmime::mailbox("[email protected]"));
+ bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
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)
diff --git a/examples/example3.cpp b/examples/example3.cpp
index 1bfa21c8..c3654545 100644
--- a/examples/example3.cpp
+++ b/examples/example3.cpp
@@ -48,12 +48,12 @@ int main()
mb.setExpeditor(vmime::mailbox("[email protected]"));
vmime::addressList to;
- to.appendAddress(new vmime::mailbox("[email protected]"));
+ to.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
mb.setRecipients(to);
vmime::addressList bcc;
- bcc.appendAddress(new vmime::mailbox("[email protected]"));
+ bcc.appendAddress(vmime::create <vmime::mailbox>("[email protected]"));
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)
diff --git a/examples/example6.cpp b/examples/example6.cpp
index 349238d9..3368e59c 100644
--- a/examples/example6.cpp
+++ b/examples/example6.cpp
@@ -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);
}
*/
}
diff --git a/examples/example7.cpp b/examples/example7.cpp
index 16492bb4..7161f4e6 100644
--- a/examples/example7.cpp
+++ b/examples/example7.cpp
@@ -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;
diff --git a/src/address.cpp b/src/address.cpp
index b0e11521..13a0ad59 100644
--- a/src/address.cpp
+++ b/src/address.cpp
@@ -62,7 +62,7 @@ address-list = (address *("," address)) / obs-addr-list
*/
-address* address::parseNext(const string& buffer, const string::size_type position,
+ref <address> address::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
bool escaped = false;
@@ -171,22 +171,14 @@ address* address::parseNext(const string& buffer, const string::size_type positi
// Parse extracted address (mailbox or group)
if (pos != start)
{
- address* parsedAddress = isGroup
- ? static_cast<address*>(new mailboxGroup)
- : static_cast<address*>(new mailbox);
+ ref <address> parsedAddress = isGroup
+ ? create <mailboxGroup>().dynamicCast <address>()
+ : create <mailbox>().dynamicCast <address>();
- try
- {
- parsedAddress->parse(buffer, start, pos, NULL);
- parsedAddress->setParsedBounds(start, pos);
+ parsedAddress->parse(buffer, start, pos, NULL);
+ parsedAddress->setParsedBounds(start, pos);
- return (parsedAddress);
- }
- catch (std::exception&)
- {
- delete (parsedAddress);
- throw;
- }
+ return (parsedAddress);
}
return (NULL);
diff --git a/src/addressList.cpp b/src/addressList.cpp
index 9693a663..e4f9ab04 100644
--- a/src/addressList.cpp
+++ b/src/addressList.cpp
@@ -54,7 +54,7 @@ void addressList::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- address* parsedAddress = address::parseNext(buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(buffer, pos, end, &pos);
if (parsedAddress != NULL)
m_list.push_back(parsedAddress);
@@ -74,7 +74,7 @@ void addressList::generate(utility::outputStream& os, const string::size_type ma
if (!m_list.empty())
{
- for (std::vector <address*>::const_iterator i = m_list.begin() ; ; )
+ for (std::vector <ref <address> >::const_iterator i = m_list.begin() ; ; )
{
(*i)->generate(os, maxLineLength - 2, pos, &pos);
@@ -97,10 +97,10 @@ void addressList::copyFrom(const component& other)
removeAllAddresses();
- for (std::vector <address*>::const_iterator it = addrList.m_list.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = addrList.m_list.begin() ;
it != addrList.m_list.end() ; ++it)
{
- m_list.push_back(static_cast <address*>((*it)->clone()));
+ m_list.push_back((*it)->clone().dynamicCast <address>());
}
}
@@ -117,27 +117,27 @@ addressList& addressList::operator=(const mailboxList& other)
removeAllAddresses();
for (int i = 0 ; i < other.getMailboxCount() ; ++i)
- m_list.push_back(other.getMailboxAt(i)->clone());
+ m_list.push_back(other.getMailboxAt(i)->clone().dynamicCast <address>());
return (*this);
}
-addressList* addressList::clone() const
+ref <component> addressList::clone() const
{
- return new addressList(*this);
+ return vmime::create <addressList>(*this);
}
-void addressList::appendAddress(address* addr)
+void addressList::appendAddress(ref <address> addr)
{
m_list.push_back(addr);
}
-void addressList::insertAddressBefore(address* beforeAddress, address* addr)
+void addressList::insertAddressBefore(ref <address> beforeAddress, ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeAddress);
if (it == m_list.end())
@@ -147,15 +147,15 @@ void addressList::insertAddressBefore(address* beforeAddress, address* addr)
}
-void addressList::insertAddressBefore(const int pos, address* addr)
+void addressList::insertAddressBefore(const int pos, ref <address> addr)
{
m_list.insert(m_list.begin() + pos, addr);
}
-void addressList::insertAddressAfter(address* afterAddress, address* addr)
+void addressList::insertAddressAfter(ref <address> afterAddress, ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterAddress);
if (it == m_list.end())
@@ -165,31 +165,27 @@ void addressList::insertAddressAfter(address* afterAddress, address* addr)
}
-void addressList::insertAddressAfter(const int pos, address* addr)
+void addressList::insertAddressAfter(const int pos, ref <address> addr)
{
m_list.insert(m_list.begin() + pos + 1, addr);
}
-void addressList::removeAddress(address* addr)
+void addressList::removeAddress(ref <address> addr)
{
- const std::vector <address*>::iterator it = std::find
+ const std::vector <ref <address> >::iterator it = std::find
(m_list.begin(), m_list.end(), addr);
if (it == m_list.end())
throw exceptions::no_such_address();
- delete (*it);
-
m_list.erase(it);
}
void addressList::removeAddress(const int pos)
{
- const std::vector <address*>::iterator it = m_list.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <address> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -197,7 +193,7 @@ void addressList::removeAddress(const int pos)
void addressList::removeAllAddresses()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -213,25 +209,25 @@ const bool addressList::isEmpty() const
}
-address* addressList::getAddressAt(const int pos)
+ref <address> addressList::getAddressAt(const int pos)
{
return (m_list[pos]);
}
-const address* addressList::getAddressAt(const int pos) const
+const ref <const address> addressList::getAddressAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const address*> addressList::getAddressList() const
+const std::vector <ref <const address> > addressList::getAddressList() const
{
- std::vector <const address*> list;
+ std::vector <ref <const address> > list;
list.reserve(m_list.size());
- for (std::vector <address*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -241,15 +237,15 @@ const std::vector <const address*> addressList::getAddressList() const
}
-const std::vector <address*> addressList::getAddressList()
+const std::vector <ref <address> > addressList::getAddressList()
{
return (m_list);
}
-const std::vector <const component*> addressList::getChildComponents() const
+const std::vector <ref <const component> > addressList::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_list, list);
diff --git a/src/base.cpp b/src/base.cpp
index 235bedbf..79ad0655 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -96,6 +96,11 @@ const string CRLF = "\r\n";
const string SUPPORTED_MIME_VERSION = "1.0";
+/** Null reference.
+ */
+const null_ref null = null_ref();
+
+
// Line length limits
namespace lineLengthLimits
{
diff --git a/src/body.cpp b/src/body.cpp
index 5438d2e0..135b1e14 100644
--- a/src/body.cpp
+++ b/src/body.cpp
@@ -37,23 +37,13 @@ namespace vmime
body::body()
- : m_contents(new emptyContentHandler()), m_part(NULL), m_header(NULL)
-{
-}
-
-
-body::body(bodyPart* parentPart)
- : m_contents(new emptyContentHandler()),
- m_part(parentPart), m_header(parentPart != NULL ? parentPart->getHeader() : NULL)
+ : m_contents(create <emptyContentHandler>()), m_part(NULL), m_header(NULL)
{
}
body::~body()
{
- delete (m_contents);
-
- removeAllParts();
}
@@ -68,16 +58,16 @@ void body::parse(const string& buffer, const string::size_type position,
try
{
- const contentTypeField& ctf = dynamic_cast <contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::MULTIPART)
+ if (ctf->getValue().getType() == mediaTypes::MULTIPART)
{
isMultipart = true;
try
{
- boundary = ctf.getBoundary();
+ boundary = ctf->getBoundary();
}
catch (exceptions::no_such_parameter&)
{
@@ -175,18 +165,9 @@ void body::parse(const string& buffer, const string::size_type position,
if (index > 0)
{
- bodyPart* part = new bodyPart;
-
- try
- {
- part->parse(buffer, partStart, partEnd, NULL);
- }
- catch (std::exception&)
- {
- delete (part);
- throw;
- }
+ ref <bodyPart> part = vmime::create <bodyPart>();
+ part->parse(buffer, partStart, partEnd, NULL);
part->m_parent = m_part;
m_parts.push_back(part);
@@ -196,7 +177,7 @@ void body::parse(const string& buffer, const string::size_type position,
pos = buffer.find(boundarySep, partStart);
}
- setContentsImpl(emptyContentHandler());
+ m_contents = vmime::create <emptyContentHandler>();
if (partStart < end)
m_epilogText = string(buffer.begin() + partStart, buffer.begin() + end);
@@ -205,7 +186,7 @@ void body::parse(const string& buffer, const string::size_type position,
else
{
// Extract the (encoded) contents
- setContentsImpl(stringContentHandler(buffer, position, end, getEncoding()));
+ m_contents = vmime::create <stringContentHandler>(buffer, position, end, getEncoding());
}
setParsedBounds(position, end);
@@ -231,10 +212,10 @@ void body::generate(utility::outputStream& os, const string::size_type maxLineLe
{
try
{
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();
- boundary = ctf.getBoundary();
+ boundary = ctf->getBoundary();
}
catch (exceptions::no_such_field&)
{
@@ -400,10 +381,10 @@ const mediaType body::getContentType() const
{
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();
- return (ctf.getValue());
+ return (ctf->getValue());
}
catch (exceptions::no_such_field&)
{
@@ -417,12 +398,10 @@ const charset body::getCharset() const
{
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- const class charset& cs = ctf.getCharset();
-
- return (cs);
+ return (ctf->getCharset());
}
catch (exceptions::no_such_parameter&)
{
@@ -441,10 +420,10 @@ const encoding body::getEncoding() const
{
try
{
- const contentEncodingField& cef = dynamic_cast<contentEncodingField&>
- (*m_header->findField(fields::CONTENT_TRANSFER_ENCODING));
+ const ref <const contentEncodingField> cef =
+ m_header->findField(fields::CONTENT_TRANSFER_ENCODING).dynamicCast <contentEncodingField>();
- return (cef.getValue());
+ return (cef->getValue());
}
catch (exceptions::no_such_field&)
{
@@ -454,15 +433,22 @@ const encoding body::getEncoding() const
}
+void body::setParentPart(weak_ref <bodyPart> parent)
+{
+ m_part = parent;
+ m_header = (parent != NULL ? parent->getHeader() : NULL);
+}
+
+
const bool body::isRootPart() const
{
return (m_part == NULL || m_part->getParentPart() == NULL);
}
-body* body::clone() const
+ref <component> body::clone() const
{
- body* bdy = new body(NULL);
+ ref <body> bdy = vmime::create <body>();
bdy->copyFrom(*this);
@@ -477,13 +463,13 @@ void body::copyFrom(const component& other)
m_prologText = bdy.m_prologText;
m_epilogText = bdy.m_epilogText;
- setContentsImpl(*bdy.m_contents);
+ m_contents = bdy.m_contents;
removeAllParts();
for (int p = 0 ; p < bdy.getPartCount() ; ++p)
{
- bodyPart* part = bdy.getPartAt(p)->clone();
+ ref <bodyPart> part = bdy.getPartAt(p)->clone().dynamicCast <bodyPart>();
part->m_parent = m_part;
@@ -523,19 +509,19 @@ void body::setEpilogText(const string& epilogText)
}
-const contentHandler& body::getContents() const
+const ref <const contentHandler> body::getContents() const
{
- return (*m_contents);
+ return (m_contents);
}
-void body::setContents(const contentHandler& contents)
+void body::setContents(ref <contentHandler> contents)
{
- setContentsImpl(contents);
+ m_contents = contents;
}
-void body::initNewPart(bodyPart* part)
+void body::initNewPart(ref <bodyPart> part)
{
part->m_parent = m_part;
@@ -544,23 +530,23 @@ void body::initNewPart(bodyPart* part)
// Check whether we have a boundary string
try
{
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->findField(fields::CONTENT_TYPE));
+ ref <contentTypeField> ctf =
+ m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
try
{
- const string boundary = ctf.getBoundary();
+ const string boundary = ctf->getBoundary();
if (boundary.empty() || !isValidBoundary(boundary))
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setBoundary(generateRandomBoundaryString());
}
catch (exceptions::no_such_parameter&)
{
// No "boundary" parameter: generate a random one.
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setBoundary(generateRandomBoundaryString());
}
- if (ctf.getValue().getType() != mediaTypes::MULTIPART)
+ if (ctf->getValue().getType() != mediaTypes::MULTIPART)
{
// Warning: multi-part body but the Content-Type is
// not specified as "multipart/..."
@@ -570,17 +556,17 @@ void body::initNewPart(bodyPart* part)
{
// No "Content-Type" field: create a new one and generate
// a random boundary string.
- contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*m_header->getField(fields::CONTENT_TYPE));
+ ref <contentTypeField> ctf =
+ m_header->getField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- ctf.setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
- ctf.setBoundary(generateRandomBoundaryString());
+ ctf->setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
+ ctf->setBoundary(generateRandomBoundaryString());
}
}
}
-void body::appendPart(bodyPart* part)
+void body::appendPart(ref <bodyPart> part)
{
initNewPart(part);
@@ -588,11 +574,11 @@ void body::appendPart(bodyPart* part)
}
-void body::insertPartBefore(bodyPart* beforePart, bodyPart* part)
+void body::insertPartBefore(ref <bodyPart> beforePart, ref <bodyPart> part)
{
initNewPart(part);
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), beforePart);
if (it == m_parts.end())
@@ -602,7 +588,7 @@ void body::insertPartBefore(bodyPart* beforePart, bodyPart* part)
}
-void body::insertPartBefore(const int pos, bodyPart* part)
+void body::insertPartBefore(const int pos, ref <bodyPart> part)
{
initNewPart(part);
@@ -610,11 +596,11 @@ void body::insertPartBefore(const int pos, bodyPart* part)
}
-void body::insertPartAfter(bodyPart* afterPart, bodyPart* part)
+void body::insertPartAfter(ref <bodyPart> afterPart, ref <bodyPart> part)
{
initNewPart(part);
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), afterPart);
if (it == m_parts.end())
@@ -624,7 +610,7 @@ void body::insertPartAfter(bodyPart* afterPart, bodyPart* part)
}
-void body::insertPartAfter(const int pos, bodyPart* part)
+void body::insertPartAfter(const int pos, ref <bodyPart> part)
{
initNewPart(part);
@@ -632,31 +618,27 @@ void body::insertPartAfter(const int pos, bodyPart* part)
}
-void body::removePart(bodyPart* part)
+void body::removePart(ref <bodyPart> part)
{
- const std::vector <bodyPart*>::iterator it = std::find
+ const std::vector <ref <bodyPart> >::iterator it = std::find
(m_parts.begin(), m_parts.end(), part);
if (it == m_parts.end())
throw exceptions::no_such_part();
- delete (*it);
-
m_parts.erase(it);
}
void body::removePart(const int pos)
{
- delete (m_parts[pos]);
-
m_parts.erase(m_parts.begin() + pos);
}
void body::removeAllParts()
{
- free_container(m_parts);
+ m_parts.clear();
}
@@ -672,25 +654,25 @@ const bool body::isEmpty() const
}
-bodyPart* body::getPartAt(const int pos)
+ref <bodyPart> body::getPartAt(const int pos)
{
return (m_parts[pos]);
}
-const bodyPart* body::getPartAt(const int pos) const
+const ref <const bodyPart> body::getPartAt(const int pos) const
{
return (m_parts[pos]);
}
-const std::vector <const bodyPart*> body::getPartList() const
+const std::vector <ref <const bodyPart> > body::getPartList() const
{
- std::vector <const bodyPart*> list;
+ std::vector <ref <const bodyPart> > list;
list.reserve(m_parts.size());
- for (std::vector <bodyPart*>::const_iterator it = m_parts.begin() ;
+ for (std::vector <ref <bodyPart> >::const_iterator it = m_parts.begin() ;
it != m_parts.end() ; ++it)
{
list.push_back(*it);
@@ -700,15 +682,15 @@ const std::vector <const bodyPart*> body::getPartList() const
}
-const std::vector <bodyPart*> body::getPartList()
+const std::vector <ref <bodyPart> > body::getPartList()
{
return (m_parts);
}
-const std::vector <const component*> body::getChildComponents() const
+const std::vector <ref <const component> > body::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_parts, list);
@@ -716,11 +698,4 @@ const std::vector <const component*> body::getChildComponents() const
}
-void body::setContentsImpl(const contentHandler& cts)
-{
- delete (m_contents);
- m_contents = cts.clone();
-}
-
-
} // vmime
diff --git a/src/bodyPart.cpp b/src/bodyPart.cpp
index 6995ccac..898fab23 100644
--- a/src/bodyPart.cpp
+++ b/src/bodyPart.cpp
@@ -25,8 +25,11 @@ namespace vmime
bodyPart::bodyPart()
- : m_body(this), m_parent(NULL)
+ : m_header(vmime::create <header>()),
+ m_body(vmime::create <body>()),
+ m_parent(NULL)
{
+ m_body->setParentPart(this);
}
@@ -35,10 +38,10 @@ void bodyPart::parse(const string& buffer, const string::size_type position,
{
// Parse the headers
string::size_type pos = position;
- m_header.parse(buffer, pos, end, &pos);
+ m_header->parse(buffer, pos, end, &pos);
// Parse the body contents
- m_body.parse(buffer, pos, end, NULL);
+ m_body->parse(buffer, pos, end, NULL);
setParsedBounds(position, end);
@@ -50,25 +53,25 @@ void bodyPart::parse(const string& buffer, const string::size_type position,
void bodyPart::generate(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
- m_header.generate(os, maxLineLength);
+ m_header->generate(os, maxLineLength);
os << CRLF;
- m_body.generate(os, maxLineLength);
+ m_body->generate(os, maxLineLength);
if (newLinePos)
*newLinePos = 0;
}
-bodyPart* bodyPart::clone() const
+ref <component> bodyPart::clone() const
{
- bodyPart* p = new bodyPart;
+ ref <bodyPart> p = vmime::create <bodyPart>();
- p->m_parent = NULL;
+ p->m_parent = null;
- p->m_header.copyFrom(m_header);
- p->m_body.copyFrom(m_body);
+ p->m_header->copyFrom(*m_header);
+ p->m_body->copyFrom(*m_body);
return (p);
}
@@ -78,8 +81,8 @@ void bodyPart::copyFrom(const component& other)
{
const bodyPart& bp = dynamic_cast <const bodyPart&>(other);
- m_header = bp.m_header;
- m_body = bp.m_body;
+ m_header->copyFrom(*(bp.m_header));
+ m_body->copyFrom(*(bp.m_body));
}
@@ -90,42 +93,42 @@ bodyPart& bodyPart::operator=(const bodyPart& other)
}
-const header* bodyPart::getHeader() const
+const ref <const header> bodyPart::getHeader() const
{
- return (&m_header);
+ return (m_header);
}
-header* bodyPart::getHeader()
+ref <header> bodyPart::getHeader()
{
- return (&m_header);
+ return (m_header);
}
-const body* bodyPart::getBody() const
+const ref <const body> bodyPart::getBody() const
{
- return (&m_body);
+ return (m_body);
}
-body* bodyPart::getBody()
+ref <body> bodyPart::getBody()
{
- return (&m_body);
+ return (m_body);
}
-bodyPart* bodyPart::getParentPart() const
+weak_ref <bodyPart> bodyPart::getParentPart() const
{
return (m_parent);
}
-const std::vector <const component*> bodyPart::getChildComponents() const
+const std::vector <ref <const component> > bodyPart::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&m_header);
- list.push_back(&m_body);
+ list.push_back(m_header);
+ list.push_back(m_body);
return (list);
}
diff --git a/src/charset.cpp b/src/charset.cpp
index cc2ba9ba..2a39b03f 100644
--- a/src/charset.cpp
+++ b/src/charset.cpp
@@ -280,9 +280,9 @@ const bool charset::operator!=(const charset& value) const
}
-charset* charset::clone() const
+ref <component> charset::clone() const
{
- return new charset(m_name);
+ return vmime::create <charset>(m_name);
}
@@ -298,9 +298,9 @@ void charset::copyFrom(const component& other)
}
-const std::vector <const component*> charset::getChildComponents() const
+const std::vector <ref <const component> > charset::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/component.cpp b/src/component.cpp
index c0301f7c..c237bd74 100644
--- a/src/component.cpp
+++ b/src/component.cpp
@@ -75,19 +75,19 @@ void component::setParsedBounds(const string::size_type start, const string::siz
}
-const std::vector <component*> component::getChildComponents()
+const std::vector <ref <component> > component::getChildComponents()
{
- const std::vector <const component*> constList =
+ const std::vector <ref <const component> > constList =
const_cast <const component*>(this)->getChildComponents();
- std::vector <component*> list;
+ std::vector <ref <component> > list;
- const std::vector <const component*>::size_type count = constList.size();
+ const std::vector <ref <const component> >::size_type count = constList.size();
list.resize(count);
- for (std::vector <const component*>::size_type i = 0 ; i < count ; ++i)
- list[i] = const_cast <component*>(constList[i]);
+ for (std::vector <ref <const component> >::size_type i = 0 ; i < count ; ++i)
+ list[i] = constList[i].constCast <component>();
return (list);
}
diff --git a/src/contentDisposition.cpp b/src/contentDisposition.cpp
index a2c53843..0b93cdda 100644
--- a/src/contentDisposition.cpp
+++ b/src/contentDisposition.cpp
@@ -85,9 +85,9 @@ const bool contentDisposition::operator!=(const contentDisposition& value) const
}
-contentDisposition* contentDisposition::clone() const
+ref <component> contentDisposition::clone() const
{
- return new contentDisposition(*this);
+ return vmime::create <contentDisposition>(*this);
}
@@ -118,9 +118,9 @@ void contentDisposition::setName(const string& name)
}
-const std::vector <const component*> contentDisposition::getChildComponents() const
+const std::vector <ref <const component> > contentDisposition::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index d2807a2a..a98fcc8b 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -730,15 +730,15 @@ const datetime datetime::now()
}
-datetime* datetime::clone() const
+ref <component> datetime::clone() const
{
- return new datetime(*this);
+ return vmime::create <datetime>(*this);
}
-const std::vector <const component*> datetime::getChildComponents() const
+const std::vector <ref <const component> > datetime::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/defaultAttachment.cpp b/src/defaultAttachment.cpp
index fe0e6d2f..dc8f8ccc 100644
--- a/src/defaultAttachment.cpp
+++ b/src/defaultAttachment.cpp
@@ -30,16 +30,16 @@ defaultAttachment::defaultAttachment()
}
-defaultAttachment::defaultAttachment(const contentHandler& data,
+defaultAttachment::defaultAttachment(ref <contentHandler> data,
const encoding& enc, const mediaType& type, const text& desc)
- : m_type(type), m_desc(desc), m_data(data.clone()), m_encoding(enc)
+ : m_type(type), m_desc(desc), m_data(data), m_encoding(enc)
{
}
-defaultAttachment::defaultAttachment(const contentHandler& data,
+defaultAttachment::defaultAttachment(ref <contentHandler> data,
const mediaType& type, const text& desc)
- : m_type(type), m_desc(desc), m_data(data.clone()),
+ : m_type(type), m_desc(desc), m_data(data),
m_encoding(encoding::decide(data))
{
}
@@ -47,25 +47,21 @@ defaultAttachment::defaultAttachment(const contentHandler& data,
defaultAttachment::defaultAttachment(const defaultAttachment& attach)
: attachment(), m_type(attach.m_type), m_desc(attach.m_desc),
- m_data(attach.m_data->clone()), m_encoding(attach.m_encoding)
+ m_data(attach.m_data->clone().dynamicCast <contentHandler>()), m_encoding(attach.m_encoding)
{
}
defaultAttachment::~defaultAttachment()
{
- delete (m_data);
}
defaultAttachment& defaultAttachment::operator=(const defaultAttachment& attach)
{
- if (m_data)
- delete (m_data);
-
m_type = attach.m_type;
m_desc = attach.m_desc;
- m_data = attach.m_data->clone();
+ m_data = attach.m_data->clone().dynamicCast <contentHandler>();
m_encoding = attach.m_encoding;
return (*this);
@@ -75,7 +71,7 @@ defaultAttachment& defaultAttachment::operator=(const defaultAttachment& attach)
void defaultAttachment::generateIn(bodyPart& parent) const
{
// Create and append a new part for this attachment
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
generatePart(*part);
@@ -85,13 +81,13 @@ void defaultAttachment::generateIn(bodyPart& parent) const
void defaultAttachment::generatePart(bodyPart& part) const
{
// Set header fields
- part.getHeader()->ContentType().setValue(m_type);
- if (!m_desc.isEmpty()) part.getHeader()->ContentDescription().setValue(m_desc);
- part.getHeader()->ContentTransferEncoding().setValue(m_encoding);
- part.getHeader()->ContentDisposition().setValue(contentDisposition(contentDispositionTypes::ATTACHMENT));
+ part.getHeader()->ContentType()->setValue(m_type);
+ if (!m_desc.isEmpty()) part.getHeader()->ContentDescription()->setValue(m_desc);
+ part.getHeader()->ContentTransferEncoding()->setValue(m_encoding);
+ part.getHeader()->ContentDisposition()->setValue(contentDisposition(contentDispositionTypes::ATTACHMENT));
// Set contents
- part.getBody()->setContents(*m_data);
+ part.getBody()->setContents(m_data);
}
@@ -107,9 +103,9 @@ const text& defaultAttachment::getDescription() const
}
-const contentHandler& defaultAttachment::getData() const
+const ref <const contentHandler> defaultAttachment::getData() const
{
- return (*m_data);
+ return (m_data);
}
diff --git a/src/defaultParameter.cpp b/src/defaultParameter.cpp
index 3a70eb72..5a0d2132 100644
--- a/src/defaultParameter.cpp
+++ b/src/defaultParameter.cpp
@@ -26,6 +26,7 @@ namespace vmime
defaultParameter::defaultParameter()
+ : m_value(vmime::create <word>())
{
}
@@ -37,36 +38,49 @@ defaultParameter& defaultParameter::operator=(const defaultParameter& other)
}
-const word& defaultParameter::getValue() const
+const ref <const component> defaultParameter::getValueImp() const
{
return (m_value);
}
-word& defaultParameter::getValue()
+const ref <component> defaultParameter::getValueImp()
{
return (m_value);
}
+const word& defaultParameter::getValue() const
+{
+ return (*m_value);
+}
+
+
+word& defaultParameter::getValue()
+{
+ return (*m_value);
+}
+
+
void defaultParameter::setValue(const word& value)
{
- m_value = value;
+ *m_value = value;
}
void defaultParameter::setValue(const component& value)
{
const word& v = dynamic_cast <const word&>(value);
- m_value = v;
+ *m_value = v;
}
void defaultParameter::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
- m_value = word(string(buffer.begin() + position, buffer.begin() + end),
- charset(charsets::US_ASCII));
+ m_value = vmime::create <word>
+ (string(buffer.begin() + position, buffer.begin() + end),
+ charset(charsets::US_ASCII));
if (newPosition)
*newPosition = end;
@@ -177,7 +191,7 @@ void defaultParameter::parse(const std::vector <valueChunk>& chunks)
}
}
- m_value = word(value.str(), ch);
+ m_value = vmime::create <word>(value.str(), ch);
}
@@ -185,7 +199,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
const string::size_type curLinePos, string::size_type* newLinePos) const
{
const string& name = getName();
- const string& value = m_value.getBuffer();
+ const string& value = m_value->getBuffer();
// For compatibility with implementations that do not understand RFC-2231,
// also generate a normal "7bit/us-ascii" parameter
@@ -298,7 +312,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
// + at least 5 characters for the value
const string::size_type firstSectionLength =
name.length() + 4 /* *0*= */ + 2 /* '' */
- + m_value.getCharset().getName().length();
+ + m_value->getCharset().getName().length();
if (pos + firstSectionLength + 5 >= maxLineLength)
{
@@ -395,7 +409,7 @@ void defaultParameter::generate(utility::outputStream& os, const string::size_ty
if (sectionNumber == 0)
{
- os << m_value.getCharset().getName();
+ os << m_value->getCharset().getName();
os << '\'' << /* No language */ '\'';
}
diff --git a/src/disposition.cpp b/src/disposition.cpp
index b894f85e..0ed98f9e 100644
--- a/src/disposition.cpp
+++ b/src/disposition.cpp
@@ -40,9 +40,9 @@ disposition::disposition(const string& actionMode, const string& sendingMode,
}
-disposition* disposition::clone() const
+ref <component> disposition::clone() const
{
- disposition* disp = new disposition;
+ ref <disposition> disp = vmime::create <disposition>();
disp->m_actionMode = m_actionMode;
disp->m_sendingMode = m_sendingMode;
@@ -75,9 +75,9 @@ disposition& disposition::operator=(const disposition& other)
}
-const std::vector <const component*> disposition::getChildComponents() const
+const std::vector <ref <const component> > disposition::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/emptyContentHandler.cpp b/src/emptyContentHandler.cpp
index 4dea2763..57153fa9 100644
--- a/src/emptyContentHandler.cpp
+++ b/src/emptyContentHandler.cpp
@@ -29,9 +29,9 @@ emptyContentHandler::emptyContentHandler()
}
-contentHandler* emptyContentHandler::clone() const
+ref <contentHandler> emptyContentHandler::clone() const
{
- return new emptyContentHandler();
+ return vmime::create <emptyContentHandler>();
}
diff --git a/src/encoderFactory.cpp b/src/encoderFactory.cpp
index 055dcecf..bd4227bf 100644
--- a/src/encoderFactory.cpp
+++ b/src/encoderFactory.cpp
@@ -46,11 +46,6 @@ encoderFactory::encoderFactory()
encoderFactory::~encoderFactory()
{
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
- it != m_encoders.end() ; ++it)
- {
- delete (*it);
- }
}
@@ -61,17 +56,17 @@ encoderFactory* encoderFactory::getInstance()
}
-encoder* encoderFactory::create(const string& name)
+ref <encoder> encoderFactory::create(const string& name)
{
return (getEncoderByName(name)->create());
}
-const encoderFactory::registeredEncoder* encoderFactory::getEncoderByName(const string& name) const
+const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderByName(const string& name) const
{
const string lcName(utility::stringUtils::toLower(name));
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
+ for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
if ((*it)->getName() == lcName)
@@ -88,17 +83,17 @@ const int encoderFactory::getEncoderCount() const
}
-const encoderFactory::registeredEncoder* encoderFactory::getEncoderAt(const int pos) const
+const ref <const encoderFactory::registeredEncoder> encoderFactory::getEncoderAt(const int pos) const
{
return (m_encoders[pos]);
}
-const std::vector <const encoderFactory::registeredEncoder*> encoderFactory::getEncoderList() const
+const std::vector <ref <const encoderFactory::registeredEncoder> > encoderFactory::getEncoderList() const
{
- std::vector <const registeredEncoder*> res;
+ std::vector <ref <const registeredEncoder> > res;
- for (std::vector <registeredEncoder*>::const_iterator it = m_encoders.begin() ;
+ for (std::vector <ref <registeredEncoder> >::const_iterator it = m_encoders.begin() ;
it != m_encoders.end() ; ++it)
{
res.push_back(*it);
diff --git a/src/encoding.cpp b/src/encoding.cpp
index 632333fb..94168645 100644
--- a/src/encoding.cpp
+++ b/src/encoding.cpp
@@ -69,7 +69,7 @@ void encoding::generate(utility::outputStream& os, const string::size_type /* ma
}
-encoder* encoding::getEncoder() const
+ref <encoder> encoding::getEncoder() const
{
return (encoderFactory::getInstance()->create(generate()));
}
@@ -155,16 +155,16 @@ const encoding encoding::decide
}
-const encoding encoding::decide(const contentHandler& /* data */)
+const encoding encoding::decide(ref <const contentHandler> /* data */)
{
// TODO: a better solution to do that?
return (encoding(encodingTypes::BASE64));
}
-encoding* encoding::clone() const
+ref <component> encoding::clone() const
{
- return new encoding(*this);
+ return vmime::create <encoding>(*this);
}
@@ -188,9 +188,9 @@ void encoding::setName(const string& name)
}
-const std::vector <const component*> encoding::getChildComponents() const
+const std::vector <ref <const component> > encoding::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index 423020b2..de1a3ba3 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -37,7 +37,7 @@ fileAttachment::fileAttachment(const string& filename, const mediaType& type, co
setData(filename);
- m_encoding = encoding::decide(*m_data);
+ m_encoding = encoding::decide(m_data);
}
@@ -64,7 +64,9 @@ void fileAttachment::setData(const string& filename)
throw exceptions::open_file_error();
}
- m_data = new streamContentHandler(new utility::inputStreamPointerAdapter(file, true), 0, true);
+ ref <utility::inputStream> is = vmime::create <utility::inputStreamPointerAdapter>(file, true);
+
+ m_data = vmime::create <streamContentHandler>(is, 0);
}
@@ -72,13 +74,13 @@ void fileAttachment::generatePart(bodyPart& part) const
{
defaultAttachment::generatePart(part);
- contentDispositionField& cdf = part.getHeader()->ContentDisposition();
+ ref <contentDispositionField> cdf = part.getHeader()->ContentDisposition();
- if (m_fileInfo.hasSize()) cdf.setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
- if (m_fileInfo.hasFilename()) cdf.setFilename(m_fileInfo.getFilename());
- if (m_fileInfo.hasCreationDate()) cdf.setCreationDate(m_fileInfo.getCreationDate());
- if (m_fileInfo.hasModificationDate()) cdf.setModificationDate(m_fileInfo.getModificationDate());
- if (m_fileInfo.hasReadDate()) cdf.setReadDate(m_fileInfo.getReadDate());
+ if (m_fileInfo.hasSize()) cdf->setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
+ if (m_fileInfo.hasFilename()) cdf->setFilename(m_fileInfo.getFilename());
+ if (m_fileInfo.hasCreationDate()) cdf->setCreationDate(m_fileInfo.getCreationDate());
+ if (m_fileInfo.hasModificationDate()) cdf->setModificationDate(m_fileInfo.getModificationDate());
+ if (m_fileInfo.hasReadDate()) cdf->setReadDate(m_fileInfo.getReadDate());
}
diff --git a/src/header.cpp b/src/header.cpp
index a89f750d..41718e47 100644
--- a/src/header.cpp
+++ b/src/header.cpp
@@ -64,7 +64,7 @@ void header::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- headerField* field = headerField::parseNext(buffer, pos, end, &pos);
+ ref <headerField> field = headerField::parseNext(buffer, pos, end, &pos);
if (field == NULL) break;
m_fields.push_back(field);
@@ -81,7 +81,7 @@ void header::generate(utility::outputStream& os, const string::size_type maxLine
const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
// Generate the fields
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
it != m_fields.end() ; ++it)
{
(*it)->generate(os, maxLineLength);
@@ -93,26 +93,16 @@ void header::generate(utility::outputStream& os, const string::size_type maxLine
}
-header* header::clone() const
+ref <component> header::clone() const
{
- header* hdr = new header();
+ ref <header> hdr = vmime::create <header>();
- try
- {
- hdr->m_fields.reserve(m_fields.size());
+ hdr->m_fields.reserve(m_fields.size());
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
- it != m_fields.end() ; ++it)
- {
- hdr->m_fields.push_back((*it)->clone());
- }
- }
- catch (std::exception&)
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
+ it != m_fields.end() ; ++it)
{
- free_container(hdr->m_fields);
-
- delete (hdr);
- throw;
+ hdr->m_fields.push_back((*it)->clone().dynamicCast <headerField>());
}
return (hdr);
@@ -123,29 +113,20 @@ void header::copyFrom(const component& other)
{
const header& h = dynamic_cast <const header&>(other);
- std::vector <headerField*> fields;
-
- try
- {
- fields.reserve(h.m_fields.size());
-
- for (std::vector <headerField*>::const_iterator it = h.m_fields.begin() ;
- it != h.m_fields.end() ; ++it)
- {
- fields.push_back((*it)->clone());
- }
+ std::vector <ref <headerField> > fields;
- free_container(m_fields);
+ fields.reserve(h.m_fields.size());
- m_fields.resize(fields.size());
-
- std::copy(fields.begin(), fields.end(), m_fields.begin());
- }
- catch (std::exception&)
+ for (std::vector <ref <headerField> >::const_iterator it = h.m_fields.begin() ;
+ it != h.m_fields.end() ; ++it)
{
- free_container(fields);
- throw;
+ fields.push_back((*it)->clone().dynamicCast <headerField>());
}
+
+ m_fields.clear();
+ m_fields.resize(fields.size());
+
+ std::copy(fields.begin(), fields.end(), m_fields.begin());
}
@@ -160,8 +141,8 @@ const bool header::hasField(const string& fieldName) const
{
const string name = utility::stringUtils::toLower(fieldName);
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -169,13 +150,13 @@ const bool header::hasField(const string& fieldName) const
}
-headerField* header::findField(const string& fieldName) const
+ref <headerField> header::findField(const string& fieldName) const
{
const string name = utility::stringUtils::toLower(fieldName);
// Find the first field that matches the specified name
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -192,14 +173,14 @@ headerField* header::findField(const string& fieldName) const
}
-std::vector <headerField*> header::findAllFields(const string& fieldName)
+std::vector <ref <headerField> > header::findAllFields(const string& fieldName)
{
const string name = utility::stringUtils::toLower(fieldName);
- std::vector <headerField*> result;
+ std::vector <ref <headerField> > result;
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end ; ++pos)
{
@@ -214,30 +195,22 @@ std::vector <headerField*> header::findAllFields(const string& fieldName)
}
-headerField* header::getField(const string& fieldName)
+ref <headerField> header::getField(const string& fieldName)
{
const string name = utility::stringUtils::toLower(fieldName);
// Find the first field that matches the specified name
- std::vector <headerField*>::const_iterator pos = m_fields.begin();
- const std::vector <headerField*>::const_iterator end = m_fields.end();
+ std::vector <ref <headerField> >::const_iterator pos = m_fields.begin();
+ const std::vector <ref <headerField> >::const_iterator end = m_fields.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
// If no field with this name can be found, create a new one
if (pos == end)
{
- headerField* field = headerFieldFactory::getInstance()->create(fieldName);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(fieldName);
- try
- {
- appendField(field);
- }
- catch (std::exception&)
- {
- delete (field);
- throw;
- }
+ appendField(field);
// Return a reference to the new field
return (field);
@@ -250,15 +223,15 @@ headerField* header::getField(const string& fieldName)
}
-void header::appendField(headerField* field)
+void header::appendField(ref <headerField> field)
{
m_fields.push_back(field);
}
-void header::insertFieldBefore(headerField* beforeField, headerField* field)
+void header::insertFieldBefore(ref <headerField> beforeField, ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), beforeField);
if (it == m_fields.end())
@@ -268,15 +241,15 @@ void header::insertFieldBefore(headerField* beforeField, headerField* field)
}
-void header::insertFieldBefore(const int pos, headerField* field)
+void header::insertFieldBefore(const int pos, ref <headerField> field)
{
m_fields.insert(m_fields.begin() + pos, field);
}
-void header::insertFieldAfter(headerField* afterField, headerField* field)
+void header::insertFieldAfter(ref <headerField> afterField, ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), afterField);
if (it == m_fields.end())
@@ -286,31 +259,27 @@ void header::insertFieldAfter(headerField* afterField, headerField* field)
}
-void header::insertFieldAfter(const int pos, headerField* field)
+void header::insertFieldAfter(const int pos, ref <headerField> field)
{
m_fields.insert(m_fields.begin() + pos + 1, field);
}
-void header::removeField(headerField* field)
+void header::removeField(ref <headerField> field)
{
- const std::vector <headerField*>::iterator it = std::find
+ const std::vector <ref <headerField> >::iterator it = std::find
(m_fields.begin(), m_fields.end(), field);
if (it == m_fields.end())
throw exceptions::no_such_field();
- delete (*it);
-
m_fields.erase(it);
}
void header::removeField(const int pos)
{
- const std::vector <headerField*>::iterator it = m_fields.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <headerField> >::iterator it = m_fields.begin() + pos;
m_fields.erase(it);
}
@@ -318,7 +287,7 @@ void header::removeField(const int pos)
void header::removeAllFields()
{
- free_container(m_fields);
+ m_fields.clear();
}
@@ -334,25 +303,25 @@ const bool header::isEmpty() const
}
-headerField* header::getFieldAt(const int pos)
+ref <headerField> header::getFieldAt(const int pos)
{
return (m_fields[pos]);
}
-const headerField* header::getFieldAt(const int pos) const
+const ref <const headerField> header::getFieldAt(const int pos) const
{
return (m_fields[pos]);
}
-const std::vector <const headerField*> header::getFieldList() const
+const std::vector <ref <const headerField> > header::getFieldList() const
{
- std::vector <const headerField*> list;
+ std::vector <ref <const headerField> > list;
list.reserve(m_fields.size());
- for (std::vector <headerField*>::const_iterator it = m_fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator it = m_fields.begin() ;
it != m_fields.end() ; ++it)
{
list.push_back(*it);
@@ -362,15 +331,15 @@ const std::vector <const headerField*> header::getFieldList() const
}
-const std::vector <headerField*> header::getFieldList()
+const std::vector <ref <headerField> > header::getFieldList()
{
return (m_fields);
}
-const std::vector <const component*> header::getChildComponents() const
+const std::vector <ref <const component> > header::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_fields, list);
diff --git a/src/headerField.cpp b/src/headerField.cpp
index 72a3927e..7f2c8ca4 100644
--- a/src/headerField.cpp
+++ b/src/headerField.cpp
@@ -44,9 +44,9 @@ headerField::~headerField()
}
-headerField* headerField::clone() const
+ref <component> headerField::clone() const
{
- headerField* field = headerFieldFactory::getInstance()->create(m_name);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(m_name);
field->copyFrom(*this);
@@ -69,7 +69,7 @@ headerField& headerField::operator=(const headerField& other)
}
-headerField* headerField::parseNext(const string& buffer, const string::size_type position,
+ref <headerField> headerField::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
string::size_type pos = position;
@@ -191,7 +191,7 @@ headerField* headerField::parseNext(const string& buffer, const string::size_typ
}
// Return a new field
- headerField* field = headerFieldFactory::getInstance()->create(name);
+ ref <headerField> field = headerFieldFactory::getInstance()->create(name);
field->parse(buffer, contentsStart, contentsEnd, NULL);
field->setParsedBounds(nameStart, pos);
@@ -248,11 +248,11 @@ const bool headerField::isCustom() const
}
-const std::vector <const component*> headerField::getChildComponents() const
+const std::vector <ref <const component> > headerField::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&getValue());
+ list.push_back(getValueImp());
return (list);
}
diff --git a/src/headerFieldFactory.cpp b/src/headerFieldFactory.cpp
index fa990c6f..bdc58bce 100644
--- a/src/headerFieldFactory.cpp
+++ b/src/headerFieldFactory.cpp
@@ -76,11 +76,11 @@ headerFieldFactory* headerFieldFactory::getInstance()
}
-headerField* headerFieldFactory::create
+ref <headerField> headerFieldFactory::create
(const string& name, const string& body)
{
NameMap::const_iterator pos = m_nameMap.find(utility::stringUtils::toLower(name));
- headerField* field = NULL;
+ ref <headerField> field = NULL;
if (pos != m_nameMap.end())
{
diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp
index 36a82217..aa477dc6 100644
--- a/src/htmlTextPart.cpp
+++ b/src/htmlTextPart.cpp
@@ -29,18 +29,14 @@ namespace vmime
htmlTextPart::htmlTextPart()
- : m_plainText(new emptyContentHandler),
- m_text(new emptyContentHandler)
+ : m_plainText(vmime::create <emptyContentHandler>()),
+ m_text(vmime::create <emptyContentHandler>())
{
}
htmlTextPart::~htmlTextPart()
{
- free_container(m_objects);
-
- delete (m_plainText);
- delete (m_text);
}
@@ -62,48 +58,48 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
if (!m_plainText->isEmpty())
{
// -- Create a new part
- bodyPart* part = new bodyPart();
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
// -- Set header fields
- part->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
- part->getHeader()->ContentType().setCharset(m_charset);
- part->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
+ part->getHeader()->ContentType()->setCharset(m_charset);
+ part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents
- part->getBody()->setContents(*m_plainText);
+ part->getBody()->setContents(m_plainText);
}
// HTML text
// -- Create a new part
- bodyPart* htmlPart = new bodyPart();
+ ref <bodyPart> htmlPart = vmime::create <bodyPart>();
// -- Set header fields
- htmlPart->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
- htmlPart->getHeader()->ContentType().setCharset(m_charset);
- htmlPart->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ htmlPart->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
+ htmlPart->getHeader()->ContentType()->setCharset(m_charset);
+ htmlPart->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents
- htmlPart->getBody()->setContents(*m_text);
+ htmlPart->getBody()->setContents(m_text);
// Handle the case we have embedded objects
if (!m_objects.empty())
{
// Create a "multipart/related" body part
- bodyPart* relPart = new bodyPart();
+ ref <bodyPart> relPart = vmime::create <bodyPart>();
parent.getBody()->appendPart(relPart);
- relPart->getHeader()->ContentType().
+ relPart->getHeader()->ContentType()->
setValue(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_RELATED));
// Add the HTML part into this part
relPart->getBody()->appendPart(htmlPart);
// Also add objects into this part
- for (std::vector <embeddedObject*>::const_iterator it = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator it = m_objects.begin() ;
it != m_objects.end() ; ++it)
{
- bodyPart* objPart = new bodyPart();
+ ref <bodyPart> objPart = vmime::create <bodyPart>();
relPart->getBody()->appendPart(objPart);
string id = (*it)->getId();
@@ -111,13 +107,13 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
if (id.substr(0, 4) == "CID:")
id = id.substr(4);
- objPart->getHeader()->ContentType().setValue((*it)->getType());
- objPart->getHeader()->ContentId().setValue(messageId("<" + id + ">"));
- objPart->getHeader()->ContentDisposition().setValue(contentDisposition(contentDispositionTypes::INLINE));
- objPart->getHeader()->ContentTransferEncoding().setValue((*it)->getEncoding());
+ objPart->getHeader()->ContentType()->setValue((*it)->getType());
+ objPart->getHeader()->ContentId()->setValue(messageId("<" + id + ">"));
+ objPart->getHeader()->ContentDisposition()->setValue(contentDisposition(contentDispositionTypes::INLINE));
+ objPart->getHeader()->ContentTransferEncoding()->setValue((*it)->getEncoding());
//encoding(encodingTypes::BASE64);
- objPart->getBody()->setContents((*it)->getData());
+ objPart->getBody()->setContents((*it)->getData()->clone());
}
}
else
@@ -129,16 +125,16 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
void htmlTextPart::findEmbeddedParts(const bodyPart& part,
- std::vector <const bodyPart*>& cidParts, std::vector <const bodyPart*>& locParts)
+ std::vector <ref <const bodyPart> >& cidParts, std::vector <ref <const bodyPart> >& locParts)
{
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- dynamic_cast<messageIdField&>(*p.getHeader()->findField(fields::CONTENT_ID));
- cidParts.push_back(&p);
+ p->getHeader()->findField(fields::CONTENT_ID);
+ cidParts.push_back(p);
}
catch (exceptions::no_such_field)
{
@@ -146,8 +142,8 @@ void htmlTextPart::findEmbeddedParts(const bodyPart& part,
// Maybe there is a "Content-Location" field...
try
{
- dynamic_cast<messageIdField&>(*p.getHeader()->findField(fields::CONTENT_ID));
- locParts.push_back(&p);
+ p->getHeader()->findField(fields::CONTENT_ID);
+ locParts.push_back(p);
}
catch (exceptions::no_such_field)
{
@@ -156,7 +152,7 @@ void htmlTextPart::findEmbeddedParts(const bodyPart& part,
}
}
- findEmbeddedParts(p, cidParts, locParts);
+ findEmbeddedParts(*p, cidParts, locParts);
}
}
@@ -167,26 +163,25 @@ void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id)
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*part.getHeader()->findField(fields::CONTENT_TYPE));
-
- type = ctf.getValue();
+ const ref <const contentTypeField> ctf = part.getHeader()->ContentType();
+ type = ctf->getValue();
}
catch (exceptions::no_such_field)
{
// No "Content-type" field: assume "application/octet-stream".
}
- m_objects.push_back(new embeddedObject
- (part.getBody()->getContents(), part.getBody()->getEncoding(), id, type));
+ m_objects.push_back(vmime::create <embeddedObject>
+ (part.getBody()->getContents()->clone().dynamicCast <contentHandler>(),
+ part.getBody()->getEncoding(), id, type));
}
void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const bodyPart& textPart)
{
// Search for possible embedded objects in the _whole_ message.
- std::vector <const bodyPart*> cidParts;
- std::vector <const bodyPart*> locParts;
+ std::vector <ref <const bodyPart> > cidParts;
+ std::vector <ref <const bodyPart> > locParts;
findEmbeddedParts(message, cidParts, locParts);
@@ -194,19 +189,18 @@ void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const
std::ostringstream oss;
utility::outputStreamAdapter adapter(oss);
- textPart.getBody()->getContents().extract(adapter);
+ textPart.getBody()->getContents()->extract(adapter);
const string data = oss.str();
- delete (m_text);
- m_text = textPart.getBody()->getContents().clone();
+ m_text = textPart.getBody()->getContents()->clone();
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*textPart.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ textPart.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- m_charset = ctf.getCharset();
+ m_charset = ctf->getCharset();
}
catch (exceptions::no_such_field)
{
@@ -219,39 +213,38 @@ void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const
// Extract embedded objects. The algorithm is quite simple: for each previously
// found inline part, we check if its CID/Location is contained in the HTML text.
- for (std::vector <const bodyPart*>::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p)
+ for (std::vector <ref <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p)
{
- const messageIdField& midField = dynamic_cast<messageIdField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_ID));
+ const ref <const messageIdField> midField =
+ (*p)->getHeader()->findField(fields::CONTENT_ID).dynamicCast <messageIdField>();
- const string searchFor("CID:" + midField.getValue().getId());
+ const string searchFor("CID:" + midField->getValue().getId());
if (data.find(searchFor) != string::npos)
{
// This part is referenced in the HTML text.
// Add it to the embedded object list.
- addEmbeddedObject(**p, "CID:" + midField.getValue().getId());
+ addEmbeddedObject(**p, "CID:" + midField->getValue().getId());
}
}
- for (std::vector <const bodyPart*>::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p)
+ for (std::vector <ref <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p)
{
- const defaultField& locField = dynamic_cast<defaultField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_LOCATION));
+ const ref <const defaultField> locField =
+ (*p)->getHeader()->findField(fields::CONTENT_LOCATION).dynamicCast <defaultField>();
- if (data.find(locField.getValue()) != string::npos)
+ if (data.find(locField->getValue()) != string::npos)
{
// This part is referenced in the HTML text.
// Add it to the embedded object list.
- addEmbeddedObject(**p, locField.getValue());
+ addEmbeddedObject(**p, locField->getValue());
}
}
// Extract plain text, if any.
if (!findPlainTextPart(message, parent, textPart))
{
- delete (m_plainText);
- m_plainText = new emptyContentHandler();
+ m_plainText = vmime::create <emptyContentHandler>();
}
}
@@ -261,22 +254,22 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
// We search for the nearest "multipart/alternative" part.
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*part.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ part.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::MULTIPART &&
- ctf.getValue().getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
+ if (ctf->getValue().getType() == mediaTypes::MULTIPART &&
+ ctf->getValue().getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
{
- bodyPart const* foundPart = NULL;
+ ref <const bodyPart> foundPart = NULL;
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart* p = part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
if (p == &parent || // if "text/html" is in "multipart/related"
p == &textPart) // if not...
{
- foundPart = &(*p);
+ foundPart = p;
}
}
@@ -287,18 +280,17 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
// Now, search for the alternative plain text part
for (int i = 0 ; !found && i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*p.getHeader()->findField(fields::CONTENT_TYPE));
+ const ref <const contentTypeField> ctf =
+ p->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
- if (ctf.getValue().getType() == mediaTypes::TEXT &&
- ctf.getValue().getSubType() == mediaTypes::TEXT_PLAIN)
+ if (ctf->getValue().getType() == mediaTypes::TEXT &&
+ ctf->getValue().getSubType() == mediaTypes::TEXT_PLAIN)
{
- delete (m_plainText);
- m_plainText = p.getBody()->getContents().clone();
+ m_plainText = p->getBody()->getContents()->clone();
found = true;
}
}
@@ -343,29 +335,27 @@ void htmlTextPart::setCharset(const charset& ch)
}
-const contentHandler& htmlTextPart::getPlainText() const
+const ref <const contentHandler> htmlTextPart::getPlainText() const
{
- return (*m_plainText);
+ return (m_plainText);
}
-void htmlTextPart::setPlainText(const contentHandler& plainText)
+void htmlTextPart::setPlainText(ref <contentHandler> plainText)
{
- delete (m_plainText);
- m_plainText = plainText.clone();
+ m_plainText = plainText->clone();
}
-const contentHandler& htmlTextPart::getText() const
+const ref <const contentHandler> htmlTextPart::getText() const
{
- return (*m_text);
+ return (m_text);
}
-void htmlTextPart::setText(const contentHandler& text)
+void htmlTextPart::setText(ref <contentHandler> text)
{
- delete (m_text);
- m_text = text.clone();
+ m_text = text->clone();
}
@@ -375,15 +365,15 @@ const int htmlTextPart::getObjectCount() const
}
-const htmlTextPart::embeddedObject* htmlTextPart::getObjectAt(const int pos) const
+const ref <const htmlTextPart::embeddedObject> htmlTextPart::getObjectAt(const int pos) const
{
return (m_objects[pos]);
}
-const htmlTextPart::embeddedObject* htmlTextPart::findObject(const string& id) const
+const ref <const htmlTextPart::embeddedObject> htmlTextPart::findObject(const string& id) const
{
- for (std::vector <embeddedObject*>::const_iterator o = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator o = m_objects.begin() ;
o != m_objects.end() ; ++o)
{
if ((*o)->getId() == id)
@@ -396,7 +386,7 @@ const htmlTextPart::embeddedObject* htmlTextPart::findObject(const string& id) c
const bool htmlTextPart::hasObject(const string& id) const
{
- for (std::vector <embeddedObject*>::const_iterator o = m_objects.begin() ;
+ for (std::vector <ref <embeddedObject> >::const_iterator o = m_objects.begin() ;
o != m_objects.end() ; ++o)
{
if ((*o)->getId() == id)
@@ -407,19 +397,19 @@ const bool htmlTextPart::hasObject(const string& id) const
}
-const string htmlTextPart::addObject(const contentHandler& data,
+const string htmlTextPart::addObject(ref <contentHandler> data,
const vmime::encoding& enc, const mediaType& type)
{
const messageId mid(messageId::generateId());
const string id = "CID:" + mid.getId();
- m_objects.push_back(new embeddedObject(data, enc, id, type));
+ m_objects.push_back(vmime::create <embeddedObject>(data, enc, id, type));
return (id);
}
-const string htmlTextPart::addObject(const contentHandler& data, const mediaType& type)
+const string htmlTextPart::addObject(ref <contentHandler> data, const mediaType& type)
{
return (addObject(data, encoding::decide(data), type));
}
@@ -427,7 +417,7 @@ const string htmlTextPart::addObject(const contentHandler& data, const mediaType
const string htmlTextPart::addObject(const string& data, const mediaType& type)
{
- stringContentHandler cts(data);
+ ref <stringContentHandler> cts = vmime::create <stringContentHandler>(data);
return (addObject(cts, encoding::decide(cts), type));
}
@@ -438,16 +428,17 @@ const string htmlTextPart::addObject(const string& data, const mediaType& type)
//
htmlTextPart::embeddedObject::embeddedObject
- (const contentHandler& data, const encoding& enc,
+ (ref <contentHandler> data, const encoding& enc,
const string& id, const mediaType& type)
- : m_data(data.clone()), m_encoding(enc), m_id(id), m_type(type)
+ : m_data(data->clone().dynamicCast <contentHandler>()),
+ m_encoding(enc), m_id(id), m_type(type)
{
}
-const contentHandler& htmlTextPart::embeddedObject::getData() const
+const ref <const contentHandler> htmlTextPart::embeddedObject::getData() const
{
- return (*m_data);
+ return (m_data);
}
diff --git a/src/mailbox.cpp b/src/mailbox.cpp
index 9580d8e4..3fb1a10e 100644
--- a/src/mailbox.cpp
+++ b/src/mailbox.cpp
@@ -455,9 +455,9 @@ mailbox& mailbox::operator=(const mailbox& other)
}
-mailbox* mailbox::clone() const
+ref <component>mailbox::clone() const
{
- return new mailbox(*this);
+ return vmime::create <mailbox>(*this);
}
@@ -504,9 +504,9 @@ void mailbox::setEmail(const string& email)
}
-const std::vector <const component*> mailbox::getChildComponents() const
+const std::vector <ref <const component> > mailbox::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/mailboxField.cpp b/src/mailboxField.cpp
index 3580b011..db62b36c 100644
--- a/src/mailboxField.cpp
+++ b/src/mailboxField.cpp
@@ -44,7 +44,7 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
// Here, we cannot simply call "m_mailbox.parse()" because it
// may have more than one address specified (even if this field
// should contain only one). We are never too much careful...
- address* parsedAddress = address::parseNext(buffer, position, end, newPosition);
+ ref <address> parsedAddress = address::parseNext(buffer, position, end, newPosition);
if (parsedAddress)
{
@@ -52,7 +52,7 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
{
// If it is a group of mailboxes, take the first
// mailbox of the group
- mailboxGroup* group = static_cast <mailboxGroup*>(parsedAddress);
+ ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>();
if (!group->isEmpty())
getValue() = *(group->getMailboxAt(0));
@@ -60,12 +60,10 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
else
{
// Parse only if it is a mailbox
- getValue() = *static_cast <mailbox*>(parsedAddress);
+ getValue() = *parsedAddress.staticCast <mailbox>();
}
}
- delete (parsedAddress);
-
getValue().setParsedBounds(position, end);
setParsedBounds(position, end);
diff --git a/src/mailboxGroup.cpp b/src/mailboxGroup.cpp
index c018c3ce..1a5d3729 100644
--- a/src/mailboxGroup.cpp
+++ b/src/mailboxGroup.cpp
@@ -76,26 +76,24 @@ void mailboxGroup::parse(const string& buffer, const string::size_type position,
while (pos < end)
{
- address* parsedAddress = address::parseNext(buffer, pos, end, &pos);
+ ref <address> parsedAddress = address::parseNext(buffer, pos, end, &pos);
if (parsedAddress)
{
if (parsedAddress->isGroup())
{
- mailboxGroup* group = static_cast <mailboxGroup*>(parsedAddress);
+ ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>();
// Sub-groups are not allowed in mailbox groups: so, we add all
// the contents of the sub-group into this group...
for (int i = 0 ; i < group->getMailboxCount() ; ++i)
{
- m_list.push_back(group->getMailboxAt(i)->clone());
+ m_list.push_back(group->getMailboxAt(i)->clone().staticCast <mailbox>());
}
-
- delete (parsedAddress);
}
else
{
- m_list.push_back(static_cast <mailbox*>(parsedAddress));
+ m_list.push_back(parsedAddress.staticCast <mailbox>());
}
}
}
@@ -160,7 +158,7 @@ void mailboxGroup::generate(utility::outputStream& os, const string::size_type m
os << ":";
++pos;
- for (std::vector <mailbox*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
if (it != m_list.begin())
@@ -193,17 +191,17 @@ void mailboxGroup::copyFrom(const component& other)
removeAllMailboxes();
- for (std::vector <mailbox*>::const_iterator it = source.m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = source.m_list.begin() ;
it != source.m_list.end() ; ++it)
{
- m_list.push_back((*it)->clone());
+ m_list.push_back((*it)->clone().staticCast <mailbox>());
}
}
-mailboxGroup* mailboxGroup::clone() const
+ref <component> mailboxGroup::clone() const
{
- return new mailboxGroup(*this);
+ return vmime::create <mailboxGroup>(*this);
}
@@ -238,15 +236,15 @@ const bool mailboxGroup::isEmpty() const
}
-void mailboxGroup::appendMailbox(mailbox* mbox)
+void mailboxGroup::appendMailbox(ref <mailbox> mbox)
{
m_list.push_back(mbox);
}
-void mailboxGroup::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
+void mailboxGroup::insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeMailbox);
if (it == m_list.end())
@@ -256,15 +254,15 @@ void mailboxGroup::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
}
-void mailboxGroup::insertMailboxBefore(const int pos, mailbox* mbox)
+void mailboxGroup::insertMailboxBefore(const int pos, ref <mailbox> mbox)
{
m_list.insert(m_list.begin() + pos, mbox);
}
-void mailboxGroup::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
+void mailboxGroup::insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterMailbox);
if (it == m_list.end())
@@ -274,31 +272,27 @@ void mailboxGroup::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
}
-void mailboxGroup::insertMailboxAfter(const int pos, mailbox* mbox)
+void mailboxGroup::insertMailboxAfter(const int pos, ref <mailbox> mbox)
{
m_list.insert(m_list.begin() + pos + 1, mbox);
}
-void mailboxGroup::removeMailbox(mailbox* mbox)
+void mailboxGroup::removeMailbox(ref <mailbox> mbox)
{
- const std::vector <mailbox*>::iterator it = std::find
+ const std::vector <ref <mailbox> >::iterator it = std::find
(m_list.begin(), m_list.end(), mbox);
if (it == m_list.end())
throw exceptions::no_such_mailbox();
- delete (*it);
-
m_list.erase(it);
}
void mailboxGroup::removeMailbox(const int pos)
{
- const std::vector <mailbox*>::iterator it = m_list.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <mailbox> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -306,7 +300,7 @@ void mailboxGroup::removeMailbox(const int pos)
void mailboxGroup::removeAllMailboxes()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -316,25 +310,25 @@ const int mailboxGroup::getMailboxCount() const
}
-mailbox* mailboxGroup::getMailboxAt(const int pos)
+ref <mailbox> mailboxGroup::getMailboxAt(const int pos)
{
return (m_list[pos]);
}
-const mailbox* mailboxGroup::getMailboxAt(const int pos) const
+const ref <const mailbox> mailboxGroup::getMailboxAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const mailbox*> mailboxGroup::getMailboxList() const
+const std::vector <ref <const mailbox> > mailboxGroup::getMailboxList() const
{
- std::vector <const mailbox*> list;
+ std::vector <ref <const mailbox> > list;
list.reserve(m_list.size());
- for (std::vector <mailbox*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <mailbox> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -344,15 +338,15 @@ const std::vector <const mailbox*> mailboxGroup::getMailboxList() const
}
-const std::vector <mailbox*> mailboxGroup::getMailboxList()
+const std::vector <ref <mailbox> > mailboxGroup::getMailboxList()
{
return (m_list);
}
-const std::vector <const component*> mailboxGroup::getChildComponents() const
+const std::vector <ref <const component> > mailboxGroup::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_list, list);
diff --git a/src/mailboxList.cpp b/src/mailboxList.cpp
index fe636e1d..e6a64669 100644
--- a/src/mailboxList.cpp
+++ b/src/mailboxList.cpp
@@ -36,13 +36,13 @@ mailboxList::mailboxList(const mailboxList& mboxList)
}
-void mailboxList::appendMailbox(mailbox* mbox)
+void mailboxList::appendMailbox(ref <mailbox> mbox)
{
m_list.appendAddress(mbox);
}
-void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
+void mailboxList::insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox)
{
try
{
@@ -55,13 +55,13 @@ void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox)
}
-void mailboxList::insertMailboxBefore(const int pos, mailbox* mbox)
+void mailboxList::insertMailboxBefore(const int pos, ref <mailbox> mbox)
{
m_list.insertAddressBefore(pos, mbox);
}
-void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
+void mailboxList::insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox)
{
try
{
@@ -74,13 +74,13 @@ void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox)
}
-void mailboxList::insertMailboxAfter(const int pos, mailbox* mbox)
+void mailboxList::insertMailboxAfter(const int pos, ref <mailbox> mbox)
{
m_list.insertAddressAfter(pos, mbox);
}
-void mailboxList::removeMailbox(mailbox* mbox)
+void mailboxList::removeMailbox(ref <mailbox> mbox)
{
try
{
@@ -117,27 +117,27 @@ const bool mailboxList::isEmpty() const
}
-mailbox* mailboxList::getMailboxAt(const int pos)
+ref <mailbox> mailboxList::getMailboxAt(const int pos)
{
- return static_cast <mailbox*>(m_list.getAddressAt(pos));
+ return m_list.getAddressAt(pos).staticCast <mailbox>();
}
-const mailbox* mailboxList::getMailboxAt(const int pos) const
+const ref <const mailbox> mailboxList::getMailboxAt(const int pos) const
{
- return static_cast <const mailbox*>(m_list.getAddressAt(pos));
+ return m_list.getAddressAt(pos).staticCast <const mailbox>();
}
-const std::vector <const mailbox*> mailboxList::getMailboxList() const
+const std::vector <ref <const mailbox> > mailboxList::getMailboxList() const
{
- const std::vector <const address*> addrList = m_list.getAddressList();
- std::vector <const mailbox*> res;
+ const std::vector <ref <const address> > addrList = m_list.getAddressList();
+ std::vector <ref <const mailbox> > res;
- for (std::vector <const address*>::const_iterator it = addrList.begin() ;
+ for (std::vector <ref <const address> >::const_iterator it = addrList.begin() ;
it != addrList.end() ; ++it)
{
- const mailbox* mbox = dynamic_cast <const mailbox*>(*it);
+ const ref <const mailbox> mbox = (*it).dynamicCast <const mailbox>();
if (mbox != NULL)
res.push_back(mbox);
@@ -147,15 +147,15 @@ const std::vector <const mailbox*> mailboxList::getMailboxList() const
}
-const std::vector <mailbox*> mailboxList::getMailboxList()
+const std::vector <ref <mailbox> > mailboxList::getMailboxList()
{
- const std::vector <address*> addrList = m_list.getAddressList();
- std::vector <mailbox*> res;
+ const std::vector <ref <address> > addrList = m_list.getAddressList();
+ std::vector <ref <mailbox> > res;
- for (std::vector <address*>::const_iterator it = addrList.begin() ;
+ for (std::vector <ref <address> >::const_iterator it = addrList.begin() ;
it != addrList.end() ; ++it)
{
- mailbox* mbox = dynamic_cast <mailbox*>(*it);
+ const ref <mailbox> mbox = (*it).dynamicCast <mailbox>();
if (mbox != NULL)
res.push_back(mbox);
@@ -165,9 +165,9 @@ const std::vector <mailbox*> mailboxList::getMailboxList()
}
-mailboxList* mailboxList::clone() const
+ref <component> mailboxList::clone() const
{
- return new mailboxList(*this);
+ return vmime::create <mailboxList>(*this);
}
@@ -186,7 +186,7 @@ mailboxList& mailboxList::operator=(const mailboxList& other)
}
-const std::vector <const component*> mailboxList::getChildComponents() const
+const std::vector <ref <const component> > mailboxList::getChildComponents() const
{
return (m_list.getChildComponents());
}
diff --git a/src/mdn/MDNHelper.cpp b/src/mdn/MDNHelper.cpp
index 324807e0..62028a12 100644
--- a/src/mdn/MDNHelper.cpp
+++ b/src/mdn/MDNHelper.cpp
@@ -27,32 +27,32 @@ namespace vmime {
namespace mdn {
-void MDNHelper::attachMDNRequest(message* msg, const mailboxList& mailboxes)
+void MDNHelper::attachMDNRequest(ref <message> msg, const mailboxList& mailboxes)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
- hdr->DispositionNotificationTo().setValue(mailboxes);
+ hdr->DispositionNotificationTo()->setValue(mailboxes);
}
-void MDNHelper::attachMDNRequest(message* msg, const mailbox& mbox)
+void MDNHelper::attachMDNRequest(ref <message> msg, const mailbox& mbox)
{
mailboxList mboxList;
- mboxList.appendMailbox(mbox.clone());
+ mboxList.appendMailbox(mbox.clone().dynamicCast <mailbox>());
attachMDNRequest(msg, mboxList);
}
-const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const message* msg)
+const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const ref <const message> msg)
{
std::vector <sendableMDNInfos> result;
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{
- const mailboxList& dnto = hdr->DispositionNotificationTo().getValue();
+ const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue();
for (int i = 0 ; i < dnto.getMailboxCount() ; ++i)
result.push_back(sendableMDNInfos(msg, *dnto.getMailboxAt(i)));
@@ -62,9 +62,9 @@ const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const message* m
}
-const bool MDNHelper::isMDN(const message* msg)
+const bool MDNHelper::isMDN(const ref <const message> msg)
{
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
// A MDN message implies the following:
// - a Content-Type field is present and its value is "multipart/report"
@@ -72,7 +72,7 @@ const bool MDNHelper::isMDN(const message* msg)
// and its value is "disposition-notification"
if (hdr->hasField(fields::CONTENT_TYPE))
{
- const contentTypeField& ctf = hdr->ContentType();
+ const contentTypeField& ctf = *(hdr->ContentType());
if (ctf.getValue().getType() == vmime::mediaTypes::MULTIPART &&
ctf.getValue().getSubType() == vmime::mediaTypes::MULTIPART_REPORT)
@@ -89,7 +89,7 @@ const bool MDNHelper::isMDN(const message* msg)
}
-receivedMDNInfos MDNHelper::getReceivedMDN(const message* msg)
+receivedMDNInfos MDNHelper::getReceivedMDN(const ref <const message> msg)
{
if (!isMDN(msg))
throw exceptions::invalid_argument();
@@ -98,7 +98,7 @@ receivedMDNInfos MDNHelper::getReceivedMDN(const message* msg)
}
-bool MDNHelper::needConfirmation(const message* msg)
+const bool MDNHelper::needConfirmation(const ref <const message> msg)
{
const header* hdr = msg->getHeader();
@@ -109,14 +109,14 @@ bool MDNHelper::needConfirmation(const message* msg)
// More than one address in Disposition-Notification-To
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{
- const mailboxList& dnto = hdr->DispositionNotificationTo().getValue();
+ const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue();
if (dnto.getMailboxCount() > 1)
return (true);
// Return-Path != Disposition-Notification-To
const mailbox& mbox = *dnto.getMailboxAt(0);
- const path& rp = hdr->ReturnPath().getValue();
+ const path& rp = hdr->ReturnPath()->getValue();
if (mbox.getEmail() != rp.getLocalPart() + "@" + rp.getDomain())
return (true);
@@ -127,32 +127,32 @@ bool MDNHelper::needConfirmation(const message* msg)
}
-message* MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
- const string& text,
- const charset& ch,
- const mailbox& expeditor,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts)
+ref <message> MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
+ const string& text,
+ const charset& ch,
+ const mailbox& expeditor,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts)
{
// Create a new message
- message* msg = new message;
+ ref <message> msg = vmime::create <message>();
// Fill-in header fields
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::MULTIPART,
- vmime::mediaTypes::MULTIPART_REPORT));
- hdr->ContentType().setReportType("disosition-notification");
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MULTIPART,
+ vmime::mediaTypes::MULTIPART_REPORT));
+ hdr->ContentType()->setReportType("disosition-notification");
- hdr->Disposition().setValue(dispo);
+ hdr->Disposition()->setValue(dispo);
- hdr->To().getValue().appendAddress(new mailbox(mdnInfos.getRecipient()));
- hdr->From().getValue() = expeditor;
- hdr->Subject().getValue().appendWord(new word("Disposition notification"));
+ hdr->To()->getValue().appendAddress(vmime::create <mailbox>(mdnInfos.getRecipient()));
+ hdr->From()->getValue() = expeditor;
+ hdr->Subject()->getValue().appendWord(vmime::create <word>("Disposition notification"));
- hdr->Date().setValue(datetime::now());
- hdr->MimeVersion().setValue(string(SUPPORTED_MIME_VERSION));
+ hdr->Date()->setValue(datetime::now());
+ hdr->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));
msg->getBody()->appendPart(createFirstMDNPart(mdnInfos, text, ch));
msg->getBody()->appendPart(createSecondMDNPart(mdnInfos,
@@ -163,39 +163,39 @@ message* MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
}
-bodyPart* MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
- const string& text, const charset& ch)
+ref <bodyPart> MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */,
+ const string& text, const charset& ch)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::TEXT,
- vmime::mediaTypes::TEXT_PLAIN));
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
+ vmime::mediaTypes::TEXT_PLAIN));
- hdr->ContentType().setCharset(ch);
+ hdr->ContentType()->setCharset(ch);
// Body
- part->getBody()->setContents(stringContentHandler(text));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(text));
return (part);
}
-bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts)
+ref <bodyPart> MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentDisposition().setValue(vmime::contentDispositionTypes::INLINE);
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::MESSAGE,
- vmime::mediaTypes::MESSAGE_DISPOSITION_NOTIFICATION));
+ hdr->ContentDisposition()->setValue(vmime::contentDispositionTypes::INLINE);
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MESSAGE,
+ vmime::mediaTypes::MESSAGE_DISPOSITION_NOTIFICATION));
// Body
//
@@ -233,8 +233,9 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
ruaText += reportingUAProducts[i];
}
- defaultField* rua = dynamic_cast <defaultField*>
- (headerFieldFactory::getInstance()->create(vmime::fields::REPORTING_UA));
+ ref <defaultField> rua =
+ (headerFieldFactory::getInstance()->create
+ (vmime::fields::REPORTING_UA)).dynamicCast <defaultField>();
rua->setValue(ruaText);
@@ -242,20 +243,21 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
}
// -- Final-Recipient
- defaultField* fr = dynamic_cast <defaultField*>
- (headerFieldFactory::getInstance()->create(vmime::fields::FINAL_RECIPIENT));
+ ref <defaultField> fr =
+ (headerFieldFactory::getInstance()->
+ create(vmime::fields::FINAL_RECIPIENT)).dynamicCast <defaultField>();
fr->setValue("rfc822; " + mdnInfos.getRecipient().getEmail());
// -- Original-Message-ID
if (mdnInfos.getMessage()->getHeader()->hasField(vmime::fields::MESSAGE_ID))
{
- fields.OriginalMessageId().setValue
- (mdnInfos.getMessage()->getHeader()->MessageId().getValue());
+ fields.OriginalMessageId()->setValue
+ (mdnInfos.getMessage()->getHeader()->MessageId()->getValue());
}
// -- Disposition
- fields.Disposition().setValue(dispo);
+ fields.Disposition()->setValue(dispo);
std::ostringstream oss;
@@ -263,22 +265,22 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
fields.generate(vos);
- part->getBody()->setContents(stringContentHandler(oss.str()));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(oss.str()));
return (part);
}
-bodyPart* MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
+ref <bodyPart> MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
{
- bodyPart* part = new bodyPart;
+ ref <bodyPart> part = vmime::create <bodyPart>();
// Header
- header* hdr = part->getHeader();
+ ref <header> hdr = part->getHeader();
- hdr->ContentDisposition().setValue(vmime::contentDispositionTypes::INLINE);
- hdr->ContentType().setValue(mediaType(vmime::mediaTypes::TEXT,
- vmime::mediaTypes::TEXT_RFC822_HEADERS));
+ hdr->ContentDisposition()->setValue(vmime::contentDispositionTypes::INLINE);
+ hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
+ vmime::mediaTypes::TEXT_RFC822_HEADERS));
// Body: original message headers
std::ostringstream oss;
@@ -286,7 +288,7 @@ bodyPart* MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos)
mdnInfos.getMessage()->getHeader()->generate(vos);
- part->getBody()->setContents(stringContentHandler(oss.str()));
+ part->getBody()->setContents(vmime::create <stringContentHandler>(oss.str()));
return (part);
}
diff --git a/src/mdn/receivedMDNInfos.cpp b/src/mdn/receivedMDNInfos.cpp
index e9a82198..7c6f2893 100644
--- a/src/mdn/receivedMDNInfos.cpp
+++ b/src/mdn/receivedMDNInfos.cpp
@@ -24,7 +24,7 @@ namespace vmime {
namespace mdn {
-receivedMDNInfos::receivedMDNInfos(const message* msg)
+receivedMDNInfos::receivedMDNInfos(const ref <const message> msg)
: m_msg(msg)
{
extract();
@@ -45,7 +45,7 @@ receivedMDNInfos& receivedMDNInfos::operator=(const receivedMDNInfos& other)
}
-const message* receivedMDNInfos::getMessage() const
+const ref <const message> receivedMDNInfos::getMessage() const
{
return (m_msg);
}
@@ -73,16 +73,16 @@ void receivedMDNInfos::copyFrom(const receivedMDNInfos& other)
void receivedMDNInfos::extract()
{
- const body* bdy = m_msg->getBody();
+ const ref <const body> bdy = m_msg->getBody();
for (int i = 0 ; i < bdy->getPartCount() ; ++i)
{
- const bodyPart* part = bdy->getPartAt(i);
+ const ref <const bodyPart> part = bdy->getPartAt(i);
if (!part->getHeader()->hasField(fields::CONTENT_TYPE))
continue;
- const mediaType& type = part->getHeader()->ContentType().getValue();
+ const mediaType& type = part->getHeader()->ContentType()->getValue();
// Extract from second part (message/disposition-notification)
if (type.getType() == vmime::mediaTypes::MESSAGE &&
@@ -91,16 +91,16 @@ void receivedMDNInfos::extract()
std::ostringstream oss;
utility::outputStreamAdapter vos(oss);
- part->getBody()->getContents().extract(vos);
+ part->getBody()->getContents()->extract(vos);
// Body actually contains fields
header fields;
fields.parse(oss.str());
- try { m_omid = fields.OriginalMessageId().getValue(); }
+ try { m_omid = fields.OriginalMessageId()->getValue(); }
catch (exceptions::no_such_field&) { /* Ignore */ }
- try { m_disp = fields.Disposition().getValue(); }
+ try { m_disp = fields.Disposition()->getValue(); }
catch (exceptions::no_such_field&) { /* Ignore */ }
}
}
diff --git a/src/mdn/sendableMDNInfos.cpp b/src/mdn/sendableMDNInfos.cpp
index e8ae8b62..40a0fe96 100644
--- a/src/mdn/sendableMDNInfos.cpp
+++ b/src/mdn/sendableMDNInfos.cpp
@@ -24,7 +24,7 @@ namespace vmime {
namespace mdn {
-sendableMDNInfos::sendableMDNInfos(const message* msg, const mailbox& mbox)
+sendableMDNInfos::sendableMDNInfos(const ref <const message> msg, const mailbox& mbox)
: m_msg(msg), m_mailbox(mbox)
{
}
@@ -44,7 +44,7 @@ sendableMDNInfos& sendableMDNInfos::operator=(const sendableMDNInfos& other)
}
-const message* sendableMDNInfos::getMessage() const
+const ref <const message> sendableMDNInfos::getMessage() const
{
return (m_msg);
}
diff --git a/src/mediaType.cpp b/src/mediaType.cpp
index deb0c129..807131fb 100644
--- a/src/mediaType.cpp
+++ b/src/mediaType.cpp
@@ -120,9 +120,9 @@ mediaType& mediaType::operator=(const string& type)
}
-mediaType* mediaType::clone() const
+ref <component> mediaType::clone() const
{
- return new mediaType(m_type, m_subType);
+ return vmime::create <mediaType>(m_type, m_subType);
}
@@ -172,9 +172,9 @@ void mediaType::setFromString(const string& type)
}
-const std::vector <const component*> mediaType::getChildComponents() const
+const std::vector <ref <const component> > mediaType::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/messageBuilder.cpp b/src/messageBuilder.cpp
index 7081332f..beb252d5 100644
--- a/src/messageBuilder.cpp
+++ b/src/messageBuilder.cpp
@@ -27,7 +27,6 @@ namespace vmime
messageBuilder::messageBuilder()
- : m_textPart(NULL)
{
// By default there is one text part of type "text/plain"
constructTextPart(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
@@ -36,19 +35,16 @@ messageBuilder::messageBuilder()
messageBuilder::~messageBuilder()
{
- delete (m_textPart);
-
- free_container(m_attach);
}
-message* messageBuilder::construct() const
+ref <message> messageBuilder::construct() const
{
// Create a new message
- message* msg = new message;
+ ref <message> msg = vmime::create <message>();
// Generate the header fields
- msg->getHeader()->Subject().setValue(m_subject);
+ msg->getHeader()->Subject()->setValue(m_subject);
if (m_from.isEmpty())
throw exceptions::no_expeditor();
@@ -56,20 +52,20 @@ message* messageBuilder::construct() const
if (m_to.isEmpty() || m_to.getAddressAt(0)->isEmpty())
throw exceptions::no_recipient();
- msg->getHeader()->From().setValue(m_from);
- msg->getHeader()->To().setValue(m_to);
+ msg->getHeader()->From()->setValue(m_from);
+ msg->getHeader()->To()->setValue(m_to);
if (!m_cc.isEmpty())
- msg->getHeader()->Cc().setValue(m_cc);
+ msg->getHeader()->Cc()->setValue(m_cc);
if (!m_bcc.isEmpty())
- msg->getHeader()->Bcc().setValue(m_bcc);
+ msg->getHeader()->Bcc()->setValue(m_bcc);
// Add a "Date" field
- msg->getHeader()->Date().setValue(datetime::now());
+ msg->getHeader()->Date()->setValue(datetime::now());
// Add a "Mime-Version" header field
- msg->getHeader()->MimeVersion().setValue(string(SUPPORTED_MIME_VERSION));
+ msg->getHeader()->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));
// If there is one or more attachments (or other parts that are
// not "text/...") and if there is more than one parts for the
@@ -92,14 +88,14 @@ message* messageBuilder::construct() const
if (!m_attach.empty() && m_textPart->getPartCount() > 1)
{
// Set parent part (message) to "multipart/mixed"
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
// Create a sub-part "multipart/alternative" for text parts
- bodyPart* subPart = new bodyPart;
+ ref <bodyPart> subPart = vmime::create <bodyPart>();
msg->getBody()->appendPart(subPart);
- subPart->getHeader()->ContentType().setValue
+ subPart->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_ALTERNATIVE));
// Generate the text parts into this sub-part (normally, this
@@ -114,13 +110,13 @@ message* messageBuilder::construct() const
// If any attachment, set message content-type to "multipart/mixed"
if (!m_attach.empty())
{
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_MIXED));
}
// Else, set it to "multipart/alternative" if there are more than one text part.
else if (m_textPart->getPartCount() > 1)
{
- msg->getHeader()->ContentType().setValue
+ msg->getHeader()->ContentType()->setValue
(mediaType(mediaTypes::MULTIPART, mediaTypes::MULTIPART_ALTERNATIVE));
}
}
@@ -128,7 +124,7 @@ message* messageBuilder::construct() const
// Generate the attachments
if (!m_attach.empty())
{
- for (std::vector <attachment*>::const_iterator a = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator a = m_attach.begin() ;
a != m_attach.end() ; ++a)
{
(*a)->generateIn(*msg);
@@ -142,9 +138,9 @@ message* messageBuilder::construct() const
const bodyPart& part = *msg->getBody()->getPartAt(0);
// First, copy (and replace) the header fields
- const std::vector <const headerField*> fields = part.getHeader()->getFieldList();
+ const std::vector <ref <const headerField> > fields = part.getHeader()->getFieldList();
- for (std::vector <const headerField*>::const_iterator it = fields.begin() ;
+ for (std::vector <ref <const headerField> >::const_iterator it = fields.begin() ;
it != fields.end() ; ++it)
{
*(msg->getHeader()->getField((*it)->getName())) = **it;
@@ -159,13 +155,13 @@ message* messageBuilder::construct() const
}
-void messageBuilder::attach(attachment* attach)
+void messageBuilder::attach(ref <attachment> attach)
{
appendAttachment(attach);
}
-void messageBuilder::appendAttachment(attachment* attach)
+void messageBuilder::appendAttachment(ref <attachment> attach)
{
m_attach.push_back(attach);
}
@@ -173,7 +169,7 @@ void messageBuilder::appendAttachment(attachment* attach)
void messageBuilder::constructTextPart(const mediaType& type)
{
- textPart* part = NULL;
+ ref <textPart> part = NULL;
try
{
@@ -184,12 +180,11 @@ void messageBuilder::constructTextPart(const mediaType& type)
throw;
}
- delete (m_textPart);
m_textPart = part;
}
-textPart* messageBuilder::getTextPart()
+ref <textPart> messageBuilder::getTextPart()
{
return (m_textPart);
}
@@ -275,19 +270,17 @@ void messageBuilder::setSubject(const text& subject)
void messageBuilder::removeAttachment(const int pos)
{
- delete (m_attach[pos]);
-
m_attach.erase(m_attach.begin() + pos);
}
-const attachment* messageBuilder::getAttachmentAt(const int pos) const
+const ref <const attachment> messageBuilder::getAttachmentAt(const int pos) const
{
return (m_attach[pos]);
}
-attachment* messageBuilder::getAttachmentAt(const int pos)
+ref <attachment> messageBuilder::getAttachmentAt(const int pos)
{
return (m_attach[pos]);
}
@@ -299,13 +292,13 @@ const int messageBuilder::getAttachmentCount() const
}
-const std::vector <const attachment*> messageBuilder::getAttachmentList() const
+const std::vector <ref <const attachment> > messageBuilder::getAttachmentList() const
{
- std::vector <const attachment*> res;
+ std::vector <ref <const attachment> > res;
res.reserve(m_attach.size());
- for (std::vector <attachment*>::const_iterator it = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator it = m_attach.begin() ;
it != m_attach.end() ; ++it)
{
res.push_back(*it);
@@ -315,7 +308,7 @@ const std::vector <const attachment*> messageBuilder::getAttachmentList() const
}
-const std::vector <attachment*> messageBuilder::getAttachmentList()
+const std::vector <ref <attachment> > messageBuilder::getAttachmentList()
{
return (m_attach);
}
diff --git a/src/messageId.cpp b/src/messageId.cpp
index 9e878c2f..b8490792 100644
--- a/src/messageId.cpp
+++ b/src/messageId.cpp
@@ -129,7 +129,7 @@ void messageId::parse(const string& buffer, const string::size_type position,
}
-messageId* messageId::parseNext(const string& buffer, const string::size_type position,
+ref <messageId> messageId::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
string::size_type pos = position;
@@ -144,7 +144,7 @@ messageId* messageId::parseNext(const string& buffer, const string::size_type po
while (pos < end && !parserHelpers::isSpace(buffer[pos]))
++pos;
- messageId* mid = new messageId();
+ ref <messageId> mid = vmime::create <messageId>();
mid->parse(buffer, begin, pos, NULL);
if (newPosition != NULL)
@@ -220,9 +220,9 @@ const bool messageId::operator!=(const messageId& mid) const
}
-messageId* messageId::clone() const
+ref <component> messageId::clone() const
{
- return new messageId(*this);
+ return vmime::create <messageId>(*this);
}
@@ -266,9 +266,9 @@ void messageId::setRight(const string& right)
}
-const std::vector <const component*> messageId::getChildComponents() const
+const std::vector <ref <const component> > messageId::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/messageIdSequence.cpp b/src/messageIdSequence.cpp
index a682a29f..8683c65d 100644
--- a/src/messageIdSequence.cpp
+++ b/src/messageIdSequence.cpp
@@ -46,9 +46,9 @@ messageIdSequence::messageIdSequence(const messageIdSequence& midSeq)
}
-messageIdSequence* messageIdSequence::clone() const
+ref <component> messageIdSequence::clone() const
{
- return new messageIdSequence(*this);
+ return vmime::create <messageIdSequence>(*this);
}
@@ -59,7 +59,7 @@ void messageIdSequence::copyFrom(const component& other)
removeAllMessageIds();
for (unsigned int i = 0 ; i < midSeq.m_list.size() ; ++i)
- m_list.push_back(midSeq.m_list[i]->clone());
+ m_list.push_back(midSeq.m_list[i]->clone().dynamicCast <messageId>());
}
@@ -70,9 +70,9 @@ messageIdSequence& messageIdSequence::operator=(const messageIdSequence& other)
}
-const std::vector <const component*> messageIdSequence::getChildComponents() const
+const std::vector <ref <const component> > messageIdSequence::getChildComponents() const
{
- std::vector <const component*> res;
+ std::vector <ref <const component> > res;
copy_vector(m_list, res);
@@ -89,7 +89,7 @@ void messageIdSequence::parse(const string& buffer, const string::size_type posi
while (pos < end)
{
- messageId* parsedMid = messageId::parseNext(buffer, pos, end, &pos);
+ ref <messageId> parsedMid = messageId::parseNext(buffer, pos, end, &pos);
if (parsedMid != NULL)
m_list.push_back(parsedMid);
@@ -109,7 +109,7 @@ void messageIdSequence::generate(utility::outputStream& os, const string::size_t
if (!m_list.empty())
{
- for (std::vector <messageId*>::const_iterator it = m_list.begin() ; ; )
+ for (std::vector <ref <messageId> >::const_iterator it = m_list.begin() ; ; )
{
(*it)->generate(os, maxLineLength - 2, pos, &pos);
@@ -126,15 +126,15 @@ void messageIdSequence::generate(utility::outputStream& os, const string::size_t
}
-void messageIdSequence::appendMessageId(messageId* mid)
+void messageIdSequence::appendMessageId(ref <messageId> mid)
{
m_list.push_back(mid);
}
-void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* mid)
+void messageIdSequence::insertMessageIdBefore(ref <messageId> beforeMid, ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <messageId> >::iterator it = std::find
(m_list.begin(), m_list.end(), beforeMid);
if (it == m_list.end())
@@ -144,15 +144,15 @@ void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* m
}
-void messageIdSequence::insertMessageIdBefore(const int pos, messageId* mid)
+void messageIdSequence::insertMessageIdBefore(const int pos, ref <messageId> mid)
{
m_list.insert(m_list.begin() + pos, mid);
}
-void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid)
+void messageIdSequence::insertMessageIdAfter(ref <messageId> afterMid, ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <messageId> >::iterator it = std::find
(m_list.begin(), m_list.end(), afterMid);
if (it == m_list.end())
@@ -162,31 +162,27 @@ void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid
}
-void messageIdSequence::insertMessageIdAfter(const int pos, messageId* mid)
+void messageIdSequence::insertMessageIdAfter(const int pos, ref <messageId> mid)
{
m_list.insert(m_list.begin() + pos + 1, mid);
}
-void messageIdSequence::removeMessageId(messageId* mid)
+void messageIdSequence::removeMessageId(ref <messageId> mid)
{
- const std::vector <messageId*>::iterator it = std::find
+ const std::vector <ref <messageId> >::iterator it = std::find
(m_list.begin(), m_list.end(), mid);
if (it == m_list.end())
throw exceptions::no_such_message_id();
- delete (*it);
-
m_list.erase(it);
}
void messageIdSequence::removeMessageId(const int pos)
{
- const std::vector <messageId*>::iterator it = m_list.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <messageId> >::iterator it = m_list.begin() + pos;
m_list.erase(it);
}
@@ -194,7 +190,7 @@ void messageIdSequence::removeMessageId(const int pos)
void messageIdSequence::removeAllMessageIds()
{
- free_container(m_list);
+ m_list.clear();
}
@@ -210,25 +206,25 @@ const bool messageIdSequence::isEmpty() const
}
-messageId* messageIdSequence::getMessageIdAt(const int pos)
+const ref <messageId> messageIdSequence::getMessageIdAt(const int pos)
{
return (m_list[pos]);
}
-const messageId* messageIdSequence::getMessageIdAt(const int pos) const
+const ref <const messageId> messageIdSequence::getMessageIdAt(const int pos) const
{
return (m_list[pos]);
}
-const std::vector <const messageId*> messageIdSequence::getMessageIdList() const
+const std::vector <ref <const messageId> > messageIdSequence::getMessageIdList() const
{
- std::vector <const messageId*> list;
+ std::vector <ref <const messageId> > list;
list.reserve(m_list.size());
- for (std::vector <messageId*>::const_iterator it = m_list.begin() ;
+ for (std::vector <ref <messageId> >::const_iterator it = m_list.begin() ;
it != m_list.end() ; ++it)
{
list.push_back(*it);
@@ -238,7 +234,7 @@ const std::vector <const messageId*> messageIdSequence::getMessageIdList() const
}
-const std::vector <messageId*> messageIdSequence::getMessageIdList()
+const std::vector <ref <messageId> > messageIdSequence::getMessageIdList()
{
return (m_list);
}
diff --git a/src/messageParser.cpp b/src/messageParser.cpp
index 6ef9652a..94fec668 100644
--- a/src/messageParser.cpp
+++ b/src/messageParser.cpp
@@ -44,14 +44,6 @@ messageParser::messageParser(const message& msg)
messageParser::~messageParser()
{
- free_container(m_attach);
- free_container(m_textParts);
-
- for (std::map <attachment*, contentDispositionField*>::iterator
- it = m_attachInfo.begin() ; it != m_attachInfo.end() ; ++it)
- {
- delete ((*it).second);
- }
}
@@ -193,14 +185,15 @@ void messageParser::findAttachments(const bodyPart& part)
}
// Construct the attachment object
- attachment* attach = new defaultAttachment
- (bdy.getContents(), bdy.getEncoding(), type, description);
+ ref <attachment> attach = vmime::create <defaultAttachment>
+ (bdy.getContents()->clone().dynamicCast <contentHandler>(),
+ bdy.getEncoding(), type, description);
if (contentDispField != NULL)
{
- m_attachInfo.insert(std::map <attachment*, contentDispositionField*>::
- value_type(attach, dynamic_cast <contentDispositionField*>
- (contentDispField->clone())));
+ m_attachInfo.insert(std::map <attachment*, ref <contentDispositionField> >::
+ value_type(attach.get(), contentDispField->clone().
+ dynamicCast <contentDispositionField>()));
}
// Add the attachment to the list
@@ -242,10 +235,10 @@ void messageParser::findTextParts(const bodyPart& msg, const bodyPart& part)
if (accept)
{
- textPart* textPart = textPartFactory::getInstance()->create(type);
- textPart->parse(msg, msg, msg);
+ ref <textPart> txtPart = textPartFactory::getInstance()->create(type);
+ txtPart->parse(msg, msg, msg);
- m_textParts.push_back(textPart);
+ m_textParts.push_back(txtPart);
}
}
// Multipart message
@@ -263,20 +256,20 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
// So, wherever the text parts are, all we have to do is to find the first
// MIME part which is a text part.
- std::vector <const bodyPart*> textParts;
+ std::vector <ref <const bodyPart> > textParts;
for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i)
{
- const bodyPart& p = *part.getBody()->getPartAt(i);
+ const ref <const bodyPart> p = part.getBody()->getPartAt(i);
try
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*p.getHeader()->findField(fields::CONTENT_TYPE));
+ const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
+ (*(p->getHeader()->findField(fields::CONTENT_TYPE)));
if (ctf.getValue().getType() == mediaTypes::TEXT)
{
- textParts.push_back(&p);
+ textParts.push_back(p);
}
}
catch (exceptions::no_such_field)
@@ -288,18 +281,18 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
if (textParts.size())
{
// Okay. So we have found at least one text part
- for (std::vector <const bodyPart*>::const_iterator p = textParts.begin() ;
+ for (std::vector <ref <const bodyPart> >::const_iterator p = textParts.begin() ;
p != textParts.end() ; ++p)
{
- const contentTypeField& ctf = dynamic_cast<contentTypeField&>
- (*(*p)->getHeader()->findField(fields::CONTENT_TYPE));
+ const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
+ (*((*p)->getHeader()->findField(fields::CONTENT_TYPE)));
try
{
- textPart* textPart = textPartFactory::getInstance()->create(ctf.getValue());
- textPart->parse(msg, part, **p);
+ ref <textPart> txtPart = textPartFactory::getInstance()->create(ctf.getValue());
+ txtPart->parse(msg, part, **p);
- m_textParts.push_back(textPart);
+ m_textParts.push_back(txtPart);
}
catch (exceptions::no_factory_available& e)
{
@@ -324,10 +317,10 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
}
-const contentDispositionField* messageParser::getAttachmentInfo(const attachment* a) const
+const ref <const contentDispositionField> messageParser::getAttachmentInfo(const ref <const attachment> a) const
{
- std::map <attachment*, contentDispositionField*>::const_iterator
- it = m_attachInfo.find(const_cast <attachment*>(a));
+ std::map <attachment*, ref <contentDispositionField> >::const_iterator
+ it = m_attachInfo.find(ref <attachment>(a.constCast <attachment>()).get());
return (it != m_attachInfo.end() ? (*it).second : NULL);
}
@@ -369,13 +362,13 @@ const datetime& messageParser::getDate() const
}
-const std::vector <const attachment*> messageParser::getAttachmentList() const
+const std::vector <ref <const attachment> > messageParser::getAttachmentList() const
{
- std::vector <const attachment*> res;
+ std::vector <ref <const attachment> > res;
res.reserve(m_attach.size());
- for (std::vector <attachment*>::const_iterator it = m_attach.begin() ;
+ for (std::vector <ref <attachment> >::const_iterator it = m_attach.begin() ;
it != m_attach.end() ; ++it)
{
res.push_back(*it);
@@ -391,19 +384,19 @@ const int messageParser::getAttachmentCount() const
}
-const attachment* messageParser::getAttachmentAt(const int pos) const
+const ref <const attachment> messageParser::getAttachmentAt(const int pos) const
{
return (m_attach[pos]);
}
-const std::vector <const textPart*> messageParser::getTextPartList() const
+const std::vector <ref <const textPart> > messageParser::getTextPartList() const
{
- std::vector <const textPart*> res;
+ std::vector <ref <const textPart> > res;
res.reserve(m_textParts.size());
- for (std::vector <textPart*>::const_iterator it = m_textParts.begin() ;
+ for (std::vector <ref <textPart> >::const_iterator it = m_textParts.begin() ;
it != m_textParts.end() ; ++it)
{
res.push_back(*it);
@@ -419,7 +412,7 @@ const int messageParser::getTextPartCount() const
}
-const textPart* messageParser::getTextPartAt(const int pos) const
+const ref <const textPart> messageParser::getTextPartAt(const int pos) const
{
return (m_textParts[pos]);
}
diff --git a/src/messaging/authenticationInfos.cpp b/src/messaging/authenticationInfos.cpp
index 99044f2f..0a7c3433 100644
--- a/src/messaging/authenticationInfos.cpp
+++ b/src/messaging/authenticationInfos.cpp
@@ -31,7 +31,7 @@ authenticationInfos::authenticationInfos(const string& username, const string& p
authenticationInfos::authenticationInfos(const authenticationInfos& infos)
- : m_username(infos.m_username), m_password(infos.m_password)
+ : object(), m_username(infos.m_username), m_password(infos.m_password)
{
}
diff --git a/src/messaging/defaultAuthenticator.cpp b/src/messaging/defaultAuthenticator.cpp
index db027339..373d3c1d 100644
--- a/src/messaging/defaultAuthenticator.cpp
+++ b/src/messaging/defaultAuthenticator.cpp
@@ -18,14 +18,15 @@
//
#include "vmime/messaging/defaultAuthenticator.hpp"
+#include "vmime/messaging/session.hpp"
namespace vmime {
namespace messaging {
-defaultAuthenticator::defaultAuthenticator(const propertySet& props, const string& prefix)
- : m_props(props), m_prefix(prefix)
+defaultAuthenticator::defaultAuthenticator(weak_ref <session> sess, const string& prefix)
+ : m_session(sess), m_prefix(prefix)
{
}
@@ -33,7 +34,8 @@ defaultAuthenticator::defaultAuthenticator(const propertySet& props, const strin
const authenticationInfos defaultAuthenticator::requestAuthInfos() const
{
return (authenticationInfos
- (m_props[m_prefix + "auth.username"], m_props[m_prefix + "auth.password"]));
+ (m_session->getProperties()[m_prefix + "auth.username"],
+ m_session->getProperties()[m_prefix + "auth.password"]));
}
diff --git a/src/messaging/events.cpp b/src/messaging/events.cpp
index edc736c1..13171832 100644
--- a/src/messaging/events.cpp
+++ b/src/messaging/events.cpp
@@ -18,6 +18,7 @@
//
#include "vmime/messaging/events.hpp"
+#include "vmime/messaging/folder.hpp"
#include <algorithm>
@@ -32,7 +33,7 @@ namespace events {
//
messageCountEvent::messageCountEvent
- (folder* folder, const Types type, const std::vector <int>& nums)
+ (ref <folder> folder, const Types type, const std::vector <int>& nums)
: m_folder(folder), m_type(type)
{
m_nums.resize(nums.size());
@@ -40,7 +41,7 @@ messageCountEvent::messageCountEvent
}
-const folder* messageCountEvent::getFolder() const { return (const_cast <folder*>(m_folder)); }
+ref <const folder> messageCountEvent::getFolder() const { return (m_folder); }
const messageCountEvent::Types messageCountEvent::getType() const { return (m_type); }
const std::vector <int>& messageCountEvent::getNumbers() const { return (m_nums); }
@@ -59,7 +60,7 @@ void messageCountEvent::dispatch(messageCountListener* listener) const
//
messageChangedEvent::messageChangedEvent
- (folder* folder, const Types type, const std::vector <int>& nums)
+ (ref <folder> folder, const Types type, const std::vector <int>& nums)
: m_folder(folder), m_type(type)
{
m_nums.resize(nums.size());
@@ -67,7 +68,7 @@ messageChangedEvent::messageChangedEvent
}
-const folder* messageChangedEvent::getFolder() const { return (const_cast <folder*>(m_folder)); }
+ref <const folder> messageChangedEvent::getFolder() const { return (m_folder); }
const messageChangedEvent::Types messageChangedEvent::getType() const { return (m_type); }
const std::vector <int>& messageChangedEvent::getNumbers() const { return (m_nums); }
@@ -83,14 +84,14 @@ void messageChangedEvent::dispatch(messageChangedListener* listener) const
//
folderEvent::folderEvent
- (folder* folder, const Types type,
+ (ref <folder> folder, const Types type,
const utility::path& oldPath, const utility::path& newPath)
: m_folder(folder), m_type(type), m_oldPath(oldPath), m_newPath(newPath)
{
}
-const folder* folderEvent::getFolder() const { return (m_folder); }
+ref <const folder> folderEvent::getFolder() const { return (m_folder); }
const folderEvent::Types folderEvent::getType() const { return (m_type); }
diff --git a/src/messaging/imap/IMAPConnection.cpp b/src/messaging/imap/IMAPConnection.cpp
index 37a132de..586a1716 100644
--- a/src/messaging/imap/IMAPConnection.cpp
+++ b/src/messaging/imap/IMAPConnection.cpp
@@ -42,7 +42,7 @@ namespace messaging {
namespace imap {
-IMAPConnection::IMAPConnection(IMAPStore* store, authenticator* auth)
+IMAPConnection::IMAPConnection(weak_ref <IMAPStore> store, ref <authenticator> auth)
: m_store(store), m_auth(auth), m_socket(NULL), m_parser(NULL), m_tag(NULL),
m_hierarchySeparator('\0'), m_state(STATE_NONE), m_timeoutHandler(NULL)
{
@@ -55,9 +55,6 @@ IMAPConnection::~IMAPConnection()
disconnect();
else if (m_socket)
internalDisconnect();
-
- delete (m_tag);
- delete (m_parser);
}
@@ -89,11 +86,8 @@ void IMAPConnection::connect()
m_socket->connect(address, port);
- delete (m_tag);
- m_tag = new IMAPTag();
-
- delete (m_parser);
- m_parser = new IMAPParser(m_tag, m_socket, m_timeoutHandler);
+ m_tag = vmime::create <IMAPTag>();
+ m_parser = vmime::create <IMAPParser>(m_tag, m_socket, m_timeoutHandler);
setState(STATE_NON_AUTHENTICATED);
@@ -164,11 +158,8 @@ void IMAPConnection::internalDisconnect()
send(true, "LOGOUT", true);
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_state = STATE_LOGOUT;
@@ -179,7 +170,7 @@ void IMAPConnection::initHierarchySeparator()
{
send(true, "LIST \"\" \"\"", true);
- utility::auto_ptr <IMAPParser::response> resp(m_parser->readResponse());
+ vmime::utility::auto_ptr <IMAPParser::response> resp(m_parser->readResponse());
if (resp->isBad() || resp->response_done()->response_tagged()->
resp_cond_state()->status() != IMAPParser::resp_cond_state::OK)
@@ -284,31 +275,31 @@ const char IMAPConnection::hierarchySeparator() const
}
-const IMAPTag* IMAPConnection::getTag() const
+ref <const IMAPTag> IMAPConnection::getTag() const
{
return (m_tag);
}
-const IMAPParser* IMAPConnection::getParser() const
+ref <const IMAPParser> IMAPConnection::getParser() const
{
return (m_parser);
}
-const IMAPStore* IMAPConnection::getStore() const
+weak_ref <const IMAPStore> IMAPConnection::getStore() const
{
return (m_store);
}
-IMAPStore* IMAPConnection::getStore()
+weak_ref <IMAPStore> IMAPConnection::getStore()
{
return (m_store);
}
-session* IMAPConnection::getSession()
+ref <session> IMAPConnection::getSession()
{
return (m_store->getSession());
}
diff --git a/src/messaging/imap/IMAPFolder.cpp b/src/messaging/imap/IMAPFolder.cpp
index 35f3509b..c567c590 100644
--- a/src/messaging/imap/IMAPFolder.cpp
+++ b/src/messaging/imap/IMAPFolder.cpp
@@ -59,7 +59,7 @@ IMAPFolder::~IMAPFolder()
}
else if (m_open)
{
- delete (m_connection);
+ m_connection = NULL;
onClose();
}
}
@@ -132,8 +132,8 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
throw exceptions::illegal_state("Store disconnected");
// Open a connection for this folder
- IMAPConnection* connection =
- new IMAPConnection(m_store, m_store->oneTimeAuthenticator());
+ ref <IMAPConnection> connection =
+ vmime::create <IMAPConnection>(m_store, m_store->oneTimeAuthenticator());
try
{
@@ -263,7 +263,6 @@ void IMAPFolder::open(const int mode, bool failIfModeIsNotAvailable)
}
catch (std::exception&)
{
- delete (connection);
throw;
}
}
@@ -277,7 +276,7 @@ void IMAPFolder::close(const bool expunge)
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- IMAPConnection* oldConnection = m_connection;
+ ref <IMAPConnection> oldConnection = m_connection;
// Emit the "CLOSE" command to expunge messages marked
// as deleted (this is fastest than "EXPUNGE")
@@ -301,8 +300,6 @@ void IMAPFolder::close(const bool expunge)
m_uidValidity = 0;
onClose();
-
- delete (oldConnection);
}
@@ -358,7 +355,10 @@ void IMAPFolder::create(const int type)
}
// Notify folder created
- events::folderEvent event(this, events::folderEvent::TYPE_CREATED, m_path, m_path);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_CREATED, m_path, m_path);
+
notifyFolder(event);
}
@@ -450,7 +450,7 @@ const bool IMAPFolder::isOpen() const
}
-message* IMAPFolder::getMessage(const int num)
+ref <message> IMAPFolder::getMessage(const int num)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -458,33 +458,33 @@ message* IMAPFolder::getMessage(const int num)
if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new IMAPMessage(this, num);
+ return vmime::create <IMAPMessage>(this, num);
}
-std::vector <message*> IMAPFolder::getMessages(const int from, const int to)
+std::vector <ref <message> > IMAPFolder::getMessages(const int from, const int to)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new IMAPMessage(this, i));
+ v.push_back(vmime::create <IMAPMessage>(this, i));
return (v);
}
-std::vector <message*> IMAPFolder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > IMAPFolder::getMessages(const std::vector <int>& nums)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- v.push_back(new IMAPMessage(this, *it));
+ v.push_back(vmime::create <IMAPMessage>(this, *it));
return (v);
}
@@ -499,16 +499,16 @@ const int IMAPFolder::getMessageCount()
}
-folder* IMAPFolder::getFolder(const folder::path::component& name)
+ref <folder> IMAPFolder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new IMAPFolder(m_path / name, m_store);
+ return vmime::create <IMAPFolder>(m_path / name, m_store);
}
-std::vector <folder*> IMAPFolder::getFolders(const bool recursive)
+std::vector <ref <folder> > IMAPFolder::getFolders(const bool recursive)
{
if (!isOpen() && !m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -556,57 +556,47 @@ std::vector <folder*> IMAPFolder::getFolders(const bool recursive)
resp->continue_req_or_response_data();
- std::vector <folder*> v;
+ std::vector <ref <folder> > v;
- try
+ for (std::vector <IMAPParser::continue_req_or_response_data*>::const_iterator
+ it = respDataList.begin() ; it != respDataList.end() ; ++it)
{
- for (std::vector <IMAPParser::continue_req_or_response_data*>::const_iterator
- it = respDataList.begin() ; it != respDataList.end() ; ++it)
+ if ((*it)->response_data() == NULL)
{
- if ((*it)->response_data() == NULL)
- {
- throw exceptions::command_error("LIST",
- m_connection->getParser()->lastLine(), "invalid response");
- }
+ throw exceptions::command_error("LIST",
+ m_connection->getParser()->lastLine(), "invalid response");
+ }
- const IMAPParser::mailbox_data* mailboxData =
- (*it)->response_data()->mailbox_data();
+ const IMAPParser::mailbox_data* mailboxData =
+ (*it)->response_data()->mailbox_data();
- if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
- continue;
+ if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST)
+ continue;
- // Get folder path
- const class IMAPParser::mailbox* mailbox =
- mailboxData->mailbox_list()->mailbox();
+ // Get folder path
+ const class IMAPParser::mailbox* mailbox =
+ mailboxData->mailbox_list()->mailbox();
- folder::path path = IMAPUtils::stringToPath
- (mailboxData->mailbox_list()->quoted_char(), mailbox->name());
+ folder::path path = IMAPUtils::stringToPath
+ (mailboxData->mailbox_list()->quoted_char(), mailbox->name());
- if (recursive || m_path.isDirectParentOf(path))
- {
- // Append folder to list
- const class IMAPParser::mailbox_flag_list* mailbox_flag_list =
- mailboxData->mailbox_list()->mailbox_flag_list();
+ if (recursive || m_path.isDirectParentOf(path))
+ {
+ // Append folder to list
+ const class IMAPParser::mailbox_flag_list* mailbox_flag_list =
+ mailboxData->mailbox_list()->mailbox_flag_list();
- v.push_back(new IMAPFolder(path, m_store,
- IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
- IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
- }
+ v.push_back(vmime::create <IMAPFolder>(path, m_store,
+ IMAPUtils::folderTypeFromFlags(mailbox_flag_list),
+ IMAPUtils::folderFlagsFromFlags(mailbox_flag_list)));
}
}
- catch (std::exception&)
- {
- for (std::vector <folder*>::iterator it = v.begin() ; it != v.end() ; ++it)
- delete (*it);
-
- throw;
- }
return (v);
}
-void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
+void IMAPFolder::fetchMessages(std::vector <ref <message> >& msg, const int options,
utility::progressionListener* progress)
{
if (!m_store)
@@ -620,10 +610,10 @@ void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <IMAPMessage*>(*it)->fetch(this, options);
+ (*it).dynamicCast <IMAPMessage>()->fetch(this, options);
if (progress)
progress->progress(++current, total);
@@ -634,14 +624,14 @@ void IMAPFolder::fetchMessages(std::vector <message*>& msg, const int options,
}
-void IMAPFolder::fetchMessage(message* msg, const int options)
+void IMAPFolder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <IMAPMessage*>(msg)->fetch(this, options);
+ msg.dynamicCast <IMAPMessage>()->fetch(this, options);
}
@@ -652,19 +642,22 @@ const int IMAPFolder::getFetchCapabilities() const
}
-folder* IMAPFolder::getParent()
+ref <folder> IMAPFolder::getParent()
{
- return (m_path.isEmpty() ? NULL : new IMAPFolder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <IMAPFolder>(m_path.getParent(), m_store);
}
-const store* IMAPFolder::getStore() const
+weak_ref <const store> IMAPFolder::getStore() const
{
return (m_store);
}
-store* IMAPFolder::getStore()
+weak_ref <store> IMAPFolder::getStore()
{
return (m_store);
}
@@ -733,7 +726,9 @@ void IMAPFolder::deleteMessage(const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -794,7 +789,9 @@ void IMAPFolder::deleteMessages(const int from, const int to)
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -851,7 +848,9 @@ void IMAPFolder::deleteMessages(const std::vector <int>& nums)
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, list);
notifyMessageChanged(event);
}
@@ -937,7 +936,9 @@ void IMAPFolder::setMessageFlags(const int from, const int to, const int flags,
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -1013,7 +1014,9 @@ void IMAPFolder::setMessageFlags(const std::vector <int>& nums, const int flags,
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -1055,7 +1058,7 @@ void IMAPFolder::setMessageFlags(const string& set, const int flags, const int m
}
-void IMAPFolder::addMessage(vmime::message* msg, const int flags,
+void IMAPFolder::addMessage(ref <vmime::message> msg, const int flags,
vmime::datetime* date, utility::progressionListener* progress)
{
std::ostringstream oss;
@@ -1166,7 +1169,9 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
std::vector <int> nums;
nums.push_back(m_messageCount + 1);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
m_messageCount++;
notifyMessageCount(event);
@@ -1177,7 +1182,9 @@ void IMAPFolder::addMessage(utility::inputStream& is, const int size, const int
{
if ((*it) != this && (*it)->getFullPath() == m_path)
{
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->m_messageCount++;
(*it)->notifyMessageCount(event);
@@ -1250,7 +1257,9 @@ void IMAPFolder::expunge()
m_messageCount -= nums.size();
// Notify message expunged
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
notifyMessageCount(event);
@@ -1262,7 +1271,9 @@ void IMAPFolder::expunge()
{
(*it)->m_messageCount = m_messageCount;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1308,7 +1319,10 @@ void IMAPFolder::rename(const folder::path& newPath)
m_path = newPath;
m_name = newPath.getLastComponent();
- events::folderEvent event(this, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
notifyFolder(event);
// Notify folders with the same path and sub-folders
@@ -1320,7 +1334,10 @@ void IMAPFolder::rename(const folder::path& newPath)
(*it)->m_path = newPath;
(*it)->m_name = newPath.getLastComponent();
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
(*it)->notifyFolder(event);
}
else if ((*it) != this && oldPath.isParentOf((*it)->getFullPath()))
@@ -1329,7 +1346,10 @@ void IMAPFolder::rename(const folder::path& newPath)
(*it)->m_path.renameParent(oldPath, newPath);
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+
(*it)->notifyFolder(event);
}
}
@@ -1354,13 +1374,15 @@ void IMAPFolder::copyMessage(const folder::path& dest, const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount++;
(*it)->notifyMessageCount(event);
}
@@ -1398,13 +1420,15 @@ void IMAPFolder::copyMessages(const folder::path& dest, const int from, const in
for (int i = from, j = 0 ; i <= to2 ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount += count;
(*it)->notifyMessageCount(event);
}
@@ -1425,13 +1449,15 @@ void IMAPFolder::copyMessages(const folder::path& dest, const std::vector <int>&
// Notify message count changed
const int count = nums.size();
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
-
for (std::list <IMAPFolder*>::iterator it = m_store->m_folders.begin() ;
it != m_store->m_folders.end() ; ++it)
{
if ((*it)->getFullPath() == dest)
{
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
+
(*it)->m_messageCount += count;
(*it)->notifyMessageCount(event);
}
@@ -1545,7 +1571,9 @@ void IMAPFolder::status(int& count, int& unseen)
for (int i = oldCount + 1, j = 0 ; i <= count ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -1557,7 +1585,9 @@ void IMAPFolder::status(int& count, int& unseen)
{
(*it)->m_messageCount = count;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
diff --git a/src/messaging/imap/IMAPMessage.cpp b/src/messaging/imap/IMAPMessage.cpp
index 03af67c6..97aa2d28 100644
--- a/src/messaging/imap/IMAPMessage.cpp
+++ b/src/messaging/imap/IMAPMessage.cpp
@@ -43,17 +43,17 @@ class IMAPpart : public part
{
private:
- IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_mpart* mpart);
- IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_1part* part);
+ friend class vmime::creator;
-public:
+ IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_mpart* mpart);
+ IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_1part* part);
- ~IMAPpart();
+public:
const structure& getStructure() const;
structure& getStructure();
- const IMAPpart* getParent() const { return (m_parent); }
+ weak_ref <const IMAPpart> getParent() const { return (m_parent); }
const mediaType& getType() const { return (m_mediaType); }
const int getSize() const { return (m_size); }
@@ -68,12 +68,13 @@ public:
}
- static IMAPpart* create(IMAPpart* parent, const int number, const IMAPParser::body* body)
+ static ref <IMAPpart> create
+ (weak_ref <IMAPpart> parent, const int number, const IMAPParser::body* body)
{
if (body->body_type_mpart())
- return new IMAPpart(parent, number, body->body_type_mpart());
+ return vmime::create <IMAPpart>(parent, number, body->body_type_mpart());
else
- return new IMAPpart(parent, number, body->body_type_1part());
+ return vmime::create <IMAPpart>(parent, number, body->body_type_1part());
}
@@ -82,14 +83,14 @@ public:
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
private:
- IMAPstructure* m_structure;
- IMAPpart* m_parent;
- header* m_header;
+ ref <IMAPstructure> m_structure;
+ weak_ref <IMAPpart> m_parent;
+ ref <header> m_header;
int m_number;
int m_size;
@@ -117,7 +118,7 @@ public:
m_parts.push_back(IMAPpart::create(NULL, 1, body));
}
- IMAPstructure(IMAPpart* parent, const std::vector <IMAPParser::body*>& list)
+ IMAPstructure(weak_ref <IMAPpart> parent, const std::vector <IMAPParser::body*>& list)
{
int number = 1;
@@ -128,11 +129,6 @@ public:
}
}
- ~IMAPstructure()
- {
- free_container(m_parts);
- }
-
const part& operator[](const int x) const
{
@@ -159,7 +155,7 @@ private:
static IMAPstructure m_emptyStructure;
- std::vector <IMAPpart*> m_parts;
+ std::vector <ref <IMAPpart> > m_parts;
};
@@ -167,17 +163,18 @@ IMAPstructure IMAPstructure::m_emptyStructure;
-IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_mpart* mpart)
+IMAPpart::IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_mpart* mpart)
: m_parent(parent), m_header(NULL), m_number(number), m_size(0)
{
m_mediaType = vmime::mediaType
("multipart", mpart->media_subtype()->value());
- m_structure = new IMAPstructure(this, mpart->list());
+ m_structure = vmime::create <IMAPstructure>
+ (thisWeakRef().dynamicCast <IMAPpart>(), mpart->list());
}
-IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_1part* part)
+IMAPpart::IMAPpart(weak_ref <IMAPpart> parent, const int number, const IMAPParser::body_type_1part* part)
: m_parent(parent), m_header(NULL), m_number(number), m_size(0)
{
if (part->body_type_text())
@@ -207,13 +204,6 @@ IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_ty
}
-IMAPpart::~IMAPpart()
-{
- delete (m_structure);
- delete (m_header);
-}
-
-
const class structure& IMAPpart::getStructure() const
{
if (m_structure != NULL)
@@ -292,8 +282,6 @@ IMAPMessage::~IMAPMessage()
{
if (m_folder)
m_folder->unregisterMessage(this);
-
- delete dynamic_cast <header*>(m_header);
}
@@ -597,62 +585,61 @@ void IMAPMessage::processFetchResponse
vmime::header& hdr = getOrCreateHeader();
// Date
- hdr.Date().setValue(env->env_date()->value());
+ hdr.Date()->setValue(env->env_date()->value());
// Subject
text subject;
text::decodeAndUnfold(env->env_subject()->value(), &subject);
- hdr.Subject().setValue(subject);
+ hdr.Subject()->setValue(subject);
// From
mailboxList from;
convertAddressList(*(env->env_from()), from);
if (!from.isEmpty())
- hdr.From().setValue(*(from.getMailboxAt(0)));
+ hdr.From()->setValue(*(from.getMailboxAt(0)));
// To
mailboxList to;
convertAddressList(*(env->env_to()), to);
- hdr.To().setValue(to);
+ hdr.To()->setValue(to);
// Sender
mailboxList sender;
convertAddressList(*(env->env_sender()), sender);
if (!sender.isEmpty())
- hdr.Sender().setValue(*(sender.getMailboxAt(0)));
+ hdr.Sender()->setValue(*(sender.getMailboxAt(0)));
// Reply-to
mailboxList replyTo;
convertAddressList(*(env->env_reply_to()), replyTo);
if (!replyTo.isEmpty())
- hdr.ReplyTo().setValue(*(replyTo.getMailboxAt(0)));
+ hdr.ReplyTo()->setValue(*(replyTo.getMailboxAt(0)));
// Cc
mailboxList cc;
convertAddressList(*(env->env_cc()), cc);
if (!cc.isEmpty())
- hdr.Cc().setValue(cc);
+ hdr.Cc()->setValue(cc);
// Bcc
mailboxList bcc;
convertAddressList(*(env->env_bcc()), bcc);
if (!bcc.isEmpty())
- hdr.Bcc().setValue(bcc);
+ hdr.Bcc()->setValue(bcc);
}
break;
}
case IMAPParser::msg_att_item::BODY_STRUCTURE:
{
- delete (m_structure);
- m_structure = new IMAPstructure((*it)->body());
+ m_structure = vmime::create <IMAPstructure>((*it)->body());
break;
}
case IMAPParser::msg_att_item::RFC822_HEADER:
@@ -677,12 +664,12 @@ void IMAPMessage::processFetchResponse
tempHeader.parse((*it)->nstring()->value());
vmime::header& hdr = getOrCreateHeader();
- std::vector <headerField*> fields = tempHeader.getFieldList();
+ std::vector <ref <headerField> > fields = tempHeader.getFieldList();
- for (std::vector <headerField*>::const_iterator jt = fields.begin() ;
+ for (std::vector <ref <headerField> >::const_iterator jt = fields.begin() ;
jt != fields.end() ; ++jt)
{
- hdr.appendField((*jt)->clone());
+ hdr.appendField((*jt)->clone().dynamicCast <headerField>());
}
}
}
@@ -710,7 +697,7 @@ header& IMAPMessage::getOrCreateHeader()
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
@@ -728,7 +715,7 @@ void IMAPMessage::convertAddressList
string email = addr.addr_mailbox()->value()
+ "@" + addr.addr_host()->value();
- dest.appendMailbox(new mailbox(name, email));
+ dest.appendMailbox(vmime::create <mailbox>(name, email));
}
}
@@ -829,7 +816,9 @@ void IMAPMessage::setFlags(const int flags, const int mode)
std::vector <int> nums;
nums.push_back(m_num);
- events::messageChangedEvent event(m_folder, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (m_folder->thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
for (std::list <IMAPFolder*>::iterator it = m_folder->m_store->m_folders.begin() ;
it != m_folder->m_store->m_folders.end() ; ++it)
diff --git a/src/messaging/imap/IMAPStore.cpp b/src/messaging/imap/IMAPStore.cpp
index 07b22351..00ef98f2 100644
--- a/src/messaging/imap/IMAPStore.cpp
+++ b/src/messaging/imap/IMAPStore.cpp
@@ -45,28 +45,27 @@ class IMAPauthenticator : public authenticator
{
public:
- IMAPauthenticator(authenticator* auth)
+ IMAPauthenticator(ref <authenticator> auth)
: m_auth(auth), m_infos(NULL)
{
}
~IMAPauthenticator()
{
- delete (m_infos);
}
const authenticationInfos requestAuthInfos() const
{
if (m_infos == NULL)
- m_infos = new authenticationInfos(m_auth->requestAuthInfos());
+ m_infos = vmime::create <authenticationInfos>(m_auth->requestAuthInfos());
return (*m_infos);
}
private:
- authenticator* m_auth;
- mutable authenticationInfos* m_infos;
+ ref <authenticator> m_auth;
+ mutable ref <authenticationInfos> m_infos;
};
#endif // VMIME_BUILDING_DOC
@@ -77,7 +76,7 @@ private:
// IMAPStore
//
-IMAPStore::IMAPStore(session* sess, authenticator* auth)
+IMAPStore::IMAPStore(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth),
m_connection(NULL), m_oneTimeAuth(NULL)
{
@@ -91,7 +90,7 @@ IMAPStore::~IMAPStore()
}
-authenticator* IMAPStore::oneTimeAuthenticator()
+ref <authenticator> IMAPStore::oneTimeAuthenticator()
{
return (m_oneTimeAuth);
}
@@ -103,30 +102,30 @@ const string IMAPStore::getProtocolName() const
}
-folder* IMAPStore::getRootFolder()
+ref <folder> IMAPStore::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(folder::path(), this);
+ return vmime::create <IMAPFolder>(folder::path(), this);
}
-folder* IMAPStore::getDefaultFolder()
+ref <folder> IMAPStore::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(folder::path::component("INBOX"), this);
+ return vmime::create <IMAPFolder>(folder::path::component("INBOX"), this);
}
-folder* IMAPStore::getFolder(const folder::path& path)
+ref <folder> IMAPStore::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new IMAPFolder(path, this);
+ return vmime::create <IMAPFolder>(path, this);
}
@@ -141,9 +140,10 @@ void IMAPStore::connect()
if (isConnected())
throw exceptions::already_connected();
- m_oneTimeAuth = new IMAPauthenticator(getAuthenticator());
+ m_oneTimeAuth = vmime::create <IMAPauthenticator>(getAuthenticator());
- m_connection = new IMAPConnection(this, m_oneTimeAuth);
+ m_connection = vmime::create <IMAPConnection>
+ (thisWeakRef().dynamicCast <IMAPStore>(), m_oneTimeAuth);
try
{
@@ -151,7 +151,6 @@ void IMAPStore::connect()
}
catch (std::exception&)
{
- delete (m_connection);
m_connection = NULL;
throw;
}
@@ -180,10 +179,8 @@ void IMAPStore::disconnect()
m_connection->disconnect();
- delete (m_oneTimeAuth);
m_oneTimeAuth = NULL;
- delete (m_connection);
m_connection = NULL;
}
@@ -205,7 +202,7 @@ void IMAPStore::noop()
}
-IMAPConnection* IMAPStore::connection()
+ref <IMAPConnection> IMAPStore::connection()
{
return (m_connection);
}
diff --git a/src/messaging/imap/IMAPTag.cpp b/src/messaging/imap/IMAPTag.cpp
index bc6b656d..c1cf659d 100644
--- a/src/messaging/imap/IMAPTag.cpp
+++ b/src/messaging/imap/IMAPTag.cpp
@@ -36,7 +36,7 @@ IMAPTag::IMAPTag(const int number)
IMAPTag::IMAPTag(const IMAPTag& tag)
- : m_number(tag.m_number)
+ : object(), m_number(tag.m_number)
{
m_tag.resize(4);
}
diff --git a/src/messaging/maildir/maildirFolder.cpp b/src/messaging/maildir/maildirFolder.cpp
index fa337d09..d24ab5e5 100644
--- a/src/messaging/maildir/maildirFolder.cpp
+++ b/src/messaging/maildir/maildirFolder.cpp
@@ -36,7 +36,7 @@ namespace messaging {
namespace maildir {
-maildirFolder::maildirFolder(const folder::path& path, maildirStore* store)
+maildirFolder::maildirFolder(const folder::path& path, weak_ref <maildirStore> store)
: m_store(store), m_path(path),
m_name(path.isEmpty() ? folder::path::component("") : path.getLastComponent()),
m_mode(-1), m_open(false), m_unreadMessageCount(0), m_messageCount(0)
@@ -91,14 +91,14 @@ const int maildirFolder::getFlags()
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
- utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
+ ref <utility::fileIterator> it = rootDir->getFiles();
while (it->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = it->nextElement();
+ ref <utility::file> file = it->nextElement();
if (maildirUtils::isSubfolderDirectory(*file))
{
@@ -204,14 +204,14 @@ void maildirFolder::create(const int /* type */)
if (!fsf->isValidPath(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT)))
throw exceptions::invalid_folder_name();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> newDir = fsf->create
+ ref <utility::file> newDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW));
- utility::auto_ptr <utility::file> tmpDir = fsf->create
+ ref <utility::file> tmpDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP));
- utility::auto_ptr <utility::file> curDir = fsf->create
+ ref <utility::file> curDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CUR));
rootDir->createDirectory(true);
@@ -226,7 +226,10 @@ void maildirFolder::create(const int /* type */)
}
// Notify folder created
- events::folderEvent event(this, events::folderEvent::TYPE_CREATED, m_path, m_path);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_CREATED, m_path, m_path);
+
notifyFolder(event);
}
@@ -235,14 +238,14 @@ const bool maildirFolder::exists()
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> newDir = fsf->create
+ ref <utility::file> newDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW));
- utility::auto_ptr <utility::file> tmpDir = fsf->create
+ ref <utility::file> tmpDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP));
- utility::auto_ptr <utility::file> curDir = fsf->create
+ ref <utility::file> curDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CUR));
return (rootDir->exists() && rootDir->isDirectory() &&
@@ -269,40 +272,36 @@ void maildirFolder::scanFolder()
utility::file::path newDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_NEW);
- utility::auto_ptr <utility::file> newDir = fsf->create(newDirPath);
+ ref <utility::file> newDir = fsf->create(newDirPath);
utility::file::path curDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_CUR);
- utility::auto_ptr <utility::file> curDir = fsf->create(curDirPath);
+ ref <utility::file> curDir = fsf->create(curDirPath);
// New received messages (new/)
- utility::fileIterator* nit = newDir->getFiles();
+ ref <utility::fileIterator> nit = newDir->getFiles();
std::vector <utility::file::path::component> newMessageFilenames;
while (nit->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = nit->nextElement();
+ ref <utility::file> file = nit->nextElement();
if (maildirUtils::isMessageFile(*file))
newMessageFilenames.push_back(file->getFullPath().getLastComponent());
}
- delete (nit); // Free directory
-
// Current messages (cur/)
- utility::fileIterator* cit = curDir->getFiles();
+ ref <utility::fileIterator> cit = curDir->getFiles();
std::vector <utility::file::path::component> curMessageFilenames;
while (cit->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = cit->nextElement();
+ ref <utility::file> file = cit->nextElement();
if (maildirUtils::isMessageFile(*file))
curMessageFilenames.push_back(file->getFullPath().getLastComponent());
}
- delete (cit); // Free directory
-
// Update/delete existing messages (found in previous scan)
for (unsigned int i = 0 ; i < m_messageInfos.size() ; ++i)
{
@@ -347,7 +346,7 @@ void maildirFolder::scanFolder()
maildirUtils::buildFilename(maildirUtils::extractId(*it), 0);
// Move messages from 'new' to 'cur'
- utility::auto_ptr <utility::file> file = fsf->create(newDirPath / *it);
+ ref <utility::file> file = fsf->create(newDirPath / *it);
file->rename(curDirPath / newFilename);
// Append to message list
@@ -391,7 +390,7 @@ void maildirFolder::scanFolder()
}
-message* maildirFolder::getMessage(const int num)
+ref <message> maildirFolder::getMessage(const int num)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
@@ -399,33 +398,40 @@ message* maildirFolder::getMessage(const int num)
if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new maildirMessage(this, num);
+ return vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), num);
}
-std::vector <message*> maildirFolder::getMessages(const int from, const int to)
+std::vector <ref <message> > maildirFolder::getMessages(const int from, const int to)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new maildirMessage(this, i));
+ {
+ v.push_back(vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), i));
+ }
return (v);
}
-std::vector <message*> maildirFolder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > maildirFolder::getMessages(const std::vector <int>& nums)
{
if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- v.push_back(new maildirMessage(this, *it));
+ {
+ v.push_back(vmime::create <maildirMessage>
+ (thisWeakRef().dynamicCast <maildirFolder>(), *it));
+ }
return (v);
}
@@ -437,68 +443,54 @@ const int maildirFolder::getMessageCount()
}
-folder* maildirFolder::getFolder(const folder::path::component& name)
+ref <folder> maildirFolder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new maildirFolder(m_path / name, m_store);
+ return vmime::create <maildirFolder>(m_path / name, m_store);
}
-std::vector <folder*> maildirFolder::getFolders(const bool recursive)
+std::vector <ref <folder> > maildirFolder::getFolders(const bool recursive)
{
if (!isOpen() && !m_store)
throw exceptions::illegal_state("Store disconnected");
- std::vector <folder*> list;
+ std::vector <ref <folder> > list;
- try
- {
- listFolders(list, recursive);
- }
- catch (std::exception&)
- {
- for (std::vector <folder*>::iterator it = list.begin() ; it != list.end() ; ++it)
- delete (*it);
-
- throw;
- }
- catch (vmime::exception&)
- {
- for (std::vector <folder*>::iterator it = list.begin() ; it != list.end() ; ++it)
- delete (*it);
-
- throw;
- }
+ listFolders(list, recursive);
return (list);
}
-void maildirFolder::listFolders(std::vector <folder*>& list, const bool recursive)
+void maildirFolder::listFolders(std::vector <ref <folder> >& list, const bool recursive)
{
try
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path,
m_path.isEmpty() ? maildirUtils::FOLDER_PATH_ROOT
: maildirUtils::FOLDER_PATH_CONTAINER));
if (rootDir->exists())
{
- utility::auto_ptr <utility::fileIterator> it = rootDir->getFiles();
+ ref <utility::fileIterator> it = rootDir->getFiles();
while (it->hasMoreElements())
{
- utility::auto_ptr <utility::file> file = it->nextElement();
+ ref <utility::file> file = it->nextElement();
if (maildirUtils::isSubfolderDirectory(*file))
{
- const utility::path subPath = m_path / file->getFullPath().getLastComponent();
- maildirFolder* subFolder = new maildirFolder(subPath, m_store);
+ const utility::path subPath =
+ m_path / file->getFullPath().getLastComponent();
+
+ ref <maildirFolder> subFolder =
+ vmime::create <maildirFolder>(subPath, m_store);
list.push_back(subFolder);
@@ -531,9 +523,9 @@ void maildirFolder::rename(const folder::path& newPath)
// Rename the directory on the file system
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> rootDir = fsf->create
+ ref <utility::file> rootDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT));
- utility::auto_ptr <utility::file> contDir = fsf->create
+ ref <utility::file> contDir = fsf->create
(maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER));
try
@@ -582,7 +574,10 @@ void maildirFolder::rename(const folder::path& newPath)
m_path = newPath;
m_name = newPath.getLastComponent();
- events::folderEvent event(this, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
notifyFolder(event);
// Notify folders with the same path
@@ -594,7 +589,10 @@ void maildirFolder::rename(const folder::path& newPath)
(*it)->m_path = newPath;
(*it)->m_name = newPath.getLastComponent();
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, newPath);
+
(*it)->notifyFolder(event);
}
else if ((*it) != this && oldPath.isParentOf((*it)->getFullPath()))
@@ -603,7 +601,10 @@ void maildirFolder::rename(const folder::path& newPath)
(*it)->m_path.renameParent(oldPath, newPath);
- events::folderEvent event(*it, events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+ events::folderEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::folderEvent::TYPE_RENAMED, oldPath, (*it)->m_path);
+
(*it)->notifyFolder(event);
}
}
@@ -707,9 +708,13 @@ void maildirFolder::setMessageFlags
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
+
+ // TODO: notify other folders with the same path
}
@@ -784,9 +789,13 @@ void maildirFolder::setMessageFlags
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
+
+ // TODO: notify other folders with the same path
}
@@ -806,7 +815,7 @@ void maildirFolder::setMessageFlagsImpl
try
{
const utility::file::path::component path = m_messageInfos[num].path;
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / path);
+ ref <utility::file> file = fsf->create(curDirPath / path);
int newFlags = maildirUtils::extractFlags(path);
@@ -838,7 +847,7 @@ void maildirFolder::setMessageFlagsImpl
}
-void maildirFolder::addMessage(vmime::message* msg, const int flags,
+void maildirFolder::addMessage(ref <vmime::message> msg, const int flags,
vmime::datetime* date, utility::progressionListener* progress)
{
std::ostringstream oss;
@@ -876,7 +885,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
try
{
- utility::auto_ptr <utility::file> tmpDir = fsf->create(tmpDirPath);
+ ref <utility::file> tmpDir = fsf->create(tmpDirPath);
tmpDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -886,7 +895,7 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
try
{
- utility::auto_ptr <utility::file> curDir = fsf->create(curDirPath);
+ ref <utility::file> curDir = fsf->create(curDirPath);
curDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -912,7 +921,9 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
std::vector <int> nums;
nums.push_back(m_messageCount);
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -928,7 +939,9 @@ void maildirFolder::addMessage(utility::inputStream& is, const int size,
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
@@ -943,7 +956,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
{
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
if (progress)
progress->start(size);
@@ -953,8 +966,8 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
{
file->createFile();
- utility::auto_ptr <utility::fileWriter> fw = file->getFileWriter();
- utility::auto_ptr <utility::outputStream> os = fw->getOutputStream();
+ ref <utility::fileWriter> fw = file->getFileWriter();
+ ref <utility::outputStream> os = fw->getOutputStream();
utility::stream::value_type buffer[65536];
utility::stream::size_type total = 0;
@@ -981,7 +994,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
// Delete temporary file
try
{
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
file->remove();
}
catch (exceptions::filesystem_exception&)
@@ -1005,7 +1018,7 @@ void maildirFolder::copyMessageImpl(const utility::file::path& tmpDirPath,
// Delete temporary file
try
{
- utility::auto_ptr <utility::file> file = fsf->create(tmpDirPath / filename);
+ ref <utility::file> file = fsf->create(tmpDirPath / filename);
file->remove();
}
catch (exceptions::filesystem_exception&)
@@ -1083,7 +1096,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
// Create destination directories
try
{
- utility::auto_ptr <utility::file> destTmpDir = fsf->create(destTmpDirPath);
+ ref <utility::file> destTmpDir = fsf->create(destTmpDirPath);
destTmpDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -1093,7 +1106,7 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
try
{
- utility::auto_ptr <utility::file> destCurDir = fsf->create(destCurDirPath);
+ ref <utility::file> destCurDir = fsf->create(destCurDirPath);
destCurDir->createDirectory(true);
}
catch (exceptions::filesystem_exception&)
@@ -1114,9 +1127,9 @@ void maildirFolder::copyMessagesImpl(const folder::path& dest, const std::vector
const utility::file::path::component filename =
maildirUtils::buildFilename(maildirUtils::generateId(), flags);
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / msg.path);
- utility::auto_ptr <utility::fileReader> fr = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = fr->getInputStream();
+ ref <utility::file> file = fsf->create(curDirPath / msg.path);
+ ref <utility::fileReader> fr = file->getFileReader();
+ ref <utility::inputStream> is = fr->getInputStream();
copyMessageImpl(destTmpDirPath, destCurDirPath,
filename, *is, file->getLength(), NULL);
@@ -1168,7 +1181,9 @@ void maildirFolder::status(int& count, int& unseen)
for (int i = oldCount + 1, j = 0 ; i <= count ; ++i, ++j)
nums[j] = i;
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -1184,7 +1199,9 @@ void maildirFolder::status(int& count, int& unseen)
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1233,7 +1250,7 @@ void maildirFolder::expunge()
// Delete file from file system
try
{
- utility::auto_ptr <utility::file> file = fsf->create(curDirPath / infos.path);
+ ref <utility::file> file = fsf->create(curDirPath / infos.path);
file->remove();
}
catch (exceptions::filesystem_exception& e)
@@ -1253,7 +1270,9 @@ void maildirFolder::expunge()
m_unreadMessageCount -= unreadCount;
// Notify message expunged
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
notifyMessageCount(event);
@@ -1269,7 +1288,9 @@ void maildirFolder::expunge()
(*it)->m_messageInfos.resize(m_messageInfos.size());
std::copy(m_messageInfos.begin(), m_messageInfos.end(), (*it)->m_messageInfos.begin());
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_REMOVED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_REMOVED, nums);
(*it)->notifyMessageCount(event);
}
@@ -1277,25 +1298,28 @@ void maildirFolder::expunge()
}
-folder* maildirFolder::getParent()
+ref <folder> maildirFolder::getParent()
{
- return (m_path.isEmpty() ? NULL : new maildirFolder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <maildirFolder>(m_path.getParent(), m_store);
}
-const store* maildirFolder::getStore() const
+weak_ref <const store> maildirFolder::getStore() const
{
return (m_store);
}
-store* maildirFolder::getStore()
+weak_ref <store> maildirFolder::getStore()
{
return (m_store);
}
-void maildirFolder::fetchMessages(std::vector <message*>& msg,
+void maildirFolder::fetchMessages(std::vector <ref <message> >& msg,
const int options, utility::progressionListener* progress)
{
if (!m_store)
@@ -1309,10 +1333,12 @@ void maildirFolder::fetchMessages(std::vector <message*>& msg,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ weak_ref <maildirFolder> _this = thisWeakRef().dynamicCast <maildirFolder>();
+
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <maildirMessage*>(*it)->fetch(this, options);
+ (*it).dynamicCast <maildirMessage>()->fetch(_this, options);
if (progress)
progress->progress(++current, total);
@@ -1323,14 +1349,15 @@ void maildirFolder::fetchMessages(std::vector <message*>& msg,
}
-void maildirFolder::fetchMessage(message* msg, const int options)
+void maildirFolder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <maildirMessage*>(msg)->fetch(this, options);
+ msg.dynamicCast <maildirMessage>()->fetch
+ (thisWeakRef().dynamicCast <maildirFolder>(), options);
}
@@ -1341,7 +1368,7 @@ const int maildirFolder::getFetchCapabilities() const
}
-const utility::file::path maildirFolder::getMessageFSPath(const int number)
+const utility::file::path maildirFolder::getMessageFSPath(const int number) const
{
utility::file::path curDirPath = maildirUtils::getFolderFSPath
(m_store, m_path, maildirUtils::FOLDER_PATH_CUR);
diff --git a/src/messaging/maildir/maildirMessage.cpp b/src/messaging/maildir/maildirMessage.cpp
index e9042979..408b27c8 100644
--- a/src/messaging/maildir/maildirMessage.cpp
+++ b/src/messaging/maildir/maildirMessage.cpp
@@ -20,6 +20,7 @@
#include "vmime/messaging/maildir/maildirMessage.hpp"
#include "vmime/messaging/maildir/maildirFolder.hpp"
#include "vmime/messaging/maildir/maildirUtils.hpp"
+#include "vmime/messaging/maildir/maildirStore.hpp"
#include "vmime/message.hpp"
@@ -42,14 +43,14 @@ class maildirPart : public part
{
public:
- maildirPart(maildirPart* parent, const int number, const bodyPart& part);
+ maildirPart(weak_ref <maildirPart> parent, const int number, const bodyPart& part);
~maildirPart();
const structure& getStructure() const;
structure& getStructure();
- const maildirPart* getParent() const { return (m_parent); }
+ weak_ref <const maildirPart> getParent() const { return (m_parent); }
const mediaType& getType() const { return (m_mediaType); }
const int getSize() const { return (m_size); }
@@ -68,7 +69,7 @@ public:
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
const int getHeaderParsedOffset() const { return (m_headerParsedOffset); }
@@ -79,9 +80,9 @@ public:
private:
- maildirStructure* m_structure;
- maildirPart* m_parent;
- header* m_header;
+ ref <maildirStructure> m_structure;
+ weak_ref <maildirPart> m_parent;
+ ref <header> m_header;
int m_number;
int m_size;
@@ -110,22 +111,17 @@ private:
public:
- maildirStructure(maildirPart* parent, const bodyPart& part)
+ maildirStructure(weak_ref <maildirPart> parent, const bodyPart& part)
{
- m_parts.push_back(new maildirPart(parent, 1, part));
+ m_parts.push_back(vmime::create <maildirPart>(parent, 1, part));
}
- maildirStructure(maildirPart* parent, const std::vector <const vmime::bodyPart*>& list)
+ maildirStructure(weak_ref <maildirPart> parent, const std::vector <ref <const vmime::bodyPart> >& list)
{
int number = 1;
for (unsigned int i = 0 ; i < list.size() ; ++i)
- m_parts.push_back(new maildirPart(parent, number, *list[i]));
- }
-
- ~maildirStructure()
- {
- free_container(m_parts);
+ m_parts.push_back(vmime::create <maildirPart>(parent, number, *list[i]));
}
@@ -154,7 +150,7 @@ private:
static maildirStructure m_emptyStructure;
- std::vector <maildirPart*> m_parts;
+ std::vector <ref <maildirPart> > m_parts;
};
@@ -162,13 +158,17 @@ maildirStructure maildirStructure::m_emptyStructure;
-maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart& part)
+maildirPart::maildirPart(weak_ref <maildirPart> parent, const int number, const bodyPart& part)
: m_parent(parent), m_header(NULL), m_number(number)
{
if (part.getBody()->getPartList().size() == 0)
m_structure = NULL;
else
- m_structure = new maildirStructure(this, part.getBody()->getPartList());
+ {
+ m_structure = vmime::create <maildirStructure>
+ (thisWeakRef().dynamicCast <maildirPart>(),
+ part.getBody()->getPartList());
+ }
m_headerParsedOffset = part.getHeader()->getParsedOffset();
m_headerParsedLength = part.getHeader()->getParsedLength();
@@ -176,7 +176,7 @@ maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart&
m_bodyParsedOffset = part.getBody()->getParsedOffset();
m_bodyParsedLength = part.getBody()->getParsedLength();
- m_size = part.getBody()->getContents().getLength();
+ m_size = part.getBody()->getContents()->getLength();
m_mediaType = part.getBody()->getContentType();
}
@@ -184,8 +184,6 @@ maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart&
maildirPart::~maildirPart()
{
- delete (m_structure);
- delete (m_header);
}
@@ -212,7 +210,7 @@ structure& maildirPart::getStructure()
// maildirMessage
//
-maildirMessage::maildirMessage(maildirFolder* folder, const int num)
+maildirMessage::maildirMessage(weak_ref <maildirFolder> folder, const int num)
: m_folder(folder), m_num(num), m_size(-1), m_flags(FLAG_UNDEFINED),
m_expunged(false), m_header(NULL), m_structure(NULL)
{
@@ -224,9 +222,6 @@ maildirMessage::~maildirMessage()
{
if (m_folder)
m_folder->unregisterMessage(this);
-
- delete (m_header);
- delete (m_structure);
}
@@ -334,10 +329,10 @@ void maildirMessage::extractImpl(utility::outputStream& os, utility::progression
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = m_folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
is->skip(start + partialStart);
@@ -379,10 +374,10 @@ void maildirMessage::fetchPartHeader(part& p)
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = m_folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
is->skip(mp.getHeaderParsedOffset());
@@ -406,7 +401,7 @@ void maildirMessage::fetchPartHeader(part& p)
}
-void maildirMessage::fetch(maildirFolder* folder, const int options)
+void maildirMessage::fetch(weak_ref <maildirFolder> folder, const int options)
{
if (m_folder != folder)
throw exceptions::folder_not_found();
@@ -414,7 +409,7 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory();
const utility::file::path path = folder->getMessageFSPath(m_num);
- utility::auto_ptr <utility::file> file = fsf->create(path);
+ ref <utility::file> file = fsf->create(path);
if (options & folder::FETCH_FLAGS)
m_flags = maildirUtils::extractFlags(path.getLastComponent());
@@ -430,8 +425,8 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
{
string contents;
- utility::auto_ptr <utility::fileReader> reader = file->getFileReader();
- utility::auto_ptr <utility::inputStream> is = reader->getInputStream();
+ ref <utility::fileReader> reader = file->getFileReader();
+ ref <utility::inputStream> is = reader->getInputStream();
// Need whole message contents for structure
if (options & folder::FETCH_STRUCTURE)
@@ -480,10 +475,7 @@ void maildirMessage::fetch(maildirFolder* folder, const int options)
// Extract structure
if (options & folder::FETCH_STRUCTURE)
{
- if (m_structure)
- delete (m_structure);
-
- m_structure = new maildirStructure(NULL, msg);
+ m_structure = vmime::create <maildirStructure>(null, msg);
}
// Extract some header fields or whole header
@@ -502,7 +494,7 @@ header& maildirMessage::getOrCreateHeader()
if (m_header != NULL)
return (*m_header);
else
- return (*(m_header = new header()));
+ return (*(m_header = vmime::create <header>()));
}
diff --git a/src/messaging/maildir/maildirStore.cpp b/src/messaging/maildir/maildirStore.cpp
index 87204299..ccbd35a4 100644
--- a/src/messaging/maildir/maildirStore.cpp
+++ b/src/messaging/maildir/maildirStore.cpp
@@ -39,7 +39,7 @@ namespace messaging {
namespace maildir {
-maildirStore::maildirStore(session* sess, authenticator* auth)
+maildirStore::maildirStore(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth), m_connected(false)
{
}
@@ -58,30 +58,33 @@ const string maildirStore::getProtocolName() const
}
-folder* maildirStore::getRootFolder()
+ref <folder> maildirStore::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(folder::path(), this);
+ return vmime::create <maildirFolder>(folder::path(),
+ thisWeakRef().dynamicCast <maildirStore>());
}
-folder* maildirStore::getDefaultFolder()
+ref <folder> maildirStore::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(folder::path::component("inbox"), this);
+ return vmime::create <maildirFolder>(folder::path::component("inbox"),
+ thisWeakRef().dynamicCast <maildirStore>());
}
-folder* maildirStore::getFolder(const folder::path& path)
+ref <folder> maildirStore::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new maildirFolder(path, this);
+ return vmime::create <maildirFolder>(path,
+ thisWeakRef().dynamicCast <maildirStore>());
}
@@ -117,7 +120,7 @@ void maildirStore::connect()
m_fsPath = fsf->stringToPath(GET_PROPERTY(string, PROPERTY_SERVER_ROOTPATH));
- utility::auto_ptr <utility::file> rootDir = fsf->create(m_fsPath);
+ ref <utility::file> rootDir = fsf->create(m_fsPath);
// Try to create the root directory if it does not exist
if (!(rootDir->exists() && rootDir->isDirectory()))
diff --git a/src/messaging/maildir/maildirUtils.cpp b/src/messaging/maildir/maildirUtils.cpp
index 091fd871..9e411cd6 100644
--- a/src/messaging/maildir/maildirUtils.cpp
+++ b/src/messaging/maildir/maildirUtils.cpp
@@ -34,7 +34,7 @@ const vmime::word maildirUtils::NEW_DIR("new", vmime::charset(vmime::charsets::U
const utility::file::path maildirUtils::getFolderFSPath
- (maildirStore* store, const utility::path& folderPath, const FolderFSPathMode mode)
+ (weak_ref <maildirStore> store, const utility::path& folderPath, const FolderFSPathMode mode)
{
// Root path
utility::file::path path(store->getFileSystemPath());
diff --git a/src/messaging/pop3/POP3Folder.cpp b/src/messaging/pop3/POP3Folder.cpp
index 6f4cb237..0f0a5369 100644
--- a/src/messaging/pop3/POP3Folder.cpp
+++ b/src/messaging/pop3/POP3Folder.cpp
@@ -191,7 +191,7 @@ const bool POP3Folder::isOpen() const
}
-message* POP3Folder::getMessage(const int num)
+ref <message> POP3Folder::getMessage(const int num)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -200,11 +200,11 @@ message* POP3Folder::getMessage(const int num)
else if (num < 1 || num > m_messageCount)
throw exceptions::message_not_found();
- return new POP3Message(this, num);
+ return vmime::create <POP3Message>(this, num);
}
-std::vector <message*> POP3Folder::getMessages(const int from, const int to)
+std::vector <ref <message> > POP3Folder::getMessages(const int from, const int to)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
@@ -213,40 +213,30 @@ std::vector <message*> POP3Folder::getMessages(const int from, const int to)
else if (to < from || from < 1 || to < 1 || from > m_messageCount || to > m_messageCount)
throw exceptions::message_not_found();
- std::vector <message*> v;
+ std::vector <ref <message> > v;
for (int i = from ; i <= to ; ++i)
- v.push_back(new POP3Message(this, i));
+ v.push_back(vmime::create <POP3Message>(this, i));
return (v);
}
-std::vector <message*> POP3Folder::getMessages(const std::vector <int>& nums)
+std::vector <ref <message> > POP3Folder::getMessages(const std::vector <int>& nums)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- std::vector <message*> v;
+ std::vector <ref <message> > v;
- try
+ for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
{
- for (std::vector <int>::const_iterator it = nums.begin() ; it != nums.end() ; ++it)
- {
- if (*it < 1|| *it > m_messageCount)
- throw exceptions::message_not_found();
+ if (*it < 1|| *it > m_messageCount)
+ throw exceptions::message_not_found();
- v.push_back(new POP3Message(this, *it));
- }
- }
- catch (std::exception& e)
- {
- for (std::vector <message*>::iterator it = v.begin() ; it != v.end() ; ++it)
- delete (*it);
-
- throw;
+ v.push_back(vmime::create <POP3Message>(this, *it));
}
return (v);
@@ -264,35 +254,35 @@ const int POP3Folder::getMessageCount()
}
-folder* POP3Folder::getFolder(const folder::path::component& name)
+ref <folder> POP3Folder::getFolder(const folder::path::component& name)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
- return new POP3Folder(m_path / name, m_store);
+ return vmime::create <POP3Folder>(m_path / name, m_store);
}
-std::vector <folder*> POP3Folder::getFolders(const bool /* recursive */)
+std::vector <ref <folder> > POP3Folder::getFolders(const bool /* recursive */)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
if (m_path.isEmpty())
{
- std::vector <folder*> v;
- v.push_back(new POP3Folder(folder::path::component("INBOX"), m_store));
+ std::vector <ref <folder> > v;
+ v.push_back(vmime::create <POP3Folder>(folder::path::component("INBOX"), m_store));
return (v);
}
else
{
- std::vector <folder*> v;
+ std::vector <ref <folder> > v;
return (v);
}
}
-void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
+void POP3Folder::fetchMessages(std::vector <ref <message> >& msg, const int options,
utility::progressionListener* progress)
{
if (!m_store)
@@ -306,10 +296,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
if (progress)
progress->start(total);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- dynamic_cast <POP3Message*>(*it)->fetch(this, options);
+ (*it).dynamicCast <POP3Message>()->fetch(this, options);
if (progress)
progress->progress(++current, total);
@@ -339,10 +329,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
std::map <int, string> result;
parseMultiListOrUidlResponse(response, result);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- POP3Message* m = dynamic_cast <POP3Message*>(*it);
+ ref <POP3Message> m = (*it).dynamicCast <POP3Message>();
std::map <int, string>::const_iterator x = result.find(m->m_num);
@@ -384,10 +374,10 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
std::map <int, string> result;
parseMultiListOrUidlResponse(response, result);
- for (std::vector <message*>::iterator it = msg.begin() ;
+ for (std::vector <ref <message> >::iterator it = msg.begin() ;
it != msg.end() ; ++it)
{
- POP3Message* m = dynamic_cast <POP3Message*>(*it);
+ ref <POP3Message> m = (*it).dynamicCast <POP3Message>();
std::map <int, string>::const_iterator x = result.find(m->m_num);
@@ -402,14 +392,14 @@ void POP3Folder::fetchMessages(std::vector <message*>& msg, const int options,
}
-void POP3Folder::fetchMessage(message* msg, const int options)
+void POP3Folder::fetchMessage(ref <message> msg, const int options)
{
if (!m_store)
throw exceptions::illegal_state("Store disconnected");
else if (!isOpen())
throw exceptions::illegal_state("Folder not open");
- dynamic_cast <POP3Message*>(msg)->fetch(this, options);
+ msg.dynamicCast <POP3Message>()->fetch(this, options);
if (options & FETCH_SIZE)
{
@@ -442,7 +432,7 @@ void POP3Folder::fetchMessage(message* msg, const int options)
std::istringstream iss(string(it, response.end()));
iss >> size;
- dynamic_cast <POP3Message*>(msg)->m_size = size;
+ msg.dynamicCast <POP3Message>()->m_size = size;
}
}
}
@@ -473,7 +463,7 @@ void POP3Folder::fetchMessage(message* msg, const int options)
if (it != response.end())
{
- dynamic_cast <POP3Message*>(msg)->m_uid =
+ msg.dynamicCast <POP3Message>()->m_uid =
string(it, response.end());
}
}
@@ -488,19 +478,22 @@ const int POP3Folder::getFetchCapabilities() const
}
-folder* POP3Folder::getParent()
+ref <folder> POP3Folder::getParent()
{
- return (m_path.isEmpty() ? NULL : new POP3Folder(m_path.getParent(), m_store));
+ if (m_path.isEmpty())
+ return NULL;
+ else
+ return vmime::create <POP3Folder>(m_path.getParent(), m_store);
}
-const store* POP3Folder::getStore() const
+weak_ref <const store> POP3Folder::getStore() const
{
return (m_store);
}
-store* POP3Folder::getStore()
+weak_ref <store> POP3Folder::getStore()
{
return (m_store);
}
@@ -556,7 +549,9 @@ void POP3Folder::deleteMessage(const int num)
std::vector <int> nums;
nums.push_back(num);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -604,7 +599,9 @@ void POP3Folder::deleteMessages(const int from, const int to)
for (int i = from ; i <= to2 ; ++i)
nums.push_back(i);
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, nums);
notifyMessageChanged(event);
}
@@ -654,7 +651,9 @@ void POP3Folder::deleteMessages(const std::vector <int>& nums)
}
// Notify message flags changed
- events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list);
+ events::messageChangedEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageChangedEvent::TYPE_FLAGS, list);
notifyMessageChanged(event);
}
@@ -680,7 +679,7 @@ void POP3Folder::rename(const folder::path& /* newPath */)
}
-void POP3Folder::addMessage(vmime::message* /* msg */, const int /* flags */,
+void POP3Folder::addMessage(ref <vmime::message> /* msg */, const int /* flags */,
vmime::datetime* /* date */, utility::progressionListener* /* progress */)
{
throw exceptions::operation_not_supported();
@@ -750,7 +749,9 @@ void POP3Folder::status(int& count, int& unseen)
nums[j] = i;
// Notify message count changed
- events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ (thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
notifyMessageCount(event);
@@ -762,7 +763,9 @@ void POP3Folder::status(int& count, int& unseen)
{
(*it)->m_messageCount = count;
- events::messageCountEvent event(*it, events::messageCountEvent::TYPE_ADDED, nums);
+ events::messageCountEvent event
+ ((*it)->thisRef().dynamicCast <folder>(),
+ events::messageCountEvent::TYPE_ADDED, nums);
(*it)->notifyMessageCount(event);
}
diff --git a/src/messaging/pop3/POP3Store.cpp b/src/messaging/pop3/POP3Store.cpp
index f1a4d45e..1407df35 100644
--- a/src/messaging/pop3/POP3Store.cpp
+++ b/src/messaging/pop3/POP3Store.cpp
@@ -41,7 +41,7 @@ namespace messaging {
namespace pop3 {
-POP3Store::POP3Store(session* sess, authenticator* auth)
+POP3Store::POP3Store(ref <session> sess, ref <authenticator> auth)
: store(sess, getInfosInstance(), auth), m_socket(NULL),
m_authentified(false), m_timeoutHandler(NULL)
{
@@ -63,30 +63,30 @@ const string POP3Store::getProtocolName() const
}
-folder* POP3Store::getDefaultFolder()
+ref <folder> POP3Store::getDefaultFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(folder::path(folder::path::component("INBOX")), this);
+ return vmime::create <POP3Folder>(folder::path(folder::path::component("INBOX")), this);
}
-folder* POP3Store::getRootFolder()
+ref <folder> POP3Store::getRootFolder()
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(folder::path(), this);
+ return vmime::create <POP3Folder>(folder::path(), this);
}
-folder* POP3Store::getFolder(const folder::path& path)
+ref <folder> POP3Store::getFolder(const folder::path& path)
{
if (!isConnected())
throw exceptions::illegal_state("Not connected");
- return new POP3Folder(path, this);
+ return vmime::create <POP3Folder>(path, this);
}
@@ -244,11 +244,8 @@ void POP3Store::internalDisconnect()
sendRequest("QUIT");
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_authentified = false;
diff --git a/src/messaging/sendmail/sendmailTransport.cpp b/src/messaging/sendmail/sendmailTransport.cpp
index 969cb7ae..e9b8256b 100644
--- a/src/messaging/sendmail/sendmailTransport.cpp
+++ b/src/messaging/sendmail/sendmailTransport.cpp
@@ -46,7 +46,7 @@ namespace messaging {
namespace sendmail {
-sendmailTransport::sendmailTransport(session* sess, authenticator* auth)
+sendmailTransport::sendmailTransport(ref <session> sess, ref <authenticator> auth)
: transport(sess, getInfosInstance(), auth), m_connected(false)
{
}
@@ -145,7 +145,7 @@ void sendmailTransport::internalSend
const utility::file::path path = vmime::platformDependant::getHandler()->
getFileSystemFactory()->stringToPath(m_sendmailPath);
- utility::auto_ptr <utility::childProcess> proc =
+ ref <utility::childProcess> proc =
vmime::platformDependant::getHandler()->
getChildProcessFactory()->create(path);
diff --git a/src/messaging/service.cpp b/src/messaging/service.cpp
index c8872758..eab4db8a 100644
--- a/src/messaging/service.cpp
+++ b/src/messaging/service.cpp
@@ -26,39 +26,41 @@ namespace vmime {
namespace messaging {
-service::service(session* sess, const serviceInfos& infos, authenticator* auth)
- : m_deleteAuth(auth == NULL), m_session(sess), m_auth(auth ? auth :
- new defaultAuthenticator(sess->getProperties(), infos.getPropertyPrefix()))
+service::service(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
+ : m_session(sess), m_auth(auth)
{
+ if (!auth)
+ {
+ m_auth = vmime::create <defaultAuthenticator>
+ (sess, infos.getPropertyPrefix());
+ }
}
service::~service()
{
- if (m_deleteAuth)
- delete (m_auth);
}
-const session* service::getSession() const
+ref <const session> service::getSession() const
{
return (m_session);
}
-session* service::getSession()
+ref <session> service::getSession()
{
return (m_session);
}
-const authenticator* service::getAuthenticator() const
+ref <const authenticator> service::getAuthenticator() const
{
return (m_auth);
}
-authenticator* service::getAuthenticator()
+ref <authenticator> service::getAuthenticator()
{
return (m_auth);
}
diff --git a/src/messaging/serviceFactory.cpp b/src/messaging/serviceFactory.cpp
index ea1752dd..a706b0ba 100644
--- a/src/messaging/serviceFactory.cpp
+++ b/src/messaging/serviceFactory.cpp
@@ -37,11 +37,6 @@ serviceFactory::serviceFactory()
serviceFactory::~serviceFactory()
{
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
- it != m_services.end() ; ++it)
- {
- delete (*it);
- }
}
@@ -52,17 +47,17 @@ serviceFactory* serviceFactory::getInstance()
}
-service* serviceFactory::create
- (session* sess, const string& protocol, authenticator* auth)
+ref <service> serviceFactory::create
+ (ref <session> sess, const string& protocol, ref <authenticator> auth)
{
return (getServiceByProtocol(protocol)->create(sess, auth));
}
-service* serviceFactory::create
- (session* sess, const utility::url& u, authenticator* auth)
+ref <service> serviceFactory::create
+ (ref <session> sess, const utility::url& u, ref <authenticator> auth)
{
- service* serv = create(sess, u.getProtocol(), auth);
+ ref <service> serv = create(sess, u.getProtocol(), auth);
sess->getProperties()[serv->getInfos().getPropertyPrefix() + "server.address"] = u.getHost();
@@ -84,11 +79,11 @@ service* serviceFactory::create
}
-const serviceFactory::registeredService* serviceFactory::getServiceByProtocol(const string& protocol) const
+ref <const serviceFactory::registeredService> serviceFactory::getServiceByProtocol(const string& protocol) const
{
const string name(utility::stringUtils::toLower(protocol));
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
+ for (std::vector <ref <registeredService> >::const_iterator it = m_services.begin() ;
it != m_services.end() ; ++it)
{
if ((*it)->getName() == name)
@@ -105,17 +100,17 @@ const int serviceFactory::getServiceCount() const
}
-const serviceFactory::registeredService* serviceFactory::getServiceAt(const int pos) const
+ref <const serviceFactory::registeredService> serviceFactory::getServiceAt(const int pos) const
{
return (m_services[pos]);
}
-const std::vector <const serviceFactory::registeredService*> serviceFactory::getServiceList() const
+const std::vector <ref <const serviceFactory::registeredService> > serviceFactory::getServiceList() const
{
- std::vector <const registeredService*> res;
+ std::vector <ref <const registeredService> > res;
- for (std::vector <registeredService*>::const_iterator it = m_services.begin() ;
+ for (std::vector <ref <registeredService> >::const_iterator it = m_services.begin() ;
it != m_services.end() ; ++it)
{
res.push_back(*it);
diff --git a/src/messaging/serviceInfos.cpp b/src/messaging/serviceInfos.cpp
index 685ccf3e..a8359fd0 100644
--- a/src/messaging/serviceInfos.cpp
+++ b/src/messaging/serviceInfos.cpp
@@ -71,7 +71,7 @@ serviceInfos::~serviceInfos()
}
-const bool serviceInfos::hasProperty(session* s, const property& p) const
+const bool serviceInfos::hasProperty(ref <session> s, const property& p) const
{
return s->getProperties().hasProperty(getPropertyPrefix() + p.getName());
}
diff --git a/src/messaging/session.cpp b/src/messaging/session.cpp
index 35c188a2..12aca36d 100644
--- a/src/messaging/session.cpp
+++ b/src/messaging/session.cpp
@@ -33,6 +33,12 @@ session::session()
}
+session::session(const session& sess)
+ : object(), m_props(sess.m_props)
+{
+}
+
+
session::session(const propertySet& props)
: m_props(props)
{
@@ -44,71 +50,63 @@ session::~session()
}
-transport* session::getTransport(authenticator* auth)
+ref <transport> session::getTransport(ref <authenticator> auth)
{
return (getTransport(m_props["transport.protocol"], auth));
}
-transport* session::getTransport(const string& protocol, authenticator* auth)
+ref <transport> session::getTransport(const string& protocol, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, protocol, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, protocol, auth);
if (sv->getType() != service::TYPE_TRANSPORT)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<transport*>(sv);
+ return sv.staticCast <transport>();
}
-transport* session::getTransport(const utility::url& url, authenticator* auth)
+ref <transport> session::getTransport(const utility::url& url, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, url, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, url, auth);
if (sv->getType() != service::TYPE_TRANSPORT)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<transport*>(sv);
+ return sv.staticCast <transport>();
}
-store* session::getStore(authenticator* auth)
+ref <store> session::getStore(ref <authenticator> auth)
{
return (getStore(m_props["store.protocol"], auth));
}
-store* session::getStore(const string& protocol, authenticator* auth)
+ref <store> session::getStore(const string& protocol, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, protocol, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, protocol, auth);
if (sv->getType() != service::TYPE_STORE)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<store*>(sv);
+ return sv.staticCast <store>();
}
-store* session::getStore(const utility::url& url, authenticator* auth)
+ref <store> session::getStore(const utility::url& url, ref <authenticator> auth)
{
- service* sv = serviceFactory::getInstance()->create(this, url, auth);
+ ref <session> sess = thisRef().dynamicCast <session>();
+ ref <service> sv = serviceFactory::getInstance()->create(sess, url, auth);
if (sv->getType() != service::TYPE_STORE)
- {
- delete (sv);
throw exceptions::no_service_available();
- }
- return static_cast<store*>(sv);
+ return sv.staticCast <store>();
}
diff --git a/src/messaging/smtp/SMTPTransport.cpp b/src/messaging/smtp/SMTPTransport.cpp
index a32b0c95..5613a47d 100644
--- a/src/messaging/smtp/SMTPTransport.cpp
+++ b/src/messaging/smtp/SMTPTransport.cpp
@@ -41,7 +41,7 @@ namespace messaging {
namespace smtp {
-SMTPTransport::SMTPTransport(session* sess, authenticator* auth)
+SMTPTransport::SMTPTransport(ref <session> sess, ref <authenticator> auth)
: transport(sess, getInfosInstance(), auth), m_socket(NULL),
m_authentified(false), m_extendedSMTP(false), m_timeoutHandler(NULL)
{
@@ -239,11 +239,8 @@ void SMTPTransport::internalDisconnect()
sendRequest("QUIT");
m_socket->disconnect();
-
- delete (m_socket);
m_socket = NULL;
- delete (m_timeoutHandler);
m_timeoutHandler = NULL;
m_authentified = false;
diff --git a/src/messaging/transport.cpp b/src/messaging/transport.cpp
index 0b52aa39..59a2871c 100644
--- a/src/messaging/transport.cpp
+++ b/src/messaging/transport.cpp
@@ -28,7 +28,7 @@ namespace vmime {
namespace messaging {
-transport::transport(session* sess, const serviceInfos& infos, authenticator* auth)
+transport::transport(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
: service(sess, infos, auth)
{
}
@@ -39,7 +39,7 @@ static void extractMailboxes
{
for (int i = 0 ; i < list.getAddressCount() ; ++i)
{
- mailbox* mbox = dynamic_cast <mailbox*>(list.getAddressAt(i)->clone());
+ ref <mailbox> mbox = list.getAddressAt(i)->clone().dynamicCast <mailbox>();
if (mbox != NULL)
recipients.appendMailbox(mbox);
@@ -47,7 +47,7 @@ static void extractMailboxes
}
-void transport::send(vmime::message* msg, utility::progressionListener* progress)
+void transport::send(ref <vmime::message> msg, utility::progressionListener* progress)
{
// Extract expeditor
mailbox expeditor;
diff --git a/src/misc/importanceHelper.cpp b/src/misc/importanceHelper.cpp
index ac36538d..0fc9e16a 100644
--- a/src/misc/importanceHelper.cpp
+++ b/src/misc/importanceHelper.cpp
@@ -25,13 +25,13 @@ namespace vmime {
namespace misc {
-void importanceHelper::resetImportance(message* msg)
+void importanceHelper::resetImportance(ref <message> msg)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
try
{
- headerField* fld = hdr->findField("X-Priority");
+ ref <headerField> fld = hdr->findField("X-Priority");
hdr->removeField(fld);
}
catch (exceptions::no_such_field)
@@ -41,7 +41,7 @@ void importanceHelper::resetImportance(message* msg)
try
{
- headerField* fld = hdr->findField("Importance");
+ ref <headerField> fld = hdr->findField("Importance");
hdr->removeField(fld);
}
catch (exceptions::no_such_field)
@@ -51,13 +51,13 @@ void importanceHelper::resetImportance(message* msg)
}
-const importanceHelper::Importance importanceHelper::getImportance(const message* msg)
+const importanceHelper::Importance importanceHelper::getImportance(const ref <const message> msg)
{
- const header* hdr = msg->getHeader();
+ const ref <const header> hdr = msg->getHeader();
try
{
- const defaultField* fld = dynamic_cast <const defaultField*>(hdr->findField("X-Priority"));
+ const ref <const defaultField> fld = hdr->findField("X-Priority").dynamicCast <const defaultField>();
const string value = fld->getValue();
int n = IMPORTANCE_NORMAL;
@@ -80,7 +80,7 @@ const importanceHelper::Importance importanceHelper::getImportance(const message
}
catch (exceptions::no_such_field)
{
- const defaultField* fld = dynamic_cast <const defaultField*>(hdr->findField("Importance"));
+ const ref <const defaultField> fld = hdr->findField("Importance").dynamicCast <const defaultField>();
const string value = utility::stringUtils::toLower(utility::stringUtils::trim(fld->getValue()));
if (value == "low")
@@ -96,12 +96,12 @@ const importanceHelper::Importance importanceHelper::getImportance(const message
}
-void importanceHelper::setImportance(message* msg, const Importance i)
+void importanceHelper::setImportance(ref <message> msg, const Importance i)
{
- header* hdr = msg->getHeader();
+ ref <header> hdr = msg->getHeader();
// "X-Priority:" Field
- defaultField* fld = dynamic_cast <defaultField*>(hdr->getField("X-Priority"));
+ ref <defaultField> fld = hdr->getField("X-Priority").dynamicCast <defaultField>();
switch (i)
{
@@ -114,7 +114,7 @@ void importanceHelper::setImportance(message* msg, const Importance i)
}
// "Importance:" Field
- fld = dynamic_cast <defaultField*>(hdr->getField("Importance"));
+ fld = hdr->getField("Importance").dynamicCast <defaultField>();
switch (i)
{
diff --git a/src/object.cpp b/src/object.cpp
new file mode 100644
index 00000000..481a3564
--- /dev/null
+++ b/src/object.cpp
@@ -0,0 +1,130 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+
+#include "vmime/types.hpp"
+#include "vmime/object.hpp"
+
+#include <algorithm> // std::find
+#include <sstream> // std::ostringstream
+#include <stdexcept> // std::runtime_error
+
+
+namespace vmime
+{
+
+
+object::object()
+ : m_strongCount(0)
+{
+}
+
+
+object::object(const object&)
+ : m_strongCount(0)
+{
+ // Not used
+}
+
+
+object::~object()
+{
+ for (std::vector <utility::weak_ref_base*>::iterator
+ it = m_weakRefs.begin() ; it != m_weakRefs.end() ; ++it)
+ {
+ (*it)->notifyObjectDestroyed();
+ }
+
+#if VMIME_DEBUG
+ if (m_strongCount != 0)
+ {
+ std::ostringstream oss;
+ oss << "ERROR: Deleting object and strong count != 0."
+ << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
+
+ throw std::runtime_error(oss.str());
+ }
+#endif // VMIME_DEBUG
+}
+
+
+void object::addStrong() const
+{
+ ++m_strongCount;
+}
+
+
+void object::addWeak(utility::weak_ref_base* w) const
+{
+ m_weakRefs.push_back(w);
+}
+
+
+void object::releaseStrong() const
+{
+ if (--m_strongCount == 0)
+ delete this;
+}
+
+
+void object::releaseWeak(utility::weak_ref_base* w) const
+{
+ std::vector <utility::weak_ref_base*>::iterator
+ it = std::find(m_weakRefs.begin(), m_weakRefs.end(), w);
+
+ if (it != m_weakRefs.end())
+ m_weakRefs.erase(it);
+#if VMIME_DEBUG
+ else
+ {
+ std::ostringstream oss;
+ oss << "ERROR: weak ref does not exist anymore!"
+ << " (" << __FILE__ << ", line " << __LINE__ << ")" << std::endl;
+
+ throw std::runtime_error(oss.str());
+ }
+#endif // VMIME_DEBUG
+}
+
+
+ref <object> object::thisRef()
+{
+ return ref <object>::fromPtr(this);
+}
+
+
+ref <const object> object::thisRef() const
+{
+ return ref <const object>::fromPtr(this);
+}
+
+
+weak_ref <object> object::thisWeakRef()
+{
+ return weak_ref <object>(thisRef());
+}
+
+
+weak_ref <const object> object::thisWeakRef() const
+{
+ return weak_ref <const object>(thisRef());
+}
+
+
+} // vmime
+
diff --git a/src/parameter.cpp b/src/parameter.cpp
index 988755be..e3c84b85 100644
--- a/src/parameter.cpp
+++ b/src/parameter.cpp
@@ -25,9 +25,9 @@ namespace vmime
{
-parameter* parameter::clone() const
+ref <component> parameter::clone() const
{
- parameter* p = parameterFactory::getInstance()->create(m_name);
+ ref <parameter> p = parameterFactory::getInstance()->create(m_name);
p->copyFrom(*this);
return (p);
@@ -169,11 +169,11 @@ void parameter::generateValue(utility::outputStream& os, const string::size_type
}
-const std::vector <const component*> parameter::getChildComponents() const
+const std::vector <ref <const component> > parameter::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
- list.push_back(&getValue());
+ list.push_back(getValueImp());
return (list);
}
diff --git a/src/parameterFactory.cpp b/src/parameterFactory.cpp
index a5a7a81c..35619eec 100644
--- a/src/parameterFactory.cpp
+++ b/src/parameterFactory.cpp
@@ -49,13 +49,13 @@ parameterFactory* parameterFactory::getInstance()
}
-parameter* parameterFactory::create
+ref <parameter> parameterFactory::create
(const string& name, const string& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
- parameter* param = NULL;
+ ref <parameter> param;
if (pos != m_nameMap.end())
{
@@ -73,12 +73,12 @@ parameter* parameterFactory::create
}
-parameter* parameterFactory::create(const string& name, const component& value)
+ref <parameter> parameterFactory::create(const string& name, const component& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
- parameter* param = NULL;
+ ref <parameter> param;
if (pos != m_nameMap.end())
{
diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp
index 6e5e47ad..ccc8b8e3 100644
--- a/src/parameterizedHeaderField.cpp
+++ b/src/parameterizedHeaderField.cpp
@@ -291,7 +291,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty
const paramInfo& info = (*it).second;
// Append this parameter to the list
- parameter* param = parameterFactory::getInstance()->create((*it).first);
+ ref <parameter> param = parameterFactory::getInstance()->create((*it).first);
param->parse(info.value);
param->setParsedBounds(info.start, info.end);
@@ -314,7 +314,7 @@ void parameterizedHeaderField::generate(utility::outputStream& os, const string:
headerField::generate(os, maxLineLength, pos, &pos);
// Parameters
- for (std::vector <parameter*>::const_iterator
+ for (std::vector <ref <parameter> >::const_iterator
it = m_params.begin() ; it != m_params.end() ; ++it)
{
os << "; ";
@@ -336,10 +336,10 @@ void parameterizedHeaderField::copyFrom(const component& other)
removeAllParameters();
- for (std::vector <parameter*>::const_iterator i = source.m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator i = source.m_params.begin() ;
i != source.m_params.end() ; ++i)
{
- appendParameter((*i)->clone());
+ appendParameter((*i)->clone().dynamicCast <parameter>());
}
}
@@ -355,8 +355,8 @@ const bool parameterizedHeaderField::hasParameter(const string& paramName) const
{
const string name = utility::stringUtils::toLower(paramName);
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -364,13 +364,13 @@ const bool parameterizedHeaderField::hasParameter(const string& paramName) const
}
-parameter* parameterizedHeaderField::findParameter(const string& paramName) const
+ref <parameter> parameterizedHeaderField::findParameter(const string& paramName) const
{
const string name = utility::stringUtils::toLower(paramName);
// Find the first parameter that matches the specified name
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
@@ -387,30 +387,22 @@ parameter* parameterizedHeaderField::findParameter(const string& paramName) cons
}
-parameter* parameterizedHeaderField::getParameter(const string& paramName)
+ref <parameter> parameterizedHeaderField::getParameter(const string& paramName)
{
const string name = utility::stringUtils::toLower(paramName);
// Find the first parameter that matches the specified name
- std::vector <parameter*>::const_iterator pos = m_params.begin();
- const std::vector <parameter*>::const_iterator end = m_params.end();
+ std::vector <ref <parameter> >::const_iterator pos = m_params.begin();
+ const std::vector <ref <parameter> >::const_iterator end = m_params.end();
for ( ; pos != end && utility::stringUtils::toLower((*pos)->getName()) != name ; ++pos);
// If no parameter with this name can be found, create a new one
if (pos == end)
{
- parameter* param = parameterFactory::getInstance()->create(paramName);
+ ref <parameter> param = parameterFactory::getInstance()->create(paramName);
- try
- {
- appendParameter(param);
- }
- catch (std::exception&)
- {
- delete (param);
- throw;
- }
+ appendParameter(param);
// Return a reference to the new parameter
return (param);
@@ -423,15 +415,15 @@ parameter* parameterizedHeaderField::getParameter(const string& paramName)
}
-void parameterizedHeaderField::appendParameter(parameter* param)
+void parameterizedHeaderField::appendParameter(ref <parameter> param)
{
m_params.push_back(param);
}
-void parameterizedHeaderField::insertParameterBefore(parameter* beforeParam, parameter* param)
+void parameterizedHeaderField::insertParameterBefore(ref <parameter> beforeParam, ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), beforeParam);
if (it == m_params.end())
@@ -441,15 +433,15 @@ void parameterizedHeaderField::insertParameterBefore(parameter* beforeParam, par
}
-void parameterizedHeaderField::insertParameterBefore(const int pos, parameter* param)
+void parameterizedHeaderField::insertParameterBefore(const int pos, ref <parameter> param)
{
m_params.insert(m_params.begin() + pos, param);
}
-void parameterizedHeaderField::insertParameterAfter(parameter* afterParam, parameter* param)
+void parameterizedHeaderField::insertParameterAfter(ref <parameter> afterParam, ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), afterParam);
if (it == m_params.end())
@@ -459,15 +451,15 @@ void parameterizedHeaderField::insertParameterAfter(parameter* afterParam, param
}
-void parameterizedHeaderField::insertParameterAfter(const int pos, parameter* param)
+void parameterizedHeaderField::insertParameterAfter(const int pos, ref <parameter> param)
{
m_params.insert(m_params.begin() + pos + 1, param);
}
-void parameterizedHeaderField::removeParameter(parameter* param)
+void parameterizedHeaderField::removeParameter(ref <parameter> param)
{
- const std::vector <parameter*>::iterator it = std::find
+ const std::vector <ref <parameter> >::iterator it = std::find
(m_params.begin(), m_params.end(), param);
if (it == m_params.end())
@@ -479,9 +471,7 @@ void parameterizedHeaderField::removeParameter(parameter* param)
void parameterizedHeaderField::removeParameter(const int pos)
{
- const std::vector <parameter*>::iterator it = m_params.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <parameter> >::iterator it = m_params.begin() + pos;
m_params.erase(it);
}
@@ -489,7 +479,7 @@ void parameterizedHeaderField::removeParameter(const int pos)
void parameterizedHeaderField::removeAllParameters()
{
- free_container(m_params);
+ m_params.clear();
}
@@ -505,25 +495,25 @@ const bool parameterizedHeaderField::isEmpty() const
}
-parameter* parameterizedHeaderField::getParameterAt(const int pos)
+const ref <parameter> parameterizedHeaderField::getParameterAt(const int pos)
{
return (m_params[pos]);
}
-const parameter* parameterizedHeaderField::getParameterAt(const int pos) const
+const ref <parameter> parameterizedHeaderField::getParameterAt(const int pos) const
{
return (m_params[pos]);
}
-const std::vector <const parameter*> parameterizedHeaderField::getParameterList() const
+const std::vector <ref <const parameter> > parameterizedHeaderField::getParameterList() const
{
- std::vector <const parameter*> list;
+ std::vector <ref <const parameter> > list;
list.reserve(m_params.size());
- for (std::vector <parameter*>::const_iterator it = m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator it = m_params.begin() ;
it != m_params.end() ; ++it)
{
list.push_back(*it);
@@ -533,17 +523,17 @@ const std::vector <const parameter*> parameterizedHeaderField::getParameterList(
}
-const std::vector <parameter*> parameterizedHeaderField::getParameterList()
+const std::vector <ref <parameter> > parameterizedHeaderField::getParameterList()
{
return (m_params);
}
-const std::vector <const component*> parameterizedHeaderField::getChildComponents() const
+const std::vector <ref <const component> > parameterizedHeaderField::getChildComponents() const
{
- std::vector <const component*> list = headerField::getChildComponents();
+ std::vector <ref <const component> > list = headerField::getChildComponents();
- for (std::vector <parameter*>::const_iterator it = m_params.begin() ;
+ for (std::vector <ref <parameter> >::const_iterator it = m_params.begin() ;
it != m_params.end() ; ++it)
{
list.push_back(*it);
diff --git a/src/path.cpp b/src/path.cpp
index 153facd3..5cb6371c 100644
--- a/src/path.cpp
+++ b/src/path.cpp
@@ -89,9 +89,9 @@ void path::copyFrom(const component& other)
}
-path* path::clone() const
+ref <component> path::clone() const
{
- return new path(*this);
+ return vmime::create <path>(*this);
}
@@ -102,9 +102,9 @@ path& path::operator=(const path& other)
}
-const std::vector <const component*> path::getChildComponents() const
+const std::vector <ref <const component> > path::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/plainTextPart.cpp b/src/plainTextPart.cpp
index 8e065c76..86eb2f67 100644
--- a/src/plainTextPart.cpp
+++ b/src/plainTextPart.cpp
@@ -29,14 +29,13 @@ namespace vmime
plainTextPart::plainTextPart()
- : m_text(new emptyContentHandler)
+ : m_text(vmime::create <emptyContentHandler>())
{
}
plainTextPart::~plainTextPart()
{
- delete (m_text);
}
@@ -55,24 +54,23 @@ const int plainTextPart::getPartCount() const
void plainTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
{
// Create a new part
- bodyPart* part = new bodyPart();
+ ref <bodyPart> part = vmime::create <bodyPart>();
parent.getBody()->appendPart(part);
// Set header fields
- part->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
- part->getHeader()->ContentType().setCharset(m_charset);
- part->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
+ part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
+ part->getHeader()->ContentType()->setCharset(m_charset);
+ part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// Set contents
- part->getBody()->setContents(*m_text);
+ part->getBody()->setContents(m_text);
}
void plainTextPart::parse(const bodyPart& /* message */,
const bodyPart& /* parent */, const bodyPart& textPart)
{
- delete (m_text);
- m_text = textPart.getBody()->getContents().clone();
+ m_text = textPart.getBody()->getContents()->clone().dynamicCast <contentHandler>();
try
{
@@ -104,16 +102,15 @@ void plainTextPart::setCharset(const charset& ch)
}
-const contentHandler& plainTextPart::getText() const
+const ref <const contentHandler> plainTextPart::getText() const
{
- return (*m_text);
+ return (m_text);
}
-void plainTextPart::setText(const contentHandler& text)
+void plainTextPart::setText(ref <contentHandler> text)
{
- delete (m_text);
- m_text = text.clone();
+ m_text = text->clone().dynamicCast <contentHandler>();
}
diff --git a/src/platforms/posix/posixChildProcess.cpp b/src/platforms/posix/posixChildProcess.cpp
index 54410bf6..cd3aafb3 100644
--- a/src/platforms/posix/posixChildProcess.cpp
+++ b/src/platforms/posix/posixChildProcess.cpp
@@ -39,9 +39,9 @@ namespace posix {
// posixChildProcessFactory
-utility::childProcess* posixChildProcessFactory::create(const utility::file::path& path) const
+ref <utility::childProcess> posixChildProcessFactory::create(const utility::file::path& path) const
{
- return new posixChildProcess(path);
+ return vmime::create <posixChildProcess>(path);
}
@@ -220,9 +220,6 @@ posixChildProcess::~posixChildProcess()
if (m_pipe[1] != 0)
close(m_pipe[1]);
- delete (m_stdIn);
- delete (m_stdOut);
-
delete [] (m_argArray);
}
@@ -307,7 +304,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
if (flags & FLAG_REDIRECT_STDIN)
{
- m_stdIn = new outputStreamPosixPipeAdapter(m_pipe[1]);
+ m_stdIn = vmime::create <outputStreamPosixPipeAdapter>(m_pipe[1]);
}
else
{
@@ -317,7 +314,7 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
if (flags & FLAG_REDIRECT_STDOUT)
{
- m_stdOut = new inputStreamPosixPipeAdapter(m_pipe[0]);
+ m_stdOut = vmime::create <inputStreamPosixPipeAdapter>(m_pipe[0]);
}
else
{
@@ -330,13 +327,13 @@ void posixChildProcess::start(const std::vector <string> args, const int flags)
}
-utility::outputStream* posixChildProcess::getStdIn()
+ref <utility::outputStream> posixChildProcess::getStdIn()
{
return (m_stdIn);
}
-utility::inputStream* posixChildProcess::getStdOut()
+ref <utility::inputStream> posixChildProcess::getStdOut()
{
return (m_stdOut);
}
diff --git a/src/platforms/posix/posixFile.cpp b/src/platforms/posix/posixFile.cpp
index 83ea0f1b..2f2ef39f 100644
--- a/src/platforms/posix/posixFile.cpp
+++ b/src/platforms/posix/posixFile.cpp
@@ -68,9 +68,10 @@ const bool posixFileIterator::hasMoreElements() const
}
-vmime::utility::file* posixFileIterator::nextElement()
+ref <vmime::utility::file> posixFileIterator::nextElement()
{
- posixFile* file = new posixFile(m_path / vmime::utility::file::path::component(m_dirEntry->d_name));
+ ref <posixFile> file = vmime::create <posixFile>
+ (m_path / vmime::utility::file::path::component(m_dirEntry->d_name));
getNextElement();
@@ -182,14 +183,14 @@ posixFileWriter::posixFileWriter(const vmime::utility::file::path& path, const v
}
-vmime::utility::outputStream* posixFileWriter::getOutputStream()
+ref <vmime::utility::outputStream> posixFileWriter::getOutputStream()
{
int fd = 0;
if ((fd = ::open(m_nativePath.c_str(), O_WRONLY, 0660)) == -1)
posixFileSystemFactory::reportError(m_path, errno);
- return new posixFileWriterOutputStream(m_path, fd);
+ return vmime::create <posixFileWriterOutputStream>(m_path, fd);
}
@@ -204,14 +205,14 @@ posixFileReader::posixFileReader(const vmime::utility::file::path& path, const v
}
-vmime::utility::inputStream* posixFileReader::getInputStream()
+ref <vmime::utility::inputStream> posixFileReader::getInputStream()
{
int fd = 0;
if ((fd = ::open(m_nativePath.c_str(), O_RDONLY, 0640)) == -1)
posixFileSystemFactory::reportError(m_path, errno);
- return new posixFileReaderInputStream(m_path, fd);
+ return vmime::create <posixFileReaderInputStream>(m_path, fd);
}
@@ -299,12 +300,12 @@ const bool posixFile::exists() const
}
-const vmime::utility::file* posixFile::getParent() const
+ref <vmime::utility::file> posixFile::getParent() const
{
if (m_path.isEmpty())
return NULL;
else
- return new posixFile(m_path.getParent());
+ return vmime::create <posixFile>(m_path.getParent());
}
@@ -340,24 +341,24 @@ void posixFile::remove()
}
-vmime::utility::fileWriter* posixFile::getFileWriter()
+ref <vmime::utility::fileWriter> posixFile::getFileWriter()
{
- return new posixFileWriter(m_path, m_nativePath);
+ return vmime::create <posixFileWriter>(m_path, m_nativePath);
}
-vmime::utility::fileReader* posixFile::getFileReader()
+ref <vmime::utility::fileReader> posixFile::getFileReader()
{
- return new posixFileReader(m_path, m_nativePath);
+ return vmime::create <posixFileReader>(m_path, m_nativePath);
}
-vmime::utility::fileIterator* posixFile::getFiles() const
+ref <vmime::utility::fileIterator> posixFile::getFiles() const
{
if (!isDirectory())
throw vmime::exceptions::not_a_directory(m_path);
- return new posixFileIterator(m_path, m_nativePath);
+ return vmime::create <posixFileIterator>(m_path, m_nativePath);
}
@@ -383,9 +384,9 @@ void posixFile::createDirectoryImpl(const vmime::utility::file::path& fullPath,
// posixFileSystemFactory
//
-vmime::utility::file* posixFileSystemFactory::create(const vmime::utility::file::path& path) const
+ref <vmime::utility::file> posixFileSystemFactory::create(const vmime::utility::file::path& path) const
{
- return new posixFile(path);
+ return vmime::create <posixFile>(path);
}
diff --git a/src/platforms/posix/posixSocket.cpp b/src/platforms/posix/posixSocket.cpp
index a958680f..be346b2a 100644
--- a/src/platforms/posix/posixSocket.cpp
+++ b/src/platforms/posix/posixSocket.cpp
@@ -172,9 +172,9 @@ void posixSocket::sendRaw(const char* buffer, const int count)
// posixSocketFactory
//
-vmime::messaging::socket* posixSocketFactory::create()
+ref <vmime::messaging::socket> posixSocketFactory::create()
{
- return new posixSocket();
+ return vmime::create <posixSocket>();
}
diff --git a/src/platforms/windows/windowsFile.cpp b/src/platforms/windows/windowsFile.cpp
index 2cc7c289..4d2b708d 100644
--- a/src/platforms/windows/windowsFile.cpp
+++ b/src/platforms/windows/windowsFile.cpp
@@ -34,9 +34,9 @@ namespace platforms {
namespace windows {
-vmime::utility::file* windowsFileSystemFactory::create(const vmime::utility::file::path& path) const
+ref <vmime::utility::file> windowsFileSystemFactory::create(const vmime::utility::file::path& path) const
{
- return new windowsFile(path);
+ return vmime::create <windowsFile>(path);
}
@@ -105,7 +105,7 @@ const bool windowsFileSystemFactory::isValidPathComponent(
if (firstComponent && (buffer.length() == 2) && (buffer[1] == ':'))
{
char drive = tolower(buffer[0]);
- if ((drive >= 'a') && (drive <= 'z'))
+ if ((drive >= 'a') && (drive <= 'z'))
return true;
}
@@ -131,7 +131,7 @@ const bool windowsFileSystemFactory::isValidPathComponent(
}
string upperBuffer = vmime::utility::stringUtils::toUpper(buffer);
-
+
// Check for reserved names
if (upperBuffer.length() == 3)
{
@@ -300,12 +300,12 @@ const bool windowsFile::exists() const
return false;
}
-const vmime::utility::file* windowsFile::getParent() const
+ref <vmime::utility::file> windowsFile::getParent() const
{
if (m_path.isEmpty())
return NULL;
else
- return new windowsFile(m_path.getParent());
+ return vmime::create <windowsFile>(m_path.getParent());
}
void windowsFile::rename(const path& newName)
@@ -326,19 +326,19 @@ void windowsFile::remove()
windowsFileSystemFactory::reportError(m_path, GetLastError());
}
-vmime::utility::fileWriter* windowsFile::getFileWriter()
+ref <vmime::utility::fileWriter> windowsFile::getFileWriter()
{
- return new windowsFileWriter(m_path, m_nativePath);
+ return vmime::create <windowsFileWriter>(m_path, m_nativePath);
}
-vmime::utility::fileReader* windowsFile::getFileReader()
+ref <vmime::utility::fileReader> windowsFile::getFileReader()
{
- return new windowsFileReader(m_path, m_nativePath);
+ return vmime::create <windowsFileReader>(m_path, m_nativePath);
}
-vmime::utility::fileIterator* windowsFile::getFiles() const
+ref <vmime::utility::fileIterator> windowsFile::getFiles() const
{
- return new windowsFileIterator(m_path, m_nativePath);
+ return vmime::create <windowsFileIterator>(m_path, m_nativePath);
}
void windowsFile::createDirectoryImpl(const vmime::utility::file::path& fullPath, const vmime::utility::file::path& path, const bool recursive)
@@ -373,9 +373,10 @@ const bool windowsFileIterator::hasMoreElements() const
return m_moreElements;
}
-vmime::utility::file* windowsFileIterator::nextElement()
+ref <vmime::utility::file> windowsFileIterator::nextElement()
{
- vmime::utility::file* pFile = new windowsFile(m_path / vmime::utility::file::path::component(m_findData.cFileName));
+ ref <vmime::utility::file> pFile = vmime::create <windowsFile>
+ (m_path / vmime::utility::file::path::component(m_findData.cFileName));
findNext();
@@ -422,7 +423,7 @@ windowsFileReader::windowsFileReader(const vmime::utility::file::path& path, con
{
}
-vmime::utility::inputStream* windowsFileReader::getInputStream()
+ref <vmime::utility::inputStream> windowsFileReader::getInputStream()
{
HANDLE hFile = CreateFile(
m_nativePath.c_str(),
@@ -434,7 +435,7 @@ vmime::utility::inputStream* windowsFileReader::getInputStream()
NULL);
if (hFile == INVALID_HANDLE_VALUE)
windowsFileSystemFactory::reportError(m_path, GetLastError());
- return new windowsFileReaderInputStream(m_path, hFile);
+ return vmime::create <windowsFileReaderInputStream>(m_path, hFile);
}
windowsFileReaderInputStream::windowsFileReaderInputStream(const vmime::utility::file::path& path, HANDLE hFile)
@@ -479,7 +480,7 @@ windowsFileWriter::windowsFileWriter(const vmime::utility::file::path& path, con
{
}
-vmime::utility::outputStream* windowsFileWriter::getOutputStream()
+ref <vmime::utility::outputStream> windowsFileWriter::getOutputStream()
{
HANDLE hFile = CreateFile(
m_nativePath.c_str(),
@@ -491,7 +492,7 @@ vmime::utility::outputStream* windowsFileWriter::getOutputStream()
NULL);
if (hFile == INVALID_HANDLE_VALUE)
windowsFileSystemFactory::reportError(m_path, GetLastError());
- return new windowsFileWriterOutputStream(m_path, hFile);
+ return vmime::create <windowsFileWriterOutputStream>(m_path, hFile);
}
windowsFileWriterOutputStream::windowsFileWriterOutputStream(const vmime::utility::file::path& path, HANDLE hFile)
diff --git a/src/platforms/windows/windowsSocket.cpp b/src/platforms/windows/windowsSocket.cpp
index a572a271..b325eedd 100644
--- a/src/platforms/windows/windowsSocket.cpp
+++ b/src/platforms/windows/windowsSocket.cpp
@@ -77,7 +77,7 @@ void windowsSocket::connect(const vmime::string& address, const vmime::port_t po
// Error: cannot resolve address
throw vmime::exceptions::connection_error("Cannot resolve address.");
}
-
+
memcpy(reinterpret_cast <char*>(&addr.sin_addr), hostInfo->h_addr, hostInfo->h_length);
}
@@ -167,9 +167,9 @@ void windowsSocket::sendRaw(const char* buffer, const int count)
// posixSocketFactory
//
-vmime::messaging::socket* windowsSocketFactory::create()
+ref <vmime::messaging::socket> windowsSocketFactory::create()
{
- return new windowsSocket();
+ return vmime::create <windowsSocket>();
}
diff --git a/src/propertySet.cpp b/src/propertySet.cpp
index 88ee4f57..f1d7478c 100644
--- a/src/propertySet.cpp
+++ b/src/propertySet.cpp
@@ -37,9 +37,10 @@ propertySet::propertySet(const string& props)
propertySet::propertySet(const propertySet& set)
+ : object()
{
- for (std::list <property*>::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
- m_props.push_back(new property(**it));
+ for (std::list <ref <property> >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
+ m_props.push_back(vmime::create <property>(**it));
}
@@ -53,8 +54,8 @@ propertySet& propertySet::operator=(const propertySet& set)
{
removeAllProperties();
- for (std::list <property*>::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
- m_props.push_back(new property(**it));
+ for (std::list <ref <property> >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it)
+ m_props.push_back(vmime::create <property>(**it));
return (*this);
}
@@ -68,20 +69,17 @@ void propertySet::setFromString(const string& props)
void propertySet::removeAllProperties()
{
- free_container(m_props);
+ m_props.clear();
}
void propertySet::removeProperty(const string& name)
{
- std::list <property*>::iterator it = std::find_if
+ std::list <ref <property> >::iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
if (it != m_props.end())
- {
- delete (*it);
m_props.erase(it);
- }
}
@@ -172,24 +170,24 @@ void propertySet::parse(const string& props)
}
}
- m_props.push_back(new property(option, value));
+ m_props.push_back(vmime::create <property>(option, value));
}
}
}
-propertySet::property* propertySet::find(const string& name) const
+ref <propertySet::property> propertySet::find(const string& name) const
{
- std::list <property*>::const_iterator it = std::find_if
+ std::list <ref <property> >::const_iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
return (it != m_props.end() ? *it : NULL);
}
-propertySet::property* propertySet::findOrCreate(const string& name)
+ref <propertySet::property> propertySet::findOrCreate(const string& name)
{
- std::list <property*>::const_iterator it = std::find_if
+ std::list <ref <property> >::const_iterator it = std::find_if
(m_props.begin(), m_props.end(), propFinder(name));
if (it != m_props.end())
@@ -198,7 +196,7 @@ propertySet::property* propertySet::findOrCreate(const string& name)
}
else
{
- property* prop = new property(name, "");
+ ref <property> prop = vmime::create <property>(name, "");
m_props.push_back(prop);
return (prop);
}
@@ -223,9 +221,9 @@ const bool propertySet::hasProperty(const string& name) const
}
-const std::vector <const propertySet::property*> propertySet::getPropertyList() const
+const std::vector <ref <const propertySet::property> > propertySet::getPropertyList() const
{
- std::vector <const property*> res;
+ std::vector <ref <const property> > res;
for (list_type::const_iterator it = m_props.begin() ; it != m_props.end() ; ++it)
res.push_back(*it);
@@ -234,9 +232,9 @@ const std::vector <const propertySet::property*> propertySet::getPropertyList()
}
-const std::vector <propertySet::property*> propertySet::getPropertyList()
+const std::vector <ref <propertySet::property> > propertySet::getPropertyList()
{
- std::vector <property*> res;
+ std::vector <ref <property> > res;
for (list_type::const_iterator it = m_props.begin() ; it != m_props.end() ; ++it)
res.push_back(*it);
@@ -262,7 +260,7 @@ propertySet::property::property(const string& name)
propertySet::property::property(const property& prop)
- : m_name(prop.m_name), m_value(prop.m_value)
+ : object(), m_name(prop.m_name), m_value(prop.m_value)
{
}
diff --git a/src/relay.cpp b/src/relay.cpp
index 3724bde2..bdb14a90 100644
--- a/src/relay.cpp
+++ b/src/relay.cpp
@@ -244,9 +244,9 @@ relay& relay::operator=(const relay& other)
}
-relay* relay::clone() const
+ref <component> relay::clone() const
{
- return new relay(*this);
+ return vmime::create <relay>(*this);
}
@@ -334,10 +334,10 @@ std::vector <string>& relay::getWithList()
}
-const std::vector <const component*> relay::getChildComponents() const
+const std::vector <ref <const component> > relay::getChildComponents() const
{
// TODO: should fields inherit from 'component'? (using typeAdapter)
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/src/streamContentHandler.cpp b/src/streamContentHandler.cpp
index c5f6145c..0b9d33e3 100644
--- a/src/streamContentHandler.cpp
+++ b/src/streamContentHandler.cpp
@@ -25,15 +25,15 @@ namespace vmime
streamContentHandler::streamContentHandler()
- : m_encoding(NO_ENCODING), m_ownedStream(NULL), m_stream(NULL)
+ : m_encoding(NO_ENCODING), m_stream(null)
{
}
-streamContentHandler::streamContentHandler(utility::inputStream* is,
- const utility::stream::size_type length, const bool own, const vmime::encoding& enc)
+streamContentHandler::streamContentHandler(ref <utility::inputStream> is,
+ const utility::stream::size_type length, const vmime::encoding& enc)
{
- setData(is, length, own, enc);
+ setData(is, length, enc);
}
@@ -44,15 +44,14 @@ streamContentHandler::~streamContentHandler()
streamContentHandler::streamContentHandler(const streamContentHandler& cts)
: contentHandler(), m_encoding(cts.m_encoding),
- m_ownedStream(const_cast <utility::smart_ptr <utility::inputStream>&>(cts.m_ownedStream)),
m_stream(cts.m_stream), m_length(cts.m_length)
{
}
-contentHandler* streamContentHandler::clone() const
+ref <contentHandler> streamContentHandler::clone() const
{
- return new streamContentHandler(*this);
+ return vmime::create <streamContentHandler>(*this);
}
@@ -60,7 +59,6 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler
{
m_encoding = cts.m_encoding;
- m_ownedStream = const_cast <utility::smart_ptr <utility::inputStream>&>(cts.m_ownedStream);
m_stream = cts.m_stream;
m_length = cts.m_length;
@@ -68,29 +66,19 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler
}
-void streamContentHandler::setData(utility::inputStream* is,
- const utility::stream::size_type length, const bool own, const vmime::encoding& enc)
+void streamContentHandler::setData(ref <utility::inputStream> is,
+ const utility::stream::size_type length, const vmime::encoding& enc)
{
m_encoding = enc;
m_length = length;
-
- if (own)
- {
- m_ownedStream = is;
- m_stream = NULL;
- }
- else
- {
- m_ownedStream = NULL;
- m_stream = is;
- }
+ m_stream = is;
}
void streamContentHandler::generate(utility::outputStream& os, const vmime::encoding& enc,
const string::size_type maxLineLength) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
// Managed data is already encoded
@@ -102,20 +90,17 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
// buffer, and then re-encode to output stream...
if (m_encoding != enc)
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
std::ostringstream oss;
utility::outputStreamAdapter tempOut(oss);
- theDecoder->decode(in, tempOut);
+ theDecoder->decode(*m_stream, tempOut);
string str = oss.str();
utility::inputStreamStringAdapter tempIn(str);
@@ -125,71 +110,56 @@ void streamContentHandler::generate(utility::outputStream& os, const vmime::enco
// No encoding to perform
else
{
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
}
// Need to encode data before
else
{
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- theEncoder->encode(in, os);
+ theEncoder->encode(*m_stream, os);
}
}
void streamContentHandler::extract(utility::outputStream& os) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
// No decoding to perform
if (!isEncoded())
{
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
+ m_stream->reset(); // may not work...
- in.reset(); // may not work...
-
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
// Need to decode data
else
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
-
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
+ ref <encoder> theDecoder = m_encoding.getEncoder();
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- theDecoder->decode(in, os);
+ theDecoder->decode(*m_stream, os);
}
}
void streamContentHandler::extractRaw(utility::outputStream& os) const
{
- if (m_stream == NULL && m_ownedStream.ptr() == NULL)
+ if (!m_stream)
return;
- utility::inputStream& in = const_cast <utility::inputStream&>
- (*(m_stream ? m_stream : m_ownedStream.ptr()));
-
- in.reset(); // may not work...
+ m_stream->reset(); // may not work...
- utility::bufferedStreamCopy(in, os);
+ utility::bufferedStreamCopy(*m_stream, os);
}
@@ -201,7 +171,7 @@ const string::size_type streamContentHandler::getLength() const
const bool streamContentHandler::isEmpty() const
{
- return (m_length == 0 || (m_stream == NULL && m_ownedStream.ptr() == NULL));
+ return (m_length == 0 || !m_stream);
}
diff --git a/src/stringContentHandler.cpp b/src/stringContentHandler.cpp
index 1d4ccc5c..9c1553f4 100644
--- a/src/stringContentHandler.cpp
+++ b/src/stringContentHandler.cpp
@@ -54,9 +54,9 @@ stringContentHandler::~stringContentHandler()
}
-contentHandler* stringContentHandler::clone() const
+ref <contentHandler> stringContentHandler::clone() const
{
- return new stringContentHandler(*this);
+ return vmime::create <stringContentHandler>(*this);
}
@@ -110,8 +110,8 @@ void stringContentHandler::generate(utility::outputStream& os,
// buffer, and then re-encode to output stream...
if (m_encoding != enc)
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
@@ -136,7 +136,7 @@ void stringContentHandler::generate(utility::outputStream& os,
// Need to encode data before
else
{
- utility::auto_ptr <encoder> theEncoder(enc.getEncoder());
+ ref <encoder> theEncoder = enc.getEncoder();
theEncoder->getProperties()["maxlinelength"] = maxLineLength;
utility::inputStreamStringProxyAdapter in(m_string);
@@ -156,7 +156,7 @@ void stringContentHandler::extract(utility::outputStream& os) const
// Need to decode data
else
{
- utility::auto_ptr <encoder> theDecoder(m_encoding.getEncoder());
+ ref <encoder> theDecoder = m_encoding.getEncoder();
utility::inputStreamStringProxyAdapter in(m_string);
diff --git a/src/text.cpp b/src/text.cpp
index a24d6668..7183e53f 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -40,19 +40,19 @@ text::text(const text& t)
text::text(const string& t, const charset& ch)
{
- text::newFromString(t, ch, this);
+ createFromString(t, ch);
}
text::text(const string& t)
{
- text::newFromString(t, charset::getLocaleCharset(), this);
+ createFromString(t, charset::getLocaleCharset());
}
text::text(const word& w)
{
- appendWord(new word(w));
+ appendWord(vmime::create <word>(w));
}
@@ -69,7 +69,7 @@ void text::parse(const string& buffer, const string::size_type position,
string::size_type newPos;
- const std::vector <word*> words = word::parseMultiple(buffer, position, end, &newPos);
+ const std::vector <ref <word> > words = word::parseMultiple(buffer, position, end, &newPos);
copy_vector(words, m_words);
@@ -93,7 +93,7 @@ const wstring text::getDecodedText() const
{
wstring out;
- for (std::vector <word*>::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
+ for (std::vector <ref <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
out += (*i)->getDecodedText();
return (out);
@@ -108,8 +108,8 @@ void text::copyFrom(const component& other)
removeAllWords();
- for (std::vector <word*>::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i)
- m_words.push_back(new word(**i));
+ for (std::vector <ref <word> >::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i)
+ m_words.push_back(vmime::create <word>(**i));
}
@@ -133,8 +133,8 @@ const bool text::operator==(const text& t) const
{
bool equal = true;
- std::vector <word*>::const_iterator i = m_words.begin();
- std::vector <word*>::const_iterator j = t.m_words.begin();
+ std::vector <ref <word> >::const_iterator i = m_words.begin();
+ std::vector <ref <word> >::const_iterator j = t.m_words.begin();
for ( ; equal && i != m_words.end() ; ++i, ++j)
equal = (**i == **j);
@@ -156,26 +156,26 @@ const string text::getConvertedText(const charset& dest) const
{
string out;
- for (std::vector <word*>::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
+ for (std::vector <ref <word> >::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i)
out += (*i)->getConvertedText(dest);
return (out);
}
-void text::appendWord(word* w)
+void text::appendWord(ref <word> w)
{
m_words.push_back(w);
}
-void text::insertWordBefore(const int pos, word* w)
+void text::insertWordBefore(const int pos, ref <word> w)
{
m_words.insert(m_words.begin() + pos, w);
}
-void text::insertWordAfter(const int pos, word* w)
+void text::insertWordAfter(const int pos, ref <word> w)
{
m_words.insert(m_words.begin() + pos + 1, w);
}
@@ -183,9 +183,7 @@ void text::insertWordAfter(const int pos, word* w)
void text::removeWord(const int pos)
{
- const std::vector <word*>::iterator it = m_words.begin() + pos;
-
- delete (*it);
+ const std::vector <ref <word> >::iterator it = m_words.begin() + pos;
m_words.erase(it);
}
@@ -193,7 +191,7 @@ void text::removeWord(const int pos)
void text::removeAllWords()
{
- free_container(m_words);
+ m_words.clear();
}
@@ -209,25 +207,25 @@ const bool text::isEmpty() const
}
-word* text::getWordAt(const int pos)
+const ref <word> text::getWordAt(const int pos)
{
return (m_words[pos]);
}
-const word* text::getWordAt(const int pos) const
+const ref <const word> text::getWordAt(const int pos) const
{
return (m_words[pos]);
}
-const std::vector <const word*> text::getWordList() const
+const std::vector <ref <const word> > text::getWordList() const
{
- std::vector <const word*> list;
+ std::vector <ref <const word> > list;
list.reserve(m_words.size());
- for (std::vector <word*>::const_iterator it = m_words.begin() ;
+ for (std::vector <ref <word> >::const_iterator it = m_words.begin() ;
it != m_words.end() ; ++it)
{
list.push_back(*it);
@@ -237,19 +235,29 @@ const std::vector <const word*> text::getWordList() const
}
-const std::vector <word*> text::getWordList()
+const std::vector <ref <word> > text::getWordList()
{
return (m_words);
}
-text* text::clone() const
+ref <component> text::clone() const
+{
+ return vmime::create <text>(*this);
+}
+
+
+ref <text> text::newFromString(const string& in, const charset& ch)
{
- return new text(*this);
+ ref <text> t = vmime::create <text>();
+
+ t->createFromString(in, ch);
+
+ return t;
}
-text* text::newFromString(const string& in, const charset& ch, text* generateInExisting)
+void text::createFromString(const string& in, const charset& ch)
{
const string::const_iterator end = in.end();
string::const_iterator p = in.begin();
@@ -259,9 +267,7 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
bool prevIs8bit = false; // is previous word 8-bit?
unsigned int count = 0; // total number of words
- text* out = (generateInExisting != NULL) ? generateInExisting : new text();
-
- out->removeAllWords();
+ removeAllWords();
for ( ; ; )
{
@@ -276,12 +282,12 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
{
// No need to create a new encoded word, just append
// the current word to the previous one.
- out->getWordAt(out->getWordCount() - 1)->
- getBuffer() += string(start, p);
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += string(start, p);
}
else
{
- out->appendWord(new word(string(start, p), ch));
+ appendWord(vmime::create <word>(string(start, p), ch));
prevIs8bit = true;
++count;
@@ -291,12 +297,12 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
{
if (count && !prevIs8bit)
{
- out->getWordAt(out->getWordCount() - 1)->
- getBuffer() += string(start, p);
+ ref <word> w = getWordAt(getWordCount() - 1);
+ w->getBuffer() += string(start, p);
}
else
{
- out->appendWord(new word
+ appendWord(vmime::create <word>
(string(start, p), charset(charsets::US_ASCII)));
prevIs8bit = false;
@@ -320,8 +326,6 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE
++p;
}
}
-
- return (out);
}
@@ -341,13 +345,23 @@ void text::encodeAndFold(utility::outputStream& os, const string::size_type maxL
}
+ref <text> text::decodeAndUnfold(const string& in)
+{
+ ref <text> t = vmime::create <text>();
+
+ decodeAndUnfold(in, t.get());
+
+ return t;
+}
+
+
text* text::decodeAndUnfold(const string& in, text* generateInExisting)
{
text* out = (generateInExisting != NULL) ? generateInExisting : new text();
out->removeAllWords();
- const std::vector <word*> words = word::parseMultiple(in, 0, in.length(), NULL);
+ const std::vector <ref <word> > words = word::parseMultiple(in, 0, in.length(), NULL);
copy_vector(words, out->m_words);
@@ -355,9 +369,9 @@ text* text::decodeAndUnfold(const string& in, text* generateInExisting)
}
-const std::vector <const component*> text::getChildComponents() const
+const std::vector <ref <const component> > text::getChildComponents() const
{
- std::vector <const component*> list;
+ std::vector <ref <const component> > list;
copy_vector(m_words, list);
diff --git a/src/textPartFactory.cpp b/src/textPartFactory.cpp
index c76697b2..2c910be0 100644
--- a/src/textPartFactory.cpp
+++ b/src/textPartFactory.cpp
@@ -49,18 +49,16 @@ textPartFactory* textPartFactory::getInstance()
}
-textPart* textPartFactory::create(const mediaType& type)
+ref <textPart> textPartFactory::create(const mediaType& type)
{
- NameMap::const_iterator pos = m_nameMap.find(type.generate());
-
- if (pos != m_nameMap.end())
- {
- return ((*pos).second)();
- }
- else
+ for (MapType::const_iterator it = m_map.begin() ;
+ it != m_map.end() ; ++it)
{
- throw exceptions::no_factory_available();
+ if ((*it).first == type)
+ return ((*it).second)();
}
+
+ throw exceptions::no_factory_available();
}
diff --git a/src/utility/path.cpp b/src/utility/path.cpp
index 5e6162ab..5dadefe1 100644
--- a/src/utility/path.cpp
+++ b/src/utility/path.cpp
@@ -38,6 +38,7 @@ path::path(const component& c)
path::path(const path& p)
+ : object()
{
m_list.resize(p.m_list.size());
std::copy(p.m_list.begin(), p.m_list.end(), m_list.begin());
diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp
index 94be1447..799c6c32 100644
--- a/src/utility/stream.cpp
+++ b/src/utility/stream.cpp
@@ -284,6 +284,13 @@ inputStreamPointerAdapter::inputStreamPointerAdapter(std::istream* is, const boo
}
+inputStreamPointerAdapter::inputStreamPointerAdapter(const inputStreamPointerAdapter&)
+ : inputStream(), m_stream(NULL), m_own(false)
+{
+ // Not copiable
+}
+
+
inputStreamPointerAdapter::~inputStreamPointerAdapter()
{
if (m_own)
diff --git a/src/utility/url.cpp b/src/utility/url.cpp
index cf991b86..a2d4e32b 100644
--- a/src/utility/url.cpp
+++ b/src/utility/url.cpp
@@ -122,7 +122,7 @@ const string url::build() const
oss << urlUtils::encode(m_path);
}
- const std::vector <const propertySet::property*> params
+ const std::vector <ref <const propertySet::property> > params
= m_params.getPropertyList();
if (!params.empty())
@@ -134,7 +134,7 @@ const string url::build() const
for (unsigned int i = 0 ; i < params.size() ; ++i)
{
- const propertySet::property* prop = params[i];
+ const ref <const propertySet::property> prop = params[i];
if (i != 0)
oss << "&";
diff --git a/src/word.cpp b/src/word.cpp
index f55a66f3..cff5afe3 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -57,7 +57,7 @@ word::word(const string& buffer, const charset& charset)
}
-word* word::parseNext(const string& buffer, const string::size_type position,
+ref <word> word::parseNext(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition,
bool prevIsEncoded, bool* isEncoded, bool isFirst)
{
@@ -101,7 +101,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
if (!unencoded.empty())
{
- word* w = new word(unencoded, charset(charsets::US_ASCII));
+ ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, pos);
if (newPosition)
@@ -158,7 +158,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
pos += 2; // ?=
- word* w = new word();
+ ref <word> w = vmime::create <word>();
w->parse(buffer, wordStart, pos, NULL);
if (newPosition)
@@ -181,7 +181,7 @@ word* word::parseNext(const string& buffer, const string::size_type position,
unencoded += string(buffer.begin() + startPos, buffer.begin() + end);
- word* w = new word(unencoded, charset(charsets::US_ASCII));
+ ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, end);
if (newPosition)
@@ -193,15 +193,15 @@ word* word::parseNext(const string& buffer, const string::size_type position,
return (w);
}
- return (NULL);
+ return (null);
}
-const std::vector <word*> word::parseMultiple(const string& buffer, const string::size_type position,
+const std::vector <ref <word> > word::parseMultiple(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
- std::vector <word*> res;
- word* w = NULL;
+ std::vector <ref <word> > res;
+ ref <word> w;
string::size_type pos = position;
@@ -694,9 +694,9 @@ const string word::getConvertedText(const charset& dest) const
}
-word* word::clone() const
+ref <component> word::clone() const
{
- return new word(m_buffer, m_charset);
+ return vmime::create <word>(m_buffer, m_charset);
}
@@ -730,9 +730,9 @@ void word::setBuffer(const string& buffer)
}
-const std::vector <const component*> word::getChildComponents() const
+const std::vector <ref <const component> > word::getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
index 87d4c1ba..ffbdefda 100644
--- a/tests/parser/bodyPartTest.cpp
+++ b/tests/parser/bodyPartTest.cpp
@@ -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());
}
diff --git a/tests/parser/encoderTest.cpp b/tests/parser/encoderTest.cpp
index 5d27fffc..55c83f83 100644
--- a/tests/parser/encoderTest.cpp
+++ b/tests/parser/encoderTest.cpp
@@ -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;
diff --git a/tests/parser/headerTest.cpp b/tests/parser/headerTest.cpp
index 4ee5b443..83f0409e 100644
--- a/tests/parser/headerTest.cpp
+++ b/tests/parser/headerTest.cpp
@@ -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]));
diff --git a/tests/parser/mediaTypeTest.cpp b/tests/parser/mediaTypeTest.cpp
index 14e07715..52da8096 100644
--- a/tests/parser/mediaTypeTest.cpp
+++ b/tests/parser/mediaTypeTest.cpp
@@ -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);
diff --git a/tests/parser/messageIdSequenceTest.cpp b/tests/parser/messageIdSequenceTest.cpp
index b80a34d9..6382adef 100644
--- a/tests/parser/messageIdSequenceTest.cpp
+++ b/tests/parser/messageIdSequenceTest.cpp
@@ -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());
}
diff --git a/tests/parser/parameterTest.cpp b/tests/parser/parameterTest.cpp
index 82d784cd..9b3bd66a 100644
--- a/tests/parser/parameterTest.cpp
+++ b/tests/parser/parameterTest.cpp
@@ -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
diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp
index e43080df..54e6c5ea 100644
--- a/tests/parser/textTest.cpp
+++ b/tests/parser/textTest.cpp
@@ -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());
diff --git a/vmime/address.hpp b/vmime/address.hpp
index 405908ae..2fce4f63 100644
--- a/vmime/address.hpp
+++ b/vmime/address.hpp
@@ -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);
};
diff --git a/vmime/addressList.hpp b/vmime/addressList.hpp
index f5629ebe..d5c63c3d 100644
--- a/vmime/addressList.hpp
+++ b/vmime/addressList.hpp
@@ -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:
diff --git a/vmime/attachment.hpp b/vmime/attachment.hpp
index 60c7b29d..72fb13d0 100644
--- a/vmime/attachment.hpp
+++ b/vmime/attachment.hpp
@@ -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
diff --git a/vmime/base.hpp b/vmime/base.hpp
index 7f3fa670..175bfdd9 100644
--- a/vmime/base.hpp
+++ b/vmime/base.hpp
@@ -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
diff --git a/vmime/body.hpp b/vmime/body.hpp
index 56cc54b1..46d53f50 100644
--- a/vmime/body.hpp
+++ b/vmime/body.hpp
@@ -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:
diff --git a/vmime/bodyPart.hpp b/vmime/bodyPart.hpp
index 60c64528..a7a63274 100644
--- a/vmime/bodyPart.hpp
+++ b/vmime/bodyPart.hpp
@@ -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:
diff --git a/vmime/charset.hpp b/vmime/charset.hpp
index 3c24a0ca..db614001 100644
--- a/vmime/charset.hpp
+++ b/vmime/charset.hpp
@@ -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:
diff --git a/vmime/component.hpp b/vmime/component.hpp
index 5a22bfd5..a7a4da1e 100644
--- a/vmime/component.hpp
+++ b/vmime/component.hpp
@@ -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:
diff --git a/vmime/contentDisposition.hpp b/vmime/contentDisposition.hpp
index eb56130e..1efc56bb 100644
--- a/vmime/contentDisposition.hpp
+++ b/vmime/contentDisposition.hpp
@@ -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);
diff --git a/vmime/contentDispositionField.hpp b/vmime/contentDispositionField.hpp
index 74382c49..e813674c 100644
--- a/vmime/contentDispositionField.hpp
+++ b/vmime/contentDispositionField.hpp
@@ -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:
diff --git a/vmime/contentHandler.hpp b/vmime/contentHandler.hpp
index 45cbb48e..bdc2fde0 100644
--- a/vmime/contentHandler.hpp
+++ b/vmime/contentHandler.hpp
@@ -33,7 +33,7 @@ namespace vmime
{
-class contentHandler
+class contentHandler : public object
{
public:
@@ -47,7 +47,7 @@ public:
*
* @return copy of this object
*/
- virtual contentHandler* clone() const = 0;
+ virtual ref <contentHandler> clone() const = 0;
/** Output the contents into the specified stream. Data will be
* encoded before being written into the stream. This is used internally
diff --git a/vmime/contentTypeField.hpp b/vmime/contentTypeField.hpp
index 442d6ba4..d273c662 100644
--- a/vmime/contentTypeField.hpp
+++ b/vmime/contentTypeField.hpp
@@ -34,7 +34,7 @@ namespace vmime
class contentTypeField : public parameterizedHeaderField, public genericField <mediaType>
{
- friend class headerFieldFactory::registerer <contentTypeField>;
+ friend class vmime::creator; // create ref
protected:
diff --git a/vmime/dateTime.hpp b/vmime/dateTime.hpp
index 1b205c22..08ba99a0 100644
--- a/vmime/dateTime.hpp
+++ b/vmime/dateTime.hpp
@@ -216,7 +216,7 @@ public:
void copyFrom(const component& other);
- datetime* clone() const;
+ ref <component> clone() const;
// Comparison
const bool operator==(const datetime& other) const;
@@ -229,7 +229,7 @@ public:
// Current date and time
static const datetime now();
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
public:
diff --git a/vmime/defaultAttachment.hpp b/vmime/defaultAttachment.hpp
index 65589b48..c451d9f8 100644
--- a/vmime/defaultAttachment.hpp
+++ b/vmime/defaultAttachment.hpp
@@ -41,8 +41,8 @@ protected:
public:
- defaultAttachment(const contentHandler& data, const encoding& enc, const mediaType& type, const text& desc = NULL_TEXT);
- defaultAttachment(const contentHandler& data, const mediaType& type, const text& desc = NULL_TEXT);
+ defaultAttachment(ref <contentHandler> data, const encoding& enc, const mediaType& type, const text& desc = NULL_TEXT);
+ defaultAttachment(ref <contentHandler> data, const mediaType& type, const text& desc = NULL_TEXT);
defaultAttachment(const defaultAttachment& attach);
~defaultAttachment();
@@ -51,15 +51,15 @@ public:
const mediaType& getType() const;
const text& getDescription() const;
- const contentHandler& getData() const;
+ const ref <const contentHandler> getData() const;
const encoding& getEncoding() const;
protected:
- mediaType m_type; // Media type (eg. "application/octet-stream")
- text m_desc; // Description (eg. "The image you requested")
- contentHandler* m_data; // Attachment data (eg. the file contents)
- encoding m_encoding; // Encoding
+ mediaType m_type; // Media type (eg. "application/octet-stream")
+ text m_desc; // Description (eg. "The image you requested")
+ ref <contentHandler> m_data; // Attachment data (eg. the file contents)
+ encoding m_encoding; // Encoding
private:
diff --git a/vmime/defaultParameter.hpp b/vmime/defaultParameter.hpp
index 7c6f7af7..6160c446 100644
--- a/vmime/defaultParameter.hpp
+++ b/vmime/defaultParameter.hpp
@@ -36,7 +36,7 @@ namespace vmime
class defaultParameter : public parameter
{
- friend class parameterFactory::registerer <defaultParameter>;
+ friend class vmime::creator; // create ref
protected:
@@ -59,8 +59,11 @@ private:
void parse(const std::vector <valueChunk>& chunks);
+ const ref <const component> getValueImp() const;
+ const ref <component> getValueImp();
- word m_value;
+
+ ref <word> m_value;
};
diff --git a/vmime/disposition.hpp b/vmime/disposition.hpp
index 8421962e..452ba794 100644
--- a/vmime/disposition.hpp
+++ b/vmime/disposition.hpp
@@ -42,11 +42,11 @@ public:
disposition(const string& actionMode, const string& sendingMode, const string& type, const string& modifier);
- disposition* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
disposition& operator=(const disposition& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Set the disposition action mode.
diff --git a/vmime/emptyContentHandler.hpp b/vmime/emptyContentHandler.hpp
index cee2fcbb..636bb691 100644
--- a/vmime/emptyContentHandler.hpp
+++ b/vmime/emptyContentHandler.hpp
@@ -34,7 +34,7 @@ public:
emptyContentHandler();
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const;
diff --git a/vmime/encoder.hpp b/vmime/encoder.hpp
index 3fe81bed..a093b48d 100644
--- a/vmime/encoder.hpp
+++ b/vmime/encoder.hpp
@@ -33,7 +33,7 @@ namespace vmime
/** Encode/decode data in different encodings.
*/
-class encoder
+class encoder : public object
{
public:
diff --git a/vmime/encoderFactory.hpp b/vmime/encoderFactory.hpp
index d466b17c..3fe5d624 100644
--- a/vmime/encoderFactory.hpp
+++ b/vmime/encoderFactory.hpp
@@ -44,17 +44,15 @@ public:
static encoderFactory* getInstance();
/** Information about a registered encoder. */
- class registeredEncoder
+ class registeredEncoder : public object
{
- friend class encoderFactory;
-
protected:
virtual ~registeredEncoder() { }
public:
- virtual encoder* create() const = 0;
+ virtual ref <encoder> create() const = 0;
virtual const string& getName() const = 0;
};
@@ -64,7 +62,7 @@ private:
template <class E>
class registeredEncoderImpl : public registeredEncoder
{
- friend class encoderFactory;
+ friend class vmime::creator;
protected:
@@ -72,9 +70,9 @@ private:
public:
- encoder* create() const
+ ref <encoder> create() const
{
- return new E;
+ return vmime::create <E>();
}
const string& getName() const
@@ -88,7 +86,7 @@ private:
};
- std::vector <registeredEncoder*> m_encoders;
+ std::vector <ref <registeredEncoder> > m_encoders;
public:
@@ -99,7 +97,7 @@ public:
template <class E>
void registerName(const string& name)
{
- m_encoders.push_back(new registeredEncoderImpl <E>(utility::stringUtils::toLower(name)));
+ m_encoders.push_back(vmime::create <registeredEncoderImpl <E> >(utility::stringUtils::toLower(name)));
}
/** Create a new encoder instance from an encoding name.
@@ -109,7 +107,7 @@ public:
* @throw exceptions::no_encoder_available if no encoder is registered
* for this encoding
*/
- encoder* create(const string& name);
+ ref <encoder> create(const string& name);
/** Return information about a registered encoder.
*
@@ -118,7 +116,7 @@ public:
* @throw exceptions::no_encoder_available if no encoder is registered
* for this encoding
*/
- const registeredEncoder* getEncoderByName(const string& name) const;
+ const ref <const registeredEncoder> getEncoderByName(const string& name) const;
/** Return the number of registered encoders.
*
@@ -131,13 +129,13 @@ public:
* @param pos position of the registered encoder to return
* @return registered encoder at the specified position
*/
- const registeredEncoder* getEncoderAt(const int pos) const;
+ const ref <const registeredEncoder> getEncoderAt(const int pos) const;
/** Return a list of all registered encoders.
*
* @return list of registered encoders
*/
- const std::vector <const registeredEncoder*> getEncoderList() const;
+ const std::vector <ref <const registeredEncoder> > getEncoderList() const;
};
diff --git a/vmime/encoding.hpp b/vmime/encoding.hpp
index 5a741144..fc2efe02 100644
--- a/vmime/encoding.hpp
+++ b/vmime/encoding.hpp
@@ -66,7 +66,7 @@ public:
const bool operator==(const encoding& value) const;
const bool operator!=(const encoding& value) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Decide which encoding to use based on the specified data.
*
@@ -83,9 +83,9 @@ public:
* @param data data used to determine encoding
* @return suitable encoding for specified data
*/
- static const encoding decide(const contentHandler& data);
+ static const encoding decide(ref <const contentHandler> data);
- encoding* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
/** Use encoderFactory to obtain an encoder/decoder object
@@ -95,7 +95,7 @@ public:
* is registered for the encoding
* @return a new encoder object for the encoding type
*/
- encoder* getEncoder() const;
+ ref <encoder> getEncoder() const;
private:
diff --git a/vmime/genericField.hpp b/vmime/genericField.hpp
index 34c6e9e4..9b306c6f 100644
--- a/vmime/genericField.hpp
+++ b/vmime/genericField.hpp
@@ -37,11 +37,22 @@ namespace vmime
template <class VALUE_TYPE>
class genericField : virtual public headerField
{
- friend class headerFieldFactory::registerer <genericField <VALUE_TYPE> >;
+ friend class vmime::creator; // create ref
protected:
- genericField() { }
+ genericField() : m_value(vmime::create <VALUE_TYPE>()) { }
+
+
+ const ref <const component> getValueImp() const
+ {
+ return (m_value);
+ }
+
+ ref <component> getValueImp()
+ {
+ return (m_value);
+ }
public:
@@ -51,31 +62,31 @@ public:
return (*this);
}
- const VALUE_TYPE& getValue() const
+ template <class TYPE>
+ void setValue(const TYPE& value)
{
- return (m_value);
+ *m_value = value;
}
VALUE_TYPE& getValue()
{
- return (m_value);
+ return *m_value;
}
- template <class TYPE>
- void setValue(const TYPE& value)
+ const VALUE_TYPE& getValue() const
{
- m_value = value;
+ return *m_value;
}
void setValue(const component& value)
{
const VALUE_TYPE& v = dynamic_cast <const VALUE_TYPE&>(value);
- m_value = v;
+ *m_value = v;
}
private:
- VALUE_TYPE m_value;
+ ref <VALUE_TYPE> m_value;
};
diff --git a/vmime/genericParameter.hpp b/vmime/genericParameter.hpp
index 79d55ba4..f0be82ae 100644
--- a/vmime/genericParameter.hpp
+++ b/vmime/genericParameter.hpp
@@ -37,11 +37,22 @@ namespace vmime
template <class VALUE_TYPE>
class genericParameter : public parameter
{
- friend class parameterFactory::registerer <genericParameter <VALUE_TYPE> >;
+ friend class vmime::creator; // create ref
protected:
- genericParameter() { }
+ genericParameter() : m_value(vmime::create <VALUE_TYPE>()) { }
+
+
+ const ref <const component> getValueImp() const
+ {
+ return m_value;
+ }
+
+ const ref <component> getValueImp()
+ {
+ return m_value;
+ }
public:
@@ -53,29 +64,29 @@ public:
const VALUE_TYPE& getValue() const
{
- return (m_value);
+ return (*m_value);
}
VALUE_TYPE& getValue()
{
- return (m_value);
+ return (*m_value);
}
template <class TYPE>
void setValue(const TYPE& value)
{
- m_value = value;
+ *m_value = value;
}
void setValue(const component& value)
{
const VALUE_TYPE& v = dynamic_cast <const VALUE_TYPE&>(value);
- m_value = v;
+ *m_value = v;
}
private:
- VALUE_TYPE m_value;
+ ref <VALUE_TYPE> m_value;
};
diff --git a/vmime/header.hpp b/vmime/header.hpp
index e663e297..eecd66d8 100644
--- a/vmime/header.hpp
+++ b/vmime/header.hpp
@@ -58,10 +58,8 @@ public:
~header();
#define FIELD_ACCESS(methodName, fieldName, type) \
- type& methodName() { return dynamic_cast <type&> \
- (*getField(fields::fieldName)); } \
- const type& methodName() const { return dynamic_cast <const type&> \
- (*findField(fields::fieldName)); }
+ ref <type> methodName() { return getField(fields::fieldName).dynamicCast <type>(); } \
+ ref <const type> methodName() const { return findField(fields::fieldName).dynamicCast <const type>(); }
FIELD_ACCESS(From, FROM, mailboxField)
FIELD_ACCESS(Sender, SENDER, mailboxField)
@@ -107,14 +105,14 @@ public:
* @throw exceptions::no_such_field if no field with this name exists
* @return first field with the specified name
*/
- headerField* findField(const string& fieldName) const;
+ ref <headerField> findField(const string& fieldName) const;
/** Find all fields that match the specified name.
* If no field is found, an empty vector is returned.
*
* @return list of fields with the specified name
*/
- std::vector <headerField*> findAllFields(const string& fieldName);
+ std::vector <ref <headerField> > findAllFields(const string& fieldName);
/** Find the first field that matches the specified name.
* If no field is found, one will be created and inserted into
@@ -123,13 +121,13 @@ public:
* @return first field with the specified name or a new field
* if no field is found
*/
- headerField* getField(const string& fieldName);
+ ref <headerField> getField(const string& fieldName);
/** Add a field at the end of the list.
*
* @param field field to append
*/
- void appendField(headerField* field);
+ void appendField(ref <headerField> field);
/** Insert a new field before the specified field.
*
@@ -137,7 +135,7 @@ public:
* @param field field to insert
* @throw exceptions::no_such_field if the field is not in the list
*/
- void insertFieldBefore(headerField* beforeField, headerField* field);
+ void insertFieldBefore(ref <headerField> beforeField, ref <headerField> field);
/** Insert a new field before the specified position.
*
@@ -145,7 +143,7 @@ public:
* the beginning of the list)
* @param field field to insert
*/
- void insertFieldBefore(const int pos, headerField* field);
+ void insertFieldBefore(const int pos, ref <headerField> field);
/** Insert a new field after the specified field.
*
@@ -153,21 +151,21 @@ public:
* @param field field to insert
* @throw exceptions::no_such_field if the field is not in the list
*/
- void insertFieldAfter(headerField* afterField, headerField* field);
+ void insertFieldAfter(ref <headerField> afterField, ref <headerField> field);
/** Insert a new field after the specified position.
*
* @param pos position of the field before the new field
* @param field field to insert
*/
- void insertFieldAfter(const int pos, headerField* field);
+ void insertFieldAfter(const int pos, ref <headerField> field);
/** Remove the specified field from the list.
*
* @param field field to remove
* @throw exceptions::no_such_field if the field is not in the list
*/
- void removeField(headerField* field);
+ void removeField(ref <headerField> field);
/** Remove the field at the specified position.
*
@@ -196,36 +194,36 @@ public:
* @param pos position
* @return field at position 'pos'
*/
- headerField* getFieldAt(const int pos);
+ ref <headerField> getFieldAt(const int pos);
/** Return the field at the specified position.
*
* @param pos position
* @return field at position 'pos'
*/
- const headerField* getFieldAt(const int pos) const;
+ const ref <const headerField> getFieldAt(const int pos) const;
/** Return the field list.
*
* @return list of fields
*/
- const std::vector <const headerField*> getFieldList() const;
+ const std::vector <ref <const headerField> > getFieldList() const;
/** Return the field list.
*
* @return list of fields
*/
- const std::vector <headerField*> getFieldList();
+ const std::vector <ref <headerField> > getFieldList();
- header* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
header& operator=(const header& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
- std::vector <headerField*> m_fields;
+ std::vector <ref <headerField> > m_fields;
public:
diff --git a/vmime/headerField.hpp b/vmime/headerField.hpp
index ba4f5601..6020dd28 100644
--- a/vmime/headerField.hpp
+++ b/vmime/headerField.hpp
@@ -35,6 +35,7 @@ namespace vmime
class headerField : public component
{
friend class headerFieldFactory;
+ friend class header;
protected:
@@ -45,11 +46,11 @@ public:
~headerField();
- headerField* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
headerField& operator=(const headerField& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of this field.
*
@@ -97,10 +98,16 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
- static headerField* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
+protected:
+
+ virtual const ref <const component> getValueImp() const = 0;
+ virtual ref <component> getValueImp() = 0;
private:
+ static ref <headerField> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
+
+
string m_name;
};
diff --git a/vmime/headerFieldFactory.hpp b/vmime/headerFieldFactory.hpp
index bad8bfe7..4f02cb98 100644
--- a/vmime/headerFieldFactory.hpp
+++ b/vmime/headerFieldFactory.hpp
@@ -36,7 +36,7 @@ protected:
headerFieldFactory();
~headerFieldFactory();
- typedef headerField* (*AllocFunc)(void);
+ typedef ref <headerField> (*AllocFunc)(void);
typedef std::map <string, AllocFunc> NameMap;
NameMap m_nameMap;
@@ -51,10 +51,10 @@ public:
{
public:
- static headerField* creator()
+ static ref <headerField> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -67,7 +67,7 @@ public:
(utility::stringUtils::toLower(name), &registerer<T>::creator));
}
- headerField* create(const string& name, const string& body = NULL_STRING);
+ ref <headerField> create(const string& name, const string& body = NULL_STRING);
};
diff --git a/vmime/htmlTextPart.hpp b/vmime/htmlTextPart.hpp
index 3dd31ae4..40fa6f6f 100644
--- a/vmime/htmlTextPart.hpp
+++ b/vmime/htmlTextPart.hpp
@@ -37,39 +37,36 @@ namespace vmime
class htmlTextPart : public textPart
{
-protected:
-
- ~htmlTextPart();
-
public:
htmlTextPart();
+ ~htmlTextPart();
const mediaType getType() const;
const charset& getCharset() const;
void setCharset(const charset& ch);
- const contentHandler& getPlainText() const;
- void setPlainText(const contentHandler& plainText);
+ const ref <const contentHandler> getPlainText() const;
+ void setPlainText(ref <contentHandler> plainText);
- const contentHandler& getText() const;
- void setText(const contentHandler& text);
+ const ref <const contentHandler> getText() const;
+ void setText(ref <contentHandler> text);
/** Embedded object (eg: image for &lt;IMG> tag).
*/
- class embeddedObject
+ class embeddedObject : public object
{
public:
- embeddedObject(const contentHandler& data, const encoding& enc,
+ embeddedObject(ref <contentHandler> data, const encoding& enc,
const string& id, const mediaType& type);
/** Return data stored in this embedded object.
*
* @return stored data
*/
- const contentHandler& getData() const;
+ const ref <const contentHandler> getData() const;
/** Return the encoding used for data in this
* embedded object.
@@ -93,7 +90,7 @@ public:
private:
- contentHandler* m_data;
+ ref <contentHandler> m_data;
encoding m_encoding;
string m_id;
mediaType m_type;
@@ -114,7 +111,7 @@ public:
* @param id object identifier
* @return embedded object with the specified identifier
*/
- const embeddedObject* findObject(const string& id) const;
+ const ref <const embeddedObject> findObject(const string& id) const;
/** Return the number of embedded objects.
*
@@ -127,7 +124,7 @@ public:
* @param pos position of the embedded object
* @return embedded object at position 'pos'
*/
- const embeddedObject* getObjectAt(const int pos) const;
+ const ref <const embeddedObject> getObjectAt(const int pos) const;
/** Embed an object and returns a string which identifies it.
*
@@ -148,7 +145,7 @@ public:
* @return an unique object identifier used to identify the new
* object among all other embedded objects
*/
- const string addObject(const contentHandler& data, const mediaType& type);
+ const string addObject(ref <contentHandler> data, const mediaType& type);
/** Embed an object and returns a string which identifies it.
*
@@ -158,17 +155,17 @@ public:
* @return an unique object identifier used to identify the new
* object among all other embedded objects
*/
- const string addObject(const contentHandler& data, const encoding& enc, const mediaType& type);
+ const string addObject(ref <contentHandler> data, const encoding& enc, const mediaType& type);
private:
- contentHandler* m_plainText;
- contentHandler* m_text;
+ ref <contentHandler> m_plainText;
+ ref <contentHandler> m_text;
charset m_charset;
- std::vector <embeddedObject*> m_objects;
+ std::vector <ref <embeddedObject> > m_objects;
- void findEmbeddedParts(const bodyPart& part, std::vector <const bodyPart*>& cidParts, std::vector <const bodyPart*>& locParts);
+ void findEmbeddedParts(const bodyPart& part, std::vector <ref <const bodyPart> >& cidParts, std::vector <ref <const bodyPart> >& locParts);
void addEmbeddedObject(const bodyPart& part, const string& id);
bool findPlainTextPart(const bodyPart& part, const bodyPart& parent, const bodyPart& textPart);
diff --git a/vmime/mailbox.hpp b/vmime/mailbox.hpp
index 1c30e102..d4f8a276 100644
--- a/vmime/mailbox.hpp
+++ b/vmime/mailbox.hpp
@@ -74,14 +74,14 @@ public:
// Assignment
void copyFrom(const component& other);
- mailbox* clone() const;
+ ref <component> clone() const;
mailbox& operator=(const mailbox& other);
const bool isEmpty() const;
void clear();
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
const bool isGroup() const;
diff --git a/vmime/mailboxField.hpp b/vmime/mailboxField.hpp
index 9a97d7a0..47bd0b59 100644
--- a/vmime/mailboxField.hpp
+++ b/vmime/mailboxField.hpp
@@ -31,7 +31,7 @@ namespace vmime
class mailboxField : public genericField <mailbox>
{
- friend class headerFieldFactory::registerer <mailboxField>;
+ friend class vmime::creator; // create ref
protected:
diff --git a/vmime/mailboxGroup.hpp b/vmime/mailboxGroup.hpp
index 413d353d..d503a4df 100644
--- a/vmime/mailboxGroup.hpp
+++ b/vmime/mailboxGroup.hpp
@@ -45,10 +45,10 @@ public:
void copyFrom(const component& other);
- mailboxGroup* clone() const;
+ ref <component> clone() const;
mailboxGroup& operator=(const component& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of the group.
*
@@ -66,7 +66,7 @@ public:
*
* @param mbox mailbox to append
*/
- void appendMailbox(mailbox* mbox);
+ void appendMailbox(ref <mailbox> mbox);
/** Insert a new mailbox before the specified mailbox.
*
@@ -74,7 +74,7 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox);
+ void insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox);
/** Insert a new mailbox before the specified position.
*
@@ -82,7 +82,7 @@ public:
* the beginning of the list)
* @param mbox mailbox to insert
*/
- void insertMailboxBefore(const int pos, mailbox* mbox);
+ void insertMailboxBefore(const int pos, ref <mailbox> mbox);
/** Insert a new mailbox after the specified mailbox.
*
@@ -90,21 +90,21 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox);
+ void insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox);
/** Insert a new mailbox after the specified position.
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
*/
- void insertMailboxAfter(const int pos, mailbox* mbox);
+ void insertMailboxAfter(const int pos, ref <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void removeMailbox(mailbox* mbox);
+ void removeMailbox(ref <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
@@ -133,33 +133,33 @@ public:
* @param pos position
* @return mailbox at position 'pos'
*/
- mailbox* getMailboxAt(const int pos);
+ ref <mailbox> getMailboxAt(const int pos);
/** Return the mailbox at the specified position.
*
* @param pos position
* @return mailbox at position 'pos'
*/
- const mailbox* getMailboxAt(const int pos) const;
+ const ref <const mailbox> getMailboxAt(const int pos) const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <const mailbox*> getMailboxList() const;
+ const std::vector <ref <const mailbox> > getMailboxList() const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <mailbox*> getMailboxList();
+ const std::vector <ref <mailbox> > getMailboxList();
const bool isGroup() const;
private:
text m_name;
- std::vector <mailbox*> m_list;
+ std::vector <ref <mailbox> > m_list;
public:
diff --git a/vmime/mailboxList.hpp b/vmime/mailboxList.hpp
index 5b77e5b2..8c73e623 100644
--- a/vmime/mailboxList.hpp
+++ b/vmime/mailboxList.hpp
@@ -43,17 +43,17 @@ public:
mailboxList(const mailboxList& mboxList);
- mailboxList* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
mailboxList& operator=(const mailboxList& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a mailbox at the end of the list.
*
* @param mbox mailbox to append
*/
- void appendMailbox(mailbox* mbox);
+ void appendMailbox(ref <mailbox> mbox);
/** Insert a new mailbox before the specified mailbox.
*
@@ -61,7 +61,7 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox);
+ void insertMailboxBefore(ref <mailbox> beforeMailbox, ref <mailbox> mbox);
/** Insert a new mailbox before the specified position.
*
@@ -69,7 +69,7 @@ public:
* the beginning of the list)
* @param mbox mailbox to insert
*/
- void insertMailboxBefore(const int pos, mailbox* mbox);
+ void insertMailboxBefore(const int pos, ref <mailbox> mbox);
/** Insert a new mailbox after the specified mailbox.
*
@@ -77,21 +77,21 @@ public:
* @param mbox mailbox to insert
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox);
+ void insertMailboxAfter(ref <mailbox> afterMailbox, ref <mailbox> mbox);
/** Insert a new mailbox after the specified position.
*
* @param pos position of the mailbox before the new mailbox
* @param mbox mailbox to insert
*/
- void insertMailboxAfter(const int pos, mailbox* mbox);
+ void insertMailboxAfter(const int pos, ref <mailbox> mbox);
/** Remove the specified mailbox from the list.
*
* @param mbox mailbox to remove
* @throw exceptions::no_such_mailbox if the mailbox is not in the list
*/
- void removeMailbox(mailbox* mbox);
+ void removeMailbox(ref <mailbox> mbox);
/** Remove the mailbox at the specified position.
*
@@ -120,26 +120,26 @@ public:
* @param pos position
* @return mailbox at position 'pos'
*/
- mailbox* getMailboxAt(const int pos);
+ ref <mailbox> getMailboxAt(const int pos);
/** Return the mailbox at the specified position.
*
* @param pos position
* @return mailbox at position 'pos'
*/
- const mailbox* getMailboxAt(const int pos) const;
+ const ref <const mailbox> getMailboxAt(const int pos) const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <const mailbox*> getMailboxList() const;
+ const std::vector <ref <const mailbox> > getMailboxList() const;
/** Return the mailbox list.
*
* @return list of mailboxes
*/
- const std::vector <mailbox*> getMailboxList();
+ const std::vector <ref <mailbox> > getMailboxList();
private:
diff --git a/vmime/mdn/MDNHelper.hpp b/vmime/mdn/MDNHelper.hpp
index af923cd4..a9d8166a 100644
--- a/vmime/mdn/MDNHelper.hpp
+++ b/vmime/mdn/MDNHelper.hpp
@@ -42,14 +42,14 @@ public:
* @param msg message in which to add a MDN request
* @param mailboxes list of mailboxes to which the MDN will be sent
*/
- static void attachMDNRequest(message* msg, const mailboxList& mailboxes);
+ static void attachMDNRequest(ref <message> msg, const mailboxList& mailboxes);
/** Attach a MDN request to the specified message.
*
* @param msg message in which to add a MDN request
* @param mbox mailbox to which the MDN will be sent
*/
- static void attachMDNRequest(message* msg, const mailbox& mbox);
+ static void attachMDNRequest(ref <message> msg, const mailbox& mbox);
/** Return a list of possible MDNs that can be generated
* for the specified message.
@@ -57,14 +57,14 @@ public:
* @param msg message for which to send a MDN
* @return list of possible MDNs
*/
- static const std::vector <sendableMDNInfos> getPossibleMDNs(const message* msg);
+ static const std::vector <sendableMDNInfos> getPossibleMDNs(const ref <const message> msg);
/** Test whether the specified message is a MDN.
*
* @param msg message
* @return true if the message is a MDN, false otherwise
*/
- static const bool isMDN(const message* msg);
+ static const bool isMDN(const ref <const message> msg);
/** If the specified message is a MDN, return information
* about it.
@@ -73,7 +73,7 @@ public:
* @throw exceptions::invalid_argument if the message is not a MDN
* @return information about the MDN
*/
- static receivedMDNInfos getReceivedMDN(const message* msg);
+ static receivedMDNInfos getReceivedMDN(const ref <const message> msg);
/** Check whether we need user confirmation for sending a MDN even
* if he/she explicitely allowed automatic send of MDNs. This can
@@ -82,7 +82,7 @@ public:
* @param msg message for which to send a MDN
* @return true if user confirmation should be asked, false otherwise
*/
- static bool needConfirmation(const message* msg);
+ static const bool needConfirmation(const ref <const message> msg);
/** Build a new MDN for the message. The resulting MDN can then be
* sent over SMTP transport service.
@@ -98,26 +98,26 @@ public:
* @param reportingUAProducts list of products in the reporting user-agent (optional)
* @return a new message object containing the MDN
*/
- static message* buildMDN(const sendableMDNInfos& mdnInfos,
- const string& text,
- const charset& ch,
- const mailbox& expeditor,
- const disposition& dispo,
- const string& reportingUA = NULL_STRING,
- const std::vector <string>& reportingUAProducts
+ static ref <message> buildMDN(const sendableMDNInfos& mdnInfos,
+ const string& text,
+ const charset& ch,
+ const mailbox& expeditor,
+ const disposition& dispo,
+ const string& reportingUA = NULL_STRING,
+ const std::vector <string>& reportingUAProducts
= std::vector <string>());
private:
- static bodyPart* createFirstMDNPart(const sendableMDNInfos& mdnInfos,
- const string& text, const charset& ch);
+ static ref <bodyPart> createFirstMDNPart(const sendableMDNInfos& mdnInfos,
+ const string& text, const charset& ch);
- static bodyPart* createSecondMDNPart(const sendableMDNInfos& mdnInfos,
- const disposition& dispo,
- const string& reportingUA,
- const std::vector <string>& reportingUAProducts);
+ static ref <bodyPart> createSecondMDNPart(const sendableMDNInfos& mdnInfos,
+ const disposition& dispo,
+ const string& reportingUA,
+ const std::vector <string>& reportingUAProducts);
- static bodyPart* createThirdMDNPart(const sendableMDNInfos& mdnInfos);
+ static ref <bodyPart> createThirdMDNPart(const sendableMDNInfos& mdnInfos);
};
diff --git a/vmime/mdn/MDNInfos.hpp b/vmime/mdn/MDNInfos.hpp
index 13347eed..85f1f34a 100644
--- a/vmime/mdn/MDNInfos.hpp
+++ b/vmime/mdn/MDNInfos.hpp
@@ -21,6 +21,7 @@
#define VMIME_MDN_MDNINFOS_HPP_INCLUDED
+#include "vmime/types.hpp"
#include "vmime/message.hpp"
@@ -31,7 +32,7 @@ namespace mdn {
/** Holds information about Message Disposition Notifications (MDN).
*/
-class MDNInfos
+class MDNInfos : public object
{
public:
@@ -42,7 +43,7 @@ public:
*
* @return related message
*/
- virtual const message* getMessage() const = 0;
+ virtual const ref <const message> getMessage() const = 0;
};
diff --git a/vmime/mdn/receivedMDNInfos.hpp b/vmime/mdn/receivedMDNInfos.hpp
index 1f3d179c..2f2aa7c4 100644
--- a/vmime/mdn/receivedMDNInfos.hpp
+++ b/vmime/mdn/receivedMDNInfos.hpp
@@ -37,13 +37,13 @@ class receivedMDNInfos : public MDNInfos
{
public:
- receivedMDNInfos(const message* msg);
+ receivedMDNInfos(const ref <const message> msg);
receivedMDNInfos(const receivedMDNInfos& other);
receivedMDNInfos& operator=(const receivedMDNInfos& other);
- const message* getMessage() const;
+ const ref <const message> getMessage() const;
/** Return the identifier of the message for which this MDN
* has been generated.
@@ -65,7 +65,7 @@ private:
void extract();
- const message* m_msg;
+ ref <const message> m_msg;
disposition m_disp;
messageId m_omid;
diff --git a/vmime/mdn/sendableMDNInfos.hpp b/vmime/mdn/sendableMDNInfos.hpp
index 6e5a6f0a..0e268062 100644
--- a/vmime/mdn/sendableMDNInfos.hpp
+++ b/vmime/mdn/sendableMDNInfos.hpp
@@ -36,12 +36,12 @@ class sendableMDNInfos : public MDNInfos
{
public:
- sendableMDNInfos(const message* msg, const mailbox& mbox);
+ sendableMDNInfos(const ref <const message> msg, const mailbox& mbox);
sendableMDNInfos(const sendableMDNInfos& other);
sendableMDNInfos& operator=(const sendableMDNInfos& other);
- const message* getMessage() const;
+ const ref <const message> getMessage() const;
/** Return the recipient of the MDN (the mailbox that will receive
* the notification message).
@@ -55,7 +55,7 @@ private:
void copyFrom(const sendableMDNInfos& other);
- const message* m_msg;
+ ref <const message> m_msg;
mailbox m_mailbox;
};
diff --git a/vmime/mediaType.hpp b/vmime/mediaType.hpp
index 9a6b2f69..97b521d8 100644
--- a/vmime/mediaType.hpp
+++ b/vmime/mediaType.hpp
@@ -47,11 +47,11 @@ public:
mediaType& operator=(const string& type);
- mediaType* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
mediaType& operator=(const mediaType& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the media type.
* See the constants in vmime::mediaTypes.
diff --git a/vmime/messageBuilder.hpp b/vmime/messageBuilder.hpp
index 3c371d02..e30db6d8 100644
--- a/vmime/messageBuilder.hpp
+++ b/vmime/messageBuilder.hpp
@@ -128,17 +128,17 @@ public:
void setSubject(const text& subject);
/** Attach a new object to the message.
- * This is a synonym for messageBuilder::appendAttachment().
+ * \deprecated Use messageBuilder::appendAttachment() instead.
*
* @param attach new attachment
*/
- void attach(attachment* attach);
+ void attach(ref <attachment> attach);
/** Attach a new object to the message.
*
* @param attach new attachment
*/
- void appendAttachment(attachment* attach);
+ void appendAttachment(ref <attachment> attach);
/** Remove the attachment at the specified position.
*
@@ -151,14 +151,14 @@ public:
* @param pos position of the attachment
* @return attachment at the specified position
*/
- const attachment* getAttachmentAt(const int pos) const;
+ const ref <const attachment> getAttachmentAt(const int pos) const;
/** Return the attachment at the specified position.
*
* @param pos position of the attachment
* @return attachment at the specified position
*/
- attachment* getAttachmentAt(const int pos);
+ ref <attachment> getAttachmentAt(const int pos);
/** Return the number of attachments in the message.
*
@@ -170,13 +170,13 @@ public:
*
* @return list of attachments
*/
- const std::vector <const attachment*> getAttachmentList() const;
+ const std::vector <ref <const attachment> > getAttachmentList() const;
/** Return the list of attachments.
*
* @return list of attachments
*/
- const std::vector <attachment*> getAttachmentList();
+ const std::vector <ref <attachment> > getAttachmentList();
/** Change the type of the text part and construct a new part.
*
@@ -188,14 +188,14 @@ public:
*
* @return text part of the message
*/
- textPart* getTextPart();
+ ref <textPart> getTextPart();
/** Construct a new message based on the information specified
* in this object.
*
* @return a new message
*/
- message* construct() const;
+ ref <message> construct() const;
private:
@@ -207,9 +207,9 @@ private:
text m_subject;
- textPart* m_textPart;
+ ref <textPart> m_textPart;
- std::vector <attachment*> m_attach;
+ std::vector <ref <attachment> > m_attach;
};
diff --git a/vmime/messageId.hpp b/vmime/messageId.hpp
index 0b471ab2..9d75631d 100644
--- a/vmime/messageId.hpp
+++ b/vmime/messageId.hpp
@@ -89,11 +89,11 @@ public:
*/
const string getId() const;
- messageId* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
messageId& operator=(const messageId& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
private:
@@ -119,7 +119,7 @@ protected:
* @param newPosition will receive the new position in the input buffer
* @return a new message-id object, or null if no more message-id can be parsed from the input buffer
*/
- static messageId* parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
+ static ref <messageId> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
};
diff --git a/vmime/messageIdSequence.hpp b/vmime/messageIdSequence.hpp
index 405ab322..8bd66de6 100644
--- a/vmime/messageIdSequence.hpp
+++ b/vmime/messageIdSequence.hpp
@@ -41,18 +41,18 @@ public:
~messageIdSequence();
- messageIdSequence* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
messageIdSequence& operator=(const messageIdSequence& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a message-id at the end of the list.
*
* @param mid message-id to append
*/
- void appendMessageId(messageId* mid);
+ void appendMessageId(ref <messageId> mid);
/** Insert a new message-id before the specified message-id.
*
@@ -60,7 +60,7 @@ public:
* @param mid message-id to insert
* @throw exceptions::no_such_messageid if the message-id is not in the list
*/
- void insertMessageIdBefore(messageId* beforeMid, messageId* mid);
+ void insertMessageIdBefore(ref <messageId> beforeMid, ref <messageId> mid);
/** Insert a new message-id before the specified position.
*
@@ -68,7 +68,7 @@ public:
* the beginning of the list)
* @param mid message-id to insert
*/
- void insertMessageIdBefore(const int pos, messageId* mid);
+ void insertMessageIdBefore(const int pos, ref <messageId> mid);
/** Insert a new message-id after the specified message-id.
*
@@ -76,21 +76,21 @@ public:
* @param mid message-id to insert
* @throw exceptions::no_such_message_id if the message-id is not in the list
*/
- void insertMessageIdAfter(messageId* afterMid, messageId* mid);
+ void insertMessageIdAfter(ref <messageId> afterMid, ref <messageId> mid);
/** Insert a new message-id after the specified position.
*
* @param pos position of the message-id before the new message-id
* @param mid message-id to insert
*/
- void insertMessageIdAfter(const int pos, messageId* mid);
+ void insertMessageIdAfter(const int pos, ref <messageId> mid);
/** Remove the specified message-id from the list.
*
* @param mid message-id to remove
* @throw exceptions::no_such_message_id if the message-id is not in the list
*/
- void removeMessageId(messageId* mid);
+ void removeMessageId(ref <messageId> mid);
/** Remove the message-id at the specified position.
*
@@ -119,30 +119,30 @@ public:
* @param pos position
* @return message-id at position 'pos'
*/
- messageId* getMessageIdAt(const int pos);
+ const ref <messageId> getMessageIdAt(const int pos);
/** Return the message-id at the specified position.
*
* @param pos position
* @return message-id at position 'pos'
*/
- const messageId* getMessageIdAt(const int pos) const;
+ const ref <const messageId> getMessageIdAt(const int pos) const;
/** Return the message-id list.
*
* @return list of message-ids
*/
- const std::vector <const messageId*> getMessageIdList() const;
+ const std::vector <ref <const messageId> > getMessageIdList() const;
/** Return the message-id list.
*
* @return list of message-ids
*/
- const std::vector <messageId*> getMessageIdList();
+ const std::vector <ref <messageId> > getMessageIdList();
private:
- std::vector <messageId*> m_list;
+ std::vector <ref <messageId> > m_list;
public:
@@ -155,8 +155,6 @@ public:
};
-
-
} // vmime
diff --git a/vmime/messageParser.hpp b/vmime/messageParser.hpp
index 71d52547..82deb767 100644
--- a/vmime/messageParser.hpp
+++ b/vmime/messageParser.hpp
@@ -93,26 +93,26 @@ public:
* @param pos position of the attachment
* @return attachment at position 'pos'
*/
- const attachment* getAttachmentAt(const int pos) const;
+ const ref <const attachment> getAttachmentAt(const int pos) const;
/** Return the attachments of the message.
*
* @return list of attachments in the message
*/
- const std::vector <const attachment*> getAttachmentList() const;
+ const std::vector <ref <const attachment> > getAttachmentList() const;
/** Return information about the specified attachment.
*
* @param a attachment to retrieve information about
* @return information about the specified attachment
*/
- const contentDispositionField* getAttachmentInfo(const attachment* a) const;
+ const ref <const contentDispositionField> getAttachmentInfo(const ref <const attachment> a) const;
/** Return the text parts of the message.
*
* @return list of text parts in the message
*/
- const std::vector <const textPart*> getTextPartList() const;
+ const std::vector <ref <const textPart> > getTextPartList() const;
/** Return the number of text parts in the message.
*
@@ -125,7 +125,7 @@ public:
* @param pos position of the text part
* @return text part at position 'pos'
*/
- const textPart* getTextPartAt(const int pos) const;
+ const ref <const textPart> getTextPartAt(const int pos) const;
private:
@@ -139,10 +139,10 @@ private:
datetime m_date;
- std::vector <attachment*> m_attach;
- std::map <attachment*, contentDispositionField*> m_attachInfo;
+ std::vector <ref <attachment> > m_attach;
+ std::map <attachment*, ref <contentDispositionField> > m_attachInfo;
- std::vector <textPart*> m_textParts;
+ std::vector <ref <textPart> > m_textParts;
void parse(const message& msg);
diff --git a/vmime/messaging/authenticationInfos.hpp b/vmime/messaging/authenticationInfos.hpp
index 2ae35ad4..3682056b 100644
--- a/vmime/messaging/authenticationInfos.hpp
+++ b/vmime/messaging/authenticationInfos.hpp
@@ -31,7 +31,7 @@ namespace messaging {
/** This class encapsulates user credentials.
*/
-class authenticationInfos
+class authenticationInfos : public object
{
public:
diff --git a/vmime/messaging/authenticator.hpp b/vmime/messaging/authenticator.hpp
index 374a48e7..3aa4b9ad 100644
--- a/vmime/messaging/authenticator.hpp
+++ b/vmime/messaging/authenticator.hpp
@@ -21,6 +21,7 @@
#define VMIME_MESSAGING_AUTHENTICATOR_HPP_INCLUDED
+#include "vmime/types.hpp"
#include "vmime/messaging/authenticationInfos.hpp"
@@ -31,7 +32,7 @@ namespace messaging {
/** This class is used to obtain user credentials.
*/
-class authenticator
+class authenticator : public object
{
public:
diff --git a/vmime/messaging/defaultAuthenticator.hpp b/vmime/messaging/defaultAuthenticator.hpp
index b3f5b811..55d1af42 100644
--- a/vmime/messaging/defaultAuthenticator.hpp
+++ b/vmime/messaging/defaultAuthenticator.hpp
@@ -29,6 +29,9 @@ namespace vmime {
namespace messaging {
+class session;
+
+
/** Default implementation for authenticator. It simply returns
* the credentials set in the session properties (named 'username'
* and 'password'). This is the default implementation used if
@@ -39,11 +42,11 @@ class defaultAuthenticator : public authenticator
{
public:
- defaultAuthenticator(const propertySet& props, const string& prefix);
+ defaultAuthenticator(weak_ref <session> session, const string& prefix);
private:
- const propertySet& m_props;
+ weak_ref <session> m_session;
const string m_prefix;
const authenticationInfos requestAuthInfos() const;
diff --git a/vmime/messaging/events.hpp b/vmime/messaging/events.hpp
index 93dc9b36..a74d6459 100644
--- a/vmime/messaging/events.hpp
+++ b/vmime/messaging/events.hpp
@@ -48,13 +48,13 @@ public:
};
- messageCountEvent(folder* folder, const Types type, const std::vector <int>& nums);
+ messageCountEvent(ref <folder> folder, const Types type, const std::vector <int>& nums);
/** Return the folder in which messages have been added/removed.
*
* @return folder in which message count changed
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -76,7 +76,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
std::vector <int> m_nums;
};
@@ -111,13 +111,13 @@ public:
};
- messageChangedEvent(folder* folder, const Types type, const std::vector <int>& nums);
+ messageChangedEvent(ref <folder> folder, const Types type, const std::vector <int>& nums);
/** Return the folder in which messages have changed.
*
* @return folder in which message count changed
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -139,7 +139,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
std::vector <int> m_nums;
};
@@ -175,13 +175,13 @@ public:
};
- folderEvent(folder* folder, const Types type, const utility::path& oldPath, const utility::path& newPath);
+ folderEvent(ref <folder> folder, const Types type, const utility::path& oldPath, const utility::path& newPath);
/** Return the folder on which the event occured.
*
* @return folder on which the event occured
*/
- const folder* getFolder() const;
+ ref <const folder> getFolder() const;
/** Return the event type.
*
@@ -197,7 +197,7 @@ public:
private:
- folder* m_folder;
+ ref <folder> m_folder;
const Types m_type;
const utility::path m_oldPath;
const utility::path m_newPath;
diff --git a/vmime/messaging/folder.hpp b/vmime/messaging/folder.hpp
index 945c862b..246a0e06 100644
--- a/vmime/messaging/folder.hpp
+++ b/vmime/messaging/folder.hpp
@@ -45,11 +45,11 @@ class store;
/** Abstract representation of a folder in a message store.
*/
-class folder
+class folder : public object
{
protected:
- folder(const folder&) { }
+ folder(const folder&) : object() { }
folder() { }
public:
@@ -160,7 +160,7 @@ public:
* @param num message sequence number
* @return a new object referencing the specified message
*/
- virtual message* getMessage(const int num) = 0;
+ virtual ref <message> getMessage(const int num) = 0;
/** Get new references to messages in this folder.
*
@@ -168,14 +168,14 @@ public:
* @param to sequence number of the last message to get
* @return new objects referencing the specified messages
*/
- virtual std::vector <message*> getMessages(const int from = 1, const int to = -1) = 0;
+ virtual std::vector <ref <message> > getMessages(const int from = 1, const int to = -1) = 0;
/** Get new references to messages in this folder.
*
* @param nums sequence numbers of the messages to delete
* @return new objects referencing the specified messages
*/
- virtual std::vector <message*> getMessages(const std::vector <int>& nums) = 0;
+ virtual std::vector <ref <message> > getMessages(const std::vector <int>& nums) = 0;
/** Return the number of messages in this folder.
*
@@ -188,7 +188,7 @@ public:
* @param name sub-folder name
* @return a new object referencing the specified folder
*/
- virtual folder* getFolder(const folder::path::component& name) = 0;
+ virtual ref <folder> getFolder(const folder::path::component& name) = 0;
/** Get the list of all sub-folders in this folder.
*
@@ -196,7 +196,7 @@ public:
* If set to false, only the direct children are returned.
* @return list of sub-folders
*/
- virtual std::vector <folder*> getFolders(const bool recursive = false) = 0;
+ virtual std::vector <ref <folder> > getFolders(const bool recursive = false) = 0;
/** Rename (move) this folder to another location.
*
@@ -247,7 +247,7 @@ public:
* @param date date/time for the new message (if NULL, the current time is used)
* @param progress progression listener, or NULL if not used
*/
- virtual void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL) = 0;
+ virtual void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL) = 0;
/** Add a message to this folder.
*
@@ -296,19 +296,19 @@ public:
*
* @return parent folder object
*/
- virtual folder* getParent() = 0;
+ virtual ref <folder> getParent() = 0;
/** Return a reference to the store to which this folder belongs.
*
* @return the store object to which this folder is attached
*/
- virtual const store* getStore() const = 0;
+ virtual weak_ref <const store> getStore() const = 0;
/** Return a reference to the store to which this folder belongs.
*
* @return the store object to which this folder is attached
*/
- virtual store* getStore() = 0;
+ virtual weak_ref <store> getStore() = 0;
/** Fetchable objects.
*/
@@ -331,14 +331,14 @@ public:
* @param options objects to fetch (combination of folder::FetchOptions flags)
* @param progress progression listener, or NULL if not used
*/
- virtual void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL) = 0;
+ virtual void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL) = 0;
/** Fetch objects for the specified message.
*
* @param msg the message
* @param options objects to fetch (combination of folder::FetchOptions flags)
*/
- virtual void fetchMessage(message* msg, const int options) = 0;
+ virtual void fetchMessage(ref <message> msg, const int options) = 0;
/** Return the list of fetchable objects supported by
* the underlying protocol (see folder::FetchOptions).
diff --git a/vmime/messaging/imap/IMAPConnection.hpp b/vmime/messaging/imap/IMAPConnection.hpp
index 8cf37933..5ceca567 100644
--- a/vmime/messaging/imap/IMAPConnection.hpp
+++ b/vmime/messaging/imap/IMAPConnection.hpp
@@ -40,11 +40,11 @@ class IMAPTag;
class IMAPStore;
-class IMAPConnection
+class IMAPConnection : public object
{
public:
- IMAPConnection(IMAPStore* store, authenticator* auth);
+ IMAPConnection(weak_ref <IMAPStore> store, ref <authenticator> auth);
~IMAPConnection();
@@ -75,31 +75,31 @@ public:
IMAPParser::response* readResponse(IMAPParser::literalHandler* lh = NULL);
- const IMAPTag* getTag() const;
- const IMAPParser* getParser() const;
+ ref <const IMAPTag> getTag() const;
+ ref <const IMAPParser> getParser() const;
- const IMAPStore* getStore() const;
- IMAPStore* getStore();
+ weak_ref <const IMAPStore> getStore() const;
+ weak_ref <IMAPStore> getStore();
- session* getSession();
+ ref <session> getSession();
private:
- IMAPStore* m_store;
+ weak_ref <IMAPStore> m_store;
- authenticator* m_auth;
+ ref <authenticator> m_auth;
- socket* m_socket;
+ ref <socket> m_socket;
- IMAPParser* m_parser;
+ ref <IMAPParser> m_parser;
- IMAPTag* m_tag;
+ ref <IMAPTag> m_tag;
char m_hierarchySeparator;
ProtocolStates m_state;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
void internalDisconnect();
diff --git a/vmime/messaging/imap/IMAPFolder.hpp b/vmime/messaging/imap/IMAPFolder.hpp
index 128fea3c..0d803a7f 100644
--- a/vmime/messaging/imap/IMAPFolder.hpp
+++ b/vmime/messaging/imap/IMAPFolder.hpp
@@ -48,6 +48,7 @@ private:
friend class IMAPStore;
friend class IMAPMessage;
+ friend class vmime::creator; // vmime::create <IMAPFolder>
IMAPFolder(const folder::path& path, IMAPStore* store, const int type = TYPE_UNDEFINED, const int flags = FLAG_UNDEFINED);
@@ -74,13 +75,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -91,7 +92,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -102,14 +103,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
@@ -130,7 +131,7 @@ private:
IMAPStore* m_store;
- IMAPConnection* m_connection;
+ ref <IMAPConnection> m_connection;
folder::path m_path;
folder::path::component m_name;
diff --git a/vmime/messaging/imap/IMAPMessage.hpp b/vmime/messaging/imap/IMAPMessage.hpp
index 43199110..33e43fec 100644
--- a/vmime/messaging/imap/IMAPMessage.hpp
+++ b/vmime/messaging/imap/IMAPMessage.hpp
@@ -43,6 +43,7 @@ class IMAPMessage : public message
private:
friend class IMAPFolder;
+ friend class vmime::creator; // vmime::create <IMAPMessage>
IMAPMessage(IMAPFolder* folder, const int num);
IMAPMessage(const IMAPMessage&) : message() { }
@@ -97,8 +98,8 @@ private:
bool m_expunged;
uid m_uid;
- header* m_header;
- structure* m_structure;
+ ref <header> m_header;
+ ref <structure> m_structure;
};
diff --git a/vmime/messaging/imap/IMAPParser.hpp b/vmime/messaging/imap/IMAPParser.hpp
index 98deac3a..205644de 100644
--- a/vmime/messaging/imap/IMAPParser.hpp
+++ b/vmime/messaging/imap/IMAPParser.hpp
@@ -74,18 +74,18 @@ namespace imap {
#endif
-class IMAPParser
+class IMAPParser : public object
{
public:
- IMAPParser(IMAPTag* tag, socket* sok, timeoutHandler* _timeoutHandler)
+ IMAPParser(weak_ref <IMAPTag> tag, weak_ref <socket> sok, weak_ref <timeoutHandler> _timeoutHandler)
: m_tag(tag), m_socket(sok), m_progress(NULL),
m_literalHandler(NULL), m_timeoutHandler(_timeoutHandler)
{
}
- const IMAPTag* tag() const
+ weak_ref <const IMAPTag> tag() const
{
return (m_tag);
}
@@ -4914,14 +4914,14 @@ public:
private:
- IMAPTag* m_tag;
- socket* m_socket;
+ weak_ref <IMAPTag> m_tag;
+ weak_ref <socket> m_socket;
utility::progressionListener* m_progress;
literalHandler* m_literalHandler;
- timeoutHandler* m_timeoutHandler;
+ weak_ref <timeoutHandler> m_timeoutHandler;
string m_buffer;
diff --git a/vmime/messaging/imap/IMAPStore.hpp b/vmime/messaging/imap/IMAPStore.hpp
index 59689b87..227a0f27 100644
--- a/vmime/messaging/imap/IMAPStore.hpp
+++ b/vmime/messaging/imap/IMAPStore.hpp
@@ -52,14 +52,14 @@ class IMAPStore : public store
public:
- IMAPStore(session* sess, authenticator* auth);
+ IMAPStore(ref <session> sess, ref <authenticator> auth);
~IMAPStore();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
@@ -77,18 +77,18 @@ public:
private:
// Connection
- IMAPConnection* m_connection;
+ ref <IMAPConnection> m_connection;
// Used to request the authentication informations only the
// first time, and reuse these informations the next time.
- class authenticator* m_oneTimeAuth;
+ ref <class authenticator> m_oneTimeAuth;
- class authenticator* oneTimeAuthenticator();
+ ref <class authenticator> oneTimeAuthenticator();
- IMAPConnection* connection();
+ ref <IMAPConnection> connection();
void registerFolder(IMAPFolder* folder);
diff --git a/vmime/messaging/imap/IMAPTag.hpp b/vmime/messaging/imap/IMAPTag.hpp
index da9569ac..526efb74 100644
--- a/vmime/messaging/imap/IMAPTag.hpp
+++ b/vmime/messaging/imap/IMAPTag.hpp
@@ -29,7 +29,7 @@ namespace messaging {
namespace imap {
-class IMAPTag
+class IMAPTag : public object
{
private:
diff --git a/vmime/messaging/maildir/maildirFolder.hpp b/vmime/messaging/maildir/maildirFolder.hpp
index 106337c1..e7702673 100644
--- a/vmime/messaging/maildir/maildirFolder.hpp
+++ b/vmime/messaging/maildir/maildirFolder.hpp
@@ -49,9 +49,10 @@ private:
friend class maildirStore;
friend class maildirMessage;
+ friend class vmime::creator; // vmime::create <maildirFolder>
- maildirFolder(const folder::path& path, maildirStore* store);
+ maildirFolder(const folder::path& path, weak_ref <maildirStore> store);
maildirFolder(const maildirFolder&) : folder() { }
~maildirFolder();
@@ -75,13 +76,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -92,7 +93,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -103,14 +104,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
@@ -118,12 +119,12 @@ private:
void scanFolder();
- void listFolders(std::vector <folder*>& list, const bool recursive);
+ void listFolders(std::vector <ref <folder> >& list, const bool recursive);
void registerMessage(maildirMessage* msg);
void unregisterMessage(maildirMessage* msg);
- const utility::file::path getMessageFSPath(const int number);
+ const utility::file::path getMessageFSPath(const int number) const;
void onStoreDisconnected();
@@ -138,7 +139,7 @@ private:
void notifyMessagesCopied(const folder::path& dest);
- maildirStore* m_store;
+ weak_ref <maildirStore> m_store;
folder::path m_path;
folder::path::component m_name;
diff --git a/vmime/messaging/maildir/maildirMessage.hpp b/vmime/messaging/maildir/maildirMessage.hpp
index 6eb8a7d2..c3e2e377 100644
--- a/vmime/messaging/maildir/maildirMessage.hpp
+++ b/vmime/messaging/maildir/maildirMessage.hpp
@@ -39,10 +39,11 @@ class maildirFolder;
class maildirMessage : public message
{
friend class maildirFolder;
+ friend class vmime::creator; // vmime::create <maildirMessage>
private:
- maildirMessage(maildirFolder* folder, const int num);
+ maildirMessage(weak_ref <maildirFolder> folder, const int num);
maildirMessage(const maildirMessage&) : message() { }
~maildirMessage();
@@ -72,7 +73,7 @@ public:
private:
- void fetch(maildirFolder* folder, const int options);
+ void fetch(weak_ref <maildirFolder> folder, const int options);
void onFolderClosed();
@@ -81,7 +82,7 @@ private:
void extractImpl(utility::outputStream& os, utility::progressionListener* progress, const int start, const int length, const int partialStart, const int partialLength, const bool peek) const;
- maildirFolder* m_folder;
+ weak_ref <maildirFolder> m_folder;
int m_num;
int m_size;
@@ -89,8 +90,8 @@ private:
bool m_expunged;
uid m_uid;
- header* m_header;
- structure* m_structure;
+ ref <header> m_header;
+ ref <structure> m_structure;
};
diff --git a/vmime/messaging/maildir/maildirStore.hpp b/vmime/messaging/maildir/maildirStore.hpp
index 25007e09..23c667a4 100644
--- a/vmime/messaging/maildir/maildirStore.hpp
+++ b/vmime/messaging/maildir/maildirStore.hpp
@@ -49,14 +49,14 @@ class maildirStore : public store
public:
- maildirStore(session* sess, authenticator* auth);
+ maildirStore(ref <session> sess, ref <authenticator> auth);
~maildirStore();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
diff --git a/vmime/messaging/maildir/maildirUtils.hpp b/vmime/messaging/maildir/maildirUtils.hpp
index 583cdc6b..8f322d92 100644
--- a/vmime/messaging/maildir/maildirUtils.hpp
+++ b/vmime/messaging/maildir/maildirUtils.hpp
@@ -73,7 +73,8 @@ public:
* @param mode type of path to return (see FolderFSPathMode)
* @return filesystem path for the specified folder
*/
- static const utility::file::path getFolderFSPath(maildirStore* store, const utility::path& folderPath, const FolderFSPathMode mode);
+ static const utility::file::path getFolderFSPath(weak_ref <maildirStore> store,
+ const utility::path& folderPath, const FolderFSPathMode mode);
/** Test whether the specified file-system directory corresponds to
* a maildir sub-folder. The name of the directory should not start
diff --git a/vmime/messaging/message.hpp b/vmime/messaging/message.hpp
index b423e039..3f87f8f5 100644
--- a/vmime/messaging/message.hpp
+++ b/vmime/messaging/message.hpp
@@ -37,12 +37,12 @@ class structure;
/** A MIME part in a message.
*/
-class part
+class part : public object
{
protected:
part() { }
- part(const part&) { }
+ part(const part&) : object() { }
virtual ~part() { }
@@ -114,12 +114,12 @@ public:
/** Structure of a MIME part/message.
*/
-class structure
+class structure : public object
{
protected:
structure() { }
- structure(const structure&) { }
+ structure(const structure&) : object() { }
public:
@@ -152,12 +152,12 @@ public:
/** Abstract representation of a message in a store/transport service.
*/
-class message
+class message : public object
{
protected:
message() { }
- message(const message&) { }
+ message(const message&) : object() { }
public:
diff --git a/vmime/messaging/pop3/POP3Folder.hpp b/vmime/messaging/pop3/POP3Folder.hpp
index 8cfe12db..bb29f858 100644
--- a/vmime/messaging/pop3/POP3Folder.hpp
+++ b/vmime/messaging/pop3/POP3Folder.hpp
@@ -48,6 +48,7 @@ private:
friend class POP3Store;
friend class POP3Message;
+ friend class vmime::creator; // vmime::create <POP3Folder>
POP3Folder(const folder::path& path, POP3Store* store);
POP3Folder(const POP3Folder&) : folder() { }
@@ -73,13 +74,13 @@ public:
const bool isOpen() const;
- message* getMessage(const int num);
- std::vector <message*> getMessages(const int from = 1, const int to = -1);
- std::vector <message*> getMessages(const std::vector <int>& nums);
+ ref <message> getMessage(const int num);
+ std::vector <ref <message> > getMessages(const int from = 1, const int to = -1);
+ std::vector <ref <message> > getMessages(const std::vector <int>& nums);
const int getMessageCount();
- folder* getFolder(const folder::path::component& name);
- std::vector <folder*> getFolders(const bool recursive = false);
+ ref <folder> getFolder(const folder::path::component& name);
+ std::vector <ref <folder> > getFolders(const bool recursive = false);
void rename(const folder::path& newPath);
@@ -90,7 +91,7 @@ public:
void setMessageFlags(const int from, const int to, const int flags, const int mode = message::FLAG_MODE_SET);
void setMessageFlags(const std::vector <int>& nums, const int flags, const int mode = message::FLAG_MODE_SET);
- void addMessage(vmime::message* msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
+ void addMessage(ref <vmime::message> msg, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void addMessage(utility::inputStream& is, const int size, const int flags = message::FLAG_UNDEFINED, vmime::datetime* date = NULL, utility::progressionListener* progress = NULL);
void copyMessage(const folder::path& dest, const int num);
@@ -101,14 +102,14 @@ public:
void expunge();
- folder* getParent();
+ ref <folder> getParent();
- const store* getStore() const;
- store* getStore();
+ weak_ref <const store> getStore() const;
+ weak_ref <store> getStore();
- void fetchMessages(std::vector <message*>& msg, const int options, utility::progressionListener* progress = NULL);
- void fetchMessage(message* msg, const int options);
+ void fetchMessages(std::vector <ref <message> >& msg, const int options, utility::progressionListener* progress = NULL);
+ void fetchMessage(ref <message> msg, const int options);
const int getFetchCapabilities() const;
diff --git a/vmime/messaging/pop3/POP3Message.hpp b/vmime/messaging/pop3/POP3Message.hpp
index 55475cc1..499f3427 100644
--- a/vmime/messaging/pop3/POP3Message.hpp
+++ b/vmime/messaging/pop3/POP3Message.hpp
@@ -43,6 +43,7 @@ class POP3Message : public message
private:
friend class POP3Folder;
+ friend class vmime::creator; // vmime::create <POP3Message>
POP3Message(POP3Folder* folder, const int num);
POP3Message(const POP3Message&) : message() { }
diff --git a/vmime/messaging/pop3/POP3Store.hpp b/vmime/messaging/pop3/POP3Store.hpp
index 2de892cc..3ff291ea 100644
--- a/vmime/messaging/pop3/POP3Store.hpp
+++ b/vmime/messaging/pop3/POP3Store.hpp
@@ -46,18 +46,16 @@ class POP3Store : public store
friend class POP3Folder;
friend class POP3Message;
-private:
-
public:
- POP3Store(session* sess, authenticator* auth);
+ POP3Store(ref <session> sess, ref <authenticator> auth);
~POP3Store();
const string getProtocolName() const;
- folder* getDefaultFolder();
- folder* getRootFolder();
- folder* getFolder(const folder::path& path);
+ ref <folder> getDefaultFolder();
+ ref <folder> getRootFolder();
+ ref <folder> getFolder(const folder::path& path);
const bool isValidFolderName(const folder::path::component& name) const;
@@ -94,10 +92,10 @@ private:
std::list <POP3Folder*> m_folders;
- socket* m_socket;
+ ref <socket> m_socket;
bool m_authentified;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
// Service infos
diff --git a/vmime/messaging/sendmail/sendmailTransport.hpp b/vmime/messaging/sendmail/sendmailTransport.hpp
index accf45b9..c63a6fac 100644
--- a/vmime/messaging/sendmail/sendmailTransport.hpp
+++ b/vmime/messaging/sendmail/sendmailTransport.hpp
@@ -43,7 +43,7 @@ class sendmailTransport : public transport
{
public:
- sendmailTransport(session* sess, authenticator* auth);
+ sendmailTransport(ref <session> sess, ref <authenticator> auth);
~sendmailTransport();
const string getProtocolName() const;
diff --git a/vmime/messaging/service.hpp b/vmime/messaging/service.hpp
index d0b710d7..9d2e76d9 100644
--- a/vmime/messaging/service.hpp
+++ b/vmime/messaging/service.hpp
@@ -39,11 +39,11 @@ namespace messaging {
/** Base class for messaging services.
*/
-class service
+class service : public object
{
protected:
- service(session* sess, const serviceInfos& infos, authenticator* auth);
+ service(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth);
public:
@@ -72,13 +72,13 @@ public:
*
* @return session object
*/
- const session* getSession() const;
+ ref <const session> getSession() const;
/** Return the session object associated with this service instance.
*
* @return session object
*/
- session* getSession();
+ ref <session> getSession();
/** Return information about this service.
*
@@ -110,13 +110,13 @@ public:
*
* @return authenticator object
*/
- const authenticator* getAuthenticator() const;
+ ref <const authenticator> getAuthenticator() const;
/** Return the authenticator object used with this service instance.
*
* @return authenticator object
*/
- authenticator* getAuthenticator();
+ ref <authenticator> getAuthenticator();
/** Set a property for this service (service prefix is added automatically).
*
@@ -149,10 +149,8 @@ public:
private:
- bool m_deleteAuth;
-
- session* m_session;
- authenticator* m_auth;
+ ref <session> m_session;
+ ref <authenticator> m_auth;
};
diff --git a/vmime/messaging/serviceFactory.hpp b/vmime/messaging/serviceFactory.hpp
index 782e4c75..c7eff565 100644
--- a/vmime/messaging/serviceFactory.hpp
+++ b/vmime/messaging/serviceFactory.hpp
@@ -59,7 +59,7 @@ public:
static serviceFactory* getInstance();
/** Information about a registered service. */
- class registeredService
+ class registeredService : public object
{
friend class serviceFactory;
@@ -69,7 +69,7 @@ public:
public:
- virtual service* create(session* sess, authenticator* auth) const = 0;
+ virtual ref <service> create(ref <session> sess, ref <authenticator> auth) const = 0;
virtual const string& getName() const = 0;
virtual const serviceInfos& getInfos() const = 0;
@@ -81,6 +81,7 @@ private:
class registeredServiceImpl : public registeredService
{
friend class serviceFactory;
+ friend class vmime::creator;
protected:
@@ -91,9 +92,9 @@ private:
public:
- service* create(session* sess, authenticator* auth) const
+ ref <service> create(ref <session> sess, ref <authenticator> auth) const
{
- return new S(sess, auth);
+ return vmime::create <S>(sess, auth);
}
const serviceInfos& getInfos() const
@@ -112,7 +113,7 @@ private:
const serviceInfos& m_servInfos;
};
- std::vector <registeredService*> m_services;
+ std::vector <ref <registeredService> > m_services;
public:
@@ -124,7 +125,7 @@ public:
void registerServiceByProtocol(const string& protocol)
{
const string name = utility::stringUtils::toLower(protocol);
- m_services.push_back(new registeredServiceImpl <S>(name));
+ m_services.push_back(vmime::create <registeredServiceImpl <S> >(name));
}
/** Create a new service instance from a protocol name.
@@ -136,7 +137,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- service* create(session* sess, const string& protocol, authenticator* auth = NULL);
+ ref <service> create(ref <session> sess, const string& protocol, ref <authenticator> auth = NULL);
/** Create a new service instance from a URL.
*
@@ -148,7 +149,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- service* create(session* sess, const utility::url& u, authenticator* auth = NULL);
+ ref <service> create(ref <session> sess, const utility::url& u, ref <authenticator> auth = NULL);
/** Return information about a registered protocol.
*
@@ -157,7 +158,7 @@ public:
* @throw exceptions::no_service_available if no service is registered
* for this protocol
*/
- const registeredService* getServiceByProtocol(const string& protocol) const;
+ ref <const registeredService> getServiceByProtocol(const string& protocol) const;
/** Return the number of registered services.
*
@@ -170,13 +171,13 @@ public:
* @param pos position of the registered service to return
* @return registered service at the specified position
*/
- const registeredService* getServiceAt(const int pos) const;
+ ref <const registeredService> getServiceAt(const int pos) const;
/** Return a list of all registered services.
*
* @return list of registered services
*/
- const std::vector <const registeredService*> getServiceList() const;
+ const std::vector <ref <const registeredService> > getServiceList() const;
};
diff --git a/vmime/messaging/serviceInfos.hpp b/vmime/messaging/serviceInfos.hpp
index d812512e..bdfcd887 100644
--- a/vmime/messaging/serviceInfos.hpp
+++ b/vmime/messaging/serviceInfos.hpp
@@ -201,7 +201,7 @@ public:
* @return value of the property
*/
template <typename TYPE>
- const TYPE getPropertyValue(session* s, const property& p) const
+ const TYPE getPropertyValue(ref <session> s, const property& p) const
{
if (p.getFlags() & property::FLAG_REQUIRED)
return s->getProperties()[getPropertyPrefix() + p.getName()].template getValue <TYPE>();
@@ -217,7 +217,7 @@ public:
* @param p property to test
* @return true if the property is set, false otherwise
*/
- const bool hasProperty(session* s, const property& p) const;
+ const bool hasProperty(ref <session> s, const property& p) const;
};
diff --git a/vmime/messaging/session.hpp b/vmime/messaging/session.hpp
index bce4a2c0..e2b92634 100644
--- a/vmime/messaging/session.hpp
+++ b/vmime/messaging/session.hpp
@@ -40,11 +40,12 @@ class transport;
* for connection to a service.
*/
-class session
+class session : public object
{
public:
session();
+ session(const session& sess);
session(const propertySet& props);
virtual ~session();
@@ -59,7 +60,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(authenticator* auth = NULL);
+ ref <transport> getTransport(ref <authenticator> auth = NULL);
/** Return a transport service instance for the specified protocol.
*
@@ -69,7 +70,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(const string& protocol, authenticator* auth = NULL);
+ ref <transport> getTransport(const string& protocol, ref <authenticator> auth = NULL);
/** Return a transport service instance for the specified URL.
*
@@ -79,7 +80,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new transport service
*/
- transport* getTransport(const utility::url& url, authenticator* auth = NULL);
+ ref <transport> getTransport(const utility::url& url, ref <authenticator> auth = NULL);
/** Return a transport service instance for the protocol specified
* in the session properties.
@@ -91,7 +92,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(authenticator* auth = NULL);
+ ref <store> getStore(ref <authenticator> auth = NULL);
/** Return a store service instance for the specified protocol.
*
@@ -101,7 +102,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(const string& protocol, authenticator* auth = NULL);
+ ref <store> getStore(const string& protocol, ref <authenticator> auth = NULL);
/** Return a store service instance for the specified URL.
*
@@ -111,7 +112,7 @@ public:
* credentials by reading the session properties "auth.username" and "auth.password".
* @return a new store service
*/
- store* getStore(const utility::url& url, authenticator* auth = NULL);
+ ref <store> getStore(const utility::url& url, ref <authenticator> auth = NULL);
/** Properties for the session and for the services.
*/
diff --git a/vmime/messaging/smtp/SMTPTransport.hpp b/vmime/messaging/smtp/SMTPTransport.hpp
index 61a5a7fe..191d134c 100644
--- a/vmime/messaging/smtp/SMTPTransport.hpp
+++ b/vmime/messaging/smtp/SMTPTransport.hpp
@@ -40,7 +40,7 @@ class SMTPTransport : public transport
{
public:
- SMTPTransport(session* sess, authenticator* auth);
+ SMTPTransport(ref <session> sess, ref <authenticator> auth);
~SMTPTransport();
const string getProtocolName() const;
@@ -67,11 +67,11 @@ private:
void internalDisconnect();
- socket* m_socket;
+ ref <socket> m_socket;
bool m_authentified;
bool m_extendedSMTP;
- timeoutHandler* m_timeoutHandler;
+ ref <timeoutHandler> m_timeoutHandler;
// Service infos
diff --git a/vmime/messaging/socket.hpp b/vmime/messaging/socket.hpp
index dbbed819..dc5cdad9 100644
--- a/vmime/messaging/socket.hpp
+++ b/vmime/messaging/socket.hpp
@@ -31,7 +31,7 @@ namespace messaging {
/** Interface for connecting to servers.
*/
-class socket
+class socket : public object
{
public:
@@ -81,6 +81,14 @@ public:
* @param count number of bytes to send (size of buffer)
*/
virtual void sendRaw(const char* buffer, const int count) = 0;
+
+protected:
+
+ socket() { }
+
+private:
+
+ socket(const socket&) : object() { }
};
@@ -93,7 +101,7 @@ public:
virtual ~socketFactory() { }
- virtual socket* create() = 0;
+ virtual ref <socket> create() = 0;
};
diff --git a/vmime/messaging/store.hpp b/vmime/messaging/store.hpp
index 6b5d8be7..68dfaf98 100644
--- a/vmime/messaging/store.hpp
+++ b/vmime/messaging/store.hpp
@@ -37,7 +37,7 @@ class store : public service
{
protected:
- store(session* sess, const serviceInfos& infos, authenticator* auth)
+ store(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth)
: service(sess, infos, auth) { }
public:
@@ -47,21 +47,21 @@ public:
*
* @return default folder
*/
- virtual folder* getDefaultFolder() = 0;
+ virtual ref <folder> getDefaultFolder() = 0;
/** Return the root folder. This is protocol dependant
* and usually is the user's mail drop root folder.
*
* @return root folder
*/
- virtual folder* getRootFolder() = 0;
+ virtual ref <folder> getRootFolder() = 0;
/** Return the folder specified by the path.
*
* @param path absolute folder path
* @return folder at the specified path
*/
- virtual folder* getFolder(const folder::path& path) = 0;
+ virtual ref <folder> getFolder(const folder::path& path) = 0;
/** Test whether the specified folder name is a syntactically
* a valid name.
diff --git a/vmime/messaging/timeoutHandler.hpp b/vmime/messaging/timeoutHandler.hpp
index 79af504e..75d333e0 100644
--- a/vmime/messaging/timeoutHandler.hpp
+++ b/vmime/messaging/timeoutHandler.hpp
@@ -21,6 +21,9 @@
#define VMIME_MESSAGING_TIMEOUTHANDLER_HPP_INCLUDED
+#include "vmime/types.hpp"
+
+
namespace vmime {
namespace messaging {
@@ -28,7 +31,7 @@ namespace messaging {
/** A class to manage time-out in messaging services.
*/
-class timeoutHandler
+class timeoutHandler : public object
{
public:
@@ -63,7 +66,7 @@ public:
virtual ~timeoutHandlerFactory() { }
- virtual timeoutHandler* create() = 0;
+ virtual ref <timeoutHandler> create() = 0;
};
diff --git a/vmime/messaging/transport.hpp b/vmime/messaging/transport.hpp
index 272fdb32..8f499154 100644
--- a/vmime/messaging/transport.hpp
+++ b/vmime/messaging/transport.hpp
@@ -42,7 +42,7 @@ class transport : public service
{
protected:
- transport(session* sess, const serviceInfos& infos, authenticator* auth);
+ transport(ref <session> sess, const serviceInfos& infos, ref <authenticator> auth);
public:
@@ -51,7 +51,7 @@ public:
* @param msg message to send
* @param progress progression listener, or NULL if not used
*/
- virtual void send(vmime::message* msg, utility::progressionListener* progress = NULL);
+ virtual void send(ref <vmime::message> msg, utility::progressionListener* progress = NULL);
/** Send a message over this transport service.
*
diff --git a/vmime/misc/importanceHelper.hpp b/vmime/misc/importanceHelper.hpp
index d450defb..b9118659 100644
--- a/vmime/misc/importanceHelper.hpp
+++ b/vmime/misc/importanceHelper.hpp
@@ -54,7 +54,7 @@ public:
*
* @param msg message on which to reset importance
*/
- static void resetImportance(message* msg);
+ static void resetImportance(ref <message> msg);
/** Return the importance of the specified message.
*
@@ -62,14 +62,14 @@ public:
* @return importance of the message, or default importance is no
* information about importance is given in the message
*/
- static const Importance getImportance(const message* msg);
+ static const Importance getImportance(const ref <const message> msg);
/** Set the importance of the specified message.
*
* @param msg message on which to set importance
* @param i new message importance
*/
- static void setImportance(message* msg, const Importance i);
+ static void setImportance(ref <message> msg, const Importance i);
};
diff --git a/vmime/object.hpp b/vmime/object.hpp
new file mode 100644
index 00000000..b8024e56
--- /dev/null
+++ b/vmime/object.hpp
@@ -0,0 +1,108 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2005 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 2 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+//
+
+#ifndef VMIME_OBJECT_HPP_INCLUDED
+#define VMIME_OBJECT_HPP_INCLUDED
+
+
+#include <vector>
+
+
+namespace vmime
+{
+
+
+/** Base object for all objects in the library. This implements
+ * reference counting and auto-deletion.
+ */
+
+class object
+{
+ template <class T> friend class utility::ref;
+ template <class T> friend class utility::weak_ref;
+
+protected:
+
+ object();
+ object(const object&);
+
+ virtual ~object();
+
+#ifndef VMIME_BUILDING_DOC
+
+ /** Add a strong reference to this object. A strong
+ * reference ensure the object remains alive.
+ */
+ void addStrong() const;
+
+ /** Add a weak reference to this object. A weak
+ * reference helps to resolve circular references.
+ */
+ void addWeak(utility::weak_ref_base* w) const;
+
+ /** Release a strong reference to this object.
+ *
+ * @return true if the object is not referenced anymore.
+ */
+ void releaseStrong() const;
+
+ /** Release a weak reference to this object.
+ *
+ * @return true if the object is not referenced anymore.
+ */
+ void releaseWeak(utility::weak_ref_base* w) const;
+
+ /** Return a reference to this object.
+ *
+ * @return reference to self
+ */
+ ref <object> thisRef();
+
+ /** Return a reference to this object (const version).
+ *
+ * @return reference to self
+ */
+ ref <const object> thisRef() const;
+
+ /** Return a weak reference to this object.
+ *
+ * @return weak reference to self
+ */
+ weak_ref <object> thisWeakRef();
+
+ /** Return a weak reference to this object (const version).
+ *
+ * @return weak reference to self
+ */
+ weak_ref <const object> thisWeakRef() const;
+
+#endif // VMIME_BUILDING_DOC
+
+private:
+
+ mutable int m_strongCount;
+ mutable std::vector <utility::weak_ref_base*> m_weakRefs;
+};
+
+
+} // vmime
+
+
+#endif // VMIME_OBJECT_HPP_INCLUDED
+
diff --git a/vmime/parameter.hpp b/vmime/parameter.hpp
index b62c87ab..9c5df03b 100644
--- a/vmime/parameter.hpp
+++ b/vmime/parameter.hpp
@@ -50,11 +50,11 @@ public:
#endif // VMIME_BUILDING_DOC
- parameter* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
parameter& operator=(const parameter& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of the parameter.
*
@@ -88,6 +88,11 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
+protected:
+
+ virtual const ref <const component> getValueImp() const = 0;
+ virtual const ref <component> getValueImp() = 0;
+
private:
string m_name;
diff --git a/vmime/parameterFactory.hpp b/vmime/parameterFactory.hpp
index 28d8cbdb..e2daf731 100644
--- a/vmime/parameterFactory.hpp
+++ b/vmime/parameterFactory.hpp
@@ -36,7 +36,7 @@ protected:
parameterFactory();
~parameterFactory();
- typedef parameter* (*AllocFunc)(void);
+ typedef ref <parameter> (*AllocFunc)(void);
typedef std::map <string, AllocFunc> NameMap;
NameMap m_nameMap;
@@ -51,10 +51,10 @@ public:
{
public:
- static parameter* creator()
+ static ref <parameter> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -74,7 +74,7 @@ public:
* @param value value to be parsed
* @return created parameter
*/
- parameter* create(const string& name, const string& value = NULL_STRING);
+ ref <parameter> create(const string& name, const string& value = NULL_STRING);
/** Create a new parameter and set its value. The returned parameter
* can then be added in a vmime::parameterizedHeaderField object.
@@ -83,7 +83,7 @@ public:
* @param value value to be set
* @return created parameter
*/
- parameter* create(const string& name, const component& value);
+ ref <parameter> create(const string& name, const component& value);
};
diff --git a/vmime/parameterizedHeaderField.hpp b/vmime/parameterizedHeaderField.hpp
index 02645eb8..aadacd08 100644
--- a/vmime/parameterizedHeaderField.hpp
+++ b/vmime/parameterizedHeaderField.hpp
@@ -64,7 +64,7 @@ public:
* @throw exceptions::no_such_parameter if no parameter with this name exists
* @return first parameter with the specified name
*/
- parameter* findParameter(const string& paramName) const;
+ ref <parameter> findParameter(const string& paramName) const;
/** Find the first parameter that matches the specified name.
* If no parameter is found, one will be created and inserted into
@@ -73,13 +73,13 @@ public:
* @return first parameter with the specified name or a new field
* if no parameter is found
*/
- parameter* getParameter(const string& paramName);
+ ref <parameter> getParameter(const string& paramName);
/** Add a parameter at the end of the list.
*
* @param param parameter to append
*/
- void appendParameter(parameter* param);
+ void appendParameter(ref <parameter> param);
/** Insert a new parameter before the specified parameter.
*
@@ -87,7 +87,7 @@ public:
* @param param parameter to insert
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void insertParameterBefore(parameter* beforeParam, parameter* param);
+ void insertParameterBefore(ref <parameter> beforeParam, ref <parameter> param);
/** Insert a new parameter before the specified position.
*
@@ -95,7 +95,7 @@ public:
* the beginning of the list)
* @param param parameter to insert
*/
- void insertParameterBefore(const int pos, parameter* param);
+ void insertParameterBefore(const int pos, ref <parameter> param);
/** Insert a new parameter after the specified parameter.
*
@@ -103,21 +103,21 @@ public:
* @param param parameter to insert
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void insertParameterAfter(parameter* afterParam, parameter* param);
+ void insertParameterAfter(ref <parameter> afterParam, ref <parameter> param);
/** Insert a new parameter after the specified position.
*
* @param pos position of the parameter before the new parameter
* @param param parameter to insert
*/
- void insertParameterAfter(const int pos, parameter* param);
+ void insertParameterAfter(const int pos, ref <parameter> param);
/** Remove the specified parameter from the list.
*
* @param param parameter to remove
* @throw exceptions::no_such_parameter if the parameter is not in the list
*/
- void removeParameter(parameter* param);
+ void removeParameter(ref <parameter> param);
/** Remove the parameter at the specified position.
*
@@ -146,30 +146,30 @@ public:
* @param pos position
* @return parameter at position 'pos'
*/
- parameter* getParameterAt(const int pos);
+ const ref <parameter> getParameterAt(const int pos);
/** Return the parameter at the specified position.
*
* @param pos position
* @return parameter at position 'pos'
*/
- const parameter* getParameterAt(const int pos) const;
+ const ref <parameter> getParameterAt(const int pos) const;
/** Return the parameter list.
*
* @return list of parameters
*/
- const std::vector <const parameter*> getParameterList() const;
+ const std::vector <ref <const parameter> > getParameterList() const;
/** Return the parameter list.
*
* @return list of parameters
*/
- const std::vector <parameter*> getParameterList();
+ const std::vector <ref <parameter> > getParameterList();
private:
- std::vector <parameter*> m_params;
+ std::vector <ref <parameter> > m_params;
public:
@@ -179,7 +179,7 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
};
diff --git a/vmime/path.hpp b/vmime/path.hpp
index 5e50feb9..4559a554 100644
--- a/vmime/path.hpp
+++ b/vmime/path.hpp
@@ -69,10 +69,10 @@ public:
// Assignment
void copyFrom(const component& other);
- path* clone() const;
+ ref <component> clone() const;
path& operator=(const path& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
protected:
diff --git a/vmime/plainTextPart.hpp b/vmime/plainTextPart.hpp
index fd5b3e02..a8be4d84 100644
--- a/vmime/plainTextPart.hpp
+++ b/vmime/plainTextPart.hpp
@@ -43,12 +43,12 @@ public:
const charset& getCharset() const;
void setCharset(const charset& ch);
- const contentHandler& getText() const;
- void setText(const contentHandler& text);
+ const ref <const contentHandler> getText() const;
+ void setText(ref <contentHandler> text);
private:
- contentHandler* m_text;
+ ref <contentHandler> m_text;
charset m_charset;
const int getPartCount() const;
diff --git a/vmime/platforms/posix/posixChildProcess.hpp b/vmime/platforms/posix/posixChildProcess.hpp
index 21c79133..517bf9b3 100644
--- a/vmime/platforms/posix/posixChildProcess.hpp
+++ b/vmime/platforms/posix/posixChildProcess.hpp
@@ -41,8 +41,8 @@ public:
void start(const std::vector <string> args, const int flags = 0);
- utility::outputStream* getStdIn();
- utility::inputStream* getStdOut();
+ ref <utility::outputStream> getStdIn();
+ ref <utility::inputStream> getStdOut();
void waitForFinish();
@@ -51,8 +51,8 @@ private:
utility::file::path m_processPath;
bool m_started;
- utility::outputStream* m_stdIn;
- utility::inputStream* m_stdOut;
+ ref <utility::outputStream> m_stdIn;
+ ref <utility::inputStream> m_stdOut;
sigset_t m_oldProcMask;
pid_t m_pid;
@@ -67,7 +67,7 @@ class posixChildProcessFactory : public utility::childProcessFactory
{
public:
- utility::childProcess* create(const utility::file::path& path) const;
+ ref <utility::childProcess> create(const utility::file::path& path) const;
};
diff --git a/vmime/platforms/posix/posixFile.hpp b/vmime/platforms/posix/posixFile.hpp
index e64f8d70..b8adb026 100644
--- a/vmime/platforms/posix/posixFile.hpp
+++ b/vmime/platforms/posix/posixFile.hpp
@@ -83,7 +83,7 @@ public:
posixFileWriter(const vmime::utility::file::path& path, const vmime::string& nativePath);
- vmime::utility::outputStream* getOutputStream();
+ ref <vmime::utility::outputStream> getOutputStream();
private:
@@ -99,7 +99,7 @@ public:
posixFileReader(const vmime::utility::file::path& path, const vmime::string& nativePath);
- vmime::utility::inputStream* getInputStream();
+ ref <vmime::utility::inputStream> getInputStream();
private:
@@ -117,7 +117,7 @@ public:
~posixFileIterator();
const bool hasMoreElements() const;
- vmime::utility::file* nextElement();
+ ref <vmime::utility::file> nextElement();
private:
@@ -153,16 +153,16 @@ public:
const bool exists() const;
- const vmime::utility::file* getParent() const;
+ ref <vmime::utility::file> getParent() const;
void rename(const path& newName);
void remove();
- vmime::utility::fileWriter* getFileWriter();
- vmime::utility::fileReader* getFileReader();
+ ref <vmime::utility::fileWriter> getFileWriter();
+ ref <vmime::utility::fileReader> getFileReader();
- vmime::utility::fileIterator* getFiles() const;
+ ref <vmime::utility::fileIterator> getFiles() const;
private:
@@ -180,7 +180,7 @@ class posixFileSystemFactory : public vmime::utility::fileSystemFactory
{
public:
- vmime::utility::file* create(const vmime::utility::file::path& path) const;
+ ref <vmime::utility::file> create(const vmime::utility::file::path& path) const;
const vmime::utility::file::path stringToPath(const vmime::string& str) const;
const vmime::string pathToString(const vmime::utility::file::path& path) const;
diff --git a/vmime/platforms/posix/posixSocket.hpp b/vmime/platforms/posix/posixSocket.hpp
index 99e12940..909ada6a 100644
--- a/vmime/platforms/posix/posixSocket.hpp
+++ b/vmime/platforms/posix/posixSocket.hpp
@@ -61,7 +61,7 @@ class posixSocketFactory : public vmime::messaging::socketFactory
{
public:
- vmime::messaging::socket* create();
+ ref <vmime::messaging::socket> create();
};
diff --git a/vmime/platforms/windows/windowsFile.hpp b/vmime/platforms/windows/windowsFile.hpp
index 15465198..86d8dcc1 100644
--- a/vmime/platforms/windows/windowsFile.hpp
+++ b/vmime/platforms/windows/windowsFile.hpp
@@ -37,7 +37,7 @@ class windowsFileSystemFactory : public vmime::utility::fileSystemFactory
{
public:
- vmime::utility::file* create(const vmime::utility::file::path& path) const;
+ ref <vmime::utility::file> create(const vmime::utility::file::path& path) const;
const vmime::utility::file::path stringToPath(const vmime::string& str) const;
const vmime::string pathToString(const vmime::utility::file::path& path) const;
@@ -57,9 +57,9 @@ public:
class windowsFile : public vmime::utility::file
{
public:
+
windowsFile(const vmime::utility::file::path& path);
-public:
void createFile();
void createDirectory(const bool createAll = false);
@@ -70,34 +70,37 @@ public:
const bool canWrite() const;
const length_type getLength();
-
+
const path& getFullPath() const;
const bool exists() const;
- const file* getParent() const;
+ ref <file> getParent() const;
void rename(const path& newName);
void remove();
- vmime::utility::fileWriter* getFileWriter();
+ ref <vmime::utility::fileWriter> getFileWriter();
- vmime::utility::fileReader* getFileReader();
+ ref <vmime::utility::fileReader> getFileReader();
- vmime::utility::fileIterator* getFiles() const;
+ ref <vmime::utility::fileIterator> getFiles() const;
private:
+
static void createDirectoryImpl(const vmime::utility::file::path& fullPath, const vmime::utility::file::path& path, const bool recursive = false);
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
-
+
class windowsFileIterator : public vmime::utility::fileIterator
{
public:
+
windowsFileIterator(const vmime::utility::file::path& path, const vmime::string& nativePath);
~windowsFileIterator();
@@ -105,11 +108,13 @@ public:
vmime::utility::file* nextElement();
private:
+
void findFirst();
void findNext();
bool isCurrentOrParentDir() const;
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
WIN32_FIND_DATA m_findData;
@@ -121,12 +126,15 @@ private:
class windowsFileReader : public vmime::utility::fileReader
{
public:
+
windowsFileReader(const vmime::utility::file::path& path, const vmime::string& nativePath);
public:
- vmime::utility::inputStream* getInputStream();
+
+ ref <vmime::utility::inputStream> getInputStream();
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
@@ -135,16 +143,19 @@ private:
class windowsFileReaderInputStream : public vmime::utility::inputStream
{
public:
+
windowsFileReaderInputStream(const vmime::utility::file::path& path, HANDLE hFile);
~windowsFileReaderInputStream();
public:
+
const bool eof() const;
void reset();
const size_type read(value_type* const data, const size_type count);
const size_type skip(const size_type count);
private:
+
const vmime::utility::file::path m_path;
HANDLE m_hFile;
};
@@ -153,12 +164,15 @@ private:
class windowsFileWriter : public vmime::utility::fileWriter
{
public:
+
windowsFileWriter(const vmime::utility::file::path& path, const vmime::string& nativePath);
public:
- vmime::utility::outputStream* getOutputStream();
+
+ ref <vmime::utility::outputStream> getOutputStream();
private:
+
vmime::utility::file::path m_path;
vmime::string m_nativePath;
};
@@ -167,17 +181,21 @@ private:
class windowsFileWriterOutputStream : public vmime::utility::outputStream
{
public:
+
windowsFileWriterOutputStream(const vmime::utility::file::path& path, HANDLE hFile);
~windowsFileWriterOutputStream();
public:
+
void write(const value_type* const data, const size_type count);
private:
+
const vmime::utility::file::path m_path;
HANDLE m_hFile;
};
+
} // windows
} // platforms
} // vmime
diff --git a/vmime/platforms/windows/windowsSocket.hpp b/vmime/platforms/windows/windowsSocket.hpp
index 8a06d4d3..bbf76643 100644
--- a/vmime/platforms/windows/windowsSocket.hpp
+++ b/vmime/platforms/windows/windowsSocket.hpp
@@ -40,6 +40,7 @@ public:
~windowsSocket();
public:
+
void connect(const vmime::string& address, const vmime::port_t port);
const bool isConnected() const;
void disconnect();
@@ -51,6 +52,7 @@ public:
void sendRaw(const char* buffer, const int count);
private:
+
char m_buffer[65536];
SOCKET m_desc;
};
@@ -60,7 +62,8 @@ private:
class windowsSocketFactory : public vmime::messaging::socketFactory
{
public:
- vmime::messaging::socket* create();
+
+ ref <vmime::messaging::socket> create();
};
diff --git a/vmime/propertySet.hpp b/vmime/propertySet.hpp
index b1fc0be1..5bd03dd2 100644
--- a/vmime/propertySet.hpp
+++ b/vmime/propertySet.hpp
@@ -39,13 +39,13 @@ namespace vmime
/** Manage a list of (name,value) pairs.
*/
-class propertySet
+class propertySet : public object
{
public:
/** A property holds a (name,value) pair.
*/
- class property
+ class property : public object
{
public:
@@ -259,7 +259,7 @@ public:
template <class TYPE>
const TYPE getProperty(const string& name) const
{
- const property* const prop = find(name);
+ const ref <property> prop = find(name);
if (!prop) throw exceptions::no_such_property(name);
//return (prop->getValue <TYPE>()); // BUG: with g++ < 3.4
@@ -278,7 +278,7 @@ public:
template <class TYPE>
const TYPE getProperty(const string& name, const TYPE defaultValue) const
{
- const property* const prop = find(name);
+ const ref <property> prop = find(name);
//return (prop ? prop->getValue <TYPE>() : defaultValue); // BUG: with g++ < 3.4
return (prop ? prop->template getValue <TYPE>() : defaultValue);
}
@@ -318,13 +318,13 @@ private:
void parse(const string& props);
- class propFinder : public std::unary_function <property*, bool>
+ class propFinder : public std::unary_function <ref <property>, bool>
{
public:
propFinder(const string& name) : m_name(utility::stringUtils::toLower(name)) { }
- const bool operator()(property* const p) const
+ const bool operator()(ref <property> p) const
{
return (utility::stringUtils::toLower(p->getName()) == m_name);
}
@@ -334,10 +334,10 @@ private:
const std::string m_name;
};
- property* find(const string& name) const;
- property* findOrCreate(const string& name);
+ ref <property> find(const string& name) const;
+ ref <property> findOrCreate(const string& name);
- typedef std::list <property*> list_type;
+ typedef std::list <ref <property> > list_type;
list_type m_props;
public:
@@ -404,13 +404,13 @@ public:
*
* @return list of properties
*/
- const std::vector <const property*> getPropertyList() const;
+ const std::vector <ref <const property> > getPropertyList() const;
/** Return the property list.
*
* @return list of properties
*/
- const std::vector <property*> getPropertyList();
+ const std::vector <ref <property> > getPropertyList();
};
diff --git a/vmime/relay.hpp b/vmime/relay.hpp
index c97db613..168084fb 100644
--- a/vmime/relay.hpp
+++ b/vmime/relay.hpp
@@ -43,11 +43,11 @@ public:
public:
- relay* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
relay& operator=(const relay& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
const string& getFrom() const;
void setFrom(const string& from);
diff --git a/vmime/standardFields.hpp b/vmime/standardFields.hpp
index 8fdb2a99..89d30da8 100644
--- a/vmime/standardFields.hpp
+++ b/vmime/standardFields.hpp
@@ -44,7 +44,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericField <valueTypeClassName> { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
@@ -61,7 +61,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD_PARAM(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericParameterizedHeaderField <valueTypeClassName> { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
@@ -74,7 +74,7 @@ namespace vmime
#define DECLARE_STANDARD_FIELD_PARAM(fieldClassName, valueTypeClassName) \
class fieldClassName : public genericField <valueTypeClassName>, \
public parameterizedHeaderField { \
- friend class headerFieldFactory::registerer <fieldClassName>; \
+ friend class vmime::creator; \
protected: \
fieldClassName() { } \
fieldClassName(const fieldClassName&) \
diff --git a/vmime/standardParams.hpp b/vmime/standardParams.hpp
index 6c48835f..06e29c3e 100644
--- a/vmime/standardParams.hpp
+++ b/vmime/standardParams.hpp
@@ -35,7 +35,7 @@ namespace vmime
#define DECLARE_STANDARD_PARAM(paramClassName, valueTypeClassName) \
class paramClassName : public genericParameter <valueTypeClassName> { \
- friend class parameterFactory::registerer <paramClassName>; \
+ friend class vmime::creator; \
protected: \
paramClassName() { } \
paramClassName(const paramClassName&) \
diff --git a/vmime/streamContentHandler.hpp b/vmime/streamContentHandler.hpp
index 1dfa4071..3e668703 100644
--- a/vmime/streamContentHandler.hpp
+++ b/vmime/streamContentHandler.hpp
@@ -33,16 +33,16 @@ class streamContentHandler : public contentHandler
public:
streamContentHandler();
- streamContentHandler(utility::inputStream* is, const utility::stream::size_type length, const bool own, const vmime::encoding& enc = NO_ENCODING);
+ streamContentHandler(ref <utility::inputStream> is, const utility::stream::size_type length, const vmime::encoding& enc = NO_ENCODING);
~streamContentHandler();
streamContentHandler(const streamContentHandler& cts);
streamContentHandler& operator=(const streamContentHandler& cts);
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
- void setData(utility::inputStream* is, const utility::stream::size_type length, const bool own, const vmime::encoding& enc = NO_ENCODING);
+ void setData(ref <utility::inputStream> is, const utility::stream::size_type length, const vmime::encoding& enc = NO_ENCODING);
void generate(utility::outputStream& os, const vmime::encoding& enc, const string::size_type maxLineLength = lineLengthLimits::infinite) const;
@@ -65,8 +65,7 @@ private:
vmime::encoding m_encoding;
// Actual data
- utility::smart_ptr <utility::inputStream> m_ownedStream; // 'contentHandler' objects are copiable...
- utility::inputStream* m_stream;
+ mutable ref <utility::inputStream> m_stream;
string::size_type m_length;
};
diff --git a/vmime/stringContentHandler.hpp b/vmime/stringContentHandler.hpp
index f3e905fa..f66a4b41 100644
--- a/vmime/stringContentHandler.hpp
+++ b/vmime/stringContentHandler.hpp
@@ -42,7 +42,7 @@ public:
stringContentHandler(const stringContentHandler& cts);
stringContentHandler& operator=(const stringContentHandler& cts);
- contentHandler* clone() const;
+ ref <contentHandler> clone() const;
// Set the data contained in the body.
//
diff --git a/vmime/text.hpp b/vmime/text.hpp
index 0f42b982..ed75824c 100644
--- a/vmime/text.hpp
+++ b/vmime/text.hpp
@@ -48,18 +48,18 @@ public:
const bool operator==(const text& t) const;
const bool operator!=(const text& t) const;
- text* clone() const;
+ ref <component> clone() const;
void copyFrom(const component& other);
text& operator=(const component& other);
text& operator=(const text& other);
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
/** Add a word at the end of the list.
*
* @param w word to append
*/
- void appendWord(word* w);
+ void appendWord(ref <word> w);
/** Insert a new word before the specified position.
*
@@ -67,14 +67,14 @@ public:
* the beginning of the list)
* @param w word to insert
*/
- void insertWordBefore(const int pos, word* w);
+ void insertWordBefore(const int pos, ref <word> w);
/** Insert a new word after the specified position.
*
* @param pos position of the word before the new word
* @param w word to insert
*/
- void insertWordAfter(const int pos, word* w);
+ void insertWordAfter(const int pos, ref <word> w);
/** Remove the word at the specified position.
*
@@ -103,26 +103,26 @@ public:
* @param pos position
* @return word at position 'pos'
*/
- word* getWordAt(const int pos);
+ const ref <word> getWordAt(const int pos);
/** Return the word at the specified position.
*
* @param pos position
* @return word at position 'pos'
*/
- const word* getWordAt(const int pos) const;
+ const ref <const word> getWordAt(const int pos) const;
/** Return the word list.
*
* @return list of words
*/
- const std::vector <const word*> getWordList() const;
+ const std::vector <ref <const word> > getWordList() const;
/** Return the word list.
*
* @return list of words
*/
- const std::vector <word*> getWordList();
+ const std::vector <ref <word> > getWordList();
// Decoding
#if VMIME_WIDE_CHAR_SUPPORT
@@ -153,13 +153,27 @@ public:
*
* @param in input string
* @param ch input charset
- * @param generateInExisting if not NULL, the resulting text will be generated
- * in the specified object instead of a new created object (in this case, the
- * function returns the same pointer). Can be used to avoid copying the
- * resulting object into an existing object.
- * @return new text object or existing object if generateInExisting != NULL
- */
- static text* newFromString(const string& in, const charset& ch, text* generateInExisting = NULL);
+ * @return new text object
+ */
+ static ref <text> newFromString(const string& in, const charset& ch);
+
+ /** This function can be used to make several encoded words from a text.
+ * All the characters in the text must be in the same specified charset.
+ *
+ * <p>Eg: giving:</p>
+ * <pre> &lt;iso-8859-1> "Linux dans un t'el'ephone mobile"
+ * ("=?iso-8859-1?Q?Linux_dans_un_t=E9l=E9phone_mobile?=")
+ * </pre><p>it will return:</p>
+ * <pre> &lt;us-ascii> "Linux dans un "
+ * &lt;iso-8859-1> "t'el'ephone "
+ * &lt;us-ascii> "mobile"
+ * ("Linux dans un =?iso-8859-1?Q?t=E9l=E9phone_?= mobile")
+ * </pre>
+ *
+ * @param in input string
+ * @param ch input charset
+ */
+ void createFromString(const string& in, const charset& ch);
/** Flags used by "encodeAndFold" function.
*/
@@ -193,7 +207,18 @@ public:
* resulting object into an existing object.
* @return new text object or existing object if generateInExisting != NULL
*/
- static text* decodeAndUnfold(const string& in, text* generateInExisting = NULL);
+ static ref <text> decodeAndUnfold(const string& in);
+
+ /** Decode and unfold text (RFC-2047).
+ *
+ * @param in input string
+ * @param generateInExisting if not NULL, the resulting text will be generated
+ * in the specified object instead of a new created object (in this case, the
+ * function returns the same pointer). Can be used to avoid copying the
+ * resulting object into an existing object.
+ * @return new text object or existing object if generateInExisting != NULL
+ */
+ static text* decodeAndUnfold(const string& in, text* generateInExisting);
using component::parse;
@@ -205,7 +230,7 @@ public:
private:
- std::vector <word*> m_words;
+ std::vector <ref <word> > m_words;
};
diff --git a/vmime/textPart.hpp b/vmime/textPart.hpp
index 5186592a..42aeecae 100644
--- a/vmime/textPart.hpp
+++ b/vmime/textPart.hpp
@@ -35,7 +35,7 @@ namespace vmime
/** Generic text part.
*/
-class textPart
+class textPart : public object
{
friend class textPartFactory;
friend class messageBuilder; // for generateIn, getPartCount
@@ -69,13 +69,13 @@ public:
*
* @return text of the part
*/
- virtual const contentHandler& getText() const = 0;
+ virtual const ref <const contentHandler> getText() const = 0;
/** Set the text contained in the part.
*
* @param text text of the part
*/
- virtual void setText(const contentHandler& text) = 0;
+ virtual void setText(ref <contentHandler> text) = 0;
protected:
diff --git a/vmime/textPartFactory.hpp b/vmime/textPartFactory.hpp
index d117edb8..5a7486ba 100644
--- a/vmime/textPartFactory.hpp
+++ b/vmime/textPartFactory.hpp
@@ -36,10 +36,10 @@ protected:
textPartFactory();
~textPartFactory();
- typedef textPart* (*AllocFunc)(void);
- typedef std::map <string, AllocFunc> NameMap;
+ typedef ref <textPart> (*AllocFunc)(void);
+ typedef std::vector <std::pair <mediaType, AllocFunc> > MapType;
- NameMap m_nameMap;
+ MapType m_map;
#ifndef VMIME_BUILDING_DOC
template <class TYPE>
@@ -47,10 +47,10 @@ protected:
{
public:
- static textPart* creator()
+ static ref <textPart> creator()
{
// Allocate a new object
- return new TYPE();
+ return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
@@ -62,10 +62,10 @@ public:
template <class T>
void registerType(const mediaType& type)
{
- m_nameMap.insert(NameMap::value_type(type.generate(), &registerer<T>::creator));
+ m_map.push_back(MapType::value_type(type, &registerer<T>::creator));
}
- textPart* create(const mediaType& type);
+ ref <textPart> create(const mediaType& type);
};
diff --git a/vmime/typeAdapter.hpp b/vmime/typeAdapter.hpp
index 9565b567..0dc59808 100644
--- a/vmime/typeAdapter.hpp
+++ b/vmime/typeAdapter.hpp
@@ -30,7 +30,7 @@ namespace vmime
{
-/** An adapter to allow any type being treated as a 'component'.
+/** An adapter to allow any type to act as a 'component'.
*/
template <class TYPE>
@@ -43,7 +43,7 @@ public:
}
typeAdapter(typeAdapter& a)
- : m_value(a.m_value)
+ : component(), m_value(a.m_value)
{
}
@@ -53,9 +53,9 @@ public:
}
- typeAdapter* clone() const
+ ref <component> clone() const
{
- return new typeAdapter(*this);
+ return create <typeAdapter>(*this);
}
@@ -112,9 +112,9 @@ public:
*newLinePos = curLinePos + oss.str().length();
}
- const std::vector <const component*> getChildComponents() const
+ const std::vector <ref <const component> > getChildComponents() const
{
- return std::vector <const component*>();
+ return std::vector <ref <const component> >();
}
private:
diff --git a/vmime/types.hpp b/vmime/types.hpp
index 9a2d7f19..1028fed3 100644
--- a/vmime/types.hpp
+++ b/vmime/types.hpp
@@ -25,6 +25,7 @@
#include <string>
#include "vmime/config.hpp"
+#include "vmime/utility/smartPtr.hpp"
namespace vmime
@@ -37,7 +38,20 @@ namespace vmime
typedef unsigned short port_t;
typedef int char_t;
+
+ // Some aliases
+ namespace utils = utility;
+
+ using vmime::utility::ref;
+ using vmime::utility::weak_ref;
+ using vmime::utility::null_ref;
+
+ extern const null_ref null;
}
+// This is here because 'vmime::ref' need to be declared...
+#include "vmime/object.hpp"
+
+
#endif // VMIME_TYPES_HPP_INCLUDED
diff --git a/vmime/utility/childProcess.hpp b/vmime/utility/childProcess.hpp
index b6d876bf..e7499350 100644
--- a/vmime/utility/childProcess.hpp
+++ b/vmime/utility/childProcess.hpp
@@ -35,7 +35,7 @@ namespace utility {
* and/or standard output.
*/
-class childProcess
+class childProcess : public object
{
public:
@@ -61,13 +61,13 @@ public:
*
* @return output stream wrapper for child's stdin
*/
- virtual utility::outputStream* getStdIn() = 0;
+ virtual ref <utility::outputStream> getStdIn() = 0;
/** Return a wrapper to the child process standard output.
*
* @return input stream wrapper for child's stdout
*/
- virtual utility::inputStream* getStdOut() = 0;
+ virtual ref <utility::inputStream> getStdOut() = 0;
/** Wait for the process to finish.
*
@@ -91,7 +91,7 @@ public:
*
* @param path full path of the process executable file
*/
- virtual childProcess* create(const utility::file::path& path) const = 0;
+ virtual ref <childProcess> create(const utility::file::path& path) const = 0;
};
diff --git a/vmime/utility/file.hpp b/vmime/utility/file.hpp
index 89fbeebe..ca93bb00 100644
--- a/vmime/utility/file.hpp
+++ b/vmime/utility/file.hpp
@@ -40,7 +40,7 @@ class file;
/** File list iterator (see file::getFiles).
*/
-class fileIterator
+class fileIterator : public object
{
public:
@@ -57,40 +57,40 @@ public:
*
* @return next file or NULL
*/
- virtual file* nextElement() = 0;
+ virtual ref <file> nextElement() = 0;
};
/** Write to a file.
*/
-class fileWriter
+class fileWriter : public object
{
public:
virtual ~fileWriter() { }
- virtual utility::outputStream* getOutputStream() = 0;
+ virtual ref <utility::outputStream> getOutputStream() = 0;
};
/** Read from a file.
*/
-class fileReader
+class fileReader : public object
{
public:
virtual ~fileReader() { }
- virtual utility::inputStream* getInputStream() = 0;
+ virtual ref <utility::inputStream> getInputStream() = 0;
};
/** Abstract representation of a file or directory.
*/
-class file
+class file : public object
{
public:
@@ -161,7 +161,7 @@ public:
*
* @return parent directory (or NULL if root)
*/
- virtual const file* getParent() const = 0;
+ virtual ref <file> getParent() const = 0;
/** Rename the file/directory.
*
@@ -181,13 +181,13 @@ public:
*
* @return file writer object
*/
- virtual fileWriter* getFileWriter() = 0;
+ virtual ref <fileWriter> getFileWriter() = 0;
/** Return an object capable of reading from this file.
*
* @return file reader object
*/
- virtual fileReader* getFileReader() = 0;
+ virtual ref <fileReader> getFileReader() = 0;
/** Enumerate files contained in this directory.
*
@@ -195,7 +195,15 @@ public:
* @throw exceptions::not_a_directory if this is not a directory,
* exceptions::filesystem_exception if another error occurs
*/
- virtual fileIterator* getFiles() const = 0;
+ virtual ref <fileIterator> getFiles() const = 0;
+
+protected:
+
+ file() { }
+
+private:
+
+ file(const file&) : object() { }
};
@@ -213,7 +221,7 @@ public:
* @param path full path (absolute) of the file
* @return new file object for the path
*/
- virtual file* create(const file::path& path) const = 0;
+ virtual ref <file> create(const file::path& path) const = 0;
/** Parse a path contained in a string.
*
diff --git a/vmime/utility/path.hpp b/vmime/utility/path.hpp
index 06d1403f..fde3b7f7 100644
--- a/vmime/utility/path.hpp
+++ b/vmime/utility/path.hpp
@@ -34,7 +34,7 @@ namespace utility {
/** Abstract representation of a path (filesystem, mailbox, etc).
*/
-class path
+class path : public object
{
public:
diff --git a/vmime/utility/smartPtr.hpp b/vmime/utility/smartPtr.hpp
index 7b895629..65ea2ff6 100644
--- a/vmime/utility/smartPtr.hpp
+++ b/vmime/utility/smartPtr.hpp
@@ -21,6 +21,13 @@
#define VMIME_UTILITY_SMARTPTR_HPP_INCLUDED
+#include <map>
+
+
+// Forward reference to 'object'
+namespace vmime { class object; }
+
+
namespace vmime {
namespace utility {
@@ -47,116 +54,489 @@ public:
};
-/** Smart auto-delete, referencable and copiable pointer.
+/** Null reference.
*/
-template <class T>
-class smart_ptr
+class null_ref
{
private:
- struct data
+ int foo;
+};
+
+
+/** Strong reference (smart pointer).
+ */
+
+template <class T>
+class ref
+{
+public:
+
+ template <class U> friend class ref;
+ template <class U> friend class weak_ref;
+
+
+ ref() : m_ptr(0) { }
+ ref(const ref& r) : m_ptr(0) { attach(r); }
+ ref(const null_ref&) : m_ptr(0) { }
+
+ virtual ~ref() { detach(); }
+
+ // Allow creating NULL ref (NULL casts to anything*)
+ ref(class null_pointer*) : m_ptr(0) { }
+
+
+ // Access to wrapped object
+ operator const T*() const { return m_ptr; }
+
+ T& operator *() { return *m_ptr; }
+ const T& operator *() const { return *m_ptr; }
+
+ T* operator ->() { return m_ptr; }
+ const T* operator ->() const { return m_ptr; }
+
+ const T* const get() const { return m_ptr; }
+ T* const get() { return m_ptr; }
+
+
+ // dynamic_cast
+ template <class U>
+ ref <U> dynamicCast() const
{
- int refCount;
- T* ptr;
- };
+ U* p = dynamic_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return ref <U>();
- data* m_data;
+ p->addStrong();
+ ref <U> r;
+ r.m_ptr = p;
- typedef std::map <T*, data*> MapType;
- static MapType sm_map;
+ return r;
+ }
-public:
+ // static_cast
+ template <class U>
+ ref <U> staticCast() const
+ {
+ U* p = static_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return ref <U>();
- smart_ptr() : m_data(NULL) { }
- smart_ptr(T* const p) : m_data(NULL) { if (p) { attach(p); } }
- smart_ptr(const smart_ptr& p) : m_data(NULL) { if (p.m_data) { attach(p); } }
+ p->addStrong();
- ~smart_ptr() { detach(); }
+ ref <U> r;
+ r.m_ptr = p;
- smart_ptr& operator=(smart_ptr& p)
+ return r;
+ }
+
+ // const_cast
+ template <class U>
+ ref <U> constCast() const
{
- attach(p);
- return (*this);
+ U* p = const_cast <U*>(m_ptr);
+ if (!p) return ref <U>();
+
+ m_ptr->addStrong();
+
+ ref <U> r;
+ r.m_ptr = p;
+
+ return r;
}
- smart_ptr& operator=(T* const p)
+ // Implicit downcast
+ template <class U>
+ operator ref <const U>() const
{
- if (!p)
- detach();
- else
- attach(p);
+ if (m_ptr)
+ m_ptr->addStrong();
+
+ ref <const U> r;
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
- return (*this);
+ return r;
}
- operator T*() { return (m_data ? m_data->ptr : NULL); }
- operator const T*() { return (m_data ? m_data->ptr : NULL); }
+ template <class U>
+ operator ref <U>()
+ {
+ if (m_ptr)
+ m_ptr->addStrong();
- T& operator *() { return (*(m_data->ptr)); }
- T* operator ->() { return (m_data->ptr); }
+ ref <U> r;
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
- const T* const ptr() const { return (m_data ? m_data->ptr : NULL); }
- T* const ptr() { return (m_data ? m_data->ptr : NULL); }
+ return r;
+ }
-private:
+ template <class U>
+ ref <T>& operator=(const ref <U>& other)
+ {
+ U* ptr = other.m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ if (ptr)
+ ptr->addStrong();
+
+ detach();
+
+ m_ptr = ptr;
+
+ return *this;
+ }
+
+ // Implicit non-const => const conversion
+ operator ref <const T>() const
+ {
+ if (m_ptr)
+ m_ptr->addStrong();
+
+ ref <const T> r;
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ // Copy
+ ref& operator=(const ref& p)
+ {
+ attach(p);
+ return *this;
+ }
+
+ // NULL-pointer comparison
+ bool operator==(const class null_pointer*) const { return m_ptr == 0; }
+ bool operator!=(const class null_pointer*) const { return m_ptr != 0; }
+
+ /** Create a ref<> from a raw pointer.
+ *
+ * WARNING: you should use this function only if you know what
+ * you are doing. In general, you should create ref objects using
+ * vmime::create().
+ *
+ * When this function returns, the pointer is owned by the ref,
+ * you should not attempt to delete it manually.
+ *
+ * @param ptr raw pointer to encapsulate
+ * @return a ref which encapsulates the specified raw pointer
+ */
+ static ref <T> fromPtr(T* const ptr)
+ {
+ if (ptr)
+ ptr->addStrong();
+
+ ref <T> r;
+ r.m_ptr = ptr;
+
+ return r;
+ }
+
+protected:
void detach()
{
- if (m_data)
+ if (m_ptr)
{
- if (m_data->refCount == 1)
- {
- typename MapType::iterator it = sm_map.find(m_data->ptr);
- if (it != sm_map.end()) sm_map.erase(it);
-
- delete (m_data->ptr);
- delete (m_data);
- }
- else
- {
- m_data->refCount--;
- }
-
- m_data = NULL;
+ m_ptr->releaseStrong();
+ m_ptr = 0;
}
}
- void attach(T* const p)
+ template <class U>
+ void attach(U* const ptr)
+ {
+ if (ptr)
+ ptr->addStrong();
+
+ detach();
+
+ m_ptr = ptr;
+ }
+
+ template <class U>
+ void attach(const ref <U>& r)
+ {
+ if (r.m_ptr)
+ r.m_ptr->addStrong();
+
+ detach();
+
+ m_ptr = r.m_ptr;
+ }
+
+private:
+
+ T* m_ptr;
+};
+
+
+
+template <class T, class U>
+bool operator==(const ref <T>& a, const ref <U>& b)
+{
+ return (a.get() == b.get());
+}
+
+template <class T, class U>
+bool operator!=(const ref <T>& a, const ref <U>& b)
+{
+ return (a.get() != b.get());
+}
+
+template <class T>
+bool operator==(const ref <T>& a, T* const p)
+{
+ return (a.get() == p);
+}
+
+template <class T>
+bool operator!=(const ref <T>& a, T* const p)
+{
+ return (a.get() != p);
+}
+
+template <class T>
+bool operator==(T* const p, const ref <T>& a)
+{
+ return (a.get() == p);
+}
+
+template <class T>
+bool operator!=(T* const p, const ref <T>& a)
+{
+ return (a.get() != p);
+}
+
+
+
+/** Base class for weak references.
+ */
+
+class weak_ref_base
+{
+ friend class vmime::object; // calls 'notifyObjectDestroyed'
+
+protected:
+
+ weak_ref_base() { }
+ weak_ref_base(const weak_ref_base&) { }
+ virtual ~weak_ref_base() { }
+
+
+ virtual void notifyObjectDestroyed() = 0;
+};
+
+
+/** Weak reference.
+ * Avoid circular references.
+ */
+
+template <class T>
+class weak_ref : public weak_ref_base
+{
+public:
+
+ template <class U> friend class weak_ref;
+
+
+ weak_ref() : m_ptr(0) { }
+ weak_ref(const ref <T>& r) : m_ptr(0) { attach(r); }
+ weak_ref(const weak_ref& r) : weak_ref_base(), m_ptr(0) { attach(r); }
+ weak_ref(const null_ref&) : m_ptr(0) { }
+ weak_ref(T* const p) : m_ptr(0) { attach(p); }
+
+ ~weak_ref() { detach(); }
+
+
+ // Access to wrapped object
+ operator const T*() const { return m_ptr; }
+
+ T& operator *() { return *m_ptr; }
+ const T& operator *() const { return *m_ptr; }
+
+ T* operator ->() { return m_ptr; }
+ const T* operator ->() const { return m_ptr; }
+
+ const T* const get() const { return m_ptr; }
+ T* const get() { return m_ptr; }
+
+ // dynamic_cast
+ template <class U>
+ weak_ref <U> dynamicCast() const
+ {
+ U* p = dynamic_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // static_cast
+ template <class U>
+ weak_ref <U> staticCast() const
+ {
+ U* p = static_cast <U*>(const_cast <T*>(m_ptr));
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // const_cast
+ template <class U>
+ weak_ref <U> constCast() const
+ {
+ U* p = const_cast <U*>(m_ptr);
+ if (!p) return weak_ref <U>();
+
+ weak_ref <U> r;
+
+ p->addWeak(&r);
+
+ r.m_ptr = p;
+
+ return r;
+ }
+
+ // Implicit downcast
+ template <class U>
+ operator weak_ref <const U>()
+ {
+ weak_ref <const U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ return r;
+ }
+
+ // Implicit downcast
+ template <class U>
+ operator weak_ref <U>()
+ {
+ weak_ref <U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ return r;
+ }
+
+ template <class U>
+ weak_ref <T>& operator=(const weak_ref <U>& other)
{
+ U* ptr = other.m_ptr; // will type check at compile-time (prevent from implicit upcast)
+
+ if (ptr)
+ ptr->addWeak(this);
+
detach();
- typename MapType::iterator it = sm_map.find(p);
+ m_ptr = ptr;
+
+ return *this;
+ }
+
+ // Implicit non-const => const conversion
+ operator weak_ref <const T>() const
+ {
+ weak_ref <const T> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ template <class U>
+ operator weak_ref <const U>() const
+ {
+ weak_ref <const U> r;
+
+ if (m_ptr)
+ m_ptr->addWeak(&r);
+
+ r.m_ptr = m_ptr;
+
+ return r;
+ }
+
+ // Copy
+ weak_ref& operator=(const weak_ref& p)
+ {
+ attach(p);
+ return *this;
+ }
+
+ // NULL-pointer comparison
+ bool operator==(const class null_pointer*) const { return m_ptr == 0; }
+ bool operator!=(const class null_pointer*) const { return m_ptr != 0; }
+
+private:
- if (it != sm_map.end())
+ void notifyObjectDestroyed()
+ {
+ m_ptr = 0;
+ }
+
+ void detach()
+ {
+ if (m_ptr)
{
- (*it).second->refCount++;
+ m_ptr->releaseWeak(this);
+ m_ptr = 0;
}
- else
- {
- m_data = new data;
- m_data->refCount = 1;
- m_data->ptr = p;
+ }
- sm_map.insert(typename MapType::value_type(p, m_data));
- }
+ void attach(const ref <T>& r)
+ {
+ if (r.m_ptr)
+ r.m_ptr->addWeak(this);
+
+ detach();
+
+ m_ptr = r.m_ptr;
}
- void attach(const smart_ptr <T>& p)
+ void attach(const weak_ref& r)
{
- data* newData = p.m_data;
- if (newData) newData->refCount++;
+ if (r.m_ptr)
+ r.m_ptr->addWeak(this);
detach();
- m_data = newData;
+ m_ptr = r.m_ptr;
}
-};
+ void attach(T* const p)
+ {
+ if (p)
+ p->addWeak(this);
-template <class T>
-typename smart_ptr <T>::MapType smart_ptr <T>::sm_map;
+ detach();
+
+ m_ptr = p;
+ }
+
+
+ T* m_ptr;
+};
} // utility
diff --git a/vmime/utility/stream.hpp b/vmime/utility/stream.hpp
index bfcd6192..5dd9d4dc 100644
--- a/vmime/utility/stream.hpp
+++ b/vmime/utility/stream.hpp
@@ -54,7 +54,7 @@ class stringProxy;
/** Base class for input/output stream.
*/
-class stream
+class stream : public object
{
public:
@@ -264,6 +264,8 @@ public:
private:
+ inputStreamStringAdapter(const inputStreamStringAdapter&);
+
const string m_buffer; // do _NOT_ keep a reference...
const string::size_type m_begin;
const string::size_type m_end;
@@ -289,6 +291,8 @@ public:
private:
+ inputStreamStringProxyAdapter(const inputStreamStringProxyAdapter&);
+
const stringProxy& m_buffer;
string::size_type m_pos;
};
@@ -315,6 +319,8 @@ public:
private:
+ inputStreamPointerAdapter(const inputStreamPointerAdapter&);
+
std::istream* m_stream;
const bool m_own;
};
@@ -336,6 +342,8 @@ public:
private:
+ outputStreamSocketAdapter(const outputStreamSocketAdapter&);
+
messaging::socket& m_socket;
};
@@ -356,6 +364,8 @@ public:
private:
+ inputStreamSocketAdapter(const inputStreamSocketAdapter&);
+
messaging::socket& m_socket;
};
diff --git a/vmime/word.hpp b/vmime/word.hpp
index 6b180173..adb944b7 100644
--- a/vmime/word.hpp
+++ b/vmime/word.hpp
@@ -35,6 +35,8 @@ namespace vmime
class word : public component
{
+ friend class text;
+
public:
word();
@@ -100,7 +102,7 @@ public:
*
* @return a copy of this word
*/
- word* clone() const;
+ ref <component> clone() const;
using component::parse;
@@ -111,13 +113,14 @@ public:
void generate(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos, const int flags, const bool isFirstWord) const;
- const std::vector <const component*> getChildComponents() const;
+ const std::vector <ref <const component> > getChildComponents() const;
+
+private:
- static 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);
+ static ref <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);
- static const std::vector <word*> parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
+ static const std::vector <ref <word> > parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition);
-private:
// The "m_buffer" of this word holds the data, and this data is encoded
// in the specified "m_charset".