It would be nice to get the name or filename of an embedded html object.
-- src/htmlTextPart.cpp (revision 572) +++ src/htmlTextPart.cpp (working copy) @@ -25,6 +25,7 @@ #include "vmime/exception.hpp" #include "vmime/contentTypeField.hpp" +#include "vmime/contentDispositionField.hpp" #include "vmime/contentDisposition.hpp" #include "vmime/text.hpp" @@ -168,7 +169,7 @@ // but referencing the same content. mediaType type; - + string name = ""; try { const ref <const headerField> ctf = part.getHeader()->ContentType(); @@ -179,9 +180,44 @@ // No "Content-type" field: assume "application/octet-stream". } + try + { + const ref <const contentTypeField> ctf = part.getHeader()->ContentType().dynamicCast<const contentTypeField>(); + ref<parameter> pname = ctf->findParameter("name"); + const word& wname = pname->getValue(); + name = wname.getConvertedText(vmime::charsets::UTF_8); + } + catch (exceptions::no_such_field) + { + // No "Content-type" field: assume "application/octet-stream". + } + catch (exceptions::no_such_parameter) + { + // No "Content-type" field: assume "application/octet-stream". + } + + if (name == "") { + + try + { + const ref <const contentDispositionField> cdf = part.getHeader()->ContentDisposition().dynamicCast<const contentDispositionField>(); + ref<parameter> pfilename = cdf->findParameter("filename"); + const word& wname = pfilename->getValue(); + name = wname.getConvertedText(vmime::charsets::UTF_8); + } + catch (exceptions::no_such_field) + { + // No "Content-type" field: assume "application/octet-stream". + } + catch (exceptions::no_such_parameter) + { + // No "Content-type" field: assume "application/octet-stream". + } + } + m_objects.push_back(vmime::create <embeddedObject> (part.getBody()->getContents()->clone().dynamicCast <contentHandler>(), - part.getBody()->getEncoding(), id, type)); + part.getBody()->getEncoding(), id, type, name)); } @@ -467,9 +503,9 @@
htmlTextPart::embeddedObject::embeddedObject (ref <contentHandler> data, const encoding& enc, - const string& id, const mediaType& type) + const string& id, const mediaType& type, const string& name) : m_data(data->clone().dynamicCast <contentHandler>()), - m_encoding(enc), m_id(id), m_type(type) + m_encoding(enc), m_id(id), m_type(type), m_name(name) { }
@@ -491,6 +527,10 @@ return m_id; }
+const string& htmlTextPart::embeddedObject::getName() const +{ + return m_name; +}
const mediaType& htmlTextPart::embeddedObject::getType() const { Index: vmime/htmlTextPart.hpp =================================================================== -- vmime/htmlTextPart.hpp (revision 572) +++ vmime/htmlTextPart.hpp (working copy) @@ -64,7 +64,8 @@ public:
embeddedObject(ref <contentHandler> data, const encoding& enc, - const string& id, const mediaType& type); + const string& id, const mediaType& type, + const string& name = "");
/** Return data stored in this embedded object. * @@ -92,12 +93,19 @@ */ const mediaType& getType() const;
+ /** Return the name of this embedded object. + * + * @return object name + */ + const string& getName() const;
ref <contentHandler> m_data; encoding m_encoding; string m_id; mediaType m_type; + string m_name; };
Log in to post a comment.
It would be nice to get the name or filename of an embedded html object.
Index: src/htmlTextPart.cpp
-- src/htmlTextPart.cpp (revision 572)
+++ src/htmlTextPart.cpp (working copy)
@@ -25,6 +25,7 @@
#include "vmime/exception.hpp"
#include "vmime/contentTypeField.hpp"
+#include "vmime/contentDispositionField.hpp"
#include "vmime/contentDisposition.hpp"
#include "vmime/text.hpp"
@@ -168,7 +169,7 @@
// but referencing the same content.
mediaType type;
-
+ string name = "";
try
{
const ref <const headerField> ctf = part.getHeader()->ContentType();
@@ -179,9 +180,44 @@
// No "Content-type" field: assume "application/octet-stream".
}
+ try
+ {
+ const ref <const contentTypeField> ctf = part.getHeader()->ContentType().dynamicCast<const contentTypeField>();
+ ref<parameter> pname = ctf->findParameter("name");
+ const word& wname = pname->getValue();
+ name = wname.getConvertedText(vmime::charsets::UTF_8);
+ }
+ catch (exceptions::no_such_field)
+ {
+ // No "Content-type" field: assume "application/octet-stream".
+ }
+ catch (exceptions::no_such_parameter)
+ {
+ // No "Content-type" field: assume "application/octet-stream".
+ }
+
+ if (name == "") {
+
+ try
+ {
+ const ref <const contentDispositionField> cdf = part.getHeader()->ContentDisposition().dynamicCast<const contentDispositionField>();
+ ref<parameter> pfilename = cdf->findParameter("filename");
+ const word& wname = pfilename->getValue();
+ name = wname.getConvertedText(vmime::charsets::UTF_8);
+ }
+ catch (exceptions::no_such_field)
+ {
+ // No "Content-type" field: assume "application/octet-stream".
+ }
+ catch (exceptions::no_such_parameter)
+ {
+ // No "Content-type" field: assume "application/octet-stream".
+ }
+ }
+
m_objects.push_back(vmime::create <embeddedObject>
(part.getBody()->getContents()->clone().dynamicCast <contentHandler>(),
- part.getBody()->getEncoding(), id, type));
+ part.getBody()->getEncoding(), id, type, name));
}
@@ -467,9 +503,9 @@
htmlTextPart::embeddedObject::embeddedObject
(ref <contentHandler> data, const encoding& enc,
- const string& id, const mediaType& type)
+ const string& id, const mediaType& type, const string& name)
: m_data(data->clone().dynamicCast <contentHandler>()),
- m_encoding(enc), m_id(id), m_type(type)
+ m_encoding(enc), m_id(id), m_type(type), m_name(name)
{
}
@@ -491,6 +527,10 @@
return m_id;
}
+const string& htmlTextPart::embeddedObject::getName() const
+{
+ return m_name;
+}
const mediaType& htmlTextPart::embeddedObject::getType() const
{
Index: vmime/htmlTextPart.hpp
===================================================================
-- vmime/htmlTextPart.hpp (revision 572)
+++ vmime/htmlTextPart.hpp (working copy)
@@ -64,7 +64,8 @@
public:
embeddedObject(ref <contentHandler> data, const encoding& enc,
- const string& id, const mediaType& type);
+ const string& id, const mediaType& type,
+ const string& name = "");
/** Return data stored in this embedded object.
*
@@ -92,12 +93,19 @@
*/
const mediaType& getType() const;
+ /** Return the name of this embedded object.
+ *
+ * @return object name
+ */
+ const string& getName() const;
ref <contentHandler> m_data;
encoding m_encoding;
string m_id;
mediaType m_type;
+ string m_name;
};