From 681297e10b666e13cc463f6fbb16236f36c3266c Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 12 Jul 2005 22:28:02 +0000 Subject: [PATCH] Reference counting and smart pointers. --- ChangeLog | 5 + README.refcounting | 105 ++++ SConstruct | 21 + examples/example1.cpp | 11 +- examples/example2.cpp | 13 +- examples/example3.cpp | 17 +- examples/example6.cpp | 55 +- examples/example7.cpp | 4 +- src/address.cpp | 22 +- src/addressList.cpp | 56 +- src/base.cpp | 5 + src/body.cpp | 155 +++-- src/bodyPart.cpp | 53 +- src/charset.cpp | 8 +- src/component.cpp | 12 +- src/contentDisposition.cpp | 8 +- src/dateTime.cpp | 8 +- src/defaultAttachment.cpp | 32 +- src/defaultParameter.cpp | 34 +- src/disposition.cpp | 8 +- src/emptyContentHandler.cpp | 4 +- src/encoderFactory.cpp | 19 +- src/encoding.cpp | 12 +- src/fileAttachment.cpp | 18 +- src/header.cpp | 137 ++--- src/headerField.cpp | 14 +- src/headerFieldFactory.cpp | 4 +- src/htmlTextPart.cpp | 179 +++--- src/mailbox.cpp | 8 +- src/mailboxField.cpp | 8 +- src/mailboxGroup.cpp | 62 +- src/mailboxList.cpp | 46 +- src/mdn/MDNHelper.cpp | 132 ++--- src/mdn/receivedMDNInfos.cpp | 16 +- src/mdn/sendableMDNInfos.cpp | 4 +- src/mediaType.cpp | 8 +- src/messageBuilder.cpp | 61 +- src/messageId.cpp | 12 +- src/messageIdSequence.cpp | 52 +- src/messageParser.cpp | 69 +-- src/messaging/authenticationInfos.cpp | 2 +- src/messaging/defaultAuthenticator.cpp | 8 +- src/messaging/events.cpp | 13 +- src/messaging/imap/IMAPConnection.cpp | 27 +- src/messaging/imap/IMAPFolder.cpp | 206 ++++--- src/messaging/imap/IMAPMessage.cpp | 83 ++- src/messaging/imap/IMAPStore.cpp | 35 +- src/messaging/imap/IMAPTag.cpp | 2 +- src/messaging/maildir/maildirFolder.cpp | 223 ++++---- src/messaging/maildir/maildirMessage.cpp | 72 ++- src/messaging/maildir/maildirStore.cpp | 19 +- src/messaging/maildir/maildirUtils.cpp | 2 +- src/messaging/pop3/POP3Folder.cpp | 99 ++-- src/messaging/pop3/POP3Store.cpp | 17 +- src/messaging/sendmail/sendmailTransport.cpp | 4 +- src/messaging/service.cpp | 20 +- src/messaging/serviceFactory.cpp | 27 +- src/messaging/serviceInfos.cpp | 2 +- src/messaging/session.cpp | 50 +- src/messaging/smtp/SMTPTransport.cpp | 5 +- src/messaging/transport.cpp | 6 +- src/misc/importanceHelper.cpp | 24 +- src/object.cpp | 130 +++++ src/parameter.cpp | 10 +- src/parameterFactory.cpp | 8 +- src/parameterizedHeaderField.cpp | 78 ++- src/path.cpp | 8 +- src/plainTextPart.cpp | 25 +- src/platforms/posix/posixChildProcess.cpp | 15 +- src/platforms/posix/posixFile.cpp | 33 +- src/platforms/posix/posixSocket.cpp | 4 +- src/platforms/windows/windowsFile.cpp | 37 +- src/platforms/windows/windowsSocket.cpp | 6 +- src/propertySet.cpp | 38 +- src/relay.cpp | 8 +- src/streamContentHandler.cpp | 88 +-- src/stringContentHandler.cpp | 12 +- src/text.cpp | 94 ++-- src/textPartFactory.cpp | 18 +- src/utility/path.cpp | 1 + src/utility/stream.cpp | 7 + src/utility/url.cpp | 4 +- src/word.cpp | 24 +- tests/parser/bodyPartTest.cpp | 2 +- tests/parser/encoderTest.cpp | 4 +- tests/parser/headerTest.cpp | 50 +- tests/parser/mediaTypeTest.cpp | 6 +- tests/parser/messageIdSequenceTest.cpp | 6 +- tests/parser/parameterTest.cpp | 23 +- tests/parser/textTest.cpp | 8 +- vmime/address.hpp | 4 +- vmime/addressList.hpp | 26 +- vmime/attachment.hpp | 4 +- vmime/base.hpp | 96 +++- vmime/body.hpp | 47 +- vmime/bodyPart.hpp | 20 +- vmime/charset.hpp | 4 +- vmime/component.hpp | 8 +- vmime/contentDisposition.hpp | 4 +- vmime/contentDispositionField.hpp | 2 +- vmime/contentHandler.hpp | 4 +- vmime/contentTypeField.hpp | 2 +- vmime/dateTime.hpp | 4 +- vmime/defaultAttachment.hpp | 14 +- vmime/defaultParameter.hpp | 7 +- vmime/disposition.hpp | 4 +- vmime/emptyContentHandler.hpp | 2 +- vmime/encoder.hpp | 2 +- vmime/encoderFactory.hpp | 24 +- vmime/encoding.hpp | 8 +- vmime/genericField.hpp | 31 +- vmime/genericParameter.hpp | 25 +- vmime/header.hpp | 38 +- vmime/headerField.hpp | 13 +- vmime/headerFieldFactory.hpp | 8 +- vmime/htmlTextPart.hpp | 37 +- vmime/mailbox.hpp | 4 +- vmime/mailboxField.hpp | 2 +- vmime/mailboxGroup.hpp | 26 +- vmime/mailboxList.hpp | 24 +- vmime/mdn/MDNHelper.hpp | 40 +- vmime/mdn/MDNInfos.hpp | 5 +- vmime/mdn/receivedMDNInfos.hpp | 6 +- vmime/mdn/sendableMDNInfos.hpp | 6 +- vmime/mediaType.hpp | 4 +- vmime/messageBuilder.hpp | 22 +- vmime/messageId.hpp | 6 +- vmime/messageIdSequence.hpp | 28 +- vmime/messageParser.hpp | 16 +- vmime/messaging/authenticationInfos.hpp | 2 +- vmime/messaging/authenticator.hpp | 3 +- vmime/messaging/defaultAuthenticator.hpp | 7 +- vmime/messaging/events.hpp | 18 +- vmime/messaging/folder.hpp | 26 +- vmime/messaging/imap/IMAPConnection.hpp | 26 +- vmime/messaging/imap/IMAPFolder.hpp | 25 +- vmime/messaging/imap/IMAPMessage.hpp | 5 +- vmime/messaging/imap/IMAPParser.hpp | 12 +- vmime/messaging/imap/IMAPStore.hpp | 16 +- vmime/messaging/imap/IMAPTag.hpp | 2 +- vmime/messaging/maildir/maildirFolder.hpp | 31 +- vmime/messaging/maildir/maildirMessage.hpp | 11 +- vmime/messaging/maildir/maildirStore.hpp | 8 +- vmime/messaging/maildir/maildirUtils.hpp | 3 +- vmime/messaging/message.hpp | 12 +- vmime/messaging/pop3/POP3Folder.hpp | 23 +- vmime/messaging/pop3/POP3Message.hpp | 1 + vmime/messaging/pop3/POP3Store.hpp | 14 +- .../messaging/sendmail/sendmailTransport.hpp | 2 +- vmime/messaging/service.hpp | 18 +- vmime/messaging/serviceFactory.hpp | 23 +- vmime/messaging/serviceInfos.hpp | 4 +- vmime/messaging/session.hpp | 15 +- vmime/messaging/smtp/SMTPTransport.hpp | 6 +- vmime/messaging/socket.hpp | 12 +- vmime/messaging/store.hpp | 8 +- vmime/messaging/timeoutHandler.hpp | 7 +- vmime/messaging/transport.hpp | 4 +- vmime/misc/importanceHelper.hpp | 6 +- vmime/object.hpp | 108 ++++ vmime/parameter.hpp | 9 +- vmime/parameterFactory.hpp | 10 +- vmime/parameterizedHeaderField.hpp | 28 +- vmime/path.hpp | 4 +- vmime/plainTextPart.hpp | 6 +- vmime/platforms/posix/posixChildProcess.hpp | 10 +- vmime/platforms/posix/posixFile.hpp | 16 +- vmime/platforms/posix/posixSocket.hpp | 2 +- vmime/platforms/windows/windowsFile.hpp | 38 +- vmime/platforms/windows/windowsSocket.hpp | 5 +- vmime/propertySet.hpp | 22 +- vmime/relay.hpp | 4 +- vmime/standardFields.hpp | 6 +- vmime/standardParams.hpp | 2 +- vmime/streamContentHandler.hpp | 9 +- vmime/stringContentHandler.hpp | 2 +- vmime/text.hpp | 61 +- vmime/textPart.hpp | 6 +- vmime/textPartFactory.hpp | 14 +- vmime/typeAdapter.hpp | 12 +- vmime/types.hpp | 14 + vmime/utility/childProcess.hpp | 8 +- vmime/utility/file.hpp | 32 +- vmime/utility/path.hpp | 2 +- vmime/utility/smartPtr.hpp | 532 +++++++++++++++--- vmime/utility/stream.hpp | 12 +- vmime/word.hpp | 15 +- 187 files changed, 3003 insertions(+), 2153 deletions(-) create mode 100644 README.refcounting create mode 100644 src/object.cpp create mode 100644 vmime/object.hpp 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 + + * 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 * *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 subFolders = folder->getFolders(); + + ...do something with result... + + for (std::vector ::iterator + it = subFolders.begin() ; it != subFolders.end() ; ++it) + { + delete *it; + } + +Now, you can simply write: + + std::vector 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 mbox = + vmime::create ("me@somewhere.com"); + + +III. Casting +============ + +Like raw C++ pointers, you can cast VMime references. Implicit downcast is +also supported. + +To do a dynamic cast, write: + + vmime::ref foo = ... + vmime::ref mbox = foo.dynamicCast () + +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 foo = ... + vmime::ref mbox = foo.staticCast () + +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 foo_const = ... + vmime::ref 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 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("me@somewhere.com")); vmime::addressList to; - to.appendAddress(new vmime::mailbox("you@elsewhere.com")); + to.appendAddress(vmime::create ("you@elsewhere.com")); mb.setRecipients(to); vmime::addressList bcc; - bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com")); + bcc.appendAddress(vmime::create ("you-bcc@nowhere.com")); mb.setBlindCopyRecipients(bcc); mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder")); // Message body - mb.getTextPart()->setText(vmime::stringContentHandler( + mb.getTextPart()->setText(vmime::create ( "I'm writing this short text to test message construction " \ "using the vmime::messageBuilder component.")); // Construction - vmime::message* msg = mb.construct(); + vmime::ref 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("me@somewhere.com")); vmime::addressList to; - to.appendAddress(new vmime::mailbox("you@elsewhere.com")); + to.appendAddress(vmime::create ("you@elsewhere.com")); mb.setRecipients(to); vmime::addressList bcc; - bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com")); + bcc.appendAddress(vmime::create ("you-bcc@nowhere.com")); mb.setBlindCopyRecipients(bcc); mb.setSubject(vmime::text("My first message generated with vmime::messageBuilder")); // Message body - mb.getTextPart()->setText(vmime::stringContentHandler( + mb.getTextPart()->setText(vmime::create ( "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 a = vmime::create ( "./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 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("me@somewhere.com")); vmime::addressList to; - to.appendAddress(new vmime::mailbox("you@elsewhere.com")); + to.appendAddress(vmime::create ("you@elsewhere.com")); mb.setRecipients(to); vmime::addressList bcc; - bcc.appendAddress(new vmime::mailbox("you-bcc@nowhere.com")); + bcc.appendAddress(vmime::create ("you-bcc@nowhere.com")); mb.setBlindCopyRecipients(bcc); @@ -65,7 +65,7 @@ int main() // Fill in the text part: the message is available in two formats: HTML and plain text. // HTML text part also includes an inline image (embedded into the message). - vmime::htmlTextPart& textPart = dynamic_cast(*mb.getTextPart()); + vmime::htmlTextPart& textPart = *mb.getTextPart().dynamicCast (); // -- 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 HTML text.
"))); - textPart.setPlainText(vmime::stringContentHandler("This is the plain text (without HTML formatting).")); + textPart.setText(vmime::create + (vmime::string("This is the HTML text.
"))); + textPart.setPlainText(vmime::create + ("This is the plain text (without HTML formatting).")); // Construction - vmime::message* msg = mb.construct(); + vmime::ref 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 g_session - = new vmime::messaging::session(); +static vmime::ref g_session + = vmime::create (); // 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 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 p = f->getParent(); + vmime::ref 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 folder, const int level = 0) { for (int j = 0 ; j < level * 2 ; ++j) std::cout << " "; std::cout << getFolderPathString(folder) << std::endl; - std::vector subFolders = folder->getFolders(false); + std::vector > 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 tr = - g_session->getTransport(url, &auth); + vmime::ref tr = + g_session->getTransport(url, vmime::create ()); // 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 (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 st; - vmime::utility::auto_ptr 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 ()); + else + st = g_session->getStore(url); // Connect to the mail store st->connect(); // Open the default folder in this store - vmime::utility::auto_ptr f = st->getDefaultFolder(); -// vmime::utility::auto_ptr f = st->getFolder(vmime::utility::path("a")); + vmime::ref f = st->getDefaultFolder(); +// vmime::ref 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 > MessageList; + typedef std::map > MessageList; MessageList msgList; try @@ -353,7 +348,7 @@ static void connectStore() const int choice = printMenu(choices); // Request message number - vmime::utility::smart_ptr msg; + vmime::ref 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::ref 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 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 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 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 e = enc.create(); std::vector props = e->getAvailableProperties(); for (std::vector ::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::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(new mailboxGroup) - : static_cast(new mailbox); + ref
parsedAddress = isGroup + ? create ().dynamicCast
() + : create ().dynamicCast
(); - 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
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 ::const_iterator i = m_list.begin() ; ; ) + for (std::vector >::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 ::const_iterator it = addrList.m_list.begin() ; + for (std::vector >::const_iterator it = addrList.m_list.begin() ; it != addrList.m_list.end() ; ++it) { - m_list.push_back(static_cast ((*it)->clone())); + m_list.push_back((*it)->clone().dynamicCast
()); } } @@ -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
()); return (*this); } -addressList* addressList::clone() const +ref addressList::clone() const { - return new addressList(*this); + return vmime::create (*this); } -void addressList::appendAddress(address* addr) +void addressList::appendAddress(ref
addr) { m_list.push_back(addr); } -void addressList::insertAddressBefore(address* beforeAddress, address* addr) +void addressList::insertAddressBefore(ref
beforeAddress, ref
addr) { - const std::vector ::iterator it = std::find + const std::vector >::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
addr) { m_list.insert(m_list.begin() + pos, addr); } -void addressList::insertAddressAfter(address* afterAddress, address* addr) +void addressList::insertAddressAfter(ref
afterAddress, ref
addr) { - const std::vector ::iterator it = std::find + const std::vector >::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
addr) { m_list.insert(m_list.begin() + pos + 1, addr); } -void addressList::removeAddress(address* addr) +void addressList::removeAddress(ref
addr) { - const std::vector ::iterator it = std::find + const std::vector >::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 ::iterator it = m_list.begin() + pos; - - delete (*it); + const std::vector >::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
addressList::getAddressAt(const int pos) { return (m_list[pos]); } -const address* addressList::getAddressAt(const int pos) const +const ref addressList::getAddressAt(const int pos) const { return (m_list[pos]); } -const std::vector addressList::getAddressList() const +const std::vector > addressList::getAddressList() const { - std::vector list; + std::vector > list; list.reserve(m_list.size()); - for (std::vector ::const_iterator it = m_list.begin() ; + for (std::vector >::const_iterator it = m_list.begin() ; it != m_list.end() ; ++it) { list.push_back(*it); @@ -241,15 +237,15 @@ const std::vector addressList::getAddressList() const } -const std::vector addressList::getAddressList() +const std::vector > addressList::getAddressList() { return (m_list); } -const std::vector addressList::getChildComponents() const +const std::vector > addressList::getChildComponents() const { - std::vector list; + std::vector > 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 ()), 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 - (*m_header->findField(fields::CONTENT_TYPE)); + const ref ctf = + m_header->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 part = vmime::create (); + 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 (); 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 (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 - (*m_header->findField(fields::CONTENT_TYPE)); + ref ctf = + m_header->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 - (*m_header->findField(fields::CONTENT_TYPE)); + ref ctf = + m_header->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 - (*m_header->findField(fields::CONTENT_TYPE)); + const ref ctf = + m_header->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 - (*m_header->findField(fields::CONTENT_TRANSFER_ENCODING)); + const ref cef = + m_header->findField(fields::CONTENT_TRANSFER_ENCODING).dynamicCast (); - 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 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 body::clone() const { - body* bdy = new body(NULL); + ref bdy = vmime::create (); 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 part = bdy.getPartAt(p)->clone().dynamicCast (); part->m_parent = m_part; @@ -523,19 +509,19 @@ void body::setEpilogText(const string& epilogText) } -const contentHandler& body::getContents() const +const ref body::getContents() const { - return (*m_contents); + return (m_contents); } -void body::setContents(const contentHandler& contents) +void body::setContents(ref contents) { - setContentsImpl(contents); + m_contents = contents; } -void body::initNewPart(bodyPart* part) +void body::initNewPart(ref 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 - (*m_header->findField(fields::CONTENT_TYPE)); + ref ctf = + m_header->findField(fields::CONTENT_TYPE).dynamicCast (); 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 - (*m_header->getField(fields::CONTENT_TYPE)); + ref ctf = + m_header->getField(fields::CONTENT_TYPE).dynamicCast (); - 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 part) { initNewPart(part); @@ -588,11 +574,11 @@ void body::appendPart(bodyPart* part) } -void body::insertPartBefore(bodyPart* beforePart, bodyPart* part) +void body::insertPartBefore(ref beforePart, ref part) { initNewPart(part); - const std::vector ::iterator it = std::find + const std::vector >::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 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 afterPart, ref part) { initNewPart(part); - const std::vector ::iterator it = std::find + const std::vector >::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 part) { initNewPart(part); @@ -632,31 +618,27 @@ void body::insertPartAfter(const int pos, bodyPart* part) } -void body::removePart(bodyPart* part) +void body::removePart(ref part) { - const std::vector ::iterator it = std::find + const std::vector >::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 body::getPartAt(const int pos) { return (m_parts[pos]); } -const bodyPart* body::getPartAt(const int pos) const +const ref body::getPartAt(const int pos) const { return (m_parts[pos]); } -const std::vector body::getPartList() const +const std::vector > body::getPartList() const { - std::vector list; + std::vector > list; list.reserve(m_parts.size()); - for (std::vector ::const_iterator it = m_parts.begin() ; + for (std::vector >::const_iterator it = m_parts.begin() ; it != m_parts.end() ; ++it) { list.push_back(*it); @@ -700,15 +682,15 @@ const std::vector body::getPartList() const } -const std::vector body::getPartList() +const std::vector > body::getPartList() { return (m_parts); } -const std::vector body::getChildComponents() const +const std::vector > body::getChildComponents() const { - std::vector list; + std::vector > list; copy_vector(m_parts, list); @@ -716,11 +698,4 @@ const std::vector 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
()), + m_body(vmime::create ()), + 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 bodyPart::clone() const { - bodyPart* p = new bodyPart; + ref p = vmime::create (); - 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 (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 bodyPart::getHeader() const { - return (&m_header); + return (m_header); } -header* bodyPart::getHeader() +ref
bodyPart::getHeader() { - return (&m_header); + return (m_header); } -const body* bodyPart::getBody() const +const ref bodyPart::getBody() const { - return (&m_body); + return (m_body); } -body* bodyPart::getBody() +ref bodyPart::getBody() { - return (&m_body); + return (m_body); } -bodyPart* bodyPart::getParentPart() const +weak_ref bodyPart::getParentPart() const { return (m_parent); } -const std::vector bodyPart::getChildComponents() const +const std::vector > bodyPart::getChildComponents() const { - std::vector list; + std::vector > 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 charset::clone() const { - return new charset(m_name); + return vmime::create (m_name); } @@ -298,9 +298,9 @@ void charset::copyFrom(const component& other) } -const std::vector charset::getChildComponents() const +const std::vector > charset::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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::getChildComponents() +const std::vector > component::getChildComponents() { - const std::vector constList = + const std::vector > constList = const_cast (this)->getChildComponents(); - std::vector list; + std::vector > list; - const std::vector ::size_type count = constList.size(); + const std::vector >::size_type count = constList.size(); list.resize(count); - for (std::vector ::size_type i = 0 ; i < count ; ++i) - list[i] = const_cast (constList[i]); + for (std::vector >::size_type i = 0 ; i < count ; ++i) + list[i] = constList[i].constCast (); 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 contentDisposition::clone() const { - return new contentDisposition(*this); + return vmime::create (*this); } @@ -118,9 +118,9 @@ void contentDisposition::setName(const string& name) } -const std::vector contentDisposition::getChildComponents() const +const std::vector > contentDisposition::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 datetime::clone() const { - return new datetime(*this); + return vmime::create (*this); } -const std::vector datetime::getChildComponents() const +const std::vector > datetime::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 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 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 ()), 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 (); 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 part = vmime::create (); 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 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 ()) { } @@ -37,36 +38,49 @@ defaultParameter& defaultParameter::operator=(const defaultParameter& other) } -const word& defaultParameter::getValue() const +const ref defaultParameter::getValueImp() const { return (m_value); } +const ref defaultParameter::getValueImp() +{ + return (m_value); +} + + +const word& defaultParameter::getValue() const +{ + return (*m_value); +} + + word& defaultParameter::getValue() { - return (m_value); + return (*m_value); } void defaultParameter::setValue(const word& value) { - m_value = value; + *m_value = value; } void defaultParameter::setValue(const component& value) { const word& v = dynamic_cast (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 + (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 & chunks) } } - m_value = word(value.str(), ch); + m_value = vmime::create (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 disposition::clone() const { - disposition* disp = new disposition; + ref disp = vmime::create (); disp->m_actionMode = m_actionMode; disp->m_sendingMode = m_sendingMode; @@ -75,9 +75,9 @@ disposition& disposition::operator=(const disposition& other) } -const std::vector disposition::getChildComponents() const +const std::vector > disposition::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 emptyContentHandler::clone() const { - return new emptyContentHandler(); + return vmime::create (); } 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 ::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 encoderFactory::create(const string& name) { return (getEncoderByName(name)->create()); } -const encoderFactory::registeredEncoder* encoderFactory::getEncoderByName(const string& name) const +const ref encoderFactory::getEncoderByName(const string& name) const { const string lcName(utility::stringUtils::toLower(name)); - for (std::vector ::const_iterator it = m_encoders.begin() ; + for (std::vector >::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 encoderFactory::getEncoderAt(const int pos) const { return (m_encoders[pos]); } -const std::vector encoderFactory::getEncoderList() const +const std::vector > encoderFactory::getEncoderList() const { - std::vector res; + std::vector > res; - for (std::vector ::const_iterator it = m_encoders.begin() ; + for (std::vector >::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 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 /* data */) { // TODO: a better solution to do that? return (encoding(encodingTypes::BASE64)); } -encoding* encoding::clone() const +ref encoding::clone() const { - return new encoding(*this); + return vmime::create (*this); } @@ -188,9 +188,9 @@ void encoding::setName(const string& name) } -const std::vector encoding::getChildComponents() const +const std::vector > encoding::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 is = vmime::create (file, true); + + m_data = vmime::create (is, 0); } @@ -72,13 +74,13 @@ void fileAttachment::generatePart(bodyPart& part) const { defaultAttachment::generatePart(part); - contentDispositionField& cdf = part.getHeader()->ContentDisposition(); + ref 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 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 ::const_iterator it = m_fields.begin() ; + for (std::vector >::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 header::clone() const { - header* hdr = new header(); + ref
hdr = vmime::create
(); - try + hdr->m_fields.reserve(m_fields.size()); + + for (std::vector >::const_iterator it = m_fields.begin() ; + it != m_fields.end() ; ++it) { - hdr->m_fields.reserve(m_fields.size()); - - for (std::vector ::const_iterator it = m_fields.begin() ; - it != m_fields.end() ; ++it) - { - hdr->m_fields.push_back((*it)->clone()); - } - } - catch (std::exception&) - { - free_container(hdr->m_fields); - - delete (hdr); - throw; + hdr->m_fields.push_back((*it)->clone().dynamicCast ()); } return (hdr); @@ -123,29 +113,20 @@ void header::copyFrom(const component& other) { const header& h = dynamic_cast (other); - std::vector fields; + std::vector > fields; - try + fields.reserve(h.m_fields.size()); + + for (std::vector >::const_iterator it = h.m_fields.begin() ; + it != h.m_fields.end() ; ++it) { - fields.reserve(h.m_fields.size()); - - for (std::vector ::const_iterator it = h.m_fields.begin() ; - it != h.m_fields.end() ; ++it) - { - fields.push_back((*it)->clone()); - } - - free_container(m_fields); - - m_fields.resize(fields.size()); - - std::copy(fields.begin(), fields.end(), m_fields.begin()); - } - catch (std::exception&) - { - free_container(fields); - throw; + fields.push_back((*it)->clone().dynamicCast ()); } + + 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 ::const_iterator pos = m_fields.begin(); - const std::vector ::const_iterator end = m_fields.end(); + std::vector >::const_iterator pos = m_fields.begin(); + const std::vector >::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 header::findField(const string& fieldName) const { const string name = utility::stringUtils::toLower(fieldName); // Find the first field that matches the specified name - std::vector ::const_iterator pos = m_fields.begin(); - const std::vector ::const_iterator end = m_fields.end(); + std::vector >::const_iterator pos = m_fields.begin(); + const std::vector >::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 header::findAllFields(const string& fieldName) +std::vector > header::findAllFields(const string& fieldName) { const string name = utility::stringUtils::toLower(fieldName); - std::vector result; + std::vector > result; - std::vector ::const_iterator pos = m_fields.begin(); - const std::vector ::const_iterator end = m_fields.end(); + std::vector >::const_iterator pos = m_fields.begin(); + const std::vector >::const_iterator end = m_fields.end(); for ( ; pos != end ; ++pos) { @@ -214,30 +195,22 @@ std::vector header::findAllFields(const string& fieldName) } -headerField* header::getField(const string& fieldName) +ref header::getField(const string& fieldName) { const string name = utility::stringUtils::toLower(fieldName); // Find the first field that matches the specified name - std::vector ::const_iterator pos = m_fields.begin(); - const std::vector ::const_iterator end = m_fields.end(); + std::vector >::const_iterator pos = m_fields.begin(); + const std::vector >::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 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 field) { m_fields.push_back(field); } -void header::insertFieldBefore(headerField* beforeField, headerField* field) +void header::insertFieldBefore(ref beforeField, ref field) { - const std::vector ::iterator it = std::find + const std::vector >::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 field) { m_fields.insert(m_fields.begin() + pos, field); } -void header::insertFieldAfter(headerField* afterField, headerField* field) +void header::insertFieldAfter(ref afterField, ref field) { - const std::vector ::iterator it = std::find + const std::vector >::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 field) { m_fields.insert(m_fields.begin() + pos + 1, field); } -void header::removeField(headerField* field) +void header::removeField(ref field) { - const std::vector ::iterator it = std::find + const std::vector >::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 ::iterator it = m_fields.begin() + pos; - - delete (*it); + const std::vector >::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 header::getFieldAt(const int pos) { return (m_fields[pos]); } -const headerField* header::getFieldAt(const int pos) const +const ref header::getFieldAt(const int pos) const { return (m_fields[pos]); } -const std::vector header::getFieldList() const +const std::vector > header::getFieldList() const { - std::vector list; + std::vector > list; list.reserve(m_fields.size()); - for (std::vector ::const_iterator it = m_fields.begin() ; + for (std::vector >::const_iterator it = m_fields.begin() ; it != m_fields.end() ; ++it) { list.push_back(*it); @@ -362,15 +331,15 @@ const std::vector header::getFieldList() const } -const std::vector header::getFieldList() +const std::vector > header::getFieldList() { return (m_fields); } -const std::vector header::getChildComponents() const +const std::vector > header::getChildComponents() const { - std::vector list; + std::vector > 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 headerField::clone() const { - headerField* field = headerFieldFactory::getInstance()->create(m_name); + ref 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::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 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 headerField::getChildComponents() const +const std::vector > headerField::getChildComponents() const { - std::vector list; + std::vector > 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 headerFieldFactory::create (const string& name, const string& body) { NameMap::const_iterator pos = m_nameMap.find(utility::stringUtils::toLower(name)); - headerField* field = NULL; + ref 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 ()), + m_text(vmime::create ()) { } 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 part = vmime::create (); 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 htmlPart = vmime::create (); // -- 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 relPart = vmime::create (); 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 ::const_iterator it = m_objects.begin() ; + for (std::vector >::const_iterator it = m_objects.begin() ; it != m_objects.end() ; ++it) { - bodyPart* objPart = new bodyPart(); + ref objPart = vmime::create (); 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 & cidParts, std::vector & locParts) + std::vector >& cidParts, std::vector >& locParts) { for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i) { - const bodyPart& p = *part.getBody()->getPartAt(i); + ref p = part.getBody()->getPartAt(i); try { - dynamic_cast(*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(*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 - (*part.getHeader()->findField(fields::CONTENT_TYPE)); - - type = ctf.getValue(); + const ref 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 + (part.getBody()->getContents()->clone().dynamicCast (), + 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 cidParts; - std::vector locParts; + std::vector > cidParts; + std::vector > 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 - (*textPart.getHeader()->findField(fields::CONTENT_TYPE)); + const ref ctf = + textPart.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast (); - 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_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) + for (std::vector >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) { - const messageIdField& midField = dynamic_cast - (*(*p)->getHeader()->findField(fields::CONTENT_ID)); + const ref midField = + (*p)->getHeader()->findField(fields::CONTENT_ID).dynamicCast (); - 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_iterator p = locParts.begin() ; p != locParts.end() ; ++p) + for (std::vector >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) { - const defaultField& locField = dynamic_cast - (*(*p)->getHeader()->findField(fields::CONTENT_LOCATION)); + const ref locField = + (*p)->getHeader()->findField(fields::CONTENT_LOCATION).dynamicCast (); - 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 (); } } @@ -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 - (*part.getHeader()->findField(fields::CONTENT_TYPE)); + const ref ctf = + part.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 foundPart = NULL; for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i) { - const bodyPart* p = part.getBody()->getPartAt(i); + const ref 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 p = part.getBody()->getPartAt(i); try { - const contentTypeField& ctf = dynamic_cast - (*p.getHeader()->findField(fields::CONTENT_TYPE)); + const ref ctf = + p->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast (); - 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 htmlTextPart::getPlainText() const { - return (*m_plainText); + return (m_plainText); } -void htmlTextPart::setPlainText(const contentHandler& plainText) +void htmlTextPart::setPlainText(ref plainText) { - delete (m_plainText); - m_plainText = plainText.clone(); + m_plainText = plainText->clone(); } -const contentHandler& htmlTextPart::getText() const +const ref htmlTextPart::getText() const { - return (*m_text); + return (m_text); } -void htmlTextPart::setText(const contentHandler& text) +void htmlTextPart::setText(ref 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 htmlTextPart::getObjectAt(const int pos) const { return (m_objects[pos]); } -const htmlTextPart::embeddedObject* htmlTextPart::findObject(const string& id) const +const ref htmlTextPart::findObject(const string& id) const { - for (std::vector ::const_iterator o = m_objects.begin() ; + for (std::vector >::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 ::const_iterator o = m_objects.begin() ; + for (std::vector >::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 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 (data, enc, id, type)); return (id); } -const string htmlTextPart::addObject(const contentHandler& data, const mediaType& type) +const string htmlTextPart::addObject(ref 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 cts = vmime::create (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 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 ()), + m_encoding(enc), m_id(id), m_type(type) { } -const contentHandler& htmlTextPart::embeddedObject::getData() const +const ref 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 mailbox::clone() const { - return new mailbox(*this); + return vmime::create (*this); } @@ -504,9 +504,9 @@ void mailbox::setEmail(const string& email) } -const std::vector mailbox::getChildComponents() const +const std::vector > mailbox::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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
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 (parsedAddress); + ref group = parsedAddress.staticCast (); 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 (parsedAddress); + getValue() = *parsedAddress.staticCast (); } } - 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
parsedAddress = address::parseNext(buffer, pos, end, &pos); if (parsedAddress) { if (parsedAddress->isGroup()) { - mailboxGroup* group = static_cast (parsedAddress); + ref group = parsedAddress.staticCast (); // 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 ()); } - - delete (parsedAddress); } else { - m_list.push_back(static_cast (parsedAddress)); + m_list.push_back(parsedAddress.staticCast ()); } } } @@ -160,7 +158,7 @@ void mailboxGroup::generate(utility::outputStream& os, const string::size_type m os << ":"; ++pos; - for (std::vector ::const_iterator it = m_list.begin() ; + for (std::vector >::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 ::const_iterator it = source.m_list.begin() ; + for (std::vector >::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 ()); } } -mailboxGroup* mailboxGroup::clone() const +ref mailboxGroup::clone() const { - return new mailboxGroup(*this); + return vmime::create (*this); } @@ -238,15 +236,15 @@ const bool mailboxGroup::isEmpty() const } -void mailboxGroup::appendMailbox(mailbox* mbox) +void mailboxGroup::appendMailbox(ref mbox) { m_list.push_back(mbox); } -void mailboxGroup::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox) +void mailboxGroup::insertMailboxBefore(ref beforeMailbox, ref mbox) { - const std::vector ::iterator it = std::find + const std::vector >::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 mbox) { m_list.insert(m_list.begin() + pos, mbox); } -void mailboxGroup::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox) +void mailboxGroup::insertMailboxAfter(ref afterMailbox, ref mbox) { - const std::vector ::iterator it = std::find + const std::vector >::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 mbox) { m_list.insert(m_list.begin() + pos + 1, mbox); } -void mailboxGroup::removeMailbox(mailbox* mbox) +void mailboxGroup::removeMailbox(ref mbox) { - const std::vector ::iterator it = std::find + const std::vector >::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 ::iterator it = m_list.begin() + pos; - - delete (*it); + const std::vector >::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 mailboxGroup::getMailboxAt(const int pos) { return (m_list[pos]); } -const mailbox* mailboxGroup::getMailboxAt(const int pos) const +const ref mailboxGroup::getMailboxAt(const int pos) const { return (m_list[pos]); } -const std::vector mailboxGroup::getMailboxList() const +const std::vector > mailboxGroup::getMailboxList() const { - std::vector list; + std::vector > list; list.reserve(m_list.size()); - for (std::vector ::const_iterator it = m_list.begin() ; + for (std::vector >::const_iterator it = m_list.begin() ; it != m_list.end() ; ++it) { list.push_back(*it); @@ -344,15 +338,15 @@ const std::vector mailboxGroup::getMailboxList() const } -const std::vector mailboxGroup::getMailboxList() +const std::vector > mailboxGroup::getMailboxList() { return (m_list); } -const std::vector mailboxGroup::getChildComponents() const +const std::vector > mailboxGroup::getChildComponents() const { - std::vector list; + std::vector > 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 mbox) { m_list.appendAddress(mbox); } -void mailboxList::insertMailboxBefore(mailbox* beforeMailbox, mailbox* mbox) +void mailboxList::insertMailboxBefore(ref beforeMailbox, ref 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 mbox) { m_list.insertAddressBefore(pos, mbox); } -void mailboxList::insertMailboxAfter(mailbox* afterMailbox, mailbox* mbox) +void mailboxList::insertMailboxAfter(ref afterMailbox, ref 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 mbox) { m_list.insertAddressAfter(pos, mbox); } -void mailboxList::removeMailbox(mailbox* mbox) +void mailboxList::removeMailbox(ref mbox) { try { @@ -117,27 +117,27 @@ const bool mailboxList::isEmpty() const } -mailbox* mailboxList::getMailboxAt(const int pos) +ref mailboxList::getMailboxAt(const int pos) { - return static_cast (m_list.getAddressAt(pos)); + return m_list.getAddressAt(pos).staticCast (); } -const mailbox* mailboxList::getMailboxAt(const int pos) const +const ref mailboxList::getMailboxAt(const int pos) const { - return static_cast (m_list.getAddressAt(pos)); + return m_list.getAddressAt(pos).staticCast (); } -const std::vector mailboxList::getMailboxList() const +const std::vector > mailboxList::getMailboxList() const { - const std::vector addrList = m_list.getAddressList(); - std::vector res; + const std::vector > addrList = m_list.getAddressList(); + std::vector > res; - for (std::vector ::const_iterator it = addrList.begin() ; + for (std::vector >::const_iterator it = addrList.begin() ; it != addrList.end() ; ++it) { - const mailbox* mbox = dynamic_cast (*it); + const ref mbox = (*it).dynamicCast (); if (mbox != NULL) res.push_back(mbox); @@ -147,15 +147,15 @@ const std::vector mailboxList::getMailboxList() const } -const std::vector mailboxList::getMailboxList() +const std::vector > mailboxList::getMailboxList() { - const std::vector addrList = m_list.getAddressList(); - std::vector res; + const std::vector > addrList = m_list.getAddressList(); + std::vector > res; - for (std::vector ::const_iterator it = addrList.begin() ; + for (std::vector >::const_iterator it = addrList.begin() ; it != addrList.end() ; ++it) { - mailbox* mbox = dynamic_cast (*it); + const ref mbox = (*it).dynamicCast (); if (mbox != NULL) res.push_back(mbox); @@ -165,9 +165,9 @@ const std::vector mailboxList::getMailboxList() } -mailboxList* mailboxList::clone() const +ref mailboxList::clone() const { - return new mailboxList(*this); + return vmime::create (*this); } @@ -186,7 +186,7 @@ mailboxList& mailboxList::operator=(const mailboxList& other) } -const std::vector mailboxList::getChildComponents() const +const std::vector > 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 msg, const mailboxList& mailboxes) { - header* hdr = msg->getHeader(); + ref
hdr = msg->getHeader(); - hdr->DispositionNotificationTo().setValue(mailboxes); + hdr->DispositionNotificationTo()->setValue(mailboxes); } -void MDNHelper::attachMDNRequest(message* msg, const mailbox& mbox) +void MDNHelper::attachMDNRequest(ref msg, const mailbox& mbox) { mailboxList mboxList; - mboxList.appendMailbox(mbox.clone()); + mboxList.appendMailbox(mbox.clone().dynamicCast ()); attachMDNRequest(msg, mboxList); } -const std::vector MDNHelper::getPossibleMDNs(const message* msg) +const std::vector MDNHelper::getPossibleMDNs(const ref msg) { std::vector result; - const header* hdr = msg->getHeader(); + const ref 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 MDNHelper::getPossibleMDNs(const message* m } -const bool MDNHelper::isMDN(const message* msg) +const bool MDNHelper::isMDN(const ref msg) { - const header* hdr = msg->getHeader(); + const ref 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 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 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 & reportingUAProducts) +ref MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos, + const string& text, + const charset& ch, + const mailbox& expeditor, + const disposition& dispo, + const string& reportingUA, + const std::vector & reportingUAProducts) { // Create a new message - message* msg = new message; + ref msg = vmime::create (); // Fill-in header fields - header* hdr = msg->getHeader(); + ref
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 (mdnInfos.getRecipient())); + hdr->From()->getValue() = expeditor; + hdr->Subject()->getValue().appendWord(vmime::create ("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 MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos */, + const string& text, const charset& ch) { - bodyPart* part = new bodyPart; + ref part = vmime::create (); // Header - header* hdr = part->getHeader(); + ref
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 (text)); return (part); } -bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos, - const disposition& dispo, - const string& reportingUA, - const std::vector & reportingUAProducts) +ref MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos, + const disposition& dispo, + const string& reportingUA, + const std::vector & reportingUAProducts) { - bodyPart* part = new bodyPart; + ref part = vmime::create (); // Header - header* hdr = part->getHeader(); + ref
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 - (headerFieldFactory::getInstance()->create(vmime::fields::REPORTING_UA)); + ref rua = + (headerFieldFactory::getInstance()->create + (vmime::fields::REPORTING_UA)).dynamicCast (); rua->setValue(ruaText); @@ -242,20 +243,21 @@ bodyPart* MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos, } // -- Final-Recipient - defaultField* fr = dynamic_cast - (headerFieldFactory::getInstance()->create(vmime::fields::FINAL_RECIPIENT)); + ref fr = + (headerFieldFactory::getInstance()-> + create(vmime::fields::FINAL_RECIPIENT)).dynamicCast (); 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 (oss.str())); return (part); } -bodyPart* MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos) +ref MDNHelper::createThirdMDNPart(const sendableMDNInfos& mdnInfos) { - bodyPart* part = new bodyPart; + ref part = vmime::create (); // Header - header* hdr = part->getHeader(); + ref
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 (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 msg) : m_msg(msg) { extract(); @@ -45,7 +45,7 @@ receivedMDNInfos& receivedMDNInfos::operator=(const receivedMDNInfos& other) } -const message* receivedMDNInfos::getMessage() const +const ref 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 bdy = m_msg->getBody(); for (int i = 0 ; i < bdy->getPartCount() ; ++i) { - const bodyPart* part = bdy->getPartAt(i); + const ref 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 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 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 mediaType::clone() const { - return new mediaType(m_type, m_subType); + return vmime::create (m_type, m_subType); } @@ -172,9 +172,9 @@ void mediaType::setFromString(const string& type) } -const std::vector mediaType::getChildComponents() const +const std::vector > mediaType::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 messageBuilder::construct() const { // Create a new message - message* msg = new message; + ref msg = vmime::create (); // 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 subPart = vmime::create (); 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 ::const_iterator a = m_attach.begin() ; + for (std::vector >::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 fields = part.getHeader()->getFieldList(); + const std::vector > fields = part.getHeader()->getFieldList(); - for (std::vector ::const_iterator it = fields.begin() ; + for (std::vector >::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 attach) { appendAttachment(attach); } -void messageBuilder::appendAttachment(attachment* attach) +void messageBuilder::appendAttachment(ref 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 part = NULL; try { @@ -184,12 +180,11 @@ void messageBuilder::constructTextPart(const mediaType& type) throw; } - delete (m_textPart); m_textPart = part; } -textPart* messageBuilder::getTextPart() +ref 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 messageBuilder::getAttachmentAt(const int pos) const { return (m_attach[pos]); } -attachment* messageBuilder::getAttachmentAt(const int pos) +ref messageBuilder::getAttachmentAt(const int pos) { return (m_attach[pos]); } @@ -299,13 +292,13 @@ const int messageBuilder::getAttachmentCount() const } -const std::vector messageBuilder::getAttachmentList() const +const std::vector > messageBuilder::getAttachmentList() const { - std::vector res; + std::vector > res; res.reserve(m_attach.size()); - for (std::vector ::const_iterator it = m_attach.begin() ; + for (std::vector >::const_iterator it = m_attach.begin() ; it != m_attach.end() ; ++it) { res.push_back(*it); @@ -315,7 +308,7 @@ const std::vector messageBuilder::getAttachmentList() const } -const std::vector messageBuilder::getAttachmentList() +const std::vector > 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::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 mid = vmime::create (); 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 messageId::clone() const { - return new messageId(*this); + return vmime::create (*this); } @@ -266,9 +266,9 @@ void messageId::setRight(const string& right) } -const std::vector messageId::getChildComponents() const +const std::vector > messageId::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 messageIdSequence::clone() const { - return new messageIdSequence(*this); + return vmime::create (*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 ()); } @@ -70,9 +70,9 @@ messageIdSequence& messageIdSequence::operator=(const messageIdSequence& other) } -const std::vector messageIdSequence::getChildComponents() const +const std::vector > messageIdSequence::getChildComponents() const { - std::vector res; + std::vector > 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 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 ::const_iterator it = m_list.begin() ; ; ) + for (std::vector >::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 mid) { m_list.push_back(mid); } -void messageIdSequence::insertMessageIdBefore(messageId* beforeMid, messageId* mid) +void messageIdSequence::insertMessageIdBefore(ref beforeMid, ref mid) { - const std::vector ::iterator it = std::find + const std::vector >::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 mid) { m_list.insert(m_list.begin() + pos, mid); } -void messageIdSequence::insertMessageIdAfter(messageId* afterMid, messageId* mid) +void messageIdSequence::insertMessageIdAfter(ref afterMid, ref mid) { - const std::vector ::iterator it = std::find + const std::vector >::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 mid) { m_list.insert(m_list.begin() + pos + 1, mid); } -void messageIdSequence::removeMessageId(messageId* mid) +void messageIdSequence::removeMessageId(ref mid) { - const std::vector ::iterator it = std::find + const std::vector >::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 ::iterator it = m_list.begin() + pos; - - delete (*it); + const std::vector >::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 messageIdSequence::getMessageIdAt(const int pos) { return (m_list[pos]); } -const messageId* messageIdSequence::getMessageIdAt(const int pos) const +const ref messageIdSequence::getMessageIdAt(const int pos) const { return (m_list[pos]); } -const std::vector messageIdSequence::getMessageIdList() const +const std::vector > messageIdSequence::getMessageIdList() const { - std::vector list; + std::vector > list; list.reserve(m_list.size()); - for (std::vector ::const_iterator it = m_list.begin() ; + for (std::vector >::const_iterator it = m_list.begin() ; it != m_list.end() ; ++it) { list.push_back(*it); @@ -238,7 +234,7 @@ const std::vector messageIdSequence::getMessageIdList() const } -const std::vector messageIdSequence::getMessageIdList() +const std::vector > 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 ::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 attach = vmime::create + (bdy.getContents()->clone().dynamicCast (), + bdy.getEncoding(), type, description); if (contentDispField != NULL) { - m_attachInfo.insert(std::map :: - value_type(attach, dynamic_cast - (contentDispField->clone()))); + m_attachInfo.insert(std::map >:: + value_type(attach.get(), contentDispField->clone(). + dynamicCast ())); } // 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 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 textParts; + std::vector > textParts; for (int i = 0 ; i < part.getBody()->getPartCount() ; ++i) { - const bodyPart& p = *part.getBody()->getPartAt(i); + const ref p = part.getBody()->getPartAt(i); try { - const contentTypeField& ctf = dynamic_cast - (*p.getHeader()->findField(fields::CONTENT_TYPE)); + const contentTypeField& ctf = dynamic_cast + (*(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_iterator p = textParts.begin() ; + for (std::vector >::const_iterator p = textParts.begin() ; p != textParts.end() ; ++p) { - const contentTypeField& ctf = dynamic_cast - (*(*p)->getHeader()->findField(fields::CONTENT_TYPE)); + const contentTypeField& ctf = dynamic_cast + (*((*p)->getHeader()->findField(fields::CONTENT_TYPE))); try { - textPart* textPart = textPartFactory::getInstance()->create(ctf.getValue()); - textPart->parse(msg, part, **p); + ref 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 messageParser::getAttachmentInfo(const ref a) const { - std::map ::const_iterator - it = m_attachInfo.find(const_cast (a)); + std::map >::const_iterator + it = m_attachInfo.find(ref (a.constCast ()).get()); return (it != m_attachInfo.end() ? (*it).second : NULL); } @@ -369,13 +362,13 @@ const datetime& messageParser::getDate() const } -const std::vector messageParser::getAttachmentList() const +const std::vector > messageParser::getAttachmentList() const { - std::vector res; + std::vector > res; res.reserve(m_attach.size()); - for (std::vector ::const_iterator it = m_attach.begin() ; + for (std::vector >::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 messageParser::getAttachmentAt(const int pos) const { return (m_attach[pos]); } -const std::vector messageParser::getTextPartList() const +const std::vector > messageParser::getTextPartList() const { - std::vector res; + std::vector > res; res.reserve(m_textParts.size()); - for (std::vector ::const_iterator it = m_textParts.begin() ; + for (std::vector >::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 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 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 @@ -32,7 +33,7 @@ namespace events { // messageCountEvent::messageCountEvent - (folder* folder, const Types type, const std::vector & nums) + (ref folder, const Types type, const std::vector & 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 (m_folder)); } +ref messageCountEvent::getFolder() const { return (m_folder); } const messageCountEvent::Types messageCountEvent::getType() const { return (m_type); } const std::vector & 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 & nums) + (ref folder, const Types type, const std::vector & 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 (m_folder)); } +ref messageChangedEvent::getFolder() const { return (m_folder); } const messageChangedEvent::Types messageChangedEvent::getType() const { return (m_type); } const std::vector & 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, 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 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 store, ref 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 (); + m_parser = vmime::create (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 resp(m_parser->readResponse()); + vmime::utility::auto_ptr 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 IMAPConnection::getTag() const { return (m_tag); } -const IMAPParser* IMAPConnection::getParser() const +ref IMAPConnection::getParser() const { return (m_parser); } -const IMAPStore* IMAPConnection::getStore() const +weak_ref IMAPConnection::getStore() const { return (m_store); } -IMAPStore* IMAPConnection::getStore() +weak_ref IMAPConnection::getStore() { return (m_store); } -session* IMAPConnection::getSession() +ref 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 connection = + vmime::create (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 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 (), + 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 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 (this, num); } -std::vector IMAPFolder::getMessages(const int from, const int to) +std::vector > IMAPFolder::getMessages(const int from, const int to) { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - std::vector v; + std::vector > v; for (int i = from ; i <= to ; ++i) - v.push_back(new IMAPMessage(this, i)); + v.push_back(vmime::create (this, i)); return (v); } -std::vector IMAPFolder::getMessages(const std::vector & nums) +std::vector > IMAPFolder::getMessages(const std::vector & nums) { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - std::vector v; + std::vector > v; for (std::vector ::const_iterator it = nums.begin() ; it != nums.end() ; ++it) - v.push_back(new IMAPMessage(this, *it)); + v.push_back(vmime::create (this, *it)); return (v); } @@ -499,16 +499,16 @@ const int IMAPFolder::getMessageCount() } -folder* IMAPFolder::getFolder(const folder::path::component& name) +ref 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 (m_path / name, m_store); } -std::vector IMAPFolder::getFolders(const bool recursive) +std::vector > IMAPFolder::getFolders(const bool recursive) { if (!isOpen() && !m_store) throw exceptions::illegal_state("Store disconnected"); @@ -556,57 +556,47 @@ std::vector IMAPFolder::getFolders(const bool recursive) resp->continue_req_or_response_data(); - std::vector v; + std::vector > v; - try + for (std::vector ::const_iterator + it = respDataList.begin() ; it != respDataList.end() ; ++it) { - for (std::vector ::const_iterator - it = respDataList.begin() ; it != respDataList.end() ; ++it) + if ((*it)->response_data() == NULL) { - if ((*it)->response_data() == NULL) - { - throw exceptions::command_error("LIST", - m_connection->getParser()->lastLine(), "invalid response"); - } - - const IMAPParser::mailbox_data* mailboxData = - (*it)->response_data()->mailbox_data(); - - if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST) - continue; - - // Get folder path - const class IMAPParser::mailbox* mailbox = - mailboxData->mailbox_list()->mailbox(); - - folder::path path = IMAPUtils::stringToPath - (mailboxData->mailbox_list()->quoted_char(), mailbox->name()); - - if (recursive || m_path.isDirectParentOf(path)) - { - // Append folder to list - const class IMAPParser::mailbox_flag_list* mailbox_flag_list = - mailboxData->mailbox_list()->mailbox_flag_list(); - - v.push_back(new IMAPFolder(path, m_store, - IMAPUtils::folderTypeFromFlags(mailbox_flag_list), - IMAPUtils::folderFlagsFromFlags(mailbox_flag_list))); - } + throw exceptions::command_error("LIST", + m_connection->getParser()->lastLine(), "invalid response"); } - } - catch (std::exception&) - { - for (std::vector ::iterator it = v.begin() ; it != v.end() ; ++it) - delete (*it); - throw; + const IMAPParser::mailbox_data* mailboxData = + (*it)->response_data()->mailbox_data(); + + if (mailboxData == NULL || mailboxData->type() != IMAPParser::mailbox_data::LIST) + continue; + + // Get folder path + const class IMAPParser::mailbox* mailbox = + mailboxData->mailbox_list()->mailbox(); + + folder::path path = IMAPUtils::stringToPath + (mailboxData->mailbox_list()->quoted_char(), mailbox->name()); + + if (recursive || m_path.isDirectParentOf(path)) + { + // Append folder to list + const class IMAPParser::mailbox_flag_list* mailbox_flag_list = + mailboxData->mailbox_list()->mailbox_flag_list(); + + v.push_back(vmime::create (path, m_store, + IMAPUtils::folderTypeFromFlags(mailbox_flag_list), + IMAPUtils::folderFlagsFromFlags(mailbox_flag_list))); + } } return (v); } -void IMAPFolder::fetchMessages(std::vector & msg, const int options, +void IMAPFolder::fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress) { if (!m_store) @@ -620,10 +610,10 @@ void IMAPFolder::fetchMessages(std::vector & msg, const int options, if (progress) progress->start(total); - for (std::vector ::iterator it = msg.begin() ; + for (std::vector >::iterator it = msg.begin() ; it != msg.end() ; ++it) { - dynamic_cast (*it)->fetch(this, options); + (*it).dynamicCast ()->fetch(this, options); if (progress) progress->progress(++current, total); @@ -634,14 +624,14 @@ void IMAPFolder::fetchMessages(std::vector & msg, const int options, } -void IMAPFolder::fetchMessage(message* msg, const int options) +void IMAPFolder::fetchMessage(ref 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 (msg)->fetch(this, options); + msg.dynamicCast ()->fetch(this, options); } @@ -652,19 +642,22 @@ const int IMAPFolder::getFetchCapabilities() const } -folder* IMAPFolder::getParent() +ref IMAPFolder::getParent() { - return (m_path.isEmpty() ? NULL : new IMAPFolder(m_path.getParent(), m_store)); + if (m_path.isEmpty()) + return NULL; + else + return vmime::create (m_path.getParent(), m_store); } -const store* IMAPFolder::getStore() const +weak_ref IMAPFolder::getStore() const { return (m_store); } -store* IMAPFolder::getStore() +weak_ref IMAPFolder::getStore() { return (m_store); } @@ -733,7 +726,9 @@ void IMAPFolder::deleteMessage(const int num) std::vector nums; nums.push_back(num); - events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums); + events::messageChangedEvent event + (thisRef().dynamicCast (), + 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 (), + events::messageChangedEvent::TYPE_FLAGS, nums); notifyMessageChanged(event); } @@ -851,7 +848,9 @@ void IMAPFolder::deleteMessages(const std::vector & nums) } // Notify message flags changed - events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list); + events::messageChangedEvent event + (thisRef().dynamicCast (), + 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 (), + events::messageChangedEvent::TYPE_FLAGS, nums); notifyMessageChanged(event); } @@ -1013,7 +1014,9 @@ void IMAPFolder::setMessageFlags(const std::vector & nums, const int flags, } // Notify message flags changed - events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums); + events::messageChangedEvent event + (thisRef().dynamicCast (), + 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 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 nums; nums.push_back(m_messageCount + 1); - events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums); + events::messageCountEvent event + (thisRef().dynamicCast (), + 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 (), + 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 (), + 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 (), + 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 (), + 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 (), + 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 (), + 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 nums; nums.push_back(num); - events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums); - for (std::list ::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { if ((*it)->getFullPath() == dest) { + events::messageCountEvent event + ((*it)->thisRef().dynamicCast (), + 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 ::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { if ((*it)->getFullPath() == dest) { + events::messageCountEvent event + ((*it)->thisRef().dynamicCast (), + 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 & // Notify message count changed const int count = nums.size(); - events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums); - for (std::list ::iterator it = m_store->m_folders.begin() ; it != m_store->m_folders.end() ; ++it) { if ((*it)->getFullPath() == dest) { + events::messageCountEvent event + ((*it)->thisRef().dynamicCast (), + 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 (), + 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 (), + 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; + + IMAPpart(weak_ref parent, const int number, const IMAPParser::body_type_mpart* mpart); + IMAPpart(weak_ref parent, const int number, const IMAPParser::body_type_1part* part); public: - ~IMAPpart(); - const structure& getStructure() const; structure& getStructure(); - const IMAPpart* getParent() const { return (m_parent); } + weak_ref 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 create + (weak_ref 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 (parent, number, body->body_type_mpart()); else - return new IMAPpart(parent, number, body->body_type_1part()); + return vmime::create (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
())); } private: - IMAPstructure* m_structure; - IMAPpart* m_parent; - header* m_header; + ref m_structure; + weak_ref m_parent; + ref
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 & list) + IMAPstructure(weak_ref parent, const std::vector & 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 m_parts; + std::vector > 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 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 + (thisWeakRef().dynamicCast (), mpart->list()); } -IMAPpart::IMAPpart(IMAPpart* parent, const int number, const IMAPParser::body_type_1part* part) +IMAPpart::IMAPpart(weak_ref 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 (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 ((*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 fields = tempHeader.getFieldList(); + std::vector > fields = tempHeader.getFieldList(); - for (std::vector ::const_iterator jt = fields.begin() ; + for (std::vector >::const_iterator jt = fields.begin() ; jt != fields.end() ; ++jt) { - hdr.appendField((*jt)->clone()); + hdr.appendField((*jt)->clone().dynamicCast ()); } } } @@ -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
())); } @@ -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 (name, email)); } } @@ -829,7 +816,9 @@ void IMAPMessage::setFlags(const int flags, const int mode) std::vector nums; nums.push_back(m_num); - events::messageChangedEvent event(m_folder, events::messageChangedEvent::TYPE_FLAGS, nums); + events::messageChangedEvent event + (m_folder->thisRef().dynamicCast (), + events::messageChangedEvent::TYPE_FLAGS, nums); for (std::list ::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 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 (m_auth->requestAuthInfos()); return (*m_infos); } private: - authenticator* m_auth; - mutable authenticationInfos* m_infos; + ref m_auth; + mutable ref m_infos; }; #endif // VMIME_BUILDING_DOC @@ -77,7 +76,7 @@ private: // IMAPStore // -IMAPStore::IMAPStore(session* sess, authenticator* auth) +IMAPStore::IMAPStore(ref sess, ref auth) : store(sess, getInfosInstance(), auth), m_connection(NULL), m_oneTimeAuth(NULL) { @@ -91,7 +90,7 @@ IMAPStore::~IMAPStore() } -authenticator* IMAPStore::oneTimeAuthenticator() +ref IMAPStore::oneTimeAuthenticator() { return (m_oneTimeAuth); } @@ -103,30 +102,30 @@ const string IMAPStore::getProtocolName() const } -folder* IMAPStore::getRootFolder() +ref IMAPStore::getRootFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new IMAPFolder(folder::path(), this); + return vmime::create (folder::path(), this); } -folder* IMAPStore::getDefaultFolder() +ref IMAPStore::getDefaultFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new IMAPFolder(folder::path::component("INBOX"), this); + return vmime::create (folder::path::component("INBOX"), this); } -folder* IMAPStore::getFolder(const folder::path& path) +ref IMAPStore::getFolder(const folder::path& path) { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new IMAPFolder(path, this); + return vmime::create (path, this); } @@ -141,9 +140,10 @@ void IMAPStore::connect() if (isConnected()) throw exceptions::already_connected(); - m_oneTimeAuth = new IMAPauthenticator(getAuthenticator()); + m_oneTimeAuth = vmime::create (getAuthenticator()); - m_connection = new IMAPConnection(this, m_oneTimeAuth); + m_connection = vmime::create + (thisWeakRef().dynamicCast (), 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 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 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 rootDir = fsf->create + ref rootDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_CONTAINER)); - utility::auto_ptr it = rootDir->getFiles(); + ref it = rootDir->getFiles(); while (it->hasMoreElements()) { - utility::auto_ptr file = it->nextElement(); + ref 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 rootDir = fsf->create + ref rootDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT)); - utility::auto_ptr newDir = fsf->create + ref newDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW)); - utility::auto_ptr tmpDir = fsf->create + ref tmpDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP)); - utility::auto_ptr curDir = fsf->create + ref 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 (), + 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 rootDir = fsf->create + ref rootDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT)); - utility::auto_ptr newDir = fsf->create + ref newDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_NEW)); - utility::auto_ptr tmpDir = fsf->create + ref tmpDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_TMP)); - utility::auto_ptr curDir = fsf->create + ref 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 newDir = fsf->create(newDirPath); + ref newDir = fsf->create(newDirPath); utility::file::path curDirPath = maildirUtils::getFolderFSPath (m_store, m_path, maildirUtils::FOLDER_PATH_CUR); - utility::auto_ptr curDir = fsf->create(curDirPath); + ref curDir = fsf->create(curDirPath); // New received messages (new/) - utility::fileIterator* nit = newDir->getFiles(); + ref nit = newDir->getFiles(); std::vector newMessageFilenames; while (nit->hasMoreElements()) { - utility::auto_ptr file = nit->nextElement(); + ref 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 cit = curDir->getFiles(); std::vector curMessageFilenames; while (cit->hasMoreElements()) { - utility::auto_ptr file = cit->nextElement(); + ref 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 file = fsf->create(newDirPath / *it); + ref 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 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 + (thisWeakRef().dynamicCast (), num); } -std::vector maildirFolder::getMessages(const int from, const int to) +std::vector > maildirFolder::getMessages(const int from, const int to) { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - std::vector v; + std::vector > v; for (int i = from ; i <= to ; ++i) - v.push_back(new maildirMessage(this, i)); + { + v.push_back(vmime::create + (thisWeakRef().dynamicCast (), i)); + } return (v); } -std::vector maildirFolder::getMessages(const std::vector & nums) +std::vector > maildirFolder::getMessages(const std::vector & nums) { if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - std::vector v; + std::vector > v; for (std::vector ::const_iterator it = nums.begin() ; it != nums.end() ; ++it) - v.push_back(new maildirMessage(this, *it)); + { + v.push_back(vmime::create + (thisWeakRef().dynamicCast (), *it)); + } return (v); } @@ -437,68 +443,54 @@ const int maildirFolder::getMessageCount() } -folder* maildirFolder::getFolder(const folder::path::component& name) +ref 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 (m_path / name, m_store); } -std::vector maildirFolder::getFolders(const bool recursive) +std::vector > maildirFolder::getFolders(const bool recursive) { if (!isOpen() && !m_store) throw exceptions::illegal_state("Store disconnected"); - std::vector list; + std::vector > list; - try - { - listFolders(list, recursive); - } - catch (std::exception&) - { - for (std::vector ::iterator it = list.begin() ; it != list.end() ; ++it) - delete (*it); - - throw; - } - catch (vmime::exception&) - { - for (std::vector ::iterator it = list.begin() ; it != list.end() ; ++it) - delete (*it); - - throw; - } + listFolders(list, recursive); return (list); } -void maildirFolder::listFolders(std::vector & list, const bool recursive) +void maildirFolder::listFolders(std::vector >& list, const bool recursive) { try { utility::fileSystemFactory* fsf = platformDependant::getHandler()->getFileSystemFactory(); - utility::auto_ptr rootDir = fsf->create + ref 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 it = rootDir->getFiles(); + ref it = rootDir->getFiles(); while (it->hasMoreElements()) { - utility::auto_ptr file = it->nextElement(); + ref 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 subFolder = + vmime::create (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 rootDir = fsf->create + ref rootDir = fsf->create (maildirUtils::getFolderFSPath(m_store, m_path, maildirUtils::FOLDER_PATH_ROOT)); - utility::auto_ptr contDir = fsf->create + ref 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 (), + 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 (), + 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 (), + 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 (), + 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 (), + 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 file = fsf->create(curDirPath / path); + ref 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 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 tmpDir = fsf->create(tmpDirPath); + ref 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 curDir = fsf->create(curDirPath); + ref 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 nums; nums.push_back(m_messageCount); - events::messageCountEvent event(this, events::messageCountEvent::TYPE_ADDED, nums); + events::messageCountEvent event + (thisRef().dynamicCast (), + 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 (), + 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 file = fsf->create(tmpDirPath / filename); + ref 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 fw = file->getFileWriter(); - utility::auto_ptr os = fw->getOutputStream(); + ref fw = file->getFileWriter(); + ref 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 file = fsf->create(tmpDirPath / filename); + ref 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 file = fsf->create(tmpDirPath / filename); + ref 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 destTmpDir = fsf->create(destTmpDirPath); + ref 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 destCurDir = fsf->create(destCurDirPath); + ref 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 file = fsf->create(curDirPath / msg.path); - utility::auto_ptr fr = file->getFileReader(); - utility::auto_ptr is = fr->getInputStream(); + ref file = fsf->create(curDirPath / msg.path); + ref fr = file->getFileReader(); + ref 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 (), + 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 (), + events::messageCountEvent::TYPE_ADDED, nums); (*it)->notifyMessageCount(event); } @@ -1233,7 +1250,7 @@ void maildirFolder::expunge() // Delete file from file system try { - utility::auto_ptr file = fsf->create(curDirPath / infos.path); + ref 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 (), + 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 (), + events::messageCountEvent::TYPE_REMOVED, nums); (*it)->notifyMessageCount(event); } @@ -1277,25 +1298,28 @@ void maildirFolder::expunge() } -folder* maildirFolder::getParent() +ref maildirFolder::getParent() { - return (m_path.isEmpty() ? NULL : new maildirFolder(m_path.getParent(), m_store)); + if (m_path.isEmpty()) + return NULL; + else + return vmime::create (m_path.getParent(), m_store); } -const store* maildirFolder::getStore() const +weak_ref maildirFolder::getStore() const { return (m_store); } -store* maildirFolder::getStore() +weak_ref maildirFolder::getStore() { return (m_store); } -void maildirFolder::fetchMessages(std::vector & msg, +void maildirFolder::fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress) { if (!m_store) @@ -1309,10 +1333,12 @@ void maildirFolder::fetchMessages(std::vector & msg, if (progress) progress->start(total); - for (std::vector ::iterator it = msg.begin() ; + weak_ref _this = thisWeakRef().dynamicCast (); + + for (std::vector >::iterator it = msg.begin() ; it != msg.end() ; ++it) { - dynamic_cast (*it)->fetch(this, options); + (*it).dynamicCast ()->fetch(_this, options); if (progress) progress->progress(++current, total); @@ -1323,14 +1349,15 @@ void maildirFolder::fetchMessages(std::vector & msg, } -void maildirFolder::fetchMessage(message* msg, const int options) +void maildirFolder::fetchMessage(ref 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 (msg)->fetch(this, options); + msg.dynamicCast ()->fetch + (thisWeakRef().dynamicCast (), 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 parent, const int number, const bodyPart& part); ~maildirPart(); const structure& getStructure() const; structure& getStructure(); - const maildirPart* getParent() const { return (m_parent); } + weak_ref 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
())); } const int getHeaderParsedOffset() const { return (m_headerParsedOffset); } @@ -79,9 +80,9 @@ public: private: - maildirStructure* m_structure; - maildirPart* m_parent; - header* m_header; + ref m_structure; + weak_ref m_parent; + ref
m_header; int m_number; int m_size; @@ -110,22 +111,17 @@ private: public: - maildirStructure(maildirPart* parent, const bodyPart& part) + maildirStructure(weak_ref parent, const bodyPart& part) { - m_parts.push_back(new maildirPart(parent, 1, part)); + m_parts.push_back(vmime::create (parent, 1, part)); } - maildirStructure(maildirPart* parent, const std::vector & list) + maildirStructure(weak_ref parent, const std::vector >& 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 (parent, number, *list[i])); } @@ -154,7 +150,7 @@ private: static maildirStructure m_emptyStructure; - std::vector m_parts; + std::vector > m_parts; }; @@ -162,13 +158,17 @@ maildirStructure maildirStructure::m_emptyStructure; -maildirPart::maildirPart(maildirPart* parent, const int number, const bodyPart& part) +maildirPart::maildirPart(weak_ref 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 + (thisWeakRef().dynamicCast (), + 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 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 file = fsf->create(path); + ref file = fsf->create(path); - utility::auto_ptr reader = file->getFileReader(); - utility::auto_ptr is = reader->getInputStream(); + ref reader = file->getFileReader(); + ref 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 file = fsf->create(path); + ref file = fsf->create(path); - utility::auto_ptr reader = file->getFileReader(); - utility::auto_ptr is = reader->getInputStream(); + ref reader = file->getFileReader(); + ref 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 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 file = fsf->create(path); + ref 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 reader = file->getFileReader(); - utility::auto_ptr is = reader->getInputStream(); + ref reader = file->getFileReader(); + ref 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 (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
())); } 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 sess, ref auth) : store(sess, getInfosInstance(), auth), m_connected(false) { } @@ -58,30 +58,33 @@ const string maildirStore::getProtocolName() const } -folder* maildirStore::getRootFolder() +ref maildirStore::getRootFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new maildirFolder(folder::path(), this); + return vmime::create (folder::path(), + thisWeakRef().dynamicCast ()); } -folder* maildirStore::getDefaultFolder() +ref maildirStore::getDefaultFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new maildirFolder(folder::path::component("inbox"), this); + return vmime::create (folder::path::component("inbox"), + thisWeakRef().dynamicCast ()); } -folder* maildirStore::getFolder(const folder::path& path) +ref maildirStore::getFolder(const folder::path& path) { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new maildirFolder(path, this); + return vmime::create (path, + thisWeakRef().dynamicCast ()); } @@ -117,7 +120,7 @@ void maildirStore::connect() m_fsPath = fsf->stringToPath(GET_PROPERTY(string, PROPERTY_SERVER_ROOTPATH)); - utility::auto_ptr rootDir = fsf->create(m_fsPath); + ref 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 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 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 (this, num); } -std::vector POP3Folder::getMessages(const int from, const int to) +std::vector > POP3Folder::getMessages(const int from, const int to) { if (!m_store) throw exceptions::illegal_state("Store disconnected"); @@ -213,40 +213,30 @@ std::vector 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 v; + std::vector > v; for (int i = from ; i <= to ; ++i) - v.push_back(new POP3Message(this, i)); + v.push_back(vmime::create (this, i)); return (v); } -std::vector POP3Folder::getMessages(const std::vector & nums) +std::vector > POP3Folder::getMessages(const std::vector & nums) { if (!m_store) throw exceptions::illegal_state("Store disconnected"); else if (!isOpen()) throw exceptions::illegal_state("Folder not open"); - std::vector v; + std::vector > v; - try + for (std::vector ::const_iterator it = nums.begin() ; it != nums.end() ; ++it) { - for (std::vector ::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 ::iterator it = v.begin() ; it != v.end() ; ++it) - delete (*it); - - throw; + v.push_back(vmime::create (this, *it)); } return (v); @@ -264,35 +254,35 @@ const int POP3Folder::getMessageCount() } -folder* POP3Folder::getFolder(const folder::path::component& name) +ref 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 (m_path / name, m_store); } -std::vector POP3Folder::getFolders(const bool /* recursive */) +std::vector > POP3Folder::getFolders(const bool /* recursive */) { if (!m_store) throw exceptions::illegal_state("Store disconnected"); if (m_path.isEmpty()) { - std::vector v; - v.push_back(new POP3Folder(folder::path::component("INBOX"), m_store)); + std::vector > v; + v.push_back(vmime::create (folder::path::component("INBOX"), m_store)); return (v); } else { - std::vector v; + std::vector > v; return (v); } } -void POP3Folder::fetchMessages(std::vector & msg, const int options, +void POP3Folder::fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress) { if (!m_store) @@ -306,10 +296,10 @@ void POP3Folder::fetchMessages(std::vector & msg, const int options, if (progress) progress->start(total); - for (std::vector ::iterator it = msg.begin() ; + for (std::vector >::iterator it = msg.begin() ; it != msg.end() ; ++it) { - dynamic_cast (*it)->fetch(this, options); + (*it).dynamicCast ()->fetch(this, options); if (progress) progress->progress(++current, total); @@ -339,10 +329,10 @@ void POP3Folder::fetchMessages(std::vector & msg, const int options, std::map result; parseMultiListOrUidlResponse(response, result); - for (std::vector ::iterator it = msg.begin() ; + for (std::vector >::iterator it = msg.begin() ; it != msg.end() ; ++it) { - POP3Message* m = dynamic_cast (*it); + ref m = (*it).dynamicCast (); std::map ::const_iterator x = result.find(m->m_num); @@ -384,10 +374,10 @@ void POP3Folder::fetchMessages(std::vector & msg, const int options, std::map result; parseMultiListOrUidlResponse(response, result); - for (std::vector ::iterator it = msg.begin() ; + for (std::vector >::iterator it = msg.begin() ; it != msg.end() ; ++it) { - POP3Message* m = dynamic_cast (*it); + ref m = (*it).dynamicCast (); std::map ::const_iterator x = result.find(m->m_num); @@ -402,14 +392,14 @@ void POP3Folder::fetchMessages(std::vector & msg, const int options, } -void POP3Folder::fetchMessage(message* msg, const int options) +void POP3Folder::fetchMessage(ref 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 (msg)->fetch(this, options); + msg.dynamicCast ()->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 (msg)->m_size = size; + msg.dynamicCast ()->m_size = size; } } } @@ -473,7 +463,7 @@ void POP3Folder::fetchMessage(message* msg, const int options) if (it != response.end()) { - dynamic_cast (msg)->m_uid = + msg.dynamicCast ()->m_uid = string(it, response.end()); } } @@ -488,19 +478,22 @@ const int POP3Folder::getFetchCapabilities() const } -folder* POP3Folder::getParent() +ref POP3Folder::getParent() { - return (m_path.isEmpty() ? NULL : new POP3Folder(m_path.getParent(), m_store)); + if (m_path.isEmpty()) + return NULL; + else + return vmime::create (m_path.getParent(), m_store); } -const store* POP3Folder::getStore() const +weak_ref POP3Folder::getStore() const { return (m_store); } -store* POP3Folder::getStore() +weak_ref POP3Folder::getStore() { return (m_store); } @@ -556,7 +549,9 @@ void POP3Folder::deleteMessage(const int num) std::vector nums; nums.push_back(num); - events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, nums); + events::messageChangedEvent event + (thisRef().dynamicCast (), + 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 (), + events::messageChangedEvent::TYPE_FLAGS, nums); notifyMessageChanged(event); } @@ -654,7 +651,9 @@ void POP3Folder::deleteMessages(const std::vector & nums) } // Notify message flags changed - events::messageChangedEvent event(this, events::messageChangedEvent::TYPE_FLAGS, list); + events::messageChangedEvent event + (thisRef().dynamicCast (), + 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 /* 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 (), + 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 (), + 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 sess, ref 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 POP3Store::getDefaultFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new POP3Folder(folder::path(folder::path::component("INBOX")), this); + return vmime::create (folder::path(folder::path::component("INBOX")), this); } -folder* POP3Store::getRootFolder() +ref POP3Store::getRootFolder() { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new POP3Folder(folder::path(), this); + return vmime::create (folder::path(), this); } -folder* POP3Store::getFolder(const folder::path& path) +ref POP3Store::getFolder(const folder::path& path) { if (!isConnected()) throw exceptions::illegal_state("Not connected"); - return new POP3Folder(path, this); + return vmime::create (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 sess, ref 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 proc = + ref 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 sess, const serviceInfos& infos, ref auth) + : m_session(sess), m_auth(auth) { + if (!auth) + { + m_auth = vmime::create + (sess, infos.getPropertyPrefix()); + } } service::~service() { - if (m_deleteAuth) - delete (m_auth); } -const session* service::getSession() const +ref service::getSession() const { return (m_session); } -session* service::getSession() +ref service::getSession() { return (m_session); } -const authenticator* service::getAuthenticator() const +ref service::getAuthenticator() const { return (m_auth); } -authenticator* service::getAuthenticator() +ref 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 ::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 serviceFactory::create + (ref sess, const string& protocol, ref auth) { return (getServiceByProtocol(protocol)->create(sess, auth)); } -service* serviceFactory::create - (session* sess, const utility::url& u, authenticator* auth) +ref serviceFactory::create + (ref sess, const utility::url& u, ref auth) { - service* serv = create(sess, u.getProtocol(), auth); + ref 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 serviceFactory::getServiceByProtocol(const string& protocol) const { const string name(utility::stringUtils::toLower(protocol)); - for (std::vector ::const_iterator it = m_services.begin() ; + for (std::vector >::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 serviceFactory::getServiceAt(const int pos) const { return (m_services[pos]); } -const std::vector serviceFactory::getServiceList() const +const std::vector > serviceFactory::getServiceList() const { - std::vector res; + std::vector > res; - for (std::vector ::const_iterator it = m_services.begin() ; + for (std::vector >::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 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 session::getTransport(ref auth) { return (getTransport(m_props["transport.protocol"], auth)); } -transport* session::getTransport(const string& protocol, authenticator* auth) +ref session::getTransport(const string& protocol, ref auth) { - service* sv = serviceFactory::getInstance()->create(this, protocol, auth); + ref sess = thisRef().dynamicCast (); + ref sv = serviceFactory::getInstance()->create(sess, protocol, auth); if (sv->getType() != service::TYPE_TRANSPORT) - { - delete (sv); throw exceptions::no_service_available(); - } - return static_cast(sv); + return sv.staticCast (); } -transport* session::getTransport(const utility::url& url, authenticator* auth) +ref session::getTransport(const utility::url& url, ref auth) { - service* sv = serviceFactory::getInstance()->create(this, url, auth); + ref sess = thisRef().dynamicCast (); + ref sv = serviceFactory::getInstance()->create(sess, url, auth); if (sv->getType() != service::TYPE_TRANSPORT) - { - delete (sv); throw exceptions::no_service_available(); - } - return static_cast(sv); + return sv.staticCast (); } -store* session::getStore(authenticator* auth) +ref session::getStore(ref auth) { return (getStore(m_props["store.protocol"], auth)); } -store* session::getStore(const string& protocol, authenticator* auth) +ref session::getStore(const string& protocol, ref auth) { - service* sv = serviceFactory::getInstance()->create(this, protocol, auth); + ref sess = thisRef().dynamicCast (); + ref sv = serviceFactory::getInstance()->create(sess, protocol, auth); if (sv->getType() != service::TYPE_STORE) - { - delete (sv); throw exceptions::no_service_available(); - } - return static_cast(sv); + return sv.staticCast (); } -store* session::getStore(const utility::url& url, authenticator* auth) +ref session::getStore(const utility::url& url, ref auth) { - service* sv = serviceFactory::getInstance()->create(this, url, auth); + ref sess = thisRef().dynamicCast (); + ref sv = serviceFactory::getInstance()->create(sess, url, auth); if (sv->getType() != service::TYPE_STORE) - { - delete (sv); throw exceptions::no_service_available(); - } - return static_cast(sv); + return sv.staticCast (); } 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 sess, ref 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 sess, const serviceInfos& infos, ref auth) : service(sess, infos, auth) { } @@ -39,7 +39,7 @@ static void extractMailboxes { for (int i = 0 ; i < list.getAddressCount() ; ++i) { - mailbox* mbox = dynamic_cast (list.getAddressAt(i)->clone()); + ref mbox = list.getAddressAt(i)->clone().dynamicCast (); 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 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 msg) { - header* hdr = msg->getHeader(); + ref
hdr = msg->getHeader(); try { - headerField* fld = hdr->findField("X-Priority"); + ref 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 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 msg) { - const header* hdr = msg->getHeader(); + const ref hdr = msg->getHeader(); try { - const defaultField* fld = dynamic_cast (hdr->findField("X-Priority")); + const ref fld = hdr->findField("X-Priority").dynamicCast (); 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 (hdr->findField("Importance")); + const ref fld = hdr->findField("Importance").dynamicCast (); 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 msg, const Importance i) { - header* hdr = msg->getHeader(); + ref
hdr = msg->getHeader(); // "X-Priority:" Field - defaultField* fld = dynamic_cast (hdr->getField("X-Priority")); + ref fld = hdr->getField("X-Priority").dynamicCast (); switch (i) { @@ -114,7 +114,7 @@ void importanceHelper::setImportance(message* msg, const Importance i) } // "Importance:" Field - fld = dynamic_cast (hdr->getField("Importance")); + fld = hdr->getField("Importance").dynamicCast (); 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 +// +// 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 // std::find +#include // std::ostringstream +#include // std::runtime_error + + +namespace vmime +{ + + +object::object() + : m_strongCount(0) +{ +} + + +object::object(const object&) + : m_strongCount(0) +{ + // Not used +} + + +object::~object() +{ + for (std::vector ::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 ::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::thisRef() +{ + return ref ::fromPtr(this); +} + + +ref object::thisRef() const +{ + return ref ::fromPtr(this); +} + + +weak_ref object::thisWeakRef() +{ + return weak_ref (thisRef()); +} + + +weak_ref object::thisWeakRef() const +{ + return weak_ref (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 parameter::clone() const { - parameter* p = parameterFactory::getInstance()->create(m_name); + ref 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 parameter::getChildComponents() const +const std::vector > parameter::getChildComponents() const { - std::vector list; + std::vector > 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 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 param; if (pos != m_nameMap.end()) { @@ -73,12 +73,12 @@ parameter* parameterFactory::create } -parameter* parameterFactory::create(const string& name, const component& value) +ref 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 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 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 ::const_iterator + for (std::vector >::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 ::const_iterator i = source.m_params.begin() ; + for (std::vector >::const_iterator i = source.m_params.begin() ; i != source.m_params.end() ; ++i) { - appendParameter((*i)->clone()); + appendParameter((*i)->clone().dynamicCast ()); } } @@ -355,8 +355,8 @@ const bool parameterizedHeaderField::hasParameter(const string& paramName) const { const string name = utility::stringUtils::toLower(paramName); - std::vector ::const_iterator pos = m_params.begin(); - const std::vector ::const_iterator end = m_params.end(); + std::vector >::const_iterator pos = m_params.begin(); + const std::vector >::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 parameterizedHeaderField::findParameter(const string& paramName) const { const string name = utility::stringUtils::toLower(paramName); // Find the first parameter that matches the specified name - std::vector ::const_iterator pos = m_params.begin(); - const std::vector ::const_iterator end = m_params.end(); + std::vector >::const_iterator pos = m_params.begin(); + const std::vector >::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 parameterizedHeaderField::getParameter(const string& paramName) { const string name = utility::stringUtils::toLower(paramName); // Find the first parameter that matches the specified name - std::vector ::const_iterator pos = m_params.begin(); - const std::vector ::const_iterator end = m_params.end(); + std::vector >::const_iterator pos = m_params.begin(); + const std::vector >::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 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 param) { m_params.push_back(param); } -void parameterizedHeaderField::insertParameterBefore(parameter* beforeParam, parameter* param) +void parameterizedHeaderField::insertParameterBefore(ref beforeParam, ref param) { - const std::vector ::iterator it = std::find + const std::vector >::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 param) { m_params.insert(m_params.begin() + pos, param); } -void parameterizedHeaderField::insertParameterAfter(parameter* afterParam, parameter* param) +void parameterizedHeaderField::insertParameterAfter(ref afterParam, ref param) { - const std::vector ::iterator it = std::find + const std::vector >::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 param) { m_params.insert(m_params.begin() + pos + 1, param); } -void parameterizedHeaderField::removeParameter(parameter* param) +void parameterizedHeaderField::removeParameter(ref param) { - const std::vector ::iterator it = std::find + const std::vector >::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 ::iterator it = m_params.begin() + pos; - - delete (*it); + const std::vector >::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 parameterizedHeaderField::getParameterAt(const int pos) { return (m_params[pos]); } -const parameter* parameterizedHeaderField::getParameterAt(const int pos) const +const ref parameterizedHeaderField::getParameterAt(const int pos) const { return (m_params[pos]); } -const std::vector parameterizedHeaderField::getParameterList() const +const std::vector > parameterizedHeaderField::getParameterList() const { - std::vector list; + std::vector > list; list.reserve(m_params.size()); - for (std::vector ::const_iterator it = m_params.begin() ; + for (std::vector >::const_iterator it = m_params.begin() ; it != m_params.end() ; ++it) { list.push_back(*it); @@ -533,17 +523,17 @@ const std::vector parameterizedHeaderField::getParameterList( } -const std::vector parameterizedHeaderField::getParameterList() +const std::vector > parameterizedHeaderField::getParameterList() { return (m_params); } -const std::vector parameterizedHeaderField::getChildComponents() const +const std::vector > parameterizedHeaderField::getChildComponents() const { - std::vector list = headerField::getChildComponents(); + std::vector > list = headerField::getChildComponents(); - for (std::vector ::const_iterator it = m_params.begin() ; + for (std::vector >::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 path::clone() const { - return new path(*this); + return vmime::create (*this); } @@ -102,9 +102,9 @@ path& path::operator=(const path& other) } -const std::vector path::getChildComponents() const +const std::vector > path::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 ()) { } 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 part = vmime::create (); 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 (); try { @@ -104,16 +102,15 @@ void plainTextPart::setCharset(const charset& ch) } -const contentHandler& plainTextPart::getText() const +const ref plainTextPart::getText() const { - return (*m_text); + return (m_text); } -void plainTextPart::setText(const contentHandler& text) +void plainTextPart::setText(ref text) { - delete (m_text); - m_text = text.clone(); + m_text = text->clone().dynamicCast (); } 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 posixChildProcessFactory::create(const utility::file::path& path) const { - return new posixChildProcess(path); + return vmime::create (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 args, const int flags) if (flags & FLAG_REDIRECT_STDIN) { - m_stdIn = new outputStreamPosixPipeAdapter(m_pipe[1]); + m_stdIn = vmime::create (m_pipe[1]); } else { @@ -317,7 +314,7 @@ void posixChildProcess::start(const std::vector args, const int flags) if (flags & FLAG_REDIRECT_STDOUT) { - m_stdOut = new inputStreamPosixPipeAdapter(m_pipe[0]); + m_stdOut = vmime::create (m_pipe[0]); } else { @@ -330,13 +327,13 @@ void posixChildProcess::start(const std::vector args, const int flags) } -utility::outputStream* posixChildProcess::getStdIn() +ref posixChildProcess::getStdIn() { return (m_stdIn); } -utility::inputStream* posixChildProcess::getStdOut() +ref 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 posixFileIterator::nextElement() { - posixFile* file = new posixFile(m_path / vmime::utility::file::path::component(m_dirEntry->d_name)); + ref file = vmime::create + (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 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 (m_path, fd); } @@ -204,14 +205,14 @@ posixFileReader::posixFileReader(const vmime::utility::file::path& path, const v } -vmime::utility::inputStream* posixFileReader::getInputStream() +ref 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 (m_path, fd); } @@ -299,12 +300,12 @@ const bool posixFile::exists() const } -const vmime::utility::file* posixFile::getParent() const +ref posixFile::getParent() const { if (m_path.isEmpty()) return NULL; else - return new posixFile(m_path.getParent()); + return vmime::create (m_path.getParent()); } @@ -340,24 +341,24 @@ void posixFile::remove() } -vmime::utility::fileWriter* posixFile::getFileWriter() +ref posixFile::getFileWriter() { - return new posixFileWriter(m_path, m_nativePath); + return vmime::create (m_path, m_nativePath); } -vmime::utility::fileReader* posixFile::getFileReader() +ref posixFile::getFileReader() { - return new posixFileReader(m_path, m_nativePath); + return vmime::create (m_path, m_nativePath); } -vmime::utility::fileIterator* posixFile::getFiles() const +ref posixFile::getFiles() const { if (!isDirectory()) throw vmime::exceptions::not_a_directory(m_path); - return new posixFileIterator(m_path, m_nativePath); + return vmime::create (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 posixFileSystemFactory::create(const vmime::utility::file::path& path) const { - return new posixFile(path); + return vmime::create (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 posixSocketFactory::create() { - return new posixSocket(); + return vmime::create (); } 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 windowsFileSystemFactory::create(const vmime::utility::file::path& path) const { - return new windowsFile(path); + return vmime::create (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 windowsFile::getParent() const { if (m_path.isEmpty()) return NULL; else - return new windowsFile(m_path.getParent()); + return vmime::create (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 windowsFile::getFileWriter() { - return new windowsFileWriter(m_path, m_nativePath); + return vmime::create (m_path, m_nativePath); } -vmime::utility::fileReader* windowsFile::getFileReader() +ref windowsFile::getFileReader() { - return new windowsFileReader(m_path, m_nativePath); + return vmime::create (m_path, m_nativePath); } -vmime::utility::fileIterator* windowsFile::getFiles() const +ref windowsFile::getFiles() const { - return new windowsFileIterator(m_path, m_nativePath); + return vmime::create (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 windowsFileIterator::nextElement() { - vmime::utility::file* pFile = new windowsFile(m_path / vmime::utility::file::path::component(m_findData.cFileName)); + ref pFile = vmime::create + (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 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 (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 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 (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 (&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 windowsSocketFactory::create() { - return new windowsSocket(); + return vmime::create (); } 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 ::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it) - m_props.push_back(new property(**it)); + for (std::list >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it) + m_props.push_back(vmime::create (**it)); } @@ -53,8 +54,8 @@ propertySet& propertySet::operator=(const propertySet& set) { removeAllProperties(); - for (std::list ::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it) - m_props.push_back(new property(**it)); + for (std::list >::const_iterator it = set.m_props.begin() ; it != set.m_props.end() ; ++it) + m_props.push_back(vmime::create (**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 ::iterator it = std::find_if + std::list >::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 (option, value)); } } } -propertySet::property* propertySet::find(const string& name) const +ref propertySet::find(const string& name) const { - std::list ::const_iterator it = std::find_if + std::list >::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::findOrCreate(const string& name) { - std::list ::const_iterator it = std::find_if + std::list >::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 prop = vmime::create (name, ""); m_props.push_back(prop); return (prop); } @@ -223,9 +221,9 @@ const bool propertySet::hasProperty(const string& name) const } -const std::vector propertySet::getPropertyList() const +const std::vector > propertySet::getPropertyList() const { - std::vector res; + std::vector > 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 propertySet::getPropertyList() } -const std::vector propertySet::getPropertyList() +const std::vector > propertySet::getPropertyList() { - std::vector res; + std::vector > 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 relay::clone() const { - return new relay(*this); + return vmime::create (*this); } @@ -334,10 +334,10 @@ std::vector & relay::getWithList() } -const std::vector relay::getChildComponents() const +const std::vector > relay::getChildComponents() const { // TODO: should fields inherit from 'component'? (using typeAdapter) - return std::vector (); + return std::vector >(); } 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 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 &>(cts.m_ownedStream)), m_stream(cts.m_stream), m_length(cts.m_length) { } -contentHandler* streamContentHandler::clone() const +ref streamContentHandler::clone() const { - return new streamContentHandler(*this); + return vmime::create (*this); } @@ -60,7 +59,6 @@ streamContentHandler& streamContentHandler::operator=(const streamContentHandler { m_encoding = cts.m_encoding; - m_ownedStream = const_cast &>(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 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 theDecoder(m_encoding.getEncoder()); - utility::auto_ptr theEncoder(enc.getEncoder()); + ref theDecoder = m_encoding.getEncoder(); + ref theEncoder = enc.getEncoder(); theEncoder->getProperties()["maxlinelength"] = maxLineLength; - utility::inputStream& in = const_cast - (*(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 - (*(m_stream ? m_stream : m_ownedStream.ptr())); + m_stream->reset(); // may not work... - in.reset(); // may not work... - - utility::bufferedStreamCopy(in, os); + utility::bufferedStreamCopy(*m_stream, os); } } // Need to encode data before else { - utility::auto_ptr theEncoder(enc.getEncoder()); + ref theEncoder = enc.getEncoder(); theEncoder->getProperties()["maxlinelength"] = maxLineLength; - utility::inputStream& in = const_cast - (*(m_stream ? m_stream : m_ownedStream.ptr())); + m_stream->reset(); // may not work... - in.reset(); // may not work... - - theEncoder->encode(in, os); + theEncoder->encode(*m_stream, os); } } void streamContentHandler::extract(utility::outputStream& os) const { - if (m_stream == NULL && m_ownedStream.ptr() == NULL) + if (!m_stream) return; // No decoding to perform if (!isEncoded()) { - utility::inputStream& in = const_cast - (*(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 theDecoder(m_encoding.getEncoder()); + ref theDecoder = m_encoding.getEncoder(); - utility::inputStream& in = const_cast - (*(m_stream ? m_stream : m_ownedStream.ptr())); + m_stream->reset(); // may not work... - in.reset(); // may not work... - - theDecoder->decode(in, os); + theDecoder->decode(*m_stream, os); } } void streamContentHandler::extractRaw(utility::outputStream& os) const { - if (m_stream == NULL && m_ownedStream.ptr() == NULL) + if (!m_stream) return; - utility::inputStream& in = const_cast - (*(m_stream ? m_stream : m_ownedStream.ptr())); + m_stream->reset(); // may not work... - in.reset(); // may not work... - - utility::bufferedStreamCopy(in, os); + utility::bufferedStreamCopy(*m_stream, os); } @@ -201,7 +171,7 @@ const string::size_type streamContentHandler::getLength() const const bool streamContentHandler::isEmpty() const { - return (m_length == 0 || (m_stream == NULL && m_ownedStream.ptr() == NULL)); + return (m_length == 0 || !m_stream); } 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 stringContentHandler::clone() const { - return new stringContentHandler(*this); + return vmime::create (*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 theDecoder(m_encoding.getEncoder()); - utility::auto_ptr theEncoder(enc.getEncoder()); + ref theDecoder = m_encoding.getEncoder(); + ref 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 theEncoder(enc.getEncoder()); + ref 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 theDecoder(m_encoding.getEncoder()); + ref 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 (w)); } @@ -69,7 +69,7 @@ void text::parse(const string& buffer, const string::size_type position, string::size_type newPos; - const std::vector words = word::parseMultiple(buffer, position, end, &newPos); + const std::vector > 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 ::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i) + for (std::vector >::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 ::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i) - m_words.push_back(new word(**i)); + for (std::vector >::const_iterator i = t.m_words.begin() ; i != t.m_words.end() ; ++i) + m_words.push_back(vmime::create (**i)); } @@ -133,8 +133,8 @@ const bool text::operator==(const text& t) const { bool equal = true; - std::vector ::const_iterator i = m_words.begin(); - std::vector ::const_iterator j = t.m_words.begin(); + std::vector >::const_iterator i = m_words.begin(); + std::vector >::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 ::const_iterator i = m_words.begin() ; i != m_words.end() ; ++i) + for (std::vector >::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 w) { m_words.push_back(w); } -void text::insertWordBefore(const int pos, word* w) +void text::insertWordBefore(const int pos, ref w) { m_words.insert(m_words.begin() + pos, w); } -void text::insertWordAfter(const int pos, word* w) +void text::insertWordAfter(const int pos, ref 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 ::iterator it = m_words.begin() + pos; - - delete (*it); + const std::vector >::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 text::getWordAt(const int pos) { return (m_words[pos]); } -const word* text::getWordAt(const int pos) const +const ref text::getWordAt(const int pos) const { return (m_words[pos]); } -const std::vector text::getWordList() const +const std::vector > text::getWordList() const { - std::vector list; + std::vector > list; list.reserve(m_words.size()); - for (std::vector ::const_iterator it = m_words.begin() ; + for (std::vector >::const_iterator it = m_words.begin() ; it != m_words.end() ; ++it) { list.push_back(*it); @@ -237,19 +235,29 @@ const std::vector text::getWordList() const } -const std::vector text::getWordList() +const std::vector > text::getWordList() { return (m_words); } -text* text::clone() const +ref text::clone() const { - return new text(*this); + return vmime::create (*this); } -text* text::newFromString(const string& in, const charset& ch, text* generateInExisting) +ref text::newFromString(const string& in, const charset& ch) +{ + ref t = vmime::create (); + + t->createFromString(in, ch); + + return t; +} + + +void text::createFromString(const string& in, const charset& ch) { const string::const_iterator end = in.end(); string::const_iterator p = in.begin(); @@ -259,9 +267,7 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE bool prevIs8bit = false; // is previous word 8-bit? unsigned int count = 0; // total number of words - text* out = (generateInExisting != NULL) ? generateInExisting : new text(); - - out->removeAllWords(); + removeAllWords(); for ( ; ; ) { @@ -276,12 +282,12 @@ text* text::newFromString(const string& in, const charset& ch, text* generateInE { // No need to create a new encoded word, just append // the current word to the previous one. - out->getWordAt(out->getWordCount() - 1)-> - getBuffer() += string(start, p); + ref w = getWordAt(getWordCount() - 1); + w->getBuffer() += string(start, p); } else { - out->appendWord(new word(string(start, p), ch)); + appendWord(vmime::create (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 w = getWordAt(getWordCount() - 1); + w->getBuffer() += string(start, p); } else { - out->appendWord(new word + appendWord(vmime::create (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::decodeAndUnfold(const string& in) +{ + ref t = vmime::create (); + + 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 words = word::parseMultiple(in, 0, in.length(), NULL); + const std::vector > 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 text::getChildComponents() const +const std::vector > text::getChildComponents() const { - std::vector list; + std::vector > 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 textPartFactory::create(const mediaType& type) { - NameMap::const_iterator pos = m_nameMap.find(type.generate()); + for (MapType::const_iterator it = m_map.begin() ; + it != m_map.end() ; ++it) + { + if ((*it).first == type) + return ((*it).second)(); + } - if (pos != m_nameMap.end()) - { - return ((*pos).second)(); - } - else - { - throw exceptions::no_factory_available(); - } + throw exceptions::no_factory_available(); } 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 params + const std::vector > 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 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::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 w = vmime::create (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 w = vmime::create (); 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 w = vmime::create (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::parseMultiple(const string& buffer, const string::size_type position, +const std::vector > word::parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition) { - std::vector res; - word* w = NULL; + std::vector > res; + ref w; string::size_type pos = position; @@ -694,9 +694,9 @@ const string word::getConvertedText(const charset& dest) const } -word* word::clone() const +ref word::clone() const { - return new word(m_buffer, m_charset); + return vmime::create (m_buffer, m_charset); } @@ -730,9 +730,9 @@ void word::setBuffer(const string& buffer) } -const std::vector word::getChildComponents() const +const std::vector > word::getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 ("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 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 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 hf = vmime::headerFieldFactory::getInstance()->create("A", "a"); hdr.appendField(hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 hf = vmime::headerFieldFactory::getInstance()->create("B", "b"); hdr.appendField(hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 hf = vmime::headerFieldFactory::getInstance()->create("B", "b"); hdr.insertFieldBefore(hdr.getField("C"), hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 hf = vmime::headerFieldFactory::getInstance()->create("B", "b"); hdr.insertFieldBefore(1, hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 hf = vmime::headerFieldFactory::getInstance()->create("B", "b"); hdr.insertFieldAfter(hdr.getField("A"), hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 hf = vmime::headerFieldFactory::getInstance()->create("B", "b"); hdr.insertFieldAfter(0, hf); - std::vector res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 res1 = hdr1.getFieldList(); + std::vector > res1 = hdr1.getFieldList(); assert_eq("Count", static_cast (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 res2 = hdr2.getFieldList(); + std::vector > res2 = hdr2.getFieldList(); assert_eq("Count", static_cast (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 res1 = hdr1.getFieldList(); + std::vector > res1 = hdr1.getFieldList(); assert_eq("Count", static_cast (0), res1.size()); - std::vector res2 = hdr2.getFieldList(); + std::vector > res2 = hdr2.getFieldList(); assert_eq("Count", static_cast (0), res2.size()); } @@ -207,10 +207,10 @@ namespace hdr1.removeAllFields(); hdr2.removeAllFields(); - std::vector res1 = hdr1.getFieldList(); + std::vector > res1 = hdr1.getFieldList(); assert_eq("Count", static_cast (0), res1.size()); - std::vector res2 = hdr2.getFieldList(); + std::vector > res2 = hdr2.getFieldList(); assert_eq("Count", static_cast (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 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 res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 res = hdr.getFieldList(); + std::vector > res = hdr.getFieldList(); assert_eq("Count", static_cast (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 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 res = hdr.findAllFields("B"); + std::vector > res = hdr.findAllFields("B"); assert_eq("Count", static_cast (0), res.size()); } @@ -303,7 +303,7 @@ namespace vmime::header hdr; hdr.parse("A: a1\nB: b1\nB: b2\nC: c1\n"); - std::vector res = hdr.findAllFields("B"); + std::vector > res = hdr.findAllFields("B"); assert_eq("Count", static_cast (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 res = hdr.findAllFields("C"); + std::vector > res = hdr.findAllFields("C"); assert_eq("Count", static_cast (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 ("a", "b")); assert_eq("1", "", s1.generate()); vmime::messageIdSequence s2; - s2.appendMessageId(new vmime::messageId("a", "b")); - s2.appendMessageId(new vmime::messageId("c", "d")); + s2.appendMessageId(vmime::create ("a", "b")); + s2.appendMessageId(vmime::create ("c", "d")); assert_eq("2", " ", 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 m_value; + vmime::ref > m_value; public: - parameterizedHeaderField() : headerField("F"), m_value("X") { } + parameterizedHeaderField() + : headerField("F"), + m_value(vmime::create >("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 getValueImp() const { return m_value; } + vmime::ref 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 \ - (p.getParameterAt(n))->getValue().getCharset().generate()) -#define PARAM_BUFFER(p, n) (static_cast \ - (p.getParameterAt(n))->getValue().getBuffer()) +#define PARAM_CHARSET(p, n) ( \ + (p.getParameterAt(n).staticCast ())->getValue().getCharset().generate()) +#define PARAM_BUFFER(p, n) ( \ + (p.getParameterAt(n).staticCast ())->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 (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 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
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 clone() const; void copyFrom(const component& other); addressList& operator=(const addressList& other); addressList& operator=(const mailboxList& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; /** Add a address at the end of the list. * * @param addr address to append */ - void appendAddress(address* addr); + void appendAddress(ref
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
beforeAddress, ref
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
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
afterAddress, ref
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
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
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
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 getAddressAt(const int pos) const; /** Return the address list. * * @return list of addresses */ - const std::vector getAddressList() const; + const std::vector > getAddressList() const; /** Return the address list. * * @return list of addresses */ - const std::vector getAddressList(); + const std::vector > getAddressList(); private: - std::vector m_list; + std::vector > 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 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 - 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 @@ -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 + static ref create() { return ref ::fromPtr(new T); } + + template + static ref create(const P0& p0) { return ref ::fromPtr(new T(p0)); } + + template + static ref create(const P0& p0, const P1& p1) { return ref ::fromPtr(new T(p0, p1)); } + + template + static ref create(const P0& p0, const P1& p1, const P2& p2) { return ref ::fromPtr(new T(p0, p1, p2)); } + + template + static ref create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return ref ::fromPtr(new T(p0, p1, p2, p3)); } + + template + static ref create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return ref ::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 + static ref create() { return creator::create (); } + + /** Create a new object and return a reference to it. + * @return reference to the new object + */ + template + static ref create(const P0& p0) { return creator::create (p0); } + + /** Create a new object and return a reference to it. + * @return reference to the new object + */ + template + static ref create(const P0& p0, const P1& p1) { return creator::create (p0, p1); } + + /** Create a new object and return a reference to it. + * @return reference to the new object + */ + template + static ref create(const P0& p0, const P1& p1, const P2& p2) { return creator::create (p0, p1, p2); } + + /** Create a new object and return a reference to it. + * @return reference to the new object + */ + template + static ref create(const P0& p0, const P1& p1, const P2& p2, const P3& p3) { return creator::create (p0, p1, p2, p3); } + + /** Create a new object and return a reference to it. + * @return reference to the new object + */ + template + static ref create(const P0& p0, const P1& p1, const P2& p2, const P3& p3, const P4& p4) { return creator::create (p0, p1, p2, p3, p4); } + + + /** Clone helper. + * Use "vmime::clone(obj)" instead of "obj->clone().cast ()". + */ + template + ref clone(ref x) + { + return x->clone().template dynamicCast (); + } + + /** Clone helper. + * Use "vmime::clone(obj)" instead of "obj.clone().cast ()". + */ + template + ref clone(T& x) + { + return x.clone().template dynamicCast (); + } + } // 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 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 beforePart, ref 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 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 afterPart, ref 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 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 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 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 getPartAt(const int pos) const; /** Return the part list. * * @return list of parts */ - const std::vector getPartList() const; + const std::vector > getPartList() const; /** Return the part list. * * @return list of parts */ - const std::vector getPartList(); + const std::vector > getPartList(); /** Return the prolog text. * @@ -176,13 +172,13 @@ public: * * @return read-only body contents */ - const contentHandler& getContents() const; + const ref getContents() const; /** Set the body contents. * * @param contents new body contents */ - void setContents(const contentHandler& contents); + void setContents(ref 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 clone() const; void copyFrom(const component& other); body& operator=(const body& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; private: + void setParentPart(weak_ref parent); + + string m_prologText; string m_epilogText; - contentHandler* m_contents; + ref m_contents; - bodyPart* m_part; - header* m_header; + weak_ref m_part; + weak_ref
m_header; - std::vector m_parts; + std::vector > m_parts; const bool isRootPart() const; - void initNewPart(bodyPart* part); - - void setContentsImpl(const contentHandler& cts); + void initNewPart(ref 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 getHeader() const; /** Return the header section of this part. * * @return header section */ - header* getHeader(); + ref
getHeader(); /** Return the body section of this part. * * @return body section */ - const body* getBody() const; + const ref getBody() const; /** Return the body section of this part. * * @return body section */ - body* getBody(); + ref getBody(); /** Return the parent part of this part. * * @return parent part or NULL if not known */ - bodyPart* getParentPart() const; + weak_ref getParentPart() const; - bodyPart* clone() const; + ref clone() const; void copyFrom(const component& other); bodyPart& operator=(const bodyPart& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; private: - header m_header; - body m_body; + ref
m_header; + ref m_body; - bodyPart* m_parent; + weak_ref 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 getChildComponents() const; + const std::vector > 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 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 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 getChildComponents(); + const std::vector > getChildComponents(); /** Return the list of children of this component (const version). * * @return list of child components */ - virtual const std::vector getChildComponents() const = 0; + virtual const std::vector > 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 clone() const; void copyFrom(const component& other); contentDisposition& operator=(const contentDisposition& other); - const std::vector getChildComponents() const; + const std::vector > 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 { - friend class headerFieldFactory::registerer ; + 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 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 { - friend class headerFieldFactory::registerer ; + 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 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 getChildComponents() const; + const std::vector > 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 data, const encoding& enc, const mediaType& type, const text& desc = NULL_TEXT); + defaultAttachment(ref 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 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 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 ; + friend class vmime::creator; // create ref protected: @@ -59,8 +59,11 @@ private: void parse(const std::vector & chunks); + const ref getValueImp() const; + const ref getValueImp(); - word m_value; + + ref 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 clone() const; void copyFrom(const component& other); disposition& operator=(const disposition& other); - const std::vector getChildComponents() const; + const std::vector > 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 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 create() const = 0; virtual const string& getName() const = 0; }; @@ -64,7 +62,7 @@ private: template class registeredEncoderImpl : public registeredEncoder { - friend class encoderFactory; + friend class vmime::creator; protected: @@ -72,9 +70,9 @@ private: public: - encoder* create() const + ref create() const { - return new E; + return vmime::create (); } const string& getName() const @@ -88,7 +86,7 @@ private: }; - std::vector m_encoders; + std::vector > m_encoders; public: @@ -99,7 +97,7 @@ public: template void registerName(const string& name) { - m_encoders.push_back(new registeredEncoderImpl (utility::stringUtils::toLower(name))); + m_encoders.push_back(vmime::create >(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 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 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 getEncoderAt(const int pos) const; /** Return a list of all registered encoders. * * @return list of registered encoders */ - const std::vector getEncoderList() const; + const std::vector > 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 getChildComponents() const; + const std::vector > 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 data); - encoding* clone() const; + ref 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 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 genericField : virtual public headerField { - friend class headerFieldFactory::registerer >; + friend class vmime::creator; // create ref protected: - genericField() { } + genericField() : m_value(vmime::create ()) { } + + + const ref getValueImp() const + { + return (m_value); + } + + ref getValueImp() + { + return (m_value); + } public: @@ -51,31 +62,31 @@ public: return (*this); } - const VALUE_TYPE& getValue() const + template + void setValue(const TYPE& value) { - return (m_value); + *m_value = value; } VALUE_TYPE& getValue() { - return (m_value); + return *m_value; } - template - 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 (value); - m_value = v; + *m_value = v; } private: - VALUE_TYPE m_value; + ref 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 genericParameter : public parameter { - friend class parameterFactory::registerer >; + friend class vmime::creator; // create ref protected: - genericParameter() { } + genericParameter() : m_value(vmime::create ()) { } + + + const ref getValueImp() const + { + return m_value; + } + + const ref 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 void setValue(const TYPE& value) { - m_value = value; + *m_value = value; } void setValue(const component& value) { const VALUE_TYPE& v = dynamic_cast (value); - m_value = v; + *m_value = v; } private: - VALUE_TYPE m_value; + ref 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 \ - (*getField(fields::fieldName)); } \ - const type& methodName() const { return dynamic_cast \ - (*findField(fields::fieldName)); } + ref methodName() { return getField(fields::fieldName).dynamicCast (); } \ + ref methodName() const { return findField(fields::fieldName).dynamicCast (); } 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 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 findAllFields(const string& fieldName); + std::vector > 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 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 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 beforeField, ref 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 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 afterField, ref 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 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 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 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 getFieldAt(const int pos) const; /** Return the field list. * * @return list of fields */ - const std::vector getFieldList() const; + const std::vector > getFieldList() const; /** Return the field list. * * @return list of fields */ - const std::vector getFieldList(); + const std::vector > getFieldList(); - header* clone() const; + ref clone() const; void copyFrom(const component& other); header& operator=(const header& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; private: - std::vector m_fields; + std::vector > 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 clone() const; void copyFrom(const component& other); headerField& operator=(const headerField& other); - const std::vector getChildComponents() const; + const std::vector > 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 getValueImp() const = 0; + virtual ref getValueImp() = 0; private: + static ref 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 (*AllocFunc)(void); typedef std::map NameMap; NameMap m_nameMap; @@ -51,10 +51,10 @@ public: { public: - static headerField* creator() + static ref creator() { // Allocate a new object - return new TYPE(); + return vmime::create (); } }; #endif // VMIME_BUILDING_DOC @@ -67,7 +67,7 @@ public: (utility::stringUtils::toLower(name), ®isterer::creator)); } - headerField* create(const string& name, const string& body = NULL_STRING); + ref 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 getPlainText() const; + void setPlainText(ref plainText); - const contentHandler& getText() const; - void setText(const contentHandler& text); + const ref getText() const; + void setText(ref text); /** Embedded object (eg: image for <IMG> tag). */ - class embeddedObject + class embeddedObject : public object { public: - embeddedObject(const contentHandler& data, const encoding& enc, + embeddedObject(ref 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 getData() const; /** Return the encoding used for data in this * embedded object. @@ -93,7 +90,7 @@ public: private: - contentHandler* m_data; + ref 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 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 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 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 data, const encoding& enc, const mediaType& type); private: - contentHandler* m_plainText; - contentHandler* m_text; + ref m_plainText; + ref m_text; charset m_charset; - std::vector m_objects; + std::vector > m_objects; - void findEmbeddedParts(const bodyPart& part, std::vector & cidParts, std::vector & locParts); + void findEmbeddedParts(const bodyPart& part, std::vector >& cidParts, std::vector >& 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 clone() const; mailbox& operator=(const mailbox& other); const bool isEmpty() const; void clear(); - const std::vector getChildComponents() const; + const std::vector > 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 { - friend class headerFieldFactory::registerer ; + 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 clone() const; mailboxGroup& operator=(const component& other); - const std::vector getChildComponents() const; + const std::vector > 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 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 beforeMailbox, ref 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 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 afterMailbox, ref 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 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 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 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 getMailboxAt(const int pos) const; /** Return the mailbox list. * * @return list of mailboxes */ - const std::vector getMailboxList() const; + const std::vector > getMailboxList() const; /** Return the mailbox list. * * @return list of mailboxes */ - const std::vector getMailboxList(); + const std::vector > getMailboxList(); const bool isGroup() const; private: text m_name; - std::vector m_list; + std::vector > 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 clone() const; void copyFrom(const component& other); mailboxList& operator=(const mailboxList& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; /** Add a mailbox at the end of the list. * * @param mbox mailbox to append */ - void appendMailbox(mailbox* mbox); + void appendMailbox(ref 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 beforeMailbox, ref 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 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 afterMailbox, ref 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 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 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 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 getMailboxAt(const int pos) const; /** Return the mailbox list. * * @return list of mailboxes */ - const std::vector getMailboxList() const; + const std::vector > getMailboxList() const; /** Return the mailbox list. * * @return list of mailboxes */ - const std::vector getMailboxList(); + const std::vector > 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 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 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 getPossibleMDNs(const message* msg); + static const std::vector getPossibleMDNs(const ref 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 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 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 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 & reportingUAProducts + static ref buildMDN(const sendableMDNInfos& mdnInfos, + const string& text, + const charset& ch, + const mailbox& expeditor, + const disposition& dispo, + const string& reportingUA = NULL_STRING, + const std::vector & reportingUAProducts = std::vector ()); private: - static bodyPart* createFirstMDNPart(const sendableMDNInfos& mdnInfos, - const string& text, const charset& ch); + static ref 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 & reportingUAProducts); + static ref createSecondMDNPart(const sendableMDNInfos& mdnInfos, + const disposition& dispo, + const string& reportingUA, + const std::vector & reportingUAProducts); - static bodyPart* createThirdMDNPart(const sendableMDNInfos& mdnInfos); + static ref 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 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 msg); receivedMDNInfos(const receivedMDNInfos& other); receivedMDNInfos& operator=(const receivedMDNInfos& other); - const message* getMessage() const; + const ref 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 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 msg, const mailbox& mbox); sendableMDNInfos(const sendableMDNInfos& other); sendableMDNInfos& operator=(const sendableMDNInfos& other); - const message* getMessage() const; + const ref 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 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 clone() const; void copyFrom(const component& other); mediaType& operator=(const mediaType& other); - const std::vector getChildComponents() const; + const std::vector > 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 attach); /** Attach a new object to the message. * * @param attach new attachment */ - void appendAttachment(attachment* attach); + void appendAttachment(ref 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 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 getAttachmentAt(const int pos); /** Return the number of attachments in the message. * @@ -170,13 +170,13 @@ public: * * @return list of attachments */ - const std::vector getAttachmentList() const; + const std::vector > getAttachmentList() const; /** Return the list of attachments. * * @return list of attachments */ - const std::vector getAttachmentList(); + const std::vector > 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 getTextPart(); /** Construct a new message based on the information specified * in this object. * * @return a new message */ - message* construct() const; + ref construct() const; private: @@ -207,9 +207,9 @@ private: text m_subject; - textPart* m_textPart; + ref m_textPart; - std::vector m_attach; + std::vector > 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 clone() const; void copyFrom(const component& other); messageId& operator=(const messageId& other); - const std::vector getChildComponents() const; + const std::vector > 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 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 clone() const; void copyFrom(const component& other); messageIdSequence& operator=(const messageIdSequence& other); - const std::vector getChildComponents() const; + const std::vector > 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 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 beforeMid, ref 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 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 afterMid, ref 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 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 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 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 getMessageIdAt(const int pos) const; /** Return the message-id list. * * @return list of message-ids */ - const std::vector getMessageIdList() const; + const std::vector > getMessageIdList() const; /** Return the message-id list. * * @return list of message-ids */ - const std::vector getMessageIdList(); + const std::vector > getMessageIdList(); private: - std::vector m_list; + std::vector > 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 getAttachmentAt(const int pos) const; /** Return the attachments of the message. * * @return list of attachments in the message */ - const std::vector getAttachmentList() const; + const std::vector > 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 getAttachmentInfo(const ref a) const; /** Return the text parts of the message. * * @return list of text parts in the message */ - const std::vector getTextPartList() const; + const std::vector > 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 getTextPartAt(const int pos) const; private: @@ -139,10 +139,10 @@ private: datetime m_date; - std::vector m_attach; - std::map m_attachInfo; + std::vector > m_attach; + std::map > m_attachInfo; - std::vector m_textParts; + std::vector > 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, const string& prefix); private: - const propertySet& m_props; + weak_ref 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 & nums); + messageCountEvent(ref folder, const Types type, const std::vector & nums); /** Return the folder in which messages have been added/removed. * * @return folder in which message count changed */ - const folder* getFolder() const; + ref getFolder() const; /** Return the event type. * @@ -76,7 +76,7 @@ public: private: - folder* m_folder; + ref m_folder; const Types m_type; std::vector m_nums; }; @@ -111,13 +111,13 @@ public: }; - messageChangedEvent(folder* folder, const Types type, const std::vector & nums); + messageChangedEvent(ref folder, const Types type, const std::vector & nums); /** Return the folder in which messages have changed. * * @return folder in which message count changed */ - const folder* getFolder() const; + ref getFolder() const; /** Return the event type. * @@ -139,7 +139,7 @@ public: private: - folder* m_folder; + ref m_folder; const Types m_type; std::vector m_nums; }; @@ -175,13 +175,13 @@ public: }; - folderEvent(folder* folder, const Types type, const utility::path& oldPath, const utility::path& newPath); + folderEvent(ref 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 getFolder() const; /** Return the event type. * @@ -197,7 +197,7 @@ public: private: - folder* m_folder; + ref 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 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 getMessages(const int from = 1, const int to = -1) = 0; + virtual std::vector > 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 getMessages(const std::vector & nums) = 0; + virtual std::vector > getMessages(const std::vector & 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 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 getFolders(const bool recursive = false) = 0; + virtual std::vector > 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 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 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 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 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 & msg, const int options, utility::progressionListener* progress = NULL) = 0; + virtual void fetchMessages(std::vector >& 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 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 store, ref auth); ~IMAPConnection(); @@ -75,31 +75,31 @@ public: IMAPParser::response* readResponse(IMAPParser::literalHandler* lh = NULL); - const IMAPTag* getTag() const; - const IMAPParser* getParser() const; + ref getTag() const; + ref getParser() const; - const IMAPStore* getStore() const; - IMAPStore* getStore(); + weak_ref getStore() const; + weak_ref getStore(); - session* getSession(); + ref getSession(); private: - IMAPStore* m_store; + weak_ref m_store; - authenticator* m_auth; + ref m_auth; - socket* m_socket; + ref m_socket; - IMAPParser* m_parser; + ref m_parser; - IMAPTag* m_tag; + ref m_tag; char m_hierarchySeparator; ProtocolStates m_state; - timeoutHandler* m_timeoutHandler; + ref 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(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 getMessages(const int from = 1, const int to = -1); - std::vector getMessages(const std::vector & nums); + ref getMessage(const int num); + std::vector > getMessages(const int from = 1, const int to = -1); + std::vector > getMessages(const std::vector & nums); const int getMessageCount(); - folder* getFolder(const folder::path::component& name); - std::vector getFolders(const bool recursive = false); + ref getFolder(const folder::path::component& name); + std::vector > 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 & 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 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 getParent(); - const store* getStore() const; - store* getStore(); + weak_ref getStore() const; + weak_ref getStore(); - void fetchMessages(std::vector & msg, const int options, utility::progressionListener* progress = NULL); - void fetchMessage(message* msg, const int options); + void fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress = NULL); + void fetchMessage(ref msg, const int options); const int getFetchCapabilities() const; @@ -130,7 +131,7 @@ private: IMAPStore* m_store; - IMAPConnection* m_connection; + ref 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(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
m_header; + ref 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 tag, weak_ref sok, weak_ref _timeoutHandler) : m_tag(tag), m_socket(sok), m_progress(NULL), m_literalHandler(NULL), m_timeoutHandler(_timeoutHandler) { } - const IMAPTag* tag() const + weak_ref tag() const { return (m_tag); } @@ -4914,14 +4914,14 @@ public: private: - IMAPTag* m_tag; - socket* m_socket; + weak_ref m_tag; + weak_ref m_socket; utility::progressionListener* m_progress; literalHandler* m_literalHandler; - timeoutHandler* m_timeoutHandler; + weak_ref 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 sess, ref auth); ~IMAPStore(); const string getProtocolName() const; - folder* getDefaultFolder(); - folder* getRootFolder(); - folder* getFolder(const folder::path& path); + ref getDefaultFolder(); + ref getRootFolder(); + ref 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 m_connection; // Used to request the authentication informations only the // first time, and reuse these informations the next time. - class authenticator* m_oneTimeAuth; + ref m_oneTimeAuth; - class authenticator* oneTimeAuthenticator(); + ref oneTimeAuthenticator(); - IMAPConnection* connection(); + ref 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(const folder::path& path, maildirStore* store); + maildirFolder(const folder::path& path, weak_ref store); maildirFolder(const maildirFolder&) : folder() { } ~maildirFolder(); @@ -75,13 +76,13 @@ public: const bool isOpen() const; - message* getMessage(const int num); - std::vector getMessages(const int from = 1, const int to = -1); - std::vector getMessages(const std::vector & nums); + ref getMessage(const int num); + std::vector > getMessages(const int from = 1, const int to = -1); + std::vector > getMessages(const std::vector & nums); const int getMessageCount(); - folder* getFolder(const folder::path::component& name); - std::vector getFolders(const bool recursive = false); + ref getFolder(const folder::path::component& name); + std::vector > 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 & 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 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 getParent(); - const store* getStore() const; - store* getStore(); + weak_ref getStore() const; + weak_ref getStore(); - void fetchMessages(std::vector & msg, const int options, utility::progressionListener* progress = NULL); - void fetchMessage(message* msg, const int options); + void fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress = NULL); + void fetchMessage(ref msg, const int options); const int getFetchCapabilities() const; @@ -118,12 +119,12 @@ private: void scanFolder(); - void listFolders(std::vector & list, const bool recursive); + void listFolders(std::vector >& 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 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 private: - maildirMessage(maildirFolder* folder, const int num); + maildirMessage(weak_ref 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 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 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
m_header; + ref 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 sess, ref auth); ~maildirStore(); const string getProtocolName() const; - folder* getDefaultFolder(); - folder* getRootFolder(); - folder* getFolder(const folder::path& path); + ref getDefaultFolder(); + ref getRootFolder(); + ref 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 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(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 getMessages(const int from = 1, const int to = -1); - std::vector getMessages(const std::vector & nums); + ref getMessage(const int num); + std::vector > getMessages(const int from = 1, const int to = -1); + std::vector > getMessages(const std::vector & nums); const int getMessageCount(); - folder* getFolder(const folder::path::component& name); - std::vector getFolders(const bool recursive = false); + ref getFolder(const folder::path::component& name); + std::vector > 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 & 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 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 getParent(); - const store* getStore() const; - store* getStore(); + weak_ref getStore() const; + weak_ref getStore(); - void fetchMessages(std::vector & msg, const int options, utility::progressionListener* progress = NULL); - void fetchMessage(message* msg, const int options); + void fetchMessages(std::vector >& msg, const int options, utility::progressionListener* progress = NULL); + void fetchMessage(ref 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(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 sess, ref auth); ~POP3Store(); const string getProtocolName() const; - folder* getDefaultFolder(); - folder* getRootFolder(); - folder* getFolder(const folder::path& path); + ref getDefaultFolder(); + ref getRootFolder(); + ref getFolder(const folder::path& path); const bool isValidFolderName(const folder::path::component& name) const; @@ -94,10 +92,10 @@ private: std::list m_folders; - socket* m_socket; + ref m_socket; bool m_authentified; - timeoutHandler* m_timeoutHandler; + ref 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 sess, ref 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 sess, const serviceInfos& infos, ref auth); public: @@ -72,13 +72,13 @@ public: * * @return session object */ - const session* getSession() const; + ref getSession() const; /** Return the session object associated with this service instance. * * @return session object */ - session* getSession(); + ref getSession(); /** Return information about this service. * @@ -110,13 +110,13 @@ public: * * @return authenticator object */ - const authenticator* getAuthenticator() const; + ref getAuthenticator() const; /** Return the authenticator object used with this service instance. * * @return authenticator object */ - authenticator* getAuthenticator(); + ref 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 m_session; + ref 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 create(ref sess, ref 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 create(ref sess, ref auth) const { - return new S(sess, auth); + return vmime::create (sess, auth); } const serviceInfos& getInfos() const @@ -112,7 +113,7 @@ private: const serviceInfos& m_servInfos; }; - std::vector m_services; + std::vector > 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 (name)); + m_services.push_back(vmime::create >(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 create(ref sess, const string& protocol, ref 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 create(ref sess, const utility::url& u, ref 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 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 getServiceAt(const int pos) const; /** Return a list of all registered services. * * @return list of registered services */ - const std::vector getServiceList() const; + const std::vector > 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 - const TYPE getPropertyValue(session* s, const property& p) const + const TYPE getPropertyValue(ref s, const property& p) const { if (p.getFlags() & property::FLAG_REQUIRED) return s->getProperties()[getPropertyPrefix() + p.getName()].template getValue (); @@ -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 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 getTransport(ref 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 getTransport(const string& protocol, ref 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 getTransport(const utility::url& url, ref 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 getStore(ref 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 getStore(const string& protocol, ref 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 getStore(const utility::url& url, ref 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 sess, ref auth); ~SMTPTransport(); const string getProtocolName() const; @@ -67,11 +67,11 @@ private: void internalDisconnect(); - socket* m_socket; + ref m_socket; bool m_authentified; bool m_extendedSMTP; - timeoutHandler* m_timeoutHandler; + ref 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 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 sess, const serviceInfos& infos, ref auth) : service(sess, infos, auth) { } public: @@ -47,21 +47,21 @@ public: * * @return default folder */ - virtual folder* getDefaultFolder() = 0; + virtual ref 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 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 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 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 sess, const serviceInfos& infos, ref 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 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 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 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 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 +// +// 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 + + +namespace vmime +{ + + +/** Base object for all objects in the library. This implements + * reference counting and auto-deletion. + */ + +class object +{ + template friend class utility::ref; + template 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 thisRef(); + + /** Return a reference to this object (const version). + * + * @return reference to self + */ + ref thisRef() const; + + /** Return a weak reference to this object. + * + * @return weak reference to self + */ + weak_ref thisWeakRef(); + + /** Return a weak reference to this object (const version). + * + * @return weak reference to self + */ + weak_ref thisWeakRef() const; + +#endif // VMIME_BUILDING_DOC + +private: + + mutable int m_strongCount; + mutable std::vector 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 clone() const; void copyFrom(const component& other); parameter& operator=(const parameter& other); - const std::vector getChildComponents() const; + const std::vector > 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 getValueImp() const = 0; + virtual const ref 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 (*AllocFunc)(void); typedef std::map NameMap; NameMap m_nameMap; @@ -51,10 +51,10 @@ public: { public: - static parameter* creator() + static ref creator() { // Allocate a new object - return new TYPE(); + return vmime::create (); } }; #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 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 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 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 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 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 beforeParam, ref 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 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 afterParam, ref 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 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 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 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 getParameterAt(const int pos) const; /** Return the parameter list. * * @return list of parameters */ - const std::vector getParameterList() const; + const std::vector > getParameterList() const; /** Return the parameter list. * * @return list of parameters */ - const std::vector getParameterList(); + const std::vector > getParameterList(); private: - std::vector m_params; + std::vector > 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 getChildComponents() const; + const std::vector > 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 clone() const; path& operator=(const path& other); - const std::vector getChildComponents() const; + const std::vector > 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 getText() const; + void setText(ref text); private: - contentHandler* m_text; + ref 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 args, const int flags = 0); - utility::outputStream* getStdIn(); - utility::inputStream* getStdOut(); + ref getStdIn(); + ref 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 m_stdIn; + ref 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 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 getOutputStream(); private: @@ -99,7 +99,7 @@ public: posixFileReader(const vmime::utility::file::path& path, const vmime::string& nativePath); - vmime::utility::inputStream* getInputStream(); + ref getInputStream(); private: @@ -117,7 +117,7 @@ public: ~posixFileIterator(); const bool hasMoreElements() const; - vmime::utility::file* nextElement(); + ref nextElement(); private: @@ -153,16 +153,16 @@ public: const bool exists() const; - const vmime::utility::file* getParent() const; + ref getParent() const; void rename(const path& newName); void remove(); - vmime::utility::fileWriter* getFileWriter(); - vmime::utility::fileReader* getFileReader(); + ref getFileWriter(); + ref getFileReader(); - vmime::utility::fileIterator* getFiles() const; + ref 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 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 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 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 getParent() const; void rename(const path& newName); void remove(); - vmime::utility::fileWriter* getFileWriter(); + ref getFileWriter(); - vmime::utility::fileReader* getFileReader(); + ref getFileReader(); - vmime::utility::fileIterator* getFiles() const; + ref 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 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 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 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 const TYPE getProperty(const string& name) const { - const property* const prop = find(name); + const ref prop = find(name); if (!prop) throw exceptions::no_such_property(name); //return (prop->getValue ()); // BUG: with g++ < 3.4 @@ -278,7 +278,7 @@ public: template const TYPE getProperty(const string& name, const TYPE defaultValue) const { - const property* const prop = find(name); + const ref prop = find(name); //return (prop ? prop->getValue () : defaultValue); // BUG: with g++ < 3.4 return (prop ? prop->template getValue () : defaultValue); } @@ -318,13 +318,13 @@ private: void parse(const string& props); - class propFinder : public std::unary_function + class propFinder : public std::unary_function , bool> { public: propFinder(const string& name) : m_name(utility::stringUtils::toLower(name)) { } - const bool operator()(property* const p) const + const bool operator()(ref 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 find(const string& name) const; + ref findOrCreate(const string& name); - typedef std::list list_type; + typedef std::list > list_type; list_type m_props; public: @@ -404,13 +404,13 @@ public: * * @return list of properties */ - const std::vector getPropertyList() const; + const std::vector > getPropertyList() const; /** Return the property list. * * @return list of properties */ - const std::vector getPropertyList(); + const std::vector > 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 clone() const; void copyFrom(const component& other); relay& operator=(const relay& other); - const std::vector getChildComponents() const; + const std::vector > 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 { \ - friend class headerFieldFactory::registerer ; \ + 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 { \ - friend class headerFieldFactory::registerer ; \ + 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 , \ public parameterizedHeaderField { \ - friend class headerFieldFactory::registerer ; \ + 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 { \ - friend class parameterFactory::registerer ; \ + 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 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 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 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 m_ownedStream; // 'contentHandler' objects are copiable... - utility::inputStream* m_stream; + mutable ref 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 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 clone() const; void copyFrom(const component& other); text& operator=(const component& other); text& operator=(const text& other); - const std::vector getChildComponents() const; + const std::vector > getChildComponents() const; /** Add a word at the end of the list. * * @param w word to append */ - void appendWord(word* w); + void appendWord(ref 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 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 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 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 getWordAt(const int pos) const; /** Return the word list. * * @return list of words */ - const std::vector getWordList() const; + const std::vector > getWordList() const; /** Return the word list. * * @return list of words */ - const std::vector getWordList(); + const std::vector > 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 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. + * + *

Eg: giving:

+ *
   <iso-8859-1> "Linux dans un t'el'ephone mobile"
+	  *    ("=?iso-8859-1?Q?Linux_dans_un_t=E9l=E9phone_mobile?=")
+	  * 

it will return:

+ *
   <us-ascii>   "Linux dans un "
+	  *    <iso-8859-1> "t'el'ephone "
+	  *    <us-ascii>   "mobile"
+	  *    ("Linux dans un =?iso-8859-1?Q?t=E9l=E9phone_?= mobile")
+	  * 
+ * + * @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 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 m_words; + std::vector > 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 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 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 NameMap; + typedef ref (*AllocFunc)(void); + typedef std::vector > MapType; - NameMap m_nameMap; + MapType m_map; #ifndef VMIME_BUILDING_DOC template @@ -47,10 +47,10 @@ protected: { public: - static textPart* creator() + static ref creator() { // Allocate a new object - return new TYPE(); + return vmime::create (); } }; #endif // VMIME_BUILDING_DOC @@ -62,10 +62,10 @@ public: template void registerType(const mediaType& type) { - m_nameMap.insert(NameMap::value_type(type.generate(), ®isterer::creator)); + m_map.push_back(MapType::value_type(type, ®isterer::creator)); } - textPart* create(const mediaType& type); + ref 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 @@ -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 clone() const { - return new typeAdapter(*this); + return create (*this); } @@ -112,9 +112,9 @@ public: *newLinePos = curLinePos + oss.str().length(); } - const std::vector getChildComponents() const + const std::vector > getChildComponents() const { - return std::vector (); + return std::vector >(); } 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 #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 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 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 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 nextElement() = 0; }; /** Write to a file. */ -class fileWriter +class fileWriter : public object { public: virtual ~fileWriter() { } - virtual utility::outputStream* getOutputStream() = 0; + virtual ref getOutputStream() = 0; }; /** Read from a file. */ -class fileReader +class fileReader : public object { public: virtual ~fileReader() { } - virtual utility::inputStream* getInputStream() = 0; + virtual ref 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 getParent() const = 0; /** Rename the file/directory. * @@ -181,13 +181,13 @@ public: * * @return file writer object */ - virtual fileWriter* getFileWriter() = 0; + virtual ref getFileWriter() = 0; /** Return an object capable of reading from this file. * * @return file reader object */ - virtual fileReader* getFileReader() = 0; + virtual ref 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 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 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 + + +// Forward reference to 'object' +namespace vmime { class object; } + + namespace vmime { namespace utility { @@ -47,118 +54,491 @@ public: }; -/** Smart auto-delete, referencable and copiable pointer. +/** Null reference. */ -template -class smart_ptr +class null_ref { private: - struct data - { - int refCount; - T* ptr; - }; - - data* m_data; + int foo; +}; - typedef std::map MapType; - static MapType sm_map; +/** Strong reference (smart pointer). + */ +template +class ref +{ public: - 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); } } + template friend class ref; + template friend class weak_ref; - ~smart_ptr() { detach(); } - smart_ptr& operator=(smart_ptr& p) + 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 + ref dynamicCast() const + { + U* p = dynamic_cast (const_cast (m_ptr)); + if (!p) return ref (); + + p->addStrong(); + + ref r; + r.m_ptr = p; + + return r; + } + + // static_cast + template + ref staticCast() const + { + U* p = static_cast (const_cast (m_ptr)); + if (!p) return ref (); + + p->addStrong(); + + ref r; + r.m_ptr = p; + + return r; + } + + // const_cast + template + ref constCast() const + { + U* p = const_cast (m_ptr); + if (!p) return ref (); + + m_ptr->addStrong(); + + ref r; + r.m_ptr = p; + + return r; + } + + // Implicit downcast + template + operator ref () const + { + if (m_ptr) + m_ptr->addStrong(); + + ref r; + r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast) + + return r; + } + + template + operator ref () + { + if (m_ptr) + m_ptr->addStrong(); + + ref r; + r.m_ptr = m_ptr; // will type check at compile-time (prevent from implicit upcast) + + return r; + } + + template + ref & operator=(const ref & 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 + { + if (m_ptr) + m_ptr->addStrong(); + + ref r; + r.m_ptr = m_ptr; + + return r; + } + + // Copy + ref& operator=(const ref& p) { attach(p); - return (*this); + return *this; } - smart_ptr& operator=(T* const p) + // 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 fromPtr(T* const ptr) { - if (!p) - detach(); - else - attach(p); + if (ptr) + ptr->addStrong(); - return (*this); + ref r; + r.m_ptr = ptr; + + return r; } - operator T*() { return (m_data ? m_data->ptr : NULL); } - operator const T*() { return (m_data ? m_data->ptr : NULL); } - - T& operator *() { return (*(m_data->ptr)); } - T* operator ->() { return (m_data->ptr); } - - const T* const ptr() const { return (m_data ? m_data->ptr : NULL); } - T* const ptr() { return (m_data ? m_data->ptr : NULL); } - -private: +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; } } + template + void attach(U* const ptr) + { + if (ptr) + ptr->addStrong(); + + detach(); + + m_ptr = ptr; + } + + template + void attach(const ref & r) + { + if (r.m_ptr) + r.m_ptr->addStrong(); + + detach(); + + m_ptr = r.m_ptr; + } + +private: + + T* m_ptr; +}; + + + +template +bool operator==(const ref & a, const ref & b) +{ + return (a.get() == b.get()); +} + +template +bool operator!=(const ref & a, const ref & b) +{ + return (a.get() != b.get()); +} + +template +bool operator==(const ref & a, T* const p) +{ + return (a.get() == p); +} + +template +bool operator!=(const ref & a, T* const p) +{ + return (a.get() != p); +} + +template +bool operator==(T* const p, const ref & a) +{ + return (a.get() == p); +} + +template +bool operator!=(T* const p, const ref & 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 weak_ref : public weak_ref_base +{ +public: + + template friend class weak_ref; + + + weak_ref() : m_ptr(0) { } + weak_ref(const ref & 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 + weak_ref dynamicCast() const + { + U* p = dynamic_cast (const_cast (m_ptr)); + if (!p) return weak_ref (); + + weak_ref r; + + p->addWeak(&r); + + r.m_ptr = p; + + return r; + } + + // static_cast + template + weak_ref staticCast() const + { + U* p = static_cast (const_cast (m_ptr)); + if (!p) return weak_ref (); + + weak_ref r; + + p->addWeak(&r); + + r.m_ptr = p; + + return r; + } + + // const_cast + template + weak_ref constCast() const + { + U* p = const_cast (m_ptr); + if (!p) return weak_ref (); + + weak_ref r; + + p->addWeak(&r); + + r.m_ptr = p; + + return r; + } + + // Implicit downcast + template + operator weak_ref () + { + weak_ref 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 + operator weak_ref () + { + weak_ref 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 + weak_ref & operator=(const weak_ref & other) + { + U* ptr = other.m_ptr; // will type check at compile-time (prevent from implicit upcast) + + if (ptr) + ptr->addWeak(this); + + detach(); + + m_ptr = ptr; + + return *this; + } + + // Implicit non-const => const conversion + operator weak_ref () const + { + weak_ref r; + + if (m_ptr) + m_ptr->addWeak(&r); + + r.m_ptr = m_ptr; + + return r; + } + + template + operator weak_ref () const + { + weak_ref 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: + + void notifyObjectDestroyed() + { + m_ptr = 0; + } + + void detach() + { + if (m_ptr) + { + m_ptr->releaseWeak(this); + m_ptr = 0; + } + } + + void attach(const ref & r) + { + if (r.m_ptr) + r.m_ptr->addWeak(this); + + detach(); + + m_ptr = r.m_ptr; + } + + void attach(const weak_ref& r) + { + if (r.m_ptr) + r.m_ptr->addWeak(this); + + detach(); + + m_ptr = r.m_ptr; + } + void attach(T* const p) { - detach(); - - typename MapType::iterator it = sm_map.find(p); - - if (it != sm_map.end()) - { - (*it).second->refCount++; - } - 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 smart_ptr & p) - { - data* newData = p.m_data; - if (newData) newData->refCount++; + if (p) + p->addWeak(this); detach(); - m_data = newData; + m_ptr = p; } + + + T* m_ptr; }; -template -typename smart_ptr ::MapType smart_ptr ::sm_map; - - } // utility } // vmime 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 clone() const; using component::parse; @@ -111,14 +113,15 @@ 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 getChildComponents() const; - - 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 const std::vector parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition); + const std::vector > getChildComponents() const; private: + static ref 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 > parseMultiple(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition); + + // The "m_buffer" of this word holds the data, and this data is encoded // in the specified "m_charset". string m_buffer;