diff options
author | Vincent Richard <[email protected]> | 2013-06-25 16:14:39 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2013-06-25 16:14:39 +0000 |
commit | 1c4429138317cbe3350159488aabe04b6b09883b (patch) | |
tree | 076aceacce3a79e80c74d6b8a9f97cbdc011cb9d /src/fileAttachment.cpp | |
parent | Documentation. (diff) | |
download | vmime-1c4429138317cbe3350159488aabe04b6b09883b.tar.gz vmime-1c4429138317cbe3350159488aabe04b6b09883b.zip |
New content handler for file. Automatically set file size with file attachment.
Diffstat (limited to 'src/fileAttachment.cpp')
-rw-r--r-- | src/fileAttachment.cpp | 40 |
1 files changed, 20 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 |