From f9913fa28a27f23fde2d4956c62cbb2fb2bc2ee8 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 21 Nov 2013 22:16:57 +0100 Subject: Boost/C++11 shared pointers. --- src/attachmentHelper.cpp | 71 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'src/attachmentHelper.cpp') diff --git a/src/attachmentHelper.cpp b/src/attachmentHelper.cpp index 16e42bd4..7168fd93 100644 --- a/src/attachmentHelper.cpp +++ b/src/attachmentHelper.cpp @@ -39,15 +39,14 @@ namespace vmime // static bool attachmentHelper::isBodyPartAnAttachment - (ref part, const unsigned int options) + (shared_ptr part, const unsigned int options) { try { - const contentDispositionField& cdf = dynamic_cast - (*part->getHeader()->findField(fields::CONTENT_DISPOSITION)); + const contentDispositionField& cdf = + *part->getHeader()->findField (fields::CONTENT_DISPOSITION); - const contentDisposition disp = *cdf.getValue() - .dynamicCast (); + const contentDisposition disp = *cdf.getValue (); if (disp.getName() != contentDispositionTypes::INLINE) return true; @@ -80,10 +79,10 @@ bool attachmentHelper::isBodyPartAnAttachment try { - const contentTypeField& ctf = dynamic_cast - (*part->getHeader()->findField(fields::CONTENT_TYPE)); + const contentTypeField& ctf = + *part->getHeader()->findField (fields::CONTENT_TYPE); - type = *ctf.getValue().dynamicCast (); + type = *ctf.getValue (); if (ctf.hasParameter("name")) hasContentTypeName = true; @@ -125,20 +124,20 @@ bool attachmentHelper::isBodyPartAnAttachment // static -ref attachmentHelper::getBodyPartAttachment - (ref part, const unsigned int options) +shared_ptr attachmentHelper::getBodyPartAttachment + (shared_ptr part, const unsigned int options) { if (!isBodyPartAnAttachment(part, options)) - return NULL; + return null; mediaType type; try { - const contentTypeField& ctf = dynamic_cast - (*part->getHeader()->findField(fields::CONTENT_TYPE)); + const contentTypeField& ctf = + *part->getHeader()->findField (fields::CONTENT_TYPE); - type = *ctf.getValue().dynamicCast (); + type = *ctf.getValue (); } catch (exceptions::no_such_field&) { @@ -150,30 +149,30 @@ ref attachmentHelper::getBodyPartAttachment if (type.getType() == mediaTypes::MESSAGE && type.getSubType() == mediaTypes::MESSAGE_RFC822) { - return vmime::create (part); + return make_shared (part); } else { - return vmime::create (part); + return make_shared (part); } } // static -const std::vector > +const std::vector > attachmentHelper::findAttachmentsInMessage - (ref msg, const unsigned int options) + (shared_ptr msg, const unsigned int options) { return findAttachmentsInBodyPart(msg, options); } // static -const std::vector > +const std::vector > attachmentHelper::findAttachmentsInBodyPart - (ref part, const unsigned int options) + (shared_ptr part, const unsigned int options) { - std::vector > atts; + std::vector > atts; // Test this part if (isBodyPartAnAttachment(part, options)) @@ -183,11 +182,11 @@ const std::vector > // Find in sub-parts else { - ref bdy = part->getBody(); + shared_ptr bdy = part->getBody(); for (size_t i = 0 ; i < bdy->getPartCount() ; ++i) { - std::vector > partAtts = + std::vector > partAtts = findAttachmentsInBodyPart(bdy->getPartAt(i), options); std::copy(partAtts.begin(), partAtts.end(), std::back_inserter(atts)); @@ -199,7 +198,7 @@ const std::vector > // static -void attachmentHelper::addAttachment(ref msg, ref att) +void attachmentHelper::addAttachment(shared_ptr msg, shared_ptr att) { // We simply search for a "multipart/mixed" part. If no one exists, // create it in the root part. This (very simple) algorithm should @@ -208,7 +207,7 @@ void attachmentHelper::addAttachment(ref msg, ref att) vmime::mediaType mpMixed(vmime::mediaTypes::MULTIPART, vmime::mediaTypes::MULTIPART_MIXED); - ref part = findBodyPart(msg, mpMixed); + shared_ptr part = findBodyPart(msg, mpMixed); if (part == NULL) // create it { @@ -216,7 +215,7 @@ void attachmentHelper::addAttachment(ref msg, ref att) { // Create a new container part for the parts that were in // the root part of the message - ref container = vmime::create (); + shared_ptr container = make_shared (); try { @@ -238,7 +237,7 @@ void attachmentHelper::addAttachment(ref msg, ref att) } // Move parts from the root part to this new part - const std::vector > partList = + const std::vector > partList = msg->getBody()->getPartList(); msg->getBody()->removeAllParts(); @@ -253,7 +252,7 @@ void attachmentHelper::addAttachment(ref msg, ref att) // The message is a simple (RFC-822) message, and do not // contains any MIME part. Move the contents from the // root to a new child part. - ref child = vmime::create (); + shared_ptr child = make_shared (); if (msg->getHeader()->hasField(fields::CONTENT_TYPE)) { @@ -268,7 +267,7 @@ void attachmentHelper::addAttachment(ref msg, ref att) } child->getBody()->setContents(msg->getBody()->getContents()); - msg->getBody()->setContents(vmime::create ()); + msg->getBody()->setContents(make_shared ()); msg->getBody()->appendPart(child); } @@ -288,32 +287,32 @@ void attachmentHelper::addAttachment(ref msg, ref att) // static -ref attachmentHelper::findBodyPart - (ref part, const mediaType& type) +shared_ptr attachmentHelper::findBodyPart + (shared_ptr part, const mediaType& type) { if (part->getBody()->getContentType() == type) return part; // Try in sub-parts - ref bdy = part->getBody(); + shared_ptr bdy = part->getBody(); for (size_t i = 0 ; i < bdy->getPartCount() ; ++i) { - ref found = + shared_ptr found = findBodyPart(bdy->getPartAt(i), type); if (found != NULL) return found; } - return NULL; + return null; } // static -void attachmentHelper::addAttachment(ref msg, ref amsg) +void attachmentHelper::addAttachment(shared_ptr msg, shared_ptr amsg) { - ref att = vmime::create (amsg); + shared_ptr att = make_shared (amsg); addAttachment(msg, att); } -- cgit v1.2.3