aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2009-11-04 14:12:06 +0000
committerVincent Richard <[email protected]>2009-11-04 14:12:06 +0000
commitb0fbd0edf051e34db58864179cc13d37f8a56e1f (patch)
tree468c6f84d929e351d729894891e027c9876bd7bc
parentRemoved some unnecessary consts on integral types where overrides conflict. A... (diff)
downloadvmime-b0fbd0edf051e34db58864179cc13d37f8a56e1f.tar.gz
vmime-b0fbd0edf051e34db58864179cc13d37f8a56e1f.zip
Auto-detect filename. Renamed 'filename' argument to 'filepath' for disambiguity. Added constructor for input stream. Use 'word' instead of 'string' for filename.
-rw-r--r--src/fileAttachment.cpp77
-rw-r--r--src/word.cpp6
-rw-r--r--vmime/fileAttachment.hpp23
-rw-r--r--vmime/word.hpp6
4 files changed, 95 insertions, 17 deletions
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index e643491f..da7c4b7d 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -31,48 +31,93 @@
#include "vmime/contentDispositionField.hpp"
+#include "vmime/platform.hpp"
+#include "vmime/utility/file.hpp"
+
namespace vmime
{
-fileAttachment::fileAttachment(const string& filename, const mediaType& type)
+fileAttachment::fileAttachment(const string& filepath, const mediaType& type)
{
m_type = type;
- setData(filename);
+ setData(filepath);
m_encoding = encoding::decide(m_data);
}
-fileAttachment::fileAttachment(const string& filename, const mediaType& type, const text& desc)
+fileAttachment::fileAttachment(const string& filepath, const mediaType& type, const text& desc)
{
m_type = type;
m_desc = desc;
- setData(filename);
+ setData(filepath);
m_encoding = encoding::decide(m_data);
}
-fileAttachment::fileAttachment(const string& filename, const mediaType& type,
+fileAttachment::fileAttachment(const string& filepath, const mediaType& type,
const text& desc, const encoding& enc)
{
m_type = type;
m_desc = desc;
- setData(filename);
+ setData(filepath);
+
+ m_encoding = enc;
+}
+
+
+fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename, const mediaType& type)
+{
+ if (!filename.isEmpty())
+ m_fileInfo.setFilename(filename);
+
+ m_type = type;
+
+ setData(is);
+
+ m_encoding = encoding::decide(m_data);
+}
+
+
+fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename,
+ const mediaType& type, const text& desc)
+{
+ if (!filename.isEmpty())
+ m_fileInfo.setFilename(filename);
+
+ m_type = type;
+ m_desc = desc;
+
+ setData(is);
+
+ m_encoding = encoding::decide(m_data);
+}
+
+
+fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename,
+ const mediaType& type, const text& desc, const encoding& enc)
+{
+ if (!filename.isEmpty())
+ m_fileInfo.setFilename(filename);
+ m_type = type;
+ m_desc = desc;
m_encoding = enc;
+
+ setData(is);
}
-void fileAttachment::setData(const string& filename)
+void fileAttachment::setData(const string& filepath)
{
std::ifstream* file = new std::ifstream();
- file->open(filename.c_str(), std::ios::in | std::ios::binary);
+ file->open(filepath.c_str(), std::ios::in | std::ios::binary);
if (!*file)
{
@@ -82,6 +127,15 @@ void fileAttachment::setData(const string& filename)
ref <utility::inputStream> is = vmime::create <utility::inputStreamPointerAdapter>(file, true);
+ setData(is);
+
+ utility::file::path path = platform::getHandler()->getFileSystemFactory()->stringToPath(filepath);
+ m_fileInfo.setFilename(path.getLastComponent());
+}
+
+
+void fileAttachment::setData(ref <utility::inputStream> is)
+{
m_data = vmime::create <streamContentHandler>(is, 0);
}
@@ -94,7 +148,7 @@ void fileAttachment::generatePart(ref <bodyPart> part) const
dynamicCast <contentDispositionField>();
if (m_fileInfo.hasSize()) cdf->setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
- if (m_fileInfo.hasFilename()) cdf->setFilename(m_fileInfo.getFilename());
+ if (m_fileInfo.hasFilename() && !m_fileInfo.getFilename().isEmpty()) cdf->setFilename(m_fileInfo.getFilename());
if (m_fileInfo.hasCreationDate()) cdf->setCreationDate(m_fileInfo.getCreationDate());
if (m_fileInfo.hasModificationDate()) cdf->setModificationDate(m_fileInfo.getModificationDate());
if (m_fileInfo.hasReadDate()) cdf->setReadDate(m_fileInfo.getReadDate());
@@ -134,8 +188,9 @@ fileAttachment::fileInfo::~fileInfo()
}
bool fileAttachment::fileInfo::hasFilename() const { return (m_filename != NULL); }
-const string& fileAttachment::fileInfo::getFilename() const { return (*m_filename); }
-void fileAttachment::fileInfo::setFilename(const string& name) { if (m_filename) { *m_filename = name; } else { m_filename = new string(name); } }
+const word& fileAttachment::fileInfo::getFilename() const { return (*m_filename); }
+void fileAttachment::fileInfo::setFilename(const string& name) { if (m_filename) { *m_filename = name; } else { m_filename = new word(name); } }
+void fileAttachment::fileInfo::setFilename(const word& name) { if (m_filename) { *m_filename = name; } else { m_filename = new word(name); } }
bool fileAttachment::fileInfo::hasCreationDate() const { return (m_creationDate != NULL); }
const datetime& fileAttachment::fileInfo::getCreationDate() const { return (*m_creationDate); }
diff --git a/src/word.cpp b/src/word.cpp
index 958c33e7..ce5ddfcc 100644
--- a/src/word.cpp
+++ b/src/word.cpp
@@ -699,6 +699,12 @@ string& word::getBuffer()
}
+bool word::isEmpty() const
+{
+ return m_buffer.empty();
+}
+
+
void word::setBuffer(const string& buffer)
{
m_buffer = buffer;
diff --git a/vmime/fileAttachment.hpp b/vmime/fileAttachment.hpp
index 0662c8ec..1516a9da 100644
--- a/vmime/fileAttachment.hpp
+++ b/vmime/fileAttachment.hpp
@@ -41,9 +41,13 @@ class fileAttachment : public defaultAttachment
{
public:
- fileAttachment(const string& filename, const mediaType& type);
- fileAttachment(const string& filename, const mediaType& type, const text& desc);
- fileAttachment(const string& filename, const mediaType& type, const text& desc, const encoding& enc);
+ fileAttachment(const string& filepath, const mediaType& type);
+ fileAttachment(const string& filepath, const mediaType& type, const text& desc);
+ fileAttachment(const string& filepath, const mediaType& type, const text& desc, const encoding& enc);
+
+ fileAttachment(ref <utility::inputStream> is, const word& filename, const mediaType& type);
+ fileAttachment(ref <utility::inputStream> is, const word& filename, const mediaType& type, const text& desc);
+ fileAttachment(ref <utility::inputStream> is, const word& filename, const mediaType& type, const text& desc, const encoding& enc);
/** Stores information about a file attachment.
*/
@@ -65,7 +69,7 @@ public:
*
* @return file name
*/
- const string& getFilename() const;
+ const word& getFilename() const;
/** Set the value of the 'filename' property.
*
@@ -73,6 +77,12 @@ public:
*/
void setFilename(const string& name);
+ /** Set the value of the 'filename' property.
+ *
+ * @param name file name
+ */
+ void setFilename(const word& name);
+
/** Check whether the 'creation-date' property is present.
*
* @return true if the 'creation-date' property is set,
@@ -151,7 +161,7 @@ public:
private:
- string* m_filename;
+ word* m_filename;
unsigned int* m_size;
datetime* m_creationDate;
datetime* m_modifDate;
@@ -163,7 +173,8 @@ public:
private:
- void setData(const string& filename);
+ void setData(const string& filepath);
+ void setData(ref <utility::inputStream> is);
fileInfo m_fileInfo;
diff --git a/vmime/word.hpp b/vmime/word.hpp
index d787073c..78a88e83 100644
--- a/vmime/word.hpp
+++ b/vmime/word.hpp
@@ -60,6 +60,12 @@ public:
*/
string& getBuffer();
+ /** Tests whether this word is empty.
+ *
+ * @return true if the buffer is empty, false otherwise
+ */
+ bool isEmpty() const;
+
/** Set the raw data for this encoded word.
*
* @param buffer raw data buffer