diff --git a/src/body.cpp b/src/body.cpp index 8251ab1f..d24d800e 100644 --- a/src/body.cpp +++ b/src/body.cpp @@ -166,11 +166,11 @@ void body::parseImpl { isMultipart = true; - try + if (ctf->hasBoundary()) { boundary = ctf->getBoundary(); } - catch (exceptions::no_such_parameter&) + else { // No "boundary" parameter specified: we can try to // guess it by scanning the body contents... @@ -436,11 +436,11 @@ void body::generateImpl if (ctf) { - try + if (ctf->hasBoundary()) { boundary = ctf->getBoundary(); } - catch (exceptions::no_such_parameter&) + else { // No boundary string specified boundary = generateRandomBoundaryString(); @@ -701,11 +701,11 @@ const charset body::getCharset() const if (ctf) { - try + if (ctf->hasCharset()) { return (ctf->getCharset()); } - catch (exceptions::no_such_parameter&) + else { // Defaults to "us-ascii" (RFC-1521) return (vmime::charset(charsets::US_ASCII)); @@ -885,14 +885,14 @@ void body::initNewPart(shared_ptr part) if (ctf) { - try + if (ctf->hasBoundary()) { const string boundary = ctf->getBoundary(); if (boundary.empty() || !isValidBoundary(boundary)) ctf->setBoundary(generateRandomBoundaryString()); } - catch (exceptions::no_such_parameter&) + else { // No "boundary" parameter: generate a random one. ctf->setBoundary(generateRandomBoundaryString()); diff --git a/src/bodyPartAttachment.cpp b/src/bodyPartAttachment.cpp index 7b9adf01..0684a896 100644 --- a/src/bodyPartAttachment.cpp +++ b/src/bodyPartAttachment.cpp @@ -58,44 +58,21 @@ const word bodyPartAttachment::getName() const // Try the 'filename' parameter of 'Content-Disposition' field shared_ptr cdf = getContentDisposition(); - if (cdf) + if (cdf && cdf->hasFilename()) { - try - { - name = cdf->getFilename(); - } - catch (exceptions::no_such_parameter&) - { - // No 'filename' parameter - } + name = cdf->getFilename(); } - else - { - // No 'Content-Disposition' field - } - // Try the 'name' parameter of 'Content-Type' field - if (name.getBuffer().empty()) + else { shared_ptr ctf = getContentType(); if (ctf) { - try - { - shared_ptr prm = ctf->findParameter("name"); + shared_ptr prm = ctf->findParameter("name"); - if (prm != NULL) - name = prm->getValue(); - } - catch (exceptions::no_such_parameter&) - { - // No attachment name available - } - } - else - { - // No 'Content-Type' field + if (prm != NULL) + name = prm->getValue(); } } diff --git a/src/contentDispositionField.cpp b/src/contentDispositionField.cpp index 887d8928..5a9c1212 100644 --- a/src/contentDispositionField.cpp +++ b/src/contentDispositionField.cpp @@ -40,9 +40,20 @@ contentDispositionField::contentDispositionField(contentDispositionField&) } +bool contentDispositionField::hasCreationDate() const +{ + return findParameter("creation-date"); +} + + const datetime contentDispositionField::getCreationDate() const { - return findParameter("creation-date")->getValueAs (); + shared_ptr param = findParameter("creation-date"); + + if (param) + return param->getValueAs (); + else + return datetime::now(); } @@ -52,9 +63,20 @@ void contentDispositionField::setCreationDate(const datetime& creationDate) } +bool contentDispositionField::hasModificationDate() const +{ + return findParameter("modification-date"); +} + + const datetime contentDispositionField::getModificationDate() const { - return findParameter("modification-date")->getValueAs (); + shared_ptr param = findParameter("modification-date"); + + if (param) + return param->getValueAs (); + else + return datetime::now(); } @@ -64,9 +86,20 @@ void contentDispositionField::setModificationDate(const datetime& modificationDa } +bool contentDispositionField::hasReadDate() const +{ + return findParameter("read-date"); +} + + const datetime contentDispositionField::getReadDate() const { - return findParameter("read-date")->getValueAs (); + shared_ptr param = findParameter("read-date"); + + if (param) + return param->getValueAs (); + else + return datetime::now(); } @@ -76,9 +109,20 @@ void contentDispositionField::setReadDate(const datetime& readDate) } +bool contentDispositionField::hasFilename() const +{ + return findParameter("filename"); +} + + const word contentDispositionField::getFilename() const { - return findParameter("filename")->getValue(); + shared_ptr param = findParameter("filename"); + + if (param) + return param->getValue(); + else + return word(); } @@ -88,9 +132,20 @@ void contentDispositionField::setFilename(const word& filename) } +bool contentDispositionField::hasSize() const +{ + return findParameter("size"); +} + + const string contentDispositionField::getSize() const { - return findParameter("size")->getValue().getBuffer(); + shared_ptr param = findParameter("size"); + + if (param) + return param->getValue().getBuffer(); + else + return ""; } diff --git a/src/contentTypeField.cpp b/src/contentTypeField.cpp index c67654a5..9f38294a 100644 --- a/src/contentTypeField.cpp +++ b/src/contentTypeField.cpp @@ -40,9 +40,20 @@ contentTypeField::contentTypeField(contentTypeField&) } +bool contentTypeField::hasBoundary() const +{ + return findParameter("boundary"); +} + + const string contentTypeField::getBoundary() const { - return findParameter("boundary")->getValue().getBuffer(); + shared_ptr param = findParameter("boundary"); + + if (param) + return param->getValue().getBuffer(); + else + return ""; } @@ -52,9 +63,20 @@ void contentTypeField::setBoundary(const string& boundary) } +bool contentTypeField::hasCharset() const +{ + return findParameter("charset"); +} + + const charset contentTypeField::getCharset() const { - return findParameter("charset")->getValueAs (); + shared_ptr param = findParameter("charset"); + + if (param) + return param->getValueAs (); + else + return charset(); } @@ -64,9 +86,20 @@ void contentTypeField::setCharset(const charset& ch) } +bool contentTypeField::hasReportType() const +{ + return findParameter("report-type"); +} + + const string contentTypeField::getReportType() const { - return findParameter("report-type")->getValue().getBuffer(); + shared_ptr param = findParameter("report-type"); + + if (param) + return param->getValue().getBuffer(); + else + return ""; } diff --git a/src/htmlTextPart.cpp b/src/htmlTextPart.cpp index e97161cb..680d3955 100644 --- a/src/htmlTextPart.cpp +++ b/src/htmlTextPart.cpp @@ -198,21 +198,10 @@ void htmlTextPart::parse(shared_ptr message, shared_ptr ctf = textPart->getHeader()->findField (fields::CONTENT_TYPE); - if (ctf) - { - try - { - m_charset = ctf->getCharset(); - } - catch (exceptions::no_such_parameter) - { - // No "charset" parameter. - } - } + if (ctf && ctf->hasCharset()) + m_charset = ctf->getCharset(); else - { - // No "Content-type" field. - } + m_charset = charset(); // 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. diff --git a/src/parameterizedHeaderField.cpp b/src/parameterizedHeaderField.cpp index b329d1c1..19a0502a 100644 --- a/src/parameterizedHeaderField.cpp +++ b/src/parameterizedHeaderField.cpp @@ -407,14 +407,10 @@ shared_ptr parameterizedHeaderField::findParameter(const string& par // No parameter with this name can be found if (pos == end) - { - throw exceptions::no_such_parameter(paramName); - } + return null; + // Else, return a reference to the existing parameter - else - { - return (*pos); - } + return (*pos); } diff --git a/src/plainTextPart.cpp b/src/plainTextPart.cpp index bdb76c4d..7a1542d7 100644 --- a/src/plainTextPart.cpp +++ b/src/plainTextPart.cpp @@ -78,21 +78,10 @@ void plainTextPart::parse(shared_ptr /* message */, shared_ptr ctf = textPart->getHeader()->findField (fields::CONTENT_TYPE); - if (ctf) - { - try - { - m_charset = ctf->getCharset(); - } - catch (exceptions::no_such_parameter&) - { - // No "charset" parameter. - } - } + if (ctf && ctf->hasCharset()) + m_charset = ctf->getCharset(); else - { - // No "Content-type" field. - } + m_charset = charset(); } diff --git a/vmime/contentDispositionField.hpp b/vmime/contentDispositionField.hpp index 0eb32bc4..aac4c5de 100644 --- a/vmime/contentDispositionField.hpp +++ b/vmime/contentDispositionField.hpp @@ -36,6 +36,9 @@ namespace vmime { +/** Describes presentation information, as per RFC-2183. + */ + class VMIME_EXPORT contentDispositionField : public parameterizedHeaderField { friend class headerFieldFactory; @@ -47,10 +50,15 @@ protected: public: + /** Test whether the "creation-date" parameter is set. + * + * @return true if the "creation-date" parameter is set, or false otherwise + */ + bool hasCreationDate() const; + /** Return the value of the "creation-date" parameter. * * @return value of the "creation-date" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const datetime getCreationDate() const; @@ -60,10 +68,15 @@ public: */ void setCreationDate(const datetime& creationDate); + /** Test whether the "modification-date" parameter is set. + * + * @return true if the "modification-date" parameter is set, or false otherwise + */ + bool hasModificationDate() const; + /** Return the value of the "modification-date" parameter. * * @return value of the "modification-date" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const datetime getModificationDate() const; @@ -73,10 +86,15 @@ public: */ void setModificationDate(const datetime& modificationDate); + /** Test whether the "read-date" parameter is set. + * + * @return true if the "read-date" parameter is set, or false otherwise + */ + bool hasReadDate() const; + /** Return the value of the "read-date" parameter. * * @return value of the "read-date" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const datetime getReadDate() const; @@ -86,10 +104,15 @@ public: */ void setReadDate(const datetime& readDate); + /** Test whether the "filename" parameter is set. + * + * @return true if the "filename" parameter is set, or false otherwise + */ + bool hasFilename() const; + /** Return the value of the "filename" parameter. * * @return value of the "filename" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const word getFilename() const; @@ -99,10 +122,15 @@ public: */ void setFilename(const word& filename); + /** Test whether the "size" parameter is set. + * + * @return true if the "size" parameter is set, or false otherwise + */ + bool hasSize() const; + /** Return the value of the "size" parameter. * * @return value of the "size" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const string getSize() const; diff --git a/vmime/contentTypeField.hpp b/vmime/contentTypeField.hpp index b81d9a68..8604c4a3 100644 --- a/vmime/contentTypeField.hpp +++ b/vmime/contentTypeField.hpp @@ -46,11 +46,16 @@ protected: public: + /** Test whether the "boundary" parameter is set. + * + * @return true if the "boundary" parameter is set, or false otherwise + */ + bool hasBoundary() const; + /** Return the value of the "boundary" parameter. Boundary is a * random string used to separate body parts. * * @return value of the "boundary" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const string getBoundary() const; @@ -63,11 +68,16 @@ public: */ void setBoundary(const string& boundary); + /** Test whether the "charset" parameter is set. + * + * @return true if the "charset" parameter is set, or false otherwise + */ + bool hasCharset() const; + /** Return the value of the "charset" parameter. It specifies the * charset used in the body part contents. * * @return value of the "charset" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const charset getCharset() const; @@ -78,10 +88,15 @@ public: */ void setCharset(const charset& ch); + /** Test whether the "report-type" parameter is set. + * + * @return true if the "report-type" parameter is set, or false otherwise + */ + bool hasReportType() const; + /** Return the value of the "report-type" parameter (RFC-1892). * * @return value of the "report-type" parameter - * @throw exceptions::no_such_parameter if the parameter does not exist */ const string getReportType() const; diff --git a/vmime/parameterizedHeaderField.hpp b/vmime/parameterizedHeaderField.hpp index efe9c81e..78fc3e44 100644 --- a/vmime/parameterizedHeaderField.hpp +++ b/vmime/parameterizedHeaderField.hpp @@ -64,10 +64,11 @@ public: bool hasParameter(const string& paramName) const; /** Find the first parameter that matches the specified name. - * If no parameter is found, an exception is thrown. + * If no parameter is found, NULL is returned. * - * @throw exceptions::no_such_parameter if no parameter with this name exists - * @return first parameter with the specified name + * @param paramName parameter name + * @return first parameter with the specified name, or NULL if + * no parameter with this name exists */ shared_ptr findParameter(const string& paramName) const; @@ -75,6 +76,7 @@ public: * If no parameter is found, one will be created and inserted into * the parameter list. * + * @param paramName parameter name * @return first parameter with the specified name or a new field * if no parameter is found */