aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fileAttachment.cpp40
-rw-r--r--src/fileContentHandler.cpp81
2 files changed, 101 insertions, 20 deletions
diff --git a/src/fileAttachment.cpp b/src/fileAttachment.cpp
index ff6bee8a..4f4a87d3 100644
--- a/src/fileAttachment.cpp
+++ b/src/fileAttachment.cpp
@@ -79,20 +79,20 @@ fileAttachment::fileAttachment(const string& filepath, const mediaType& type,
}
-fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename, const mediaType& type)
+fileAttachment::fileAttachment(ref <contentHandler> cts, const word& filename, const mediaType& type)
{
if (!filename.isEmpty())
m_fileInfo.setFilename(filename);
m_type = type;
- setData(is);
+ setData(cts);
m_encoding = encoding::decide(m_data);
}
-fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename,
+fileAttachment::fileAttachment(ref <contentHandler> cts, const word& filename,
const mediaType& type, const text& desc)
{
if (!filename.isEmpty())
@@ -101,13 +101,13 @@ fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filena
m_type = type;
m_desc = desc;
- setData(is);
+ setData(cts);
m_encoding = encoding::decide(m_data);
}
-fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filename,
+fileAttachment::fileAttachment(ref <contentHandler> cts, const word& filename,
const mediaType& type, const text& desc, const encoding& enc)
{
if (!filename.isEmpty())
@@ -117,33 +117,33 @@ fileAttachment::fileAttachment(ref <utility::inputStream> is, const word& filena
m_desc = desc;
m_encoding = enc;
- setData(is);
+ setData(cts);
}
void fileAttachment::setData(const string& filepath)
{
- std::ifstream* file = new std::ifstream();
- file->open(filepath.c_str(), std::ios::in | std::ios::binary);
+ ref <utility::fileSystemFactory> fsf = platform::getHandler()->getFileSystemFactory();
+ utility::file::path path = fsf->stringToPath(filepath);
- if (!*file)
- {
- delete file;
- throw exceptions::open_file_error();
- }
+ ref <utility::file> file = fsf->create(path);
- ref <utility::inputStream> is = vmime::create <utility::inputStreamPointerAdapter>(file, true);
+ if (!file->isFile())
+ throw exceptions::open_file_error();
- setData(is);
+ m_data = vmime::create <streamContentHandler>
+ (file->getFileReader()->getInputStream(), file->getLength());
- utility::file::path path = platform::getHandler()->getFileSystemFactory()->stringToPath(filepath);
m_fileInfo.setFilename(path.getLastComponent());
+ m_fileInfo.setSize(file->getLength());
}
-void fileAttachment::setData(ref <utility::inputStream> is)
+void fileAttachment::setData(ref <contentHandler> cts)
{
- m_data = vmime::create <streamContentHandler>(is, 0);
+ m_data = cts;
+
+ m_fileInfo.setSize(cts->getLength());
}
@@ -212,8 +212,8 @@ const datetime& fileAttachment::fileInfo::getReadDate() const { return (*m_readD
void fileAttachment::fileInfo::setReadDate(const datetime& date) { if (m_readDate) { *m_readDate = date; } else { m_readDate = new datetime(date); } }
bool fileAttachment::fileInfo::hasSize() const { return (m_size != NULL); }
-unsigned int fileAttachment::fileInfo::getSize() const { return (*m_size); }
-void fileAttachment::fileInfo::setSize(const unsigned int& size) { if (m_size) { *m_size = size; } else { m_size = new unsigned int(size); } }
+utility::stream::size_type fileAttachment::fileInfo::getSize() const { return (*m_size); }
+void fileAttachment::fileInfo::setSize(const utility::stream::size_type size) { if (m_size) { *m_size = size; } else { m_size = new utility::stream::size_type(size); } }
} // vmime
diff --git a/src/fileContentHandler.cpp b/src/fileContentHandler.cpp
new file mode 100644
index 00000000..295bc887
--- /dev/null
+++ b/src/fileContentHandler.cpp
@@ -0,0 +1,81 @@
+//
+// VMime library (http://www.vmime.org)
+// Copyright (C) 2002-2013 Vincent Richard <[email protected]>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation; either version 3 of
+// the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// Linking this library statically or dynamically with other modules is making
+// a combined work based on this library. Thus, the terms and conditions of
+// the GNU General Public License cover the whole combination.
+//
+
+#include "vmime/fileContentHandler.hpp"
+
+
+namespace vmime
+{
+
+
+fileContentHandler::fileContentHandler()
+ : streamContentHandler()
+{
+}
+
+
+fileContentHandler::fileContentHandler
+ (ref <utility::file> file, const vmime::encoding& enc)
+{
+ setData(file, enc);
+}
+
+
+fileContentHandler::~fileContentHandler()
+{
+}
+
+
+fileContentHandler::fileContentHandler(const fileContentHandler& cts)
+ : streamContentHandler()
+{
+ setData(cts.m_file, cts.m_encoding);
+}
+
+
+fileContentHandler& fileContentHandler::operator=(const fileContentHandler& cts)
+{
+ setData(cts.m_file, cts.m_encoding);
+
+ return *this;
+}
+
+
+ref <contentHandler> fileContentHandler::clone() const
+{
+ return vmime::create <fileContentHandler>(*this);
+}
+
+
+void fileContentHandler::setData
+ (ref <utility::file> file, const vmime::encoding& enc)
+{
+ m_file = file;
+ m_encoding = enc;
+
+ streamContentHandler::setData
+ (file->getFileReader()->getInputStream(), file->getLength(), enc);
+}
+
+
+} // vmime