From 681297e10b666e13cc463f6fbb16236f36c3266c Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 12 Jul 2005 22:28:02 +0000 Subject: Reference counting and smart pointers. --- src/messageParser.cpp | 69 +++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 38 deletions(-) (limited to 'src/messageParser.cpp') 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]); } -- cgit v1.2.3