aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/body.cpp16
-rw-r--r--src/bodyPartAttachment.cpp37
-rw-r--r--src/contentDispositionField.cpp65
-rw-r--r--src/contentTypeField.cpp39
-rw-r--r--src/htmlTextPart.cpp17
-rw-r--r--src/parameterizedHeaderField.cpp10
-rw-r--r--src/plainTextPart.cpp17
7 files changed, 120 insertions, 81 deletions
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 <bodyPart> 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 <const contentDispositionField> cdf = getContentDisposition();
- if (cdf)
+ if (cdf && cdf->hasFilename())
{
- try
- {
- name = cdf->getFilename();
- }
- catch (exceptions::no_such_parameter&)
- {
- // No 'filename' parameter
- }
- }
- else
- {
- // No 'Content-Disposition' field
+ name = cdf->getFilename();
}
-
// Try the 'name' parameter of 'Content-Type' field
- if (name.getBuffer().empty())
+ else
{
shared_ptr <const contentTypeField> ctf = getContentType();
if (ctf)
{
- try
- {
- shared_ptr <const parameter> prm = ctf->findParameter("name");
-
- if (prm != NULL)
- name = prm->getValue();
- }
- catch (exceptions::no_such_parameter&)
- {
- // No attachment name available
- }
- }
- else
- {
- // No 'Content-Type' field
+ shared_ptr <const parameter> prm = ctf->findParameter("name");
+
+ 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 <datetime>();
+ shared_ptr <parameter> param = findParameter("creation-date");
+
+ if (param)
+ return param->getValueAs <datetime>();
+ 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 <datetime>();
+ shared_ptr <parameter> param = findParameter("modification-date");
+
+ if (param)
+ return param->getValueAs <datetime>();
+ 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 <datetime>();
+ shared_ptr <parameter> param = findParameter("read-date");
+
+ if (param)
+ return param->getValueAs <datetime>();
+ 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 <parameter> 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 <parameter> 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 <parameter> 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 <charset>();
+ shared_ptr <parameter> param = findParameter("charset");
+
+ if (param)
+ return param->getValueAs <charset>();
+ 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 <parameter> 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 <const bodyPart> message, shared_ptr <const
shared_ptr <const contentTypeField> ctf =
textPart->getHeader()->findField <contentTypeField>(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 <parameter> 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 <const bodyPart> /* message */,
shared_ptr <const contentTypeField> ctf =
textPart->getHeader()->findField <contentTypeField>(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();
}