From 96077ce7e6125cdba959925d0a2b7b1f8ee54046 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 22 Nov 2013 13:32:52 +0100 Subject: Do not throw exception for normal code flow (exceptions::no_such_field). --- src/htmlTextPart.cpp | 71 +++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 39 deletions(-) (limited to 'src/htmlTextPart.cpp') diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp index 0aabbdc4..e97161cb 100644 --- a/src/htmlTextPart.cpp +++ b/src/htmlTextPart.cpp @@ -135,27 +135,13 @@ void htmlTextPart::findEmbeddedParts(const bodyPart& part, { shared_ptr p = part.getBody()->getPartAt(i); - // For a part to be an embedded object, it must have a + // For a part to be an embedded object, it must have either a // Content-Id field or a Content-Location field. - try - { - p->getHeader()->findField(fields::CONTENT_ID); + if (p->getHeader()->hasField(fields::CONTENT_ID)) cidParts.push_back(p); - } - catch (exceptions::no_such_field) - { - // No "Content-id" field. - } - try - { - p->getHeader()->findField(fields::CONTENT_LOCATION); + if (p->getHeader()->hasField(fields::CONTENT_LOCATION)) locParts.push_back(p); - } - catch (exceptions::no_such_field) - { - // No "Content-Location" field. - } findEmbeddedParts(*p, cidParts, locParts); } @@ -172,12 +158,14 @@ void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id, mediaType type; - try + shared_ptr ctf = + part.getHeader()->findField(fields::CONTENT_TYPE); + + if (ctf) { - const shared_ptr ctf = part.getHeader()->ContentType(); type = *ctf->getValue (); } - catch (exceptions::no_such_field) + else { // No "Content-type" field: assume "application/octet-stream". } @@ -206,20 +194,24 @@ void htmlTextPart::parse(shared_ptr message, shared_ptr getBody()->getContents()->clone(); - try - { - const shared_ptr ctf = - textPart->getHeader()->findField (fields::CONTENT_TYPE); + // Find charset + shared_ptr ctf = + textPart->getHeader()->findField (fields::CONTENT_TYPE); - m_charset = ctf->getCharset(); - } - catch (exceptions::no_such_field) + if (ctf) { - // No "Content-type" field. + try + { + m_charset = ctf->getCharset(); + } + catch (exceptions::no_such_parameter) + { + // No "charset" parameter. + } } - catch (exceptions::no_such_parameter) + else { - // No "charset" parameter. + // No "Content-type" field. } // Extract embedded objects. The algorithm is quite simple: for each previously @@ -267,11 +259,11 @@ void htmlTextPart::parse(shared_ptr message, shared_ptr ctf = - part.getHeader()->findField(fields::CONTENT_TYPE); + const shared_ptr ctf = + part.getHeader()->findField(fields::CONTENT_TYPE); + if (ctf) + { const mediaType type = *ctf->getValue (); if (type.getType() == mediaTypes::MULTIPART && @@ -299,10 +291,11 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren { const shared_ptr p = part.getBody()->getPartAt(i); - try + const shared_ptr ctf = + p->getHeader()->findField(fields::CONTENT_TYPE); + + if (ctf) { - const shared_ptr ctf = - p->getHeader()->findField(fields::CONTENT_TYPE); const mediaType type = *ctf->getValue (); @@ -313,7 +306,7 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren found = true; } } - catch (exceptions::no_such_field) + else { // No "Content-type" field. } @@ -326,7 +319,7 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren } } } - catch (exceptions::no_such_field) + else { // No "Content-type" field. } -- cgit v1.2.3