From 1c4429138317cbe3350159488aabe04b6b09883b Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Tue, 25 Jun 2013 18:14:39 +0200 Subject: New content handler for file. Automatically set file size with file attachment. --- src/fileAttachment.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/fileAttachment.cpp') 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 is, const word& filename, const mediaType& type) +fileAttachment::fileAttachment(ref 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 is, const word& filename, +fileAttachment::fileAttachment(ref cts, const word& filename, const mediaType& type, const text& desc) { if (!filename.isEmpty()) @@ -101,13 +101,13 @@ fileAttachment::fileAttachment(ref is, const word& filena m_type = type; m_desc = desc; - setData(is); + setData(cts); m_encoding = encoding::decide(m_data); } -fileAttachment::fileAttachment(ref is, const word& filename, +fileAttachment::fileAttachment(ref cts, const word& filename, const mediaType& type, const text& desc, const encoding& enc) { if (!filename.isEmpty()) @@ -117,33 +117,33 @@ fileAttachment::fileAttachment(ref 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 fsf = platform::getHandler()->getFileSystemFactory(); + utility::file::path path = fsf->stringToPath(filepath); - if (!*file) - { - delete file; - throw exceptions::open_file_error(); - } + ref file = fsf->create(path); - ref is = vmime::create (file, true); + if (!file->isFile()) + throw exceptions::open_file_error(); - setData(is); + m_data = vmime::create + (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 is) +void fileAttachment::setData(ref cts) { - m_data = vmime::create (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 -- cgit v1.2.3